annotated_commit: make the refname accessible As git_annotated_commit seems to behave like cgit's refish, it's quite helpful to abstract away "targets" via git_annotated_commit_from_id/from_ref. As the former is accessible via git_annotated_commit_id, make the latter also available to users.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
diff --git a/include/git2/annotated_commit.h b/include/git2/annotated_commit.h
index 7fb896a..fa795bf 100644
--- a/include/git2/annotated_commit.h
+++ b/include/git2/annotated_commit.h
@@ -104,6 +104,15 @@ GIT_EXTERN(const git_oid *) git_annotated_commit_id(
const git_annotated_commit *commit);
/**
+ * Get the refname that the given `git_annotated_commit` refers to.
+ *
+ * @param commit the given annotated commit
+ * @return ref name.
+ */
+GIT_EXTERN(const char *) git_annotated_commit_ref(
+ const git_annotated_commit *commit);
+
+/**
* Frees a `git_annotated_commit`.
*
* @param commit annotated commit to free
diff --git a/src/annotated_commit.c b/src/annotated_commit.c
index 72ba80a..1aa67dd 100644
--- a/src/annotated_commit.c
+++ b/src/annotated_commit.c
@@ -196,6 +196,13 @@ const git_oid *git_annotated_commit_id(
return git_commit_id(annotated_commit->commit);
}
+const char *git_annotated_commit_ref(
+ const git_annotated_commit *annotated_commit)
+{
+ assert(annotated_commit);
+ return annotated_commit->ref_name;
+}
+
void git_annotated_commit_free(git_annotated_commit *annotated_commit)
{
if (annotated_commit == NULL)