annotated_commit: peel to commit instead of assuming we have one We want to allow the creation of annotated commits out of annotated tags and for that we have to peel the reference all the way to the commit instead of stopping at the first id it provides.
diff --git a/src/annotated_commit.c b/src/annotated_commit.c
index 3d982cb..d95d440 100644
--- a/src/annotated_commit.c
+++ b/src/annotated_commit.c
@@ -123,19 +123,19 @@ int git_annotated_commit_from_ref(
git_repository *repo,
const git_reference *ref)
{
- git_reference *resolved;
+ git_object *peeled;
int error = 0;
assert(out && repo && ref);
*out = NULL;
- if ((error = git_reference_resolve(&resolved, ref)) < 0)
+ if ((error = git_reference_peel(&peeled, ref, GIT_OBJ_COMMIT)) < 0)
return error;
error = annotated_commit_init_from_id(out,
repo,
- git_reference_target(resolved),
+ git_object_id(peeled),
git_reference_name(ref));
if (!error) {
@@ -143,7 +143,7 @@ int git_annotated_commit_from_ref(
GITERR_CHECK_ALLOC((*out)->ref_name);
}
- git_reference_free(resolved);
+ git_object_free(peeled);
return error;
}