Skip to main content

Module real_git_candidate

Module real_git_candidate 

Source
Expand description

Wrapper self-exclusion for one PATH candidate. What: Decide whether one PATH candidate is real Git, a cli-git wrapper, or unusable. Why: The wrapper shadows git on PATH and must never select itself, a copy of itself, or a script that starts the TypeScript wrapper.

In TS you’d write (pseudocode):

// classifyCandidate('/usr/bin/git', ownExecutable) === 'real-git'

Enums§

CandidateKind
What: The three verdicts for one candidate path. #[derive(...)] generates copying, debug printing and ==. Why: The resolver counts skipped wrappers separately from unusable entries so its failure message can say why nothing was selected.

Constants§

MAX_SCRIPT_INSPECTION_BYTES
What: Largest script inspected for wrapper markers, 64 kibibytes. usize is the platform’s index and length type (siblings u32, u64). Why: Generated command shims are tiny launchers; a fixed bound keeps an arbitrary PATH file from controlling how much the resolver reads. usize matches the buffer lengths it is compared with.

Functions§

classify_candidate
What: Classify one candidate against this wrapper’s own executable. Why: This is the whole self-exclusion decision: the same file (any link or spelling), an identical copy, or a TypeScript-wrapper launcher is a wrapper; any other executable regular file is Git.
has_wrapper_marker
What: Report whether script bytes contain a TypeScript-wrapper marker. Why: This is the version-independent recognition of the other wrapper’s launchers.
identical_content
What: Report whether two files have the same length and the same bytes. Why: A copy of this executable under another name or directory is still this wrapper, although its inode differs. Lengths are compared first, so real Git is never read in full for this check.
is_executable
What: Report whether file metadata says the file can be run. #[cfg(unix)] and #[cfg(not(unix))] each compile one of the two inner blocks. Why: PATH lookup only runs executable files; a non-executable git is skipped. On Unix this checks the mode bits, not the calling user’s access as access(2) would. Other systems have no execute bit: every regular file named by PATHEXT can run. The Markdown policy’s linter lookup applies the same test.
is_native_header
What: Report whether the bytes begin with a native executable signature. Why: Native candidates skip the script-marker search entirely.
same_file
What: Report whether two paths name the same existing file. Why: Self-exclusion must hold through symbolic links, hard links, relative spellings and repeated PATH directories. Either check alone suffices; an inspection failure means “not proven the same”.