8000 Merge pull request #6875 from roberth/mempack-thin-packfile · libgit2/libgit2@9ddd72f · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9ddd72f

Browse files
authored
Merge pull request #6875 from roberth/mempack-thin-packfile
2 parents d823103 + f9c35fb commit 9ddd72f

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 int 8000 o 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