◐ Shell
clean mode source ↗

Add mempack ODB backend, Index.create, and Odb.addMempackBackend by jkoppel · Pull Request #2040 · nodegit/nodegit

Exposes libgit2's mempack API so you can compute tree hashes in-memory without touching .git/objects/.

Partially addresses #1296 (adds the built-in mempack backend, but not arbitrary custom backends).

What's new

  • Mempack.create() — wraps git_mempack_new
  • Odb.prototype.addMempackBackend(backend, priority) — wraps git_odb_add_backend
  • Index.create() — wraps git_index_new (free-standing in-memory index)
  • Mempack.prototype.reset() — wraps git_mempack_reset

Usage

const repo = await NodeGit.Repository.open("/path/to/repo");
const odb = await repo.odb();

const mempack = await NodeGit.Mempack.create();
await odb.addMempackBackend(mempack, 999);

const index = await NodeGit.Index.create();
// ... add entries, then:
const treeOid = await index.writeTreeTo(repo); // writes to RAM, not disk

await mempack.reset();

Implementation notes

git_index_new was already known to the generator but ignored — just had to un-ignore it. The mempack/odb_backend stuff needed manual C++ bindings since git_odb_backend* isn't a type the generator handles. Added via cFile entries in libgit2-supplement.json, same pattern as the existing manual bindings for clone, revwalk, etc.

The vendored libgit2 already compiles odb_mempack.c so no build changes were needed beyond what the generator produces.