10000 repo: add `head_commit` helper · russell/libgit2@048421a · GitHub
[go: up one dir, main page]

Skip to content

Commit 048421a

Browse files
committed
repo: add head_commit helper
Provide a helper method to provide the HEAD's commit, much like our existing `head_tree` helper.
1 parent 25e2b9d commit 048421a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/libgit2/repository.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,6 +3314,25 @@ int git_repository_set_bare(git_repository *repo)
33143314
return 0;
33153315
}
33163316

3317+
int git_repository_head_commit(git_commit **commit, git_repository *repo)
3318+
{
3319+
git_reference *head;
3320+
git_object *obj;
3321+
int error;
3322+
3323+
if ((error = git_repository_head(&head, repo)) < 0)
3324+
return error;
3325+
3326+
if ((error = git_reference_peel(&obj, head, GIT_OBJECT_COMMIT)) < 0)
3327+
goto cleanup;
3328+
3329+
*commit = (git_commit *)obj;
3330+
3331+
cleanup:
3332+
git_reference_free(head);
3333+
return error;
3334+
}
3335+
33173336
int git_repository_head_tree(git_tree **tree, git_repository *repo)
33183337
{
33193338
git_reference *head;

src/libgit2/repository.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo)
173173
return repo->attrcache;
174174
}
175175

176+
int git_repository_head_commit(git_commit **commit, git_repository *repo);
176177
int git_repository_head_tree(git_tree **tree, git_repository *repo);
177178
int git_repository_create_head(const char *git_dir, const char *ref_name);
178179

0 commit comments

Comments
 (0)
0