Skip to main content

Module commit_index

Module commit_index 

Source
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§

IndexSelection
What: The choices that shape one private index. Why: The incumbent’s initializeCommitIndex takes 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 copyFile reports 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 HEAD since 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 --patch or git add --interactive against 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.