Creation of packfiles requires two steps:
git_packbuilder_insert
and git_packbuilder_insert_tree
.
It's important to add the objects in recency order ("in the order
that they are 'reachable' from head").
"ANY order will give you a working pack, ... [but it is] the thing
that gives packs good locality. It keeps the objects close to the
head (whether they are old or new, but they are reachable from the
head) at the head of the pack. So packs actually have absolutely
wonderful IO patterns." - Linus Torvalds
git.git/Documentation/technical/pack-heuristics.txtgit_packbuilder_write
or git_packbuilder_foreach
to
write the resulting packfile.
libgit2 will take care of the delta ordering and generation.
git_packbuilder_set_threads
can be used to adjust the number of
threads used for the process.
See tests/pack/packbuilder.c for an example.Representation of a git packbuilder
Stages that are reported by the packbuilder progress callback
Callback used to iterate over packed objects
Packbuilder progress notification function
Initialize a new packbuilder
Set number of threads to spawn
Insert a single object
Insert a root tree object
Insert a commit object
Insert objects as given by the walk
Recursively insert an object and its referenced objects
Write the contents of the packfile to an in-memory buffer
Write the new pack and corresponding index file to path
Get the packfile's hash
Create the new pack and pass each object to the callback
Get the total number of objects the packbuilder will write out
Get the number of objects the packbuilder has already written out
Set the callbacks for a packbuilder
Free the packbuilder and all associated data