From f0e37a8b863c2e6caba2b15e4d723bddfe74b46c Mon Sep 17 00:00:00 2001 From: Xavier L Date: Tue, 23 Apr 2013 12:22:29 -0400 Subject: [PATCH 1/2] Added function to insert commit into pack --- include/git2/pack.h | 12 ++++++++++++ src/pack-objects.c | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/git2/pack.h b/include/git2/pack.h index 2f033bef6..118b8d554 100644 --- a/include/git2/pack.h +++ b/include/git2/pack.h @@ -94,6 +94,18 @@ GIT_EXTERN(int) git_packbuilder_insert(git_packbuilder *pb, const git_oid *id, c */ GIT_EXTERN(int) git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *id); +/** + * Insert a commit object + * + * This will add a commit as well as the completed referenced tree. + * + * @param pb The packbuilder + * @param id The oid of the commit + * + * @return 0 or an error code + */ +GIT_EXTERN(int) git_packbuilder_insert_commit(git_packbuilder *pb, const git_oid *id); + /** * Write the new pack and the corresponding index to path * diff --git a/src/pack-objects.c b/src/pack-objects.c index 459201f58..56240125b 100644 --- a/src/pack-objects.c +++ b/src/pack-objects.c @@ -1284,6 +1284,21 @@ static int cb_tree_walk(const char *root, const git_tree_entry *entry, void *pay git_buf_cstr(&ctx->buf)); } +int git_packbuilder_insert_commit(git_packbuilder *pb, const git_oid *oid) +{ +git_commit *commit; + +if (git_commit_lookup(&commit, pb->repo, oid) < 0 || +git_packbuilder_insert(pb, oid, NULL) < 0) +return -1; + +if (git_packbuilder_insert_tree(pb, git_commit_tree_id(commit)) < 0) +return -1; + +git_commit_free(commit); +return 0; +} + int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid) { git_tree *tree; From 0b90366c3bf5c7149cf69b5fa1a8327032f8a60f Mon Sep 17 00:00:00 2001 From: Xavier L Date: Tue, 23 Apr 2013 12:27:38 -0400 Subject: [PATCH 2/2] Fixes indentation --- src/pack-objects.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pack-objects.c b/src/pack-objects.c index 56240125b..1329a9bc1 100644 --- a/src/pack-objects.c +++ b/src/pack-objects.c @@ -1286,17 +1286,17 @@ static int cb_tree_walk(const char *root, const git_tree_entry *entry, void *pay int git_packbuilder_insert_commit(git_packbuilder *pb, const git_oid *oid) { -git_commit *commit; + git_commit *commit; -if (git_commit_lookup(&commit, pb->repo, oid) < 0 || -git_packbuilder_insert(pb, oid, NULL) < 0) -return -1; + if (git_commit_lookup(&commit, pb->repo, oid) < 0 || + git_packbuilder_insert(pb, oid, NULL) < 0) + return -1; -if (git_packbuilder_insert_tree(pb, git_commit_tree_id(commit)) < 0) -return -1; + if (git_packbuilder_insert_tree(pb, git_commit_tree_id(commit)) < 0) + return -1; -git_commit_free(commit); -return 0; + git_commit_free(commit); + return 0; } int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid)