REPLAYING.md
Replaying: rebuilding branches from patch files🔗
The FORMAT document describes what the files are; this one describes how a tool turns them back into git commits, exactly. Any implementation following these steps reproduces the stored branch SHA-exact.
For each patch name in series order, maintaining a map from reference to replayed SHA
(seeded with BASE -> the STACK's base):
- Parse the patch file. Resolve each
parentsreference through the map; an unknown reference is an error (series order guarantees parents were replayed first). - Read the first parent's tree into a scratch index (no worktree is required, ever).
- If the diff section is non-empty, apply it to that index
(
git apply --cached --binary --whitespace=nowarn; the explicit whitespace flag keeps a target repo's ownapply.whitespacefrom rewriting or refusing recorded bytes). An apply failure is an error: the recorded base is the only supported target. - Write the resulting tree.
- Reassemble the raw commit object:
treeline, oneparentline per resolved parent, then the stored header block verbatim, a blank line, and the message bytes (dropping the final newline if themessage-no-final-newlinedirective was declared). Hash and store it (git hash-object -t commit -w). Record name -> SHA in the map.
The final SHA is the replayed branch tip.
When the STACK records a tip, verification compares against it;
a STACK without one can still be replayed, just not cross-checked.
docs/hacking/REPLAYING.md · 1.5 KiB · 2df663fec9