8000 Add git_mempack_write_thin_pack · libgit2/libgit2@f9c35fb · GitHub
[go: up one dir, main page]

Skip to content

Commit f9c35fb

Browse files
committed
Add git_mempack_write_thin_pack
Unlike existing functions, this produces a _thin_ packfile by making use of the fact that only new objects appear in the mempack Object Database. A thin packfile only contains certain objects, but not its whole closure of references. This makes it suitable for efficiently writing sets of new objects to a local repository, by avoiding many small I/O operations. This relies on write_pack (e.g. git_packbuilder_write_buf) to implement the "recency order" optimization step. Basic measurements comparing against the writing of individual objects show a speedup during when writing large amounts of content on machines with comparatively slow I/O operations, and little to no change on machines with fast I/O operations.
1 parent 782e29c commit f9c35fb

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

include/git2/sys/mempack.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ GIT_BEGIN_DECL
4444
*/
4545
GIT_EXTERN(int) git_mempack_new(git_odb_backend **out);
4646

47+
/**
48+
* Write a thin packfile with the objects in the memory store.
49+
*
50+
* A thin packfile is a packfile that does not contain its transitive closure of
51+
* references. This is useful for efficiently distributing additions to a
52+
* repository over the network, but also finds use in the efficient bulk
53+
* addition of objects to a repository, locally.
54+
*
55+
* This operation performs the (shallow) insert operations into the
56+
* `git_packbuilder`, but does not write the packfile to disk;
57+
* see `git_packbuilder_write_buf`.
58+
*
59+
* It also does not reset the in-memory object database; see `git_mempack_reset`.
60+
*
61+
* @param backend The mempack backend
62+
* @param pb The packbuilder to use to write the packfile
63+
*/
64+
GIT_EXTERN(int) git_mempack_write_thin_pack(git_odb_backend *backend, git_packbuilder *pb);
65+
4766
/**
4867
* Dump all the queued in-memory writes to a packfile.
4968
*

src/libgit2/odb_mempack.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,29 @@ static int git_mempack__dump(
132132
return err;
133133
}
134134

135+
int git_mempack_write_thin_pack(git_odb_backend *backend, git_packbuilder *pb)
136+
{
137+
struct memory_packer_db *db = (struct memory_packer_db *)backend;
138+
const git_oid *oid;
139+
size_t iter = 0;
140+
int err;
141+
142+
while (true) {
143+
err = git_oidmap_iterate(NULL, db->objects, &iter, &oid);
144+
145+
if (err == GIT_ITEROVER)
146+
break;
147+
else if (err != 0)
148+
return err;
149+
150+
err = git_packbuilder_insert(pb, oid, NULL);
151+
if (err != 0)
152+
return err;
153+
}
154+
155+
return 0;
156+
}
157+
135158
int git_mempack_dump(
136159
git_buf *pack,
137160
git_repository *repo,

0 commit comments

Comments
 (0)
0