summaryrefslogtreecommitdiff
path: root/src/pack-objects.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-03-12 01:26:09 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2015-03-17 20:51:14 +0100
commita61fa4c0c70fe2c203bf73d163f9003763520f31 (patch)
tree3d4dd5ab2e50dafb3589437f447146fc96518f08 /src/pack-objects.c
parentd23fb5c943c3f4accd8b5176db1b78d377bfec54 (diff)
downloadlibgit2-a61fa4c0c70fe2c203bf73d163f9003763520f31.tar.gz
packbuilder: introduce git_packbuilder_insert_recur()
This function recursively inserts the given object and any referenced ones. It can be thought of as a more general version of the functions to insert a commit or tree.
Diffstat (limited to 'src/pack-objects.c')
-rw-r--r--src/pack-objects.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/pack-objects.c b/src/pack-objects.c
index 0f43b98e0..932764698 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -1404,6 +1404,42 @@ int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid)
return error;
}
+int git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const char *name)
+{
+ git_object *obj;
+ int error;
+
+ assert(pb && id);
+
+ if ((error = git_object_lookup(&obj, pb->repo, id, GIT_OBJ_ANY)) < 0)
+ return error;
+
+ switch (git_object_type(obj)) {
+ case GIT_OBJ_BLOB:
+ error = git_packbuilder_insert(pb, id, name);
+ break;
+ case GIT_OBJ_TREE:
+ error = git_packbuilder_insert_tree(pb, id);
+ break;
+ case GIT_OBJ_COMMIT:
+ error = git_packbuilder_insert_commit(pb, id);
+ break;
+ case GIT_OBJ_TAG:
+ if ((error = git_packbuilder_insert(pb, id, name)) < 0)
+ goto cleanup;
+ error = git_packbuilder_insert_recur(pb, git_tag_target_id((git_tag *) obj), NULL);
+ break;
+
+ default:
+ giterr_set(GITERR_INVALID, "unknown object type");
+ error = -1;
+ }
+
+cleanup:
+ git_object_free(obj);
+ return error;
+}
+
uint32_t git_packbuilder_object_count(git_packbuilder *pb)
{
return pb->nr_objects;