diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2015-11-09 13:01:48 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2015-11-25 15:38:03 -0500 |
commit | 7730fe8e9cda1e160bff1e78dfa2a898799d4365 (patch) | |
tree | 967366997111bf96fef7ee1fd333f6132176d370 /src/annotated_commit.c | |
parent | 3f2bb387a43185991d7e077fa5e6c0bb467f2abc (diff) | |
download | libgit2-7730fe8e9cda1e160bff1e78dfa2a898799d4365.tar.gz |
merge: merge annotated commits instead of regular commits
Diffstat (limited to 'src/annotated_commit.c')
-rw-r--r-- | src/annotated_commit.c | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/annotated_commit.c b/src/annotated_commit.c index 036e601c1..3998a1af1 100644 --- a/src/annotated_commit.c +++ b/src/annotated_commit.c @@ -8,6 +8,7 @@ #include "common.h" #include "annotated_commit.h" #include "refs.h" +#include "cache.h" #include "git2/commit.h" #include "git2/refs.h" @@ -23,14 +24,17 @@ static int annotated_commit_init( const char *remote_url) { git_annotated_commit *annotated_commit; + git_commit *commit = NULL; int error = 0; assert(out && id); *out = NULL; - annotated_commit = git__calloc(1, sizeof(git_annotated_commit)); - GITERR_CHECK_ALLOC(annotated_commit); + if ((error = git_commit_lookup(&commit, repo, id)) < 0 || + (error = git_annotated_commit_from_commit(&annotated_commit, + commit)) < 0) + goto done; if (ref_name) { annotated_commit->ref_name = git__strdup(ref_name); @@ -42,15 +46,10 @@ static int annotated_commit_init( GITERR_CHECK_ALLOC(annotated_commit->remote_url); } - git_oid_fmt(annotated_commit->id_str, id); - annotated_commit->id_str[GIT_OID_HEXSZ] = '\0'; - - if ((error = git_commit_lookup(&annotated_commit->commit, repo, id)) < 0) { - git_annotated_commit_free(annotated_commit); - return error; - } - *out = annotated_commit; + +done: + git_commit_free(commit); return error; } @@ -96,6 +95,29 @@ int git_annotated_commit_from_head( return error; } +int git_annotated_commit_from_commit( + git_annotated_commit **out, + git_commit *commit) +{ + git_annotated_commit *annotated_commit; + + assert(out && commit); + + *out = NULL; + + annotated_commit = git__calloc(1, sizeof(git_annotated_commit)); + GITERR_CHECK_ALLOC(annotated_commit); + + git_cached_obj_incref(commit); + annotated_commit->commit = commit; + + git_oid_fmt(annotated_commit->id_str, git_commit_id(commit)); + annotated_commit->id_str[GIT_OID_HEXSZ] = '\0'; + + *out = annotated_commit; + return 0; +} + int git_annotated_commit_lookup( git_annotated_commit **out, git_repository *repo, |