mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
repo: add head_commit helper
Provide a helper method to provide the HEAD's commit, much like our existing `head_tree` helper.
This commit is contained in:
@@ -3314,6 +3314,25 @@ int git_repository_set_bare(git_repository *repo)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int git_repository_head_commit(git_commit **commit, git_repository *repo)
|
||||
{
|
||||
git_reference *head;
|
||||
git_object *obj;
|
||||
int error;
|
||||
|
||||
if ((error = git_repository_head(&head, repo)) < 0)
|
||||
return error;
|
||||
|
||||
if ((error = git_reference_peel(&obj, head, GIT_OBJECT_COMMIT)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
*commit = (git_commit *)obj;
|
||||
|
||||
cleanup:
|
||||
git_reference_free(head);
|
||||
return error;
|
||||
}
|
||||
|
||||
int git_repository_head_tree(git_tree **tree, git_repository *repo)
|
||||
{
|
||||
git_reference *head;
|
||||
|
||||
@@ -173,6 +173,7 @@ GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo)
|
||||
return repo->attrcache;
|
||||
}
|
||||
|
||||
int git_repository_head_commit(git_commit **commit, git_repository *repo);
|
||||
int git_repository_head_tree(git_tree **tree, git_repository *repo);
|
||||
int git_repository_create_head(const char *git_dir, const char *ref_name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user