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()— wrapsgit_mempack_newOdb.prototype.addMempackBackend(backend, priority)— wrapsgit_odb_add_backendIndex.create()— wrapsgit_index_new(free-standing in-memory index)Mempack.prototype.reset()— wrapsgit_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.