feat(merge): add bindings and api for merge analysis

This commit is contained in:
Aleksey Kulikov 2021-09-08 16:03:35 +03:00
parent 1f2d00b177
commit 223cc7cc14
5 changed files with 231 additions and 13 deletions

View file

@ -21,3 +21,36 @@ Pointer<git_oid> mergeBase(
return out;
}
}
/// Analyzes the given branch(es) and determines the opportunities for merging them
/// into a reference.
///
/// Throws a [LibGit2Error] if error occured.
List<int> analysis(
Pointer<git_repository> repo,
Pointer<git_reference> ourRef,
Pointer<Pointer<git_annotated_commit>> theirHead,
int theirHeadsLen,
) {
final analysisOut = calloc<Int32>();
final preferenceOut = calloc<Int32>();
final error = libgit2.git_merge_analysis_for_ref(
analysisOut,
preferenceOut,
repo,
ourRef,
theirHead,
theirHeadsLen,
);
var result = <int>[];
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
} else {
result.add(analysisOut.value);
result.add(preferenceOut.value);
calloc.free(analysisOut);
calloc.free(preferenceOut);
return result;
}
}