Skip to main content

Module git_reconstruct

Module git_reconstruct 

Source
Expand description

Byte-exact git commit object serialization from a Heddle State (#566).

Reconstructs the exact bytes git cat-file commit <sha> prints from the de-lossy fidelity fields #565 captured, so that re-framing (§0) and SHA-1-hashing the result reproduces the original commit’s object id. This is the consumer that makes #565’s fields load-bearing and the step that lets the git mirror be eliminated (#568): a commit can be rebuilt from Heddle state alone — no stored git object.

The wire format is specced byte-for-byte in .heddleco-orchestrator/briefs/spike-566-serializer-format.md; the §N references below point into it. Tag-object reconstruction (reconstruct_tag_bytes) is deferred to #575, where annotated tags become first-class content-addressed objects; lightweight tags need no object (just a ref at the commit).

Functions§

commit_object_id
The git object id (SHA-1) of a commit whose reconstructed content bytes are content: frame per §0, then hash. Equals the original commit SHA exactly when content is byte-identical to the original object.
frame_git_object
Frame an object’s content for hashing per spike §0: <kind> <ascii-decimal-len>\0<content>. A git object’s id is the SHA-1 of THIS buffer — never of the bare content (git cat-file strips the framing). <len> is the byte length of content (after all folding/newlines), with no leading zeros.
reconstruct_commit_bytes
Reconstruct the byte-exact git commit object content (the bytes git cat-file commit prints, WITHOUT the §0 framing) for state.
write_commit_object
Frame + write a reconstructed commit object’s content bytes into repo’s object database, returning its git OID — the SHA-1 of the framed object (§0), equal to the original commit’s id exactly when content is byte-identical to the original.