Expand description
The private commit index: copies, selection modes, pathspec files and listings.
What:
The private commit index of one transaction:
its timestamp-preserving copies of the real index,
its initialization for each selection mode,
the intended tree written from it,
its path listings,
the pathspec-file source, and
interactive and patch selection run against it.
Why:
Git’s staging and selection run against a private index and the shadow object store,
so the real index and object store change only at landing.
A copy keeps the real index’s timestamps, because Git re-reads a stat entry
whose time is not older than the index file (index-file-timestamps.ts, issue #544).
In TS you’d write (pseudocode):
await initializeCommitIndex({ workspace, gitPath, cwd, mode, pathspecs, baseRevision, ... });Structs§
- Index
Selection - What:
The choices that shape one private index.
Why:
The incumbent’s
initializeCommitIndextakes these as one object, and the selection modes differ only in these values.
Constants§
- PATHSPEC_
INPUT_ NAME - Name of the single-consumption stdin snapshot inside the transaction directory.
Functions§
- copy_
index_ with_ timestamps - What:
Copies an index and gives the copy the source’s access and modification times.
Why:
A copy with fresh times would make Git trust stat data captured in the same second
as a later same-size edit (issue #544).
A missing source is an error, as the incumbent’s
copyFilereports it. - initialize_
commit_ index - What:
Copies or builds the private commit index and snapshots the real index at invocation.
Why:
Index commits start from the real index, so their staged state is the state at invocation;
explicit-path commits start from the recorded base, never live
HEAD, because another landing may have moved it since invocation. - list_
changed_ index_ paths - What:
Lists the paths the private index changes against the recorded base.
Why:
The base is the recorded one, so a landing that moved
HEADsince invocation changes nothing here. - list_
unmerged_ index_ paths - What: Lists the repository paths with unmerged stages, once each, in first-seen order. Why: A conflicted path cannot be committed by automatic fixes, so preparation refuses it.
- materialize_
pathspec_ file - What: Resolves a pathspec-file source to the file the private index reads. Why: A regular source is read where it is named, relative to the invocation directory, and standard input is copied once into the transaction, so no second read sees different bytes.
- prepare_
interactive_ selection - What:
Runs
git add --patchorgit add --interactiveagainst the private index with inherited stdio. Why: The user’s terminal answers the selection, and the choice lands only in the private copy. - write_
private_ tree - What: Writes the intended tree from the private index into the shadow object store. Why: The tree is the exact content the commit will carry.