Expand description
Pure parsing of git ls-files --stage records and the delta between two index states.
What:
Parse the NUL-delimited stage records of git ls-files --stage -z,
find the paths
one staging operation changed,
and turn them into candidate records.
Why:
git add is checked before Git runs it,
by replaying it on a private copy of the
index.
The paths it would stage are exactly those whose index records differ
between the copy before and after the replay.
Comparing complete records,
conflict
stages included,
finds a resolved conflict like any other change,
and an unrelated
conflict elsewhere in the index never stops the comparison.
Pathnames stay the raw
bytes Git printed.
Git 2.56.0 (builtin/ls-files.c,
show_ce) prints,
with --stage -z:
<mode> SP <object> SP <stage> TAB <path> NUL.
In TS you’d write (pseudocode):
// const before = parseStageRecords(stdoutBefore); const after = parseStageRecords(stdoutAfter);
// const paths = stagedDelta(before, after);Structs§
- Changed
Path - What:
One path a staging operation changed,
with what the index holds there afterwards.
Vec<StageRecord>is empty when the operation removed the path from the index. Why: A candidate is built from the state after the operation; a removed path becomes a deletion only when the baseline commit has it. - Stage
Record - What:
One index entry.
u8is an unsigned byte; a stage is 0 for a merged entry and 1 to 3 for the sides of a conflict.#[derive(...)]generates cloning, debug printing and==. Why: Two states are compared record by record, so a record holds every field Git printed for the entry.
Functions§
- delta_
candidates - What:
Turn changed paths into candidate records,
given the records
git diff-indexprinted for those paths against the baseline commit. Why: A path the index still holds is a candidate with its merged entry: an addition when the baseline lacks it, otherwise a modification, even when its content now equals the baseline’s. A removed path is a deletion only when the baseline has it; a path that was never committed carries nothing to check and is dropped. A path left unmerged has no single staged content and stops the prediction. - parse_
stage_ records - What:
Parse a complete
git ls-files --stage -zlisting.Result<Vec<StageRecord>, CandidateError>is “every record, or the first failure”. Why: A listing that does not end with NUL was cut short; a partial list would hide entries from the comparison, so the whole listing is refused. - scope_
candidates - What:
Turn every entry of a scope into a candidate record,
given the records
git diff-indexprinted for the same scope against the baseline commit. Why: A direct check reads every selected file, changed or not, so every merged entry is a candidate: an addition when the baseline lacks it, otherwise a modification. A conflicted entry has no single content and stops the projection. - staged_
delta - What: The paths whose records differ between two index states, in the order the installed wrapper reports them: paths the first state held, in its order, then paths only the second state holds, in its order. Why: A path is changed when its complete record list differs, stage by stage, so a resolved conflict counts and an untouched conflict does not.