Reading and writing git repositories in Zig, without running git.
zig-git docs adr 0001-implement-git-in-zig.md
1.4 kB · 32 lines
Markdown
at main

Implement git in Zig, revision walking and diff included #

zig-git reads repositories itself — objects, packs, refs, config, the index — and also owns what makes git log and git show worth running: revision walking with git's ranges, path limiting, parent rewriting, orderings, mailmap and replace refs, and diffs. It exists so that grebe can stop running git, which grebe's own ADR 0001 declined to do because "rev-list semantics and a diff would all be ours to write". That is now the point: a library offering only objects and refs would leave both to every consumer, and grebe is the first of them.

It is layered — core, then revision, then diff, then write and transport — so a consumer that only needs objects compiles none of the rest. It is pure Zig, with no libgit2 and no C zlib.

Considered options #

  • libgit2. A C dependency whose rev-list differs from git's in the corners grebe cares about: path limiting, ordering, mailmap.
  • Objects and refs only. Small, but it moves the hard part into each consumer rather than removing it.

Consequences #

  • Correctness means agreeing with git. Tests build fixtures with the git the flake pins and compare answers with it, so moving that pin can change what the tests expect.