Skip to main content

Module shadow_refs

Module shadow_refs 

Source
Expand description

The shadow ref store: snapshot, private target, symbolic refs and HEAD. What: The shadow ref store: a snapshot of every real ref, the private target ref, symbolic refs, and the private HEAD. Why: Hooks resolve tags, other branches and remote-tracking refs as they stood at invocation. With the files backend the snapshot is one packed-refs file and the private target is a loose ref, which takes precedence over a packed entry; with reftable the snapshot is one update-ref --stdin transaction (src/shadow-repository/shadow-refs.ts).

In TS you’d write (pseudocode):

await writeShadowRefs({ gitPath, cwd, shadowPath, capture });

Structs§

RefSnapshotEntry
What: One real ref at invocation. Why: Symbolic refs and direct refs take different snapshot forms.

Constants§

PACKED_REFS_HEADER
Header Git writes for a sorted packed-refs file without peeled lines. The trailing space matches Git’s own writer, which older readers require.

Functions§

format_packed_refs
What: Formats the files-backend snapshot of every direct ref except the private target. Why: The target is written loose, so a packed copy would only be shadowed.
list_real_refs
What: Lists every real ref of the owning worktree in byte order. Why: Sorting by bytes matches the incumbent’s Buffer.compare order in the packed file.
write_shadow_refs
What: Writes the shadow ref store: the snapshot, the symbolic refs, the private target ref and HEAD. Why: The order matches the incumbent’s: symbolic refs come after their targets exist, and HEAD comes last.