88#include "common.h"
99#include "annotated_commit.h"
1010#include "refs.h"
11+ #include "cache.h"
1112
1213#include "git2/commit.h"
1314#include "git2/refs.h"
@@ -23,14 +24,17 @@ static int annotated_commit_init(
2324 const char * remote_url )
2425{
2526 git_annotated_commit * annotated_commit ;
27+ git_commit * commit = NULL ;
2628 int error = 0 ;
2729
2830 assert (out && id );
2931
3032 * out = NULL ;
3133
32- annotated_commit = git__calloc (1 , sizeof (git_annotated_commit ));
33- GITERR_CHECK_ALLOC (annotated_commit );
34+ if ((error = git_commit_lookup (& commit , repo , id )) < 0 ||
35+ (error = git_annotated_commit_from_commit (& annotated_commit ,
36+ commit )) < 0 )
37+ goto done ;
3438
3539 if (ref_name ) {
3640 annotated_commit -> ref_name = git__strdup (ref_name );
@@ -42,15 +46,10 @@ static int annotated_commit_init(
4246 GITERR_CHECK_ALLOC (annotated_commit -> remote_url );
4347 }
4448
45- git_oid_fmt (annotated_commit -> id_str , id );
46- annotated_commit -> id_str [GIT_OID_HEXSZ ] = '\0' ;
47-
48- if ((error = git_commit_lookup (& annotated_commit -> commit , repo , id )) < 0 ) {
49- git_annotated_commit_free (annotated_commit );
50- return error ;
51- }
52-
5349 * out = annotated_commit ;
50+
51+ done :
52+ git_commit_free (commit );
5453 return error ;
5554}
5655
@@ -96,6 +95,29 @@ int git_annotated_commit_from_head(
9695 return error ;
9796}
9897
98+ int git_annotated_commit_from_commit (
99+ git_annotated_commit * * out ,
100+ git_commit * commit )
101+ {
102+ git_annotated_commit * annotated_commit ;
103+
104+ assert (out && commit );
105+
106+ * out = NULL ;
107+
108+ annotated_commit = git__calloc (1 , sizeof (git_annotated_commit ));
109+ GITERR_CHECK_ALLOC (annotated_commit );
110+
111+ git_cached_obj_incref (commit );
112+ annotated_commit -> commit = commit ;
113+
114+ git_oid_fmt (annotated_commit -> id_str , git_commit_id (commit ));
115+ annotated_commit -> id_str [GIT_OID_HEXSZ ] = '\0' ;
116+
117+ * out = annotated_commit ;
118+ return 0 ;
119+ }
120+
99121int git_annotated_commit_lookup (
100122 git_annotated_commit * * out ,
101123 git_repository * repo ,
0 commit comments