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,
a toolchain launcher that replaces itself with the wrapper,
or a script that starts the TypeScript wrapper.
In TS you’d write (pseudocode):
// classifyCandidate('/usr/bin/git', ownExecutable) === 'real-git'Enums§
- Candidate
Kind - 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§
- LAUNCH_
RECORD_ SUFFIX - What:
The suffix of the record a toolchain launcher keeps beside it,
<launcher>.launch.&stris a borrowed text baked into the program. Why: The repository’smpm-shadowwrites the record when it installs a launcher (package/mpm-shadow/cli/src/toolchain/launcher.rs,RECORD_SUFFIX); the wrapper reads the same file to learn what a launcher on PATH leads to. - MAX_
SCRIPT_ INSPECTION_ BYTES - What:
Largest script inspected for wrapper markers,
64 kibibytes.
usizeis the platform’s index and length type (siblingsu32,u64). Why: Generated command shims are tiny launchers; a fixed bound keeps an arbitrary PATH file from controlling how much the resolver reads.usizematches 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),
a toolchain launcher of this wrapper,
an identical copy,
or a TypeScript-wrapper launcher is a wrapper;
any other executable regular file is Git.
Another release of the wrapper behind no record and no marker string cannot be told here; the marker every
real-Git start carries (
started_as_git.rs) stops it when it arrives. - 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-executablegitis skipped. On Unix this checks the mode bits, not the calling user’s access asaccess(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.
- is_
wrapper_ launcher - What:
Report whether the candidate is a toolchain launcher of this wrapper: a file with a launch record beside it that
names this wrapper.
The record is looked for beside the candidate’s own name and beside the file its links finally lead to.
Why:
A launcher replaces itself with the wrapper’s executable, which is another file with other bytes, so the file
checks of the identity test miss it; the record beside it says what it leads to. A symlink named
gitthat points at a launcher has no record of its own, so the file it leads to is checked as well. - record_
names_ this_ wrapper - What:
Report whether a launch record’s text names this wrapper: its tool is this crate, or the file it replaces itself
with is this executable.
Option<&Path>is “this executable’s path, or nothing when the caller has none”.serde_json::Valueis a parsed JSON document (siblings: a typed struct, which would need a derive macro). Why: The launcher of another release of the wrapper has a record naming a different file, so the file the record names cannot decide alone; the tool id is the same for every release. Both are read from the record; neither starts anything. - 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”.