This document provides a low-level, step-by-step trace through memory, disk I/O, and data structures during three fundamental version control operations in Anvil:
anvil commit (Snapshot creation)anvil merge (Three-way reconciliation)anvil push (Network packfile streaming)anvil commitWhen the user runs anvil commit -m "feat: parse tokens", the following sequence of operations occurs:
[ Working Copy ] ---- modified files ----> [ Staging Index (DIRC) ]
|
write-tree traversal
v
[ Object Database ] <--- write blobs & trees --- [ In-Memory Tree Hierarchy ]
|
+-- create commit object (pointing to root tree + parent commits)
|
+-- atomic write loose commit (.anvil/objects/xx/yyyy...)
|
[ Reference Manager ] <--- update symref/ref (refs/heads/main)
|
[ Reference Log ] <--- append history entry (.anvil/logs/refs/heads/main)
write-tree).anvil/index and loads all sorted TIndexEntry records into memory.src/crypto/anvil_sha1.pas), it groups entries and recursively instantiates TTreeObject instances.[octal_mode] [space] [filename] [\0] [binary_hash].tree <size>\0<payload>.040000) into the parent tree.TCommitObject.TreeId to the newly minted root tree hash.HEAD reference (e.g. refs/heads/main). If HEAD points to an existing commit, adds that hash to ParentIds.commit <size>\0
tree <root_tree_id>
parent <parent_id>
author Aneesh Krishna <aneesh@example.com> 1700000000 -0500
committer Aneesh Krishna <aneesh@example.com> 1700000000 -0500
feat: parse tokens
.anvil/objects/xx/yyyy... using atomic file renaming..anvil/refs/heads/main to contain the new commit hash followed by a newline..anvil/logs/refs/heads/main and appends a single reflog entry:
[old_hash] [new_hash] Aneesh Krishna <aneesh@example.com> 1700000000 -0500\tcommit: feat: parse tokens\n.anvil mergeWhen the user runs anvil merge feature-branch from main:
(O) Merge Base (LCA)
/ \
/ \
(A) HEAD (B) Feature Branch
\ /
\ /
(M) Merge Commit
HEAD) and incoming commit $B$ (refs/heads/feature-branch).TLcaFinder.refs/heads/main directly to $B$ and checks out $B$’s tree.If histories have genuinely diverged:
TTreeMerger loads root trees for $O$, $A$, and $B$.For modified files:
ThreeWayMergeStrings(AncestorText, OurText, TheirText)..anvil/index.anvil pushWhen pushing to a remote Git server:
[ Client ] [ Remote Server ]
| |
| --- pkt-line: git-receive-pack /repo.git --------------------> |
| <--- pkt-line: ref advertisement & capabilities -------------- |
| |
| --- pkt-line: old_hash new_hash refs/heads/main -------------> |
| --- pkt-line: flush-pkt (0000) ------------------------------> |
| |
| [ Delta Compactor: Pack required commits, trees, blobs ] |
| |
| === Sideband channel 1: Contiguous .pack byte stream ========> |
| <=== Sideband channel 2: Human progress updates ============== |
| |
| <--- pkt-line: unpack ok / ok refs/heads/main ---------------- |
report-status, sideband-64k, ofs-delta).[4-hex-len][0x01][pack_chunk]) and piped to the remote server.