feat(reference): add ability to peel reference until object of specified type is found

This commit is contained in:
Aleksey Kulikov 2021-09-04 14:50:34 +03:00
parent 56713da648
commit f63808b4f8
4 changed files with 91 additions and 0 deletions

View file

@ -395,6 +395,25 @@ bool compare(Pointer<git_reference> ref1, Pointer<git_reference> ref2) {
return result == 0 ? true : false;
}
/// Recursively peel reference until object of the specified type is found.
///
/// The retrieved peeled object is owned by the repository and should be closed to release memory.
///
/// If you pass GIT_OBJECT_ANY as the target type, then the object will be peeled until a
/// non-tag object is met.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_object> peel(Pointer<git_reference> ref, int type) {
final out = calloc<Pointer<git_object>>();
final error = libgit2.git_reference_peel(out, ref, type);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
}
/// Ensure the reference name is well-formed.
///
/// Valid reference names must follow one of two patterns: