feat(revparse): add bindings and api

This commit is contained in:
Aleksey Kulikov 2021-09-01 16:53:40 +03:00
parent 3b13646b1b
commit ce9384cac9
8 changed files with 372 additions and 57 deletions

View file

@ -510,33 +510,5 @@ Pointer<git_repository> wrapODB(Pointer<git_odb> odb) {
}
}
/// Find a single object, as specified by a [spec] string.
/// See `man gitrevisions`, or https://git-scm.com/docs/git-rev-parse.html#_specifying_revisions
/// for information on the syntax accepted.
///
/// The returned object should be released when no longer needed.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_object> revParseSingle(
Pointer<git_repository> repo,
String spec,
) {
final out = calloc<Pointer<git_object>>();
final specC = spec.toNativeUtf8().cast<Int8>();
final error = libgit2.git_revparse_single(
out,
repo,
specC,
);
calloc.free(specC);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
}
/// Free a previously allocated repository.
void free(Pointer<git_repository> repo) => libgit2.git_repository_free(repo);