mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
refactor: remove unnecessary local variables
This commit is contained in:
parent
cfa5268af2
commit
20ca75639d
48 changed files with 446 additions and 237 deletions
|
@ -25,20 +25,27 @@ dynamic getAttribute({
|
|||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
final attributeValue = libgit2.git_attr_value(out.value);
|
||||
|
||||
if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_UNSPECIFIED) {
|
||||
calloc.free(out);
|
||||
return null;
|
||||
} else if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_TRUE) {
|
||||
calloc.free(out);
|
||||
return true;
|
||||
} else if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_FALSE) {
|
||||
calloc.free(out);
|
||||
return false;
|
||||
} else if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_STRING) {
|
||||
return out.value.cast<Utf8>().toDartString();
|
||||
final result = out.value.cast<Utf8>().toDartString();
|
||||
calloc.free(out);
|
||||
return result;
|
||||
} else {
|
||||
calloc.free(out);
|
||||
throw Exception('The attribute value from libgit2 is invalid');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import 'libgit2_bindings.dart';
|
|||
Pointer<git_blame> file({
|
||||
required Pointer<git_repository> repoPointer,
|
||||
required String path,
|
||||
int? flags,
|
||||
required int flags,
|
||||
int? minMatchCharacters,
|
||||
Oid? newestCommit,
|
||||
Oid? oldestCommit,
|
||||
|
@ -27,12 +27,13 @@ Pointer<git_blame> file({
|
|||
);
|
||||
|
||||
if (optionsError < 0) {
|
||||
calloc.free(out);
|
||||
calloc.free(pathC);
|
||||
calloc.free(options);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
if (flags != null) {
|
||||
options.ref.flags = flags;
|
||||
}
|
||||
options.ref.flags = flags;
|
||||
|
||||
if (minMatchCharacters != null) {
|
||||
options.ref.min_match_characters = minMatchCharacters;
|
||||
|
@ -56,7 +57,11 @@ Pointer<git_blame> file({
|
|||
|
||||
final error = libgit2.git_blame_file(out, repoPointer, pathC, options);
|
||||
|
||||
calloc.free(pathC);
|
||||
calloc.free(options);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
|
|
@ -15,6 +15,7 @@ Pointer<git_blob> lookup({
|
|||
final error = libgit2.git_blob_lookup(out, repoPointer, oidPointer);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -30,8 +31,7 @@ Pointer<git_oid> id(Pointer<git_blob> blob) => libgit2.git_blob_id(blob);
|
|||
/// Searching for NUL bytes and looking for a reasonable ratio of printable to
|
||||
/// non-printable characters among the first 8000 bytes.
|
||||
bool isBinary(Pointer<git_blob> blob) {
|
||||
final result = libgit2.git_blob_is_binary(blob);
|
||||
return result == 1 ? true : false;
|
||||
return libgit2.git_blob_is_binary(blob) == 1 ? true : false;
|
||||
}
|
||||
|
||||
/// Get a read-only buffer with the raw content of a blob.
|
||||
|
@ -40,8 +40,7 @@ bool isBinary(Pointer<git_blob> blob) {
|
|||
/// internally by the object and shall not be free'd. The pointer may be invalidated
|
||||
/// at a later time.
|
||||
String content(Pointer<git_blob> blob) {
|
||||
final result = libgit2.git_blob_rawcontent(blob);
|
||||
return result.cast<Utf8>().toDartString();
|
||||
return libgit2.git_blob_rawcontent(blob).cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Get the size in bytes of the contents of a blob.
|
||||
|
@ -57,12 +56,17 @@ Pointer<git_oid> create({
|
|||
}) {
|
||||
final out = calloc<git_oid>();
|
||||
final bufferC = buffer.toNativeUtf8().cast<Void>();
|
||||
final error =
|
||||
libgit2.git_blob_create_from_buffer(out, repoPointer, bufferC, len);
|
||||
final error = libgit2.git_blob_create_from_buffer(
|
||||
out,
|
||||
repoPointer,
|
||||
bufferC,
|
||||
len,
|
||||
);
|
||||
|
||||
calloc.free(bufferC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -79,12 +83,16 @@ Pointer<git_oid> createFromWorkdir({
|
|||
}) {
|
||||
final out = calloc<git_oid>();
|
||||
final relativePathC = relativePath.toNativeUtf8().cast<Int8>();
|
||||
final error =
|
||||
libgit2.git_blob_create_from_workdir(out, repoPointer, relativePathC);
|
||||
final error = libgit2.git_blob_create_from_workdir(
|
||||
out,
|
||||
repoPointer,
|
||||
relativePathC,
|
||||
);
|
||||
|
||||
calloc.free(relativePathC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -102,7 +110,10 @@ Pointer<git_oid> createFromDisk({
|
|||
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_blob_create_from_disk(out, repoPointer, pathC);
|
||||
|
||||
calloc.free(pathC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
|
|
@ -21,6 +21,7 @@ List<Pointer<git_reference>> list({
|
|||
);
|
||||
|
||||
if (iteratorError < 0) {
|
||||
libgit2.git_branch_iterator_free(iterator.value);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -65,6 +66,7 @@ Pointer<git_reference> lookup({
|
|||
calloc.free(branchNameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -101,6 +103,7 @@ Pointer<git_reference> create({
|
|||
calloc.free(branchNameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -109,17 +112,12 @@ Pointer<git_reference> create({
|
|||
|
||||
/// Delete an existing branch reference.
|
||||
///
|
||||
/// Note that if the deletion succeeds, the reference object will not be valid anymore,
|
||||
/// and will be freed.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
void delete(Pointer<git_reference> branch) {
|
||||
final error = libgit2.git_branch_delete(branch);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
reference_bindings.free(branch);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,15 +134,19 @@ void rename({
|
|||
final out = calloc<Pointer<git_reference>>();
|
||||
final newBranchNameC = newBranchName.toNativeUtf8().cast<Int8>();
|
||||
final forceC = force ? 1 : 0;
|
||||
final error =
|
||||
libgit2.git_branch_move(out, branchPointer, newBranchNameC, forceC);
|
||||
final error = libgit2.git_branch_move(
|
||||
out,
|
||||
branchPointer,
|
||||
newBranchNameC,
|
||||
forceC,
|
||||
);
|
||||
|
||||
calloc.free(newBranchNameC);
|
||||
reference_bindings.free(out.value);
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
reference_bindings.free(out.value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,6 +190,7 @@ String name(Pointer<git_reference> ref) {
|
|||
final error = libgit2.git_branch_name(out, ref);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.value.cast<Utf8>().toDartString();
|
||||
|
|
|
@ -33,7 +33,6 @@ void head({
|
|||
for (final p in pathPointers) {
|
||||
calloc.free(p);
|
||||
}
|
||||
|
||||
calloc.free(strArray);
|
||||
calloc.free(optsC);
|
||||
|
||||
|
@ -65,7 +64,6 @@ void index({
|
|||
for (final p in pathPointers) {
|
||||
calloc.free(p);
|
||||
}
|
||||
|
||||
calloc.free(strArray);
|
||||
calloc.free(optsC);
|
||||
|
||||
|
@ -99,7 +97,6 @@ void tree({
|
|||
for (final p in pathPointers) {
|
||||
calloc.free(p);
|
||||
}
|
||||
|
||||
calloc.free(strArray);
|
||||
calloc.free(optsC);
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ Pointer<git_commit> lookup({
|
|||
final error = libgit2.git_commit_lookup(out, repoPointer, oidPointer);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -40,6 +41,7 @@ Pointer<git_commit> lookupPrefix({
|
|||
);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -68,6 +70,7 @@ Pointer<Pointer<git_annotated_commit>> annotatedLookup({
|
|||
);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -127,6 +130,7 @@ Pointer<git_oid> create({
|
|||
calloc.free(parentsC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -139,20 +143,14 @@ Pointer<git_oid> create({
|
|||
/// in that case UTF-8 is assumed.
|
||||
String messageEncoding(Pointer<git_commit> commit) {
|
||||
final result = libgit2.git_commit_message_encoding(commit);
|
||||
|
||||
if (result == nullptr) {
|
||||
return 'utf-8';
|
||||
} else {
|
||||
return result.cast<Utf8>().toDartString();
|
||||
}
|
||||
return result == nullptr ? 'utf-8' : result.cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Get the full message of a commit.
|
||||
///
|
||||
/// The returned message will be slightly prettified by removing any potential leading newlines.
|
||||
String message(Pointer<git_commit> commit) {
|
||||
final out = libgit2.git_commit_message(commit);
|
||||
return out.cast<Utf8>().toDartString();
|
||||
return libgit2.git_commit_message(commit).cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Get the id of a commit.
|
||||
|
@ -215,6 +213,8 @@ Pointer<git_index> revertCommit({
|
|||
libgit2.git_merge_options_init(opts, GIT_MERGE_OPTIONS_VERSION);
|
||||
|
||||
if (optsError < 0) {
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -230,6 +230,7 @@ Pointer<git_index> revertCommit({
|
|||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
|
|
@ -15,6 +15,7 @@ Pointer<git_config> newConfig() {
|
|||
final error = libgit2.git_config_new(out);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -32,6 +33,7 @@ Pointer<git_config> open(String path) {
|
|||
calloc.free(pathC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -50,6 +52,7 @@ Pointer<git_config> openDefault() {
|
|||
final error = libgit2.git_config_open_default(out);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -74,9 +77,12 @@ String findGlobal() {
|
|||
final error = libgit2.git_config_find_global(out);
|
||||
|
||||
if (error != 0) {
|
||||
calloc.free(out);
|
||||
throw Error();
|
||||
} else {
|
||||
return out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,9 +96,12 @@ String findSystem() {
|
|||
final error = libgit2.git_config_find_system(out);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,9 +116,12 @@ String findXdg() {
|
|||
final error = libgit2.git_config_find_xdg(out);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,6 +137,7 @@ Pointer<git_config> snapshot(Pointer<git_config> config) {
|
|||
final error = libgit2.git_config_snapshot(out, config);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -145,6 +158,7 @@ Pointer<git_config_entry> getEntry({
|
|||
calloc.free(name);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
|
|
@ -19,6 +19,7 @@ Pointer<git_credential> username(String username) {
|
|||
calloc.free(usernameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -36,13 +37,17 @@ Pointer<git_credential> userPass({
|
|||
final usernameC = username.toNativeUtf8().cast<Int8>();
|
||||
final passwordC = password.toNativeUtf8().cast<Int8>();
|
||||
|
||||
final error =
|
||||
libgit2.git_credential_userpass_plaintext_new(out, usernameC, passwordC);
|
||||
final error = libgit2.git_credential_userpass_plaintext_new(
|
||||
out,
|
||||
usernameC,
|
||||
passwordC,
|
||||
);
|
||||
|
||||
calloc.free(usernameC);
|
||||
calloc.free(passwordC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -78,6 +83,7 @@ Pointer<git_credential> sshKey({
|
|||
calloc.free(passPhraseC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -96,6 +102,7 @@ Pointer<git_credential> sshKeyFromAgent(String username) {
|
|||
calloc.free(usernameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -131,6 +138,7 @@ Pointer<git_credential> sshKeyFromMemory({
|
|||
calloc.free(passPhraseC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
|
|
@ -33,6 +33,7 @@ Pointer<git_describe_result> commit({
|
|||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -68,6 +69,7 @@ Pointer<git_describe_result> workdir({
|
|||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -91,6 +93,8 @@ String format({
|
|||
);
|
||||
|
||||
if (optsError < 0) {
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -106,7 +110,10 @@ String format({
|
|||
|
||||
final error = libgit2.git_describe_format(out, describeResultPointer, opts);
|
||||
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
|
|
|
@ -150,6 +150,7 @@ Pointer<git_diff> parse(String content) {
|
|||
calloc.free(contentC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -173,8 +174,16 @@ void findSimilar({
|
|||
required int renameLimit,
|
||||
}) {
|
||||
final opts = calloc<git_diff_find_options>();
|
||||
final optsError =
|
||||
libgit2.git_diff_find_options_init(opts, GIT_DIFF_FIND_OPTIONS_VERSION);
|
||||
final optsError = libgit2.git_diff_find_options_init(
|
||||
opts,
|
||||
GIT_DIFF_FIND_OPTIONS_VERSION,
|
||||
);
|
||||
|
||||
if (optsError < 0) {
|
||||
calloc.free(opts);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
opts.ref.flags = flags;
|
||||
opts.ref.rename_threshold = renameThreshold;
|
||||
opts.ref.copy_threshold = copyThreshold;
|
||||
|
@ -182,17 +191,13 @@ void findSimilar({
|
|||
opts.ref.break_rewrite_threshold = breakRewriteThreshold;
|
||||
opts.ref.rename_limit = renameLimit;
|
||||
|
||||
if (optsError < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
final error = libgit2.git_diff_find_similar(diffPointer, opts);
|
||||
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
calloc.free(opts);
|
||||
}
|
||||
|
||||
/// Calculate the patch ID for the given patch.
|
||||
|
@ -210,6 +215,7 @@ Pointer<git_oid> patchId(Pointer<git_diff> diff) {
|
|||
final error = libgit2.git_diff_patchid(out, diff, nullptr);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -239,8 +245,7 @@ Pointer<git_diff_delta> getDeltaByIndex({
|
|||
/// value into these letters for your own purposes. [GitDelta.untracked] will return
|
||||
/// a space (i.e. ' ').
|
||||
String statusChar(int status) {
|
||||
final result = libgit2.git_diff_status_char(status);
|
||||
return String.fromCharCode(result);
|
||||
return String.fromCharCode(libgit2.git_diff_status_char(status));
|
||||
}
|
||||
|
||||
/// Accumulate diff statistics for all patches.
|
||||
|
@ -251,6 +256,7 @@ Pointer<git_diff_stats> stats(Pointer<git_diff> diff) {
|
|||
final error = libgit2.git_diff_get_stats(out, diff);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -281,6 +287,7 @@ String statsPrint({
|
|||
final error = libgit2.git_diff_stats_to_buf(out, statsPointer, format, width);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
|
|
|
@ -49,5 +49,8 @@ List<int> aheadBehind({
|
|||
upstreamPointer,
|
||||
);
|
||||
|
||||
return [ahead.value, behind.value];
|
||||
final result = [ahead.value, behind.value];
|
||||
calloc.free(ahead);
|
||||
calloc.free(behind);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ Pointer<git_oid> writeTree(Pointer<git_index> index) {
|
|||
final error = libgit2.git_index_write_tree(out, index);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -79,6 +80,7 @@ Pointer<git_oid> writeTreeTo({
|
|||
final error = libgit2.git_index_write_tree_to(out, indexPointer, repoPointer);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -210,9 +212,9 @@ void addAll({
|
|||
required List<String> pathspec,
|
||||
}) {
|
||||
var pathspecC = calloc<git_strarray>();
|
||||
final List<Pointer<Int8>> pathPointers =
|
||||
final pathPointers =
|
||||
pathspec.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
|
||||
final Pointer<Pointer<Int8>> strArray = calloc(pathspec.length);
|
||||
final strArray = calloc<Pointer<Int8>>(pathspec.length);
|
||||
|
||||
for (var i = 0; i < pathspec.length; i++) {
|
||||
strArray[i] = pathPointers[i];
|
||||
|
@ -277,9 +279,9 @@ void removeAll({
|
|||
required List<String> pathspec,
|
||||
}) {
|
||||
final pathspecC = calloc<git_strarray>();
|
||||
final List<Pointer<Int8>> pathPointers =
|
||||
final pathPointers =
|
||||
pathspec.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
|
||||
final Pointer<Pointer<Int8>> strArray = calloc(pathspec.length);
|
||||
final strArray = calloc<Pointer<Int8>>(pathspec.length);
|
||||
|
||||
for (var i = 0; i < pathspec.length; i++) {
|
||||
strArray[i] = pathPointers[i];
|
||||
|
@ -318,10 +320,13 @@ List<Map<String, Pointer<git_index_entry>>> conflictList(
|
|||
Pointer<git_index> index,
|
||||
) {
|
||||
final iterator = calloc<Pointer<git_index_conflict_iterator>>();
|
||||
final iteratorError =
|
||||
libgit2.git_index_conflict_iterator_new(iterator, index);
|
||||
final iteratorError = libgit2.git_index_conflict_iterator_new(
|
||||
iterator,
|
||||
index,
|
||||
);
|
||||
|
||||
if (iteratorError < 0) {
|
||||
calloc.free(iterator);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ Pointer<git_mailmap> init() {
|
|||
final error = libgit2.git_mailmap_new(out);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -33,6 +34,7 @@ Pointer<git_mailmap> fromBuffer(String buffer) {
|
|||
calloc.free(bufferC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -55,6 +57,7 @@ Pointer<git_mailmap> fromRepository(Pointer<git_repository> repo) {
|
|||
final error = libgit2.git_mailmap_from_repository(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -114,6 +117,7 @@ Pointer<git_signature> resolveSignature({
|
|||
);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
|
|
@ -16,6 +16,7 @@ Pointer<git_oid> mergeBase({
|
|||
final error = libgit2.git_merge_base(out, repoPointer, aPointer, bPointer);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -45,6 +46,8 @@ List<int> analysis({
|
|||
var result = <int>[];
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(analysisOut);
|
||||
calloc.free(preferenceOut);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
result.add(analysisOut.value);
|
||||
|
@ -67,10 +70,28 @@ void merge({
|
|||
required int theirHeadsLen,
|
||||
}) {
|
||||
final mergeOpts = calloc<git_merge_options>();
|
||||
libgit2.git_merge_options_init(mergeOpts, GIT_MERGE_OPTIONS_VERSION);
|
||||
final mergeError = libgit2.git_merge_options_init(
|
||||
mergeOpts,
|
||||
GIT_MERGE_OPTIONS_VERSION,
|
||||
);
|
||||
|
||||
if (mergeError < 0) {
|
||||
calloc.free(mergeOpts);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
final checkoutOpts = calloc<git_checkout_options>();
|
||||
libgit2.git_checkout_options_init(checkoutOpts, GIT_CHECKOUT_OPTIONS_VERSION);
|
||||
final checkoutError = libgit2.git_checkout_options_init(
|
||||
checkoutOpts,
|
||||
GIT_CHECKOUT_OPTIONS_VERSION,
|
||||
);
|
||||
|
||||
if (checkoutError < 0) {
|
||||
calloc.free(mergeOpts);
|
||||
calloc.free(checkoutOpts);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
checkoutOpts.ref.checkout_strategy =
|
||||
git_checkout_strategy_t.GIT_CHECKOUT_SAFE |
|
||||
git_checkout_strategy_t.GIT_CHECKOUT_RECREATE_MISSING;
|
||||
|
@ -83,6 +104,9 @@ void merge({
|
|||
checkoutOpts,
|
||||
);
|
||||
|
||||
calloc.free(mergeOpts);
|
||||
calloc.free(checkoutOpts);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
@ -110,6 +134,7 @@ String mergeFileFromIndex({
|
|||
);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.len);
|
||||
|
@ -152,6 +177,7 @@ Pointer<git_index> mergeCommits({
|
|||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -194,6 +220,7 @@ Pointer<git_index> mergeTrees({
|
|||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -207,13 +234,24 @@ void cherryPick({
|
|||
required Pointer<git_repository> repoPointer,
|
||||
required Pointer<git_commit> commitPointer,
|
||||
}) {
|
||||
final opts = calloc<git_cherrypick_options>(sizeOf<git_cherrypick_options>());
|
||||
libgit2.git_cherrypick_options_init(opts, GIT_CHERRYPICK_OPTIONS_VERSION);
|
||||
final opts = calloc<git_cherrypick_options>();
|
||||
final optsError = libgit2.git_cherrypick_options_init(
|
||||
opts,
|
||||
GIT_CHERRYPICK_OPTIONS_VERSION,
|
||||
);
|
||||
|
||||
if (optsError < 0) {
|
||||
calloc.free(opts);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
opts.ref.checkout_opts.checkout_strategy =
|
||||
git_checkout_strategy_t.GIT_CHECKOUT_SAFE;
|
||||
|
||||
final error = libgit2.git_cherrypick(repoPointer, commitPointer, opts);
|
||||
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
@ -231,6 +269,7 @@ Pointer<git_merge_options> _initMergeOptions({
|
|||
);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(opts);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ List<Map<String, Pointer>> list(Pointer<git_repository> repo) {
|
|||
final iteratorError = libgit2.git_note_iterator_new(iterator, repo, notesRef);
|
||||
|
||||
if (iteratorError < 0) {
|
||||
calloc.free(iterator);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -32,6 +33,9 @@ List<Map<String, Pointer>> list(Pointer<git_repository> repo) {
|
|||
calloc.free(noteId);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
calloc.free(annotatedId);
|
||||
calloc.free(iterator);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
result.add({'note': out.value, 'annotatedId': annotatedId});
|
||||
|
@ -64,6 +68,7 @@ Pointer<git_note> lookup({
|
|||
calloc.free(notesRefC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -101,6 +106,7 @@ Pointer<git_oid> create({
|
|||
calloc.free(noteC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
|
|
@ -26,6 +26,7 @@ Pointer<git_object> lookup({
|
|||
final error = libgit2.git_object_lookup(out, repoPointer, oidPointer, type);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
|
|
@ -17,6 +17,7 @@ Pointer<git_odb> create() {
|
|||
final error = libgit2.git_odb_new(out);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -65,6 +66,7 @@ Pointer<git_oid> existsPrefix({
|
|||
);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -76,8 +78,7 @@ bool exists({
|
|||
required Pointer<git_odb> odbPointer,
|
||||
required Pointer<git_oid> oidPointer,
|
||||
}) {
|
||||
final result = libgit2.git_odb_exists(odbPointer, oidPointer);
|
||||
return result == 1 ? true : false;
|
||||
return libgit2.git_odb_exists(odbPointer, oidPointer) == 1 ? true : false;
|
||||
}
|
||||
|
||||
/// List of objects in the database.
|
||||
|
@ -100,11 +101,10 @@ int _forEachCb(
|
|||
/// Throws a [LibGit2Error] if error occured.
|
||||
List<Oid> objects(Pointer<git_odb> odb) {
|
||||
const except = -1;
|
||||
final payload = calloc<Pointer<git_oid>>();
|
||||
final cb =
|
||||
Pointer.fromFunction<Int32 Function(Pointer<git_oid>, Pointer<Void>)>(
|
||||
_forEachCb, except);
|
||||
final error = libgit2.git_odb_foreach(odb, cb, payload.cast());
|
||||
final error = libgit2.git_odb_foreach(odb, cb, nullptr);
|
||||
|
||||
if (error < 0) {
|
||||
_objects.clear();
|
||||
|
@ -133,6 +133,7 @@ Pointer<git_odb_object> read({
|
|||
final error = libgit2.git_odb_read(out, odbPointer, oidPointer);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -155,9 +156,7 @@ int objectType(Pointer<git_odb_object> object) {
|
|||
///
|
||||
/// This is the uncompressed, raw data as read from the ODB, without the leading header.
|
||||
String objectData(Pointer<git_odb_object> object) {
|
||||
final out = libgit2.git_odb_object_data(object);
|
||||
|
||||
return out.cast<Utf8>().toDartString();
|
||||
return libgit2.git_odb_object_data(object).cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Return the size of an ODB object.
|
||||
|
@ -192,6 +191,7 @@ Pointer<git_oid> write({
|
|||
);
|
||||
|
||||
if (streamError < 0) {
|
||||
libgit2.git_odb_stream_free(stream.value);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -203,6 +203,7 @@ Pointer<git_oid> write({
|
|||
);
|
||||
|
||||
if (writeError < 0) {
|
||||
calloc.free(buffer);
|
||||
libgit2.git_odb_stream_free(stream.value);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
@ -217,6 +218,7 @@ Pointer<git_oid> write({
|
|||
libgit2.git_odb_stream_free(stream.value);
|
||||
|
||||
if (finalizeError < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -237,6 +239,7 @@ Pointer<git_odb_backend> getBackend({
|
|||
final error = libgit2.git_odb_get_backend(out, odbPointer, position);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
|
|
@ -13,9 +13,11 @@ Pointer<git_oid> fromStrN(String hex) {
|
|||
final out = calloc<git_oid>();
|
||||
final str = hex.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_oid_fromstrn(out, str, hex.length);
|
||||
|
||||
calloc.free(str);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -29,9 +31,11 @@ Pointer<git_oid> fromSHA(String hex) {
|
|||
final out = calloc<git_oid>();
|
||||
final str = hex.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_oid_fromstr(out, str);
|
||||
|
||||
calloc.free(str);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -52,6 +56,7 @@ Pointer<git_oid> fromRaw(Array<Uint8> raw) {
|
|||
calloc.free(rawC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -64,13 +69,13 @@ Pointer<git_oid> fromRaw(Array<Uint8> raw) {
|
|||
String toSHA(Pointer<git_oid> id) {
|
||||
final out = calloc<Int8>(40);
|
||||
final error = libgit2.git_oid_fmt(out, id);
|
||||
final result = out.cast<Utf8>().toDartString(length: 40);
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.cast<Utf8>().toDartString(length: 40);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -93,6 +98,7 @@ Pointer<git_oid> copy(Pointer<git_oid> src) {
|
|||
final error = libgit2.git_oid_cpy(out, src);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
|
|
@ -12,6 +12,7 @@ Pointer<git_packbuilder> init(Pointer<git_repository> repo) {
|
|||
final error = libgit2.git_packbuilder_new(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
|
|
@ -43,13 +43,12 @@ Map<String, dynamic> fromBuffers({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = <String, dynamic>{};
|
||||
|
||||
calloc.free(oldAsPathC);
|
||||
calloc.free(newAsPathC);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
calloc.free(oldBufferC);
|
||||
calloc.free(newBufferC);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
|
@ -57,10 +56,7 @@ Map<String, dynamic> fromBuffers({
|
|||
// Returning map with pointers to patch and buffers because patch object does not
|
||||
// have refenrece to underlying buffers or blobs. So if the buffer or blob is freed/removed
|
||||
// the patch text becomes corrupted.
|
||||
result['patch'] = out.value;
|
||||
result['a'] = oldBufferC;
|
||||
result['b'] = newBufferC;
|
||||
return result;
|
||||
return {'patch': out.value, 'a': oldBufferC, 'b': newBufferC};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,22 +93,18 @@ Map<String, dynamic> fromBlobs({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = <String, dynamic>{};
|
||||
|
||||
calloc.free(oldAsPathC);
|
||||
calloc.free(newAsPathC);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
// Returning map with pointers to patch and blobs because patch object does not
|
||||
// have reference to underlying blobs. So if the blob is freed/removed the patch
|
||||
// text becomes corrupted.
|
||||
result['patch'] = out.value;
|
||||
result['a'] = oldBlobPointer;
|
||||
result['b'] = newBlobPointer;
|
||||
return result;
|
||||
return {'patch': out.value, 'a': oldBlobPointer, 'b': newBlobPointer};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,23 +144,19 @@ Map<String, dynamic> fromBlobAndBuffer({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = <String, dynamic>{};
|
||||
|
||||
calloc.free(oldAsPathC);
|
||||
calloc.free(bufferAsPathC);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
calloc.free(bufferC);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
// Returning map with pointers to patch and buffers because patch object does not
|
||||
// have reference to underlying buffers or blobs. So if the buffer or blob is freed/removed
|
||||
// the patch text becomes corrupted.
|
||||
result['patch'] = out.value;
|
||||
result['a'] = oldBlobPointer;
|
||||
result['b'] = bufferC;
|
||||
return result;
|
||||
return {'patch': out.value, 'a': oldBlobPointer, 'b': bufferC};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,6 +175,7 @@ Pointer<git_patch> fromDiff({
|
|||
final error = libgit2.git_patch_from_diff(out, diffPointer, index);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -217,14 +206,15 @@ Map<String, dynamic> hunk({
|
|||
patchPointer,
|
||||
hunkIndex,
|
||||
);
|
||||
final result = <String, dynamic>{};
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
calloc.free(linesInHunk);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
result['hunk'] = out.value;
|
||||
result['linesN'] = linesInHunk.value;
|
||||
return result;
|
||||
final linesN = linesInHunk.value;
|
||||
calloc.free(linesInHunk);
|
||||
return {'hunk': out.value, 'linesN': linesN};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,6 +235,7 @@ Pointer<git_diff_line> lines({
|
|||
);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -259,6 +250,7 @@ String text(Pointer<git_patch> patch) {
|
|||
final error = libgit2.git_patch_to_buf(out, patch);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
|
@ -302,15 +294,19 @@ Pointer<git_diff_options> _diffOptionsInit({
|
|||
required int interhunkLines,
|
||||
}) {
|
||||
final opts = calloc<git_diff_options>();
|
||||
final optsError =
|
||||
libgit2.git_diff_options_init(opts, GIT_DIFF_OPTIONS_VERSION);
|
||||
final optsError = libgit2.git_diff_options_init(
|
||||
opts,
|
||||
GIT_DIFF_OPTIONS_VERSION,
|
||||
);
|
||||
|
||||
if (optsError < 0) {
|
||||
calloc.free(opts);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
opts.ref.flags = flags;
|
||||
opts.ref.context_lines = contextLines;
|
||||
opts.ref.interhunk_lines = interhunkLines;
|
||||
|
||||
if (optsError < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return opts;
|
||||
}
|
||||
return opts;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ Pointer<git_rebase> init({
|
|||
);
|
||||
|
||||
if (optsError < 0) {
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -43,7 +45,10 @@ Pointer<git_rebase> init({
|
|||
opts,
|
||||
);
|
||||
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -63,13 +68,14 @@ int operationsCount(Pointer<git_rebase> rebase) {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Pointer<git_rebase_operation> next(Pointer<git_rebase> rebase) {
|
||||
final operation = calloc<Pointer<git_rebase_operation>>();
|
||||
final error = libgit2.git_rebase_next(operation, rebase);
|
||||
final out = calloc<Pointer<git_rebase_operation>>();
|
||||
final error = libgit2.git_rebase_next(out, rebase);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return operation.value;
|
||||
return out.value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,11 +89,11 @@ void commit({
|
|||
required Pointer<git_signature> committerPointer,
|
||||
required String? message,
|
||||
}) {
|
||||
final id = calloc<git_oid>();
|
||||
final out = calloc<git_oid>();
|
||||
final messageC = message?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||
|
||||
final error = libgit2.git_rebase_commit(
|
||||
id,
|
||||
out,
|
||||
rebasePointer,
|
||||
authorPointer ?? nullptr,
|
||||
committerPointer,
|
||||
|
@ -95,6 +101,7 @@ void commit({
|
|||
messageC,
|
||||
);
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(messageC);
|
||||
|
||||
if (error < 0) {
|
||||
|
|
|
@ -41,6 +41,7 @@ Pointer<git_reference> resolve(Pointer<git_reference> ref) {
|
|||
final error = libgit2.git_reference_resolve(out, ref);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -65,6 +66,7 @@ Pointer<git_reference> lookup({
|
|||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -88,6 +90,7 @@ Pointer<git_reference> lookupDWIM({
|
|||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -96,10 +99,7 @@ Pointer<git_reference> lookupDWIM({
|
|||
|
||||
/// Get the full name of a reference.
|
||||
String name(Pointer<git_reference> ref) {
|
||||
var result = calloc<Int8>();
|
||||
result = libgit2.git_reference_name(ref);
|
||||
|
||||
return result.cast<Utf8>().toDartString();
|
||||
return libgit2.git_reference_name(ref).cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Get the reference's short name.
|
||||
|
@ -107,8 +107,7 @@ String name(Pointer<git_reference> ref) {
|
|||
/// This will transform the reference name into a name "human-readable" version.
|
||||
/// If no shortname is appropriate, it will return the full name.
|
||||
String shorthand(Pointer<git_reference> ref) {
|
||||
final result = libgit2.git_reference_shorthand(ref);
|
||||
return result.cast<Utf8>().toDartString();
|
||||
return libgit2.git_reference_shorthand(ref).cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Rename an existing reference.
|
||||
|
@ -146,6 +145,7 @@ Pointer<git_reference> rename({
|
|||
calloc.free(logMessageC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -195,26 +195,22 @@ bool hasLog({
|
|||
|
||||
/// Check if a reference is a local branch.
|
||||
bool isBranch(Pointer<git_reference> ref) {
|
||||
final result = libgit2.git_reference_is_branch(ref);
|
||||
return result == 1 ? true : false;
|
||||
return libgit2.git_reference_is_branch(ref) == 1 ? true : false;
|
||||
}
|
||||
|
||||
/// Check if a reference is a note.
|
||||
bool isNote(Pointer<git_reference> ref) {
|
||||
final result = libgit2.git_reference_is_note(ref);
|
||||
return result == 1 ? true : false;
|
||||
return libgit2.git_reference_is_note(ref) == 1 ? true : false;
|
||||
}
|
||||
|
||||
/// Check if a reference is a remote tracking branch.
|
||||
bool isRemote(Pointer<git_reference> ref) {
|
||||
final result = libgit2.git_reference_is_remote(ref);
|
||||
return result == 1 ? true : false;
|
||||
return libgit2.git_reference_is_remote(ref) == 1 ? true : false;
|
||||
}
|
||||
|
||||
/// Check if a reference is a tag.
|
||||
bool isTag(Pointer<git_reference> ref) {
|
||||
final result = libgit2.git_reference_is_tag(ref);
|
||||
return result == 1 ? true : false;
|
||||
return libgit2.git_reference_is_tag(ref) == 1 ? true : false;
|
||||
}
|
||||
|
||||
/// Create a new direct reference.
|
||||
|
@ -263,6 +259,7 @@ Pointer<git_reference> createDirect({
|
|||
calloc.free(logMessageC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw (LibGit2Error(libgit2.git_error_last()));
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -317,6 +314,7 @@ Pointer<git_reference> createSymbolic({
|
|||
calloc.free(logMessageC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw (LibGit2Error(libgit2.git_error_last()));
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -365,6 +363,7 @@ Pointer<git_reference> setTarget({
|
|||
calloc.free(logMessageC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -401,6 +400,7 @@ Pointer<git_reference> setTargetSymbolic({
|
|||
calloc.free(logMessageC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -412,8 +412,9 @@ bool compare({
|
|||
required Pointer<git_reference> ref1Pointer,
|
||||
required Pointer<git_reference> ref2Pointer,
|
||||
}) {
|
||||
final result = libgit2.git_reference_cmp(ref1Pointer, ref2Pointer);
|
||||
return result == 0 ? true : false;
|
||||
return libgit2.git_reference_cmp(ref1Pointer, ref2Pointer) == 0
|
||||
? true
|
||||
: false;
|
||||
}
|
||||
|
||||
/// Recursively peel reference until object of the specified type is found.
|
||||
|
@ -432,6 +433,7 @@ Pointer<git_object> peel({
|
|||
final error = libgit2.git_reference_peel(out, refPointer, type);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
|
|
@ -23,6 +23,7 @@ Pointer<git_reflog> read({
|
|||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -46,8 +47,7 @@ Pointer<git_reflog_entry> getByIndex({
|
|||
|
||||
/// Get the log message.
|
||||
String entryMessage(Pointer<git_reflog_entry> entry) {
|
||||
final result = libgit2.git_reflog_entry_message(entry);
|
||||
return result.cast<Utf8>().toDartString();
|
||||
return libgit2.git_reflog_entry_message(entry).cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Get the committer of this entry.
|
||||
|
|
|
@ -68,6 +68,7 @@ String transform({
|
|||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
|
@ -90,6 +91,7 @@ String rTransform({
|
|||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
|
|
|
@ -15,6 +15,7 @@ List<String> list(Pointer<git_repository> repo) {
|
|||
final error = libgit2.git_remote_list(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
var result = <String>[];
|
||||
|
@ -42,6 +43,7 @@ Pointer<git_remote> lookup({
|
|||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -65,6 +67,7 @@ Pointer<git_remote> create({
|
|||
calloc.free(urlC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -97,6 +100,7 @@ Pointer<git_remote> createWithFetchSpec({
|
|||
calloc.free(fetchC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -148,6 +152,7 @@ List<String> rename({
|
|||
calloc.free(newNameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
var result = <String>[];
|
||||
|
@ -374,11 +379,13 @@ List<Map<String, dynamic>> lsRemotes(Pointer<git_remote> remote) {
|
|||
final size = calloc<Uint64>();
|
||||
final error = libgit2.git_remote_ls(out, size, remote);
|
||||
|
||||
var result = <Map<String, dynamic>>[];
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
calloc.free(size);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
var result = <Map<String, dynamic>>[];
|
||||
|
||||
for (var i = 0; i < size.value; i++) {
|
||||
var remote = <String, dynamic>{};
|
||||
Oid? loid;
|
||||
|
@ -401,6 +408,9 @@ List<Map<String, dynamic>> lsRemotes(Pointer<git_remote> remote) {
|
|||
result.add(remote);
|
||||
}
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(size);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -441,6 +451,14 @@ void fetch({
|
|||
);
|
||||
|
||||
if (optsError < 0) {
|
||||
for (final p in refspecsPointers) {
|
||||
calloc.free(p);
|
||||
}
|
||||
calloc.free(refspecsC);
|
||||
calloc.free(strArray);
|
||||
calloc.free(proxyOptions);
|
||||
calloc.free(reflogMessageC);
|
||||
calloc.free(opts);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -501,6 +519,13 @@ void push({
|
|||
libgit2.git_push_options_init(opts, GIT_PUSH_OPTIONS_VERSION);
|
||||
|
||||
if (optsError < 0) {
|
||||
for (final p in refspecsPointers) {
|
||||
calloc.free(p);
|
||||
}
|
||||
calloc.free(strArray);
|
||||
calloc.free(refspecsC);
|
||||
calloc.free(proxyOptions);
|
||||
calloc.free(opts);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -555,6 +580,7 @@ void prune({
|
|||
);
|
||||
|
||||
if (callbacksError < 0) {
|
||||
calloc.free(callbacksOptions);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -586,6 +612,7 @@ Pointer<git_proxy_options> _proxyOptionsInit(String? proxyOption) {
|
|||
libgit2.git_proxy_options_init(proxyOptions, GIT_PROXY_OPTIONS_VERSION);
|
||||
|
||||
if (proxyOptionsError < 0) {
|
||||
calloc.free(proxyOptions);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ Pointer<git_repository> open(String path) {
|
|||
calloc.free(pathC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -40,6 +41,7 @@ Pointer<git_repository> openBare(String barePath) {
|
|||
calloc.free(barePathC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -72,11 +74,15 @@ String discover({
|
|||
calloc.free(ceilingDirsC);
|
||||
|
||||
if (error == git_error_code.GIT_ENOTFOUND) {
|
||||
calloc.free(out);
|
||||
return '';
|
||||
} else if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,6 +113,14 @@ Pointer<git_repository> init({
|
|||
);
|
||||
|
||||
if (optsError < 0) {
|
||||
calloc.free(out);
|
||||
calloc.free(pathC);
|
||||
calloc.free(workdirPathC);
|
||||
calloc.free(descriptionC);
|
||||
calloc.free(templatePathC);
|
||||
calloc.free(initialHeadC);
|
||||
calloc.free(originUrlC);
|
||||
calloc.free(opts);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -129,6 +143,7 @@ Pointer<git_repository> init({
|
|||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -158,6 +173,11 @@ Pointer<git_repository> clone({
|
|||
libgit2.git_clone_options_init(cloneOptions, GIT_CLONE_OPTIONS_VERSION);
|
||||
|
||||
if (cloneOptionsError < 0) {
|
||||
calloc.free(out);
|
||||
calloc.free(urlC);
|
||||
calloc.free(localPathC);
|
||||
calloc.free(checkoutBranchC);
|
||||
calloc.free(cloneOptions);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -166,6 +186,12 @@ Pointer<git_repository> clone({
|
|||
libgit2.git_fetch_options_init(fetchOptions, GIT_FETCH_OPTIONS_VERSION);
|
||||
|
||||
if (fetchOptionsError < 0) {
|
||||
calloc.free(out);
|
||||
calloc.free(urlC);
|
||||
calloc.free(localPathC);
|
||||
calloc.free(checkoutBranchC);
|
||||
calloc.free(cloneOptions);
|
||||
calloc.free(fetchOptions);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -204,6 +230,7 @@ Pointer<git_repository> clone({
|
|||
RemoteCallbacks.reset();
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -213,8 +240,7 @@ Pointer<git_repository> clone({
|
|||
/// Returns the path to the `.git` folder for normal repositories or the
|
||||
/// repository itself for bare repositories.
|
||||
String path(Pointer<git_repository> repo) {
|
||||
final result = libgit2.git_repository_path(repo);
|
||||
return result.cast<Utf8>().toDartString();
|
||||
return libgit2.git_repository_path(repo).cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Get the path of the shared common directory for this repository.
|
||||
|
@ -223,8 +249,7 @@ String path(Pointer<git_repository> repo) {
|
|||
/// If the repository is a worktree, it is the parent repo's `.git` folder.
|
||||
/// Otherwise, it is the `.git` folder.
|
||||
String commonDir(Pointer<git_repository> repo) {
|
||||
final result = libgit2.git_repository_commondir(repo);
|
||||
return result.cast<Utf8>().toDartString();
|
||||
return libgit2.git_repository_commondir(repo).cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Get the currently active namespace for this repository.
|
||||
|
@ -264,8 +289,7 @@ void setNamespace({
|
|||
|
||||
/// Check if a repository is bare or not.
|
||||
bool isBare(Pointer<git_repository> repo) {
|
||||
final result = libgit2.git_repository_is_bare(repo);
|
||||
return result == 1 ? true : false;
|
||||
return libgit2.git_repository_is_bare(repo) == 1 ? true : false;
|
||||
}
|
||||
|
||||
/// Check if a repository is empty.
|
||||
|
@ -295,6 +319,7 @@ Pointer<git_reference> head(Pointer<git_repository> repo) {
|
|||
final error = libgit2.git_repository_head(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -383,6 +408,7 @@ Pointer<git_config> config(Pointer<git_repository> repo) {
|
|||
final error = libgit2.git_repository_config(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -402,6 +428,7 @@ Pointer<git_config> configSnapshot(Pointer<git_repository> repo) {
|
|||
final error = libgit2.git_repository_config_snapshot(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -421,6 +448,7 @@ Pointer<git_index> index(Pointer<git_repository> repo) {
|
|||
final error = libgit2.git_repository_index(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -429,14 +457,12 @@ Pointer<git_index> index(Pointer<git_repository> repo) {
|
|||
|
||||
/// Determine if the repository was a shallow clone.
|
||||
bool isShallow(Pointer<git_repository> repo) {
|
||||
final result = libgit2.git_repository_is_shallow(repo);
|
||||
return result == 1 ? true : false;
|
||||
return libgit2.git_repository_is_shallow(repo) == 1 ? true : false;
|
||||
}
|
||||
|
||||
/// Check if a repository is a linked work tree.
|
||||
bool isWorktree(Pointer<git_repository> repo) {
|
||||
final result = libgit2.git_repository_is_worktree(repo);
|
||||
return result == 1 ? true : false;
|
||||
return libgit2.git_repository_is_worktree(repo) == 1 ? true : false;
|
||||
}
|
||||
|
||||
/// Retrieve git's prepared message.
|
||||
|
@ -455,9 +481,12 @@ String message(Pointer<git_repository> repo) {
|
|||
final error = libgit2.git_repository_message(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.ref.ptr.cast<Utf8>().toDartString();
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString();
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -479,6 +508,7 @@ Pointer<git_odb> odb(Pointer<git_repository> repo) {
|
|||
final error = libgit2.git_repository_odb(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -499,6 +529,7 @@ Pointer<git_refdb> refdb(Pointer<git_repository> repo) {
|
|||
final error = libgit2.git_repository_refdb(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -646,6 +677,7 @@ Pointer<git_repository> wrapODB(Pointer<git_odb> odb) {
|
|||
final error = libgit2.git_repository_wrap_odb(out, odb);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
|
|
@ -22,6 +22,7 @@ Pointer<git_revspec> revParse({
|
|||
calloc.free(specC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -47,6 +48,7 @@ Pointer<git_object> revParseSingle({
|
|||
calloc.free(specC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -72,7 +74,6 @@ List revParseExt({
|
|||
final objectOut = calloc<Pointer<git_object>>();
|
||||
final referenceOut = calloc<Pointer<git_reference>>();
|
||||
final specC = spec.toNativeUtf8().cast<Int8>();
|
||||
var result = [];
|
||||
|
||||
final error = libgit2.git_revparse_ext(
|
||||
objectOut,
|
||||
|
@ -84,8 +85,11 @@ List revParseExt({
|
|||
calloc.free(specC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(objectOut);
|
||||
calloc.free(referenceOut);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
var result = [];
|
||||
result.add(objectOut.value);
|
||||
if (referenceOut.value != nullptr) {
|
||||
result.add(referenceOut.value);
|
||||
|
|
|
@ -22,6 +22,7 @@ Pointer<git_revwalk> create(Pointer<git_repository> repo) {
|
|||
final error = libgit2.git_revwalk_new(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
|
|
@ -25,6 +25,7 @@ Pointer<git_signature> create({
|
|||
calloc.free(emailC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -44,6 +45,7 @@ Pointer<git_signature> now({required String name, required String email}) {
|
|||
calloc.free(emailC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -61,6 +63,7 @@ Pointer<git_signature> defaultSignature(Pointer<git_repository> repo) {
|
|||
final error = libgit2.git_signature_default(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
|
|
@ -26,7 +26,10 @@ Pointer<git_oid> stash({
|
|||
flags,
|
||||
);
|
||||
|
||||
calloc.free(messageC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
@ -44,12 +47,14 @@ void apply({
|
|||
String? directory,
|
||||
List<String>? paths,
|
||||
}) {
|
||||
final options =
|
||||
calloc<git_stash_apply_options>(sizeOf<git_stash_apply_options>());
|
||||
final options = calloc<git_stash_apply_options>();
|
||||
final optionsError = libgit2.git_stash_apply_options_init(
|
||||
options, GIT_STASH_APPLY_OPTIONS_VERSION);
|
||||
options,
|
||||
GIT_STASH_APPLY_OPTIONS_VERSION,
|
||||
);
|
||||
|
||||
if (optionsError < 0) {
|
||||
calloc.free(options);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -67,16 +72,16 @@ void apply({
|
|||
|
||||
final error = libgit2.git_stash_apply(repoPointer, index, options);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
for (final p in pathPointers) {
|
||||
calloc.free(p);
|
||||
}
|
||||
calloc.free(strArray);
|
||||
calloc.free(optsC);
|
||||
calloc.free(options);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove a single stashed state from the stash list.
|
||||
|
@ -97,12 +102,14 @@ void pop({
|
|||
String? directory,
|
||||
List<String>? paths,
|
||||
}) {
|
||||
final options =
|
||||
calloc<git_stash_apply_options>(sizeOf<git_stash_apply_options>());
|
||||
final options = calloc<git_stash_apply_options>();
|
||||
final optionsError = libgit2.git_stash_apply_options_init(
|
||||
options, GIT_STASH_APPLY_OPTIONS_VERSION);
|
||||
options,
|
||||
GIT_STASH_APPLY_OPTIONS_VERSION,
|
||||
);
|
||||
|
||||
if (optionsError < 0) {
|
||||
calloc.free(options);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -120,16 +127,16 @@ void pop({
|
|||
|
||||
final error = libgit2.git_stash_pop(repoPointer, index, options);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
for (final p in pathPointers) {
|
||||
calloc.free(p);
|
||||
}
|
||||
calloc.free(strArray);
|
||||
calloc.free(optsC);
|
||||
calloc.free(options);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
}
|
||||
|
||||
/// List of stashed states.
|
||||
|
|
|
@ -13,6 +13,7 @@ Pointer<git_status_list> listNew(Pointer<git_repository> repo) {
|
|||
final error = libgit2.git_status_list_new(out, repo, nullptr);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -68,6 +69,7 @@ int file({required Pointer<git_repository> repoPointer, required String path}) {
|
|||
calloc.free(pathC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.value;
|
||||
|
|
|
@ -62,6 +62,7 @@ Pointer<git_submodule> lookup({
|
|||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -113,6 +114,7 @@ void update({
|
|||
);
|
||||
|
||||
if (optionsError < 0) {
|
||||
calloc.free(options);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -144,6 +146,7 @@ Pointer<git_repository> open(Pointer<git_submodule> submodule) {
|
|||
final error = libgit2.git_submodule_open(out, submodule);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -180,6 +183,7 @@ Pointer<git_submodule> addSetup({
|
|||
calloc.free(pathC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -201,6 +205,8 @@ void clone({
|
|||
);
|
||||
|
||||
if (optionsError < 0) {
|
||||
calloc.free(out);
|
||||
calloc.free(options);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -254,9 +260,12 @@ int status({
|
|||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
final result = out.value;
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,8 +305,7 @@ void reload({
|
|||
|
||||
/// Get the name of submodule.
|
||||
String name(Pointer<git_submodule> submodule) {
|
||||
final result = libgit2.git_submodule_name(submodule);
|
||||
return result.cast<Utf8>().toDartString();
|
||||
return libgit2.git_submodule_name(submodule).cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Get the path to the submodule.
|
||||
|
@ -305,14 +313,12 @@ String name(Pointer<git_submodule> submodule) {
|
|||
/// The path is almost always the same as the submodule name, but the two
|
||||
/// are actually not required to match.
|
||||
String path(Pointer<git_submodule> submodule) {
|
||||
final result = libgit2.git_submodule_path(submodule);
|
||||
return result.cast<Utf8>().toDartString();
|
||||
return libgit2.git_submodule_path(submodule).cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Get the URL for the submodule.
|
||||
String url(Pointer<git_submodule> submodule) {
|
||||
final result = libgit2.git_submodule_url(submodule);
|
||||
return result.cast<Utf8>().toDartString();
|
||||
return libgit2.git_submodule_url(submodule).cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Set the URL for the submodule in the configuration.
|
||||
|
|
|
@ -14,6 +14,7 @@ List<String> list(Pointer<git_repository> repo) {
|
|||
var result = <String>[];
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
for (var i = 0; i < out.ref.count; i++) {
|
||||
|
@ -35,6 +36,7 @@ Pointer<git_tag> lookup({
|
|||
final error = libgit2.git_tag_lookup(out, repoPointer, oidPointer);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -51,6 +53,7 @@ Pointer<git_object> target(Pointer<git_tag> tag) {
|
|||
final error = libgit2.git_tag_target(out, tag);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -113,6 +116,7 @@ Pointer<git_oid> create({
|
|||
calloc.free(messageC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
|
|
@ -18,6 +18,7 @@ Pointer<git_tree> lookup({
|
|||
final error = libgit2.git_tree_lookup(out, repoPointer, oidPointer);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -86,6 +87,7 @@ Pointer<git_tree_entry> getByPath({
|
|||
calloc.free(pathC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
|
|
@ -24,6 +24,7 @@ Pointer<git_treebuilder> create({
|
|||
final error = libgit2.git_treebuilder_new(out, repoPointer, sourcePointer);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -38,6 +39,7 @@ Pointer<git_oid> write(Pointer<git_treebuilder> bld) {
|
|||
final error = libgit2.git_treebuilder_write(out, bld);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
|
|
|
@ -28,6 +28,10 @@ Pointer<git_worktree> create({
|
|||
);
|
||||
|
||||
if (optsError < 0) {
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
calloc.free(pathC);
|
||||
calloc.free(opts);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
|
@ -43,6 +47,7 @@ Pointer<git_worktree> create({
|
|||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -63,6 +68,7 @@ Pointer<git_worktree> lookup({
|
|||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
|
@ -88,12 +94,12 @@ void prune(Pointer<git_worktree> wt) {
|
|||
List<String> list(Pointer<git_repository> repo) {
|
||||
final out = calloc<git_strarray>();
|
||||
final error = libgit2.git_worktree_list(out, repo);
|
||||
final result = <String>[];
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = <String>[];
|
||||
for (var i = 0; i < out.ref.count; i++) {
|
||||
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import 'package:ffi/ffi.dart';
|
|||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'bindings/libgit2_bindings.dart';
|
||||
import 'bindings/blame.dart' as bindings;
|
||||
import 'util.dart';
|
||||
|
||||
class Blame with IterableMixin<BlameHunk> {
|
||||
/// Initializes a new instance of the [Blame] class from
|
||||
|
@ -44,14 +43,10 @@ class Blame with IterableMixin<BlameHunk> {
|
|||
int? minLine,
|
||||
int? maxLine,
|
||||
}) {
|
||||
libgit2.git_libgit2_init();
|
||||
|
||||
final int flagsInt = flags.fold(0, (acc, e) => acc | e.value);
|
||||
|
||||
_blamePointer = bindings.file(
|
||||
repoPointer: repo.pointer,
|
||||
path: path,
|
||||
flags: flagsInt,
|
||||
flags: flags.fold(0, (acc, e) => acc | e.value),
|
||||
minMatchCharacters: minMatchCharacters,
|
||||
newestCommit: newestCommit,
|
||||
oldestCommit: oldestCommit,
|
||||
|
|
|
@ -87,14 +87,12 @@ class Blob {
|
|||
int contextLines = 3,
|
||||
int interhunkLines = 0,
|
||||
}) {
|
||||
final int flagsInt = flags.fold(0, (acc, e) => acc | e.value);
|
||||
|
||||
final result = patch_bindings.fromBlobs(
|
||||
oldBlobPointer: _blobPointer,
|
||||
oldAsPath: oldAsPath,
|
||||
newBlobPointer: newBlob?.pointer,
|
||||
newAsPath: newAsPath,
|
||||
flags: flagsInt,
|
||||
flags: flags.fold(0, (acc, e) => acc | e.value),
|
||||
contextLines: contextLines,
|
||||
interhunkLines: interhunkLines,
|
||||
);
|
||||
|
@ -115,14 +113,12 @@ class Blob {
|
|||
int contextLines = 3,
|
||||
int interhunkLines = 0,
|
||||
}) {
|
||||
final int flagsInt = flags.fold(0, (acc, e) => acc | e.value);
|
||||
|
||||
final result = patch_bindings.fromBlobAndBuffer(
|
||||
oldBlobPointer: _blobPointer,
|
||||
oldAsPath: oldAsPath,
|
||||
buffer: buffer,
|
||||
bufferAsPath: bufferAsPath,
|
||||
flags: flagsInt,
|
||||
flags: flags.fold(0, (acc, e) => acc | e.value),
|
||||
contextLines: contextLines,
|
||||
interhunkLines: interhunkLines,
|
||||
);
|
||||
|
|
|
@ -52,15 +52,14 @@ class Branch {
|
|||
name: name,
|
||||
),
|
||||
);
|
||||
late final GitBranch type;
|
||||
ref.isBranch ? type = GitBranch.local : GitBranch.remote;
|
||||
ref.free();
|
||||
|
||||
_branchPointer = bindings.lookup(
|
||||
repoPointer: repo.pointer,
|
||||
branchName: name,
|
||||
branchType: type.value,
|
||||
branchType: ref.isBranch ? GitBranch.local.value : GitBranch.remote.value,
|
||||
);
|
||||
|
||||
ref.free();
|
||||
}
|
||||
|
||||
late final Pointer<git_reference> _branchPointer;
|
||||
|
@ -93,6 +92,7 @@ class Branch {
|
|||
static void delete({required Repository repo, required String name}) {
|
||||
final branch = Branch.lookup(repo: repo, name: name);
|
||||
bindings.delete(branch.pointer);
|
||||
branch.free();
|
||||
}
|
||||
|
||||
/// Renames an existing local branch reference.
|
||||
|
|
|
@ -45,8 +45,6 @@ class Commit {
|
|||
String? updateRef,
|
||||
String? messageEncoding,
|
||||
}) {
|
||||
final parentsPointers = parents.map((parent) => parent.pointer).toList();
|
||||
|
||||
return Oid(bindings.create(
|
||||
repoPointer: repo.pointer,
|
||||
updateRef: updateRef,
|
||||
|
@ -56,7 +54,7 @@ class Commit {
|
|||
message: message,
|
||||
treePointer: tree.pointer,
|
||||
parentCount: parents.length,
|
||||
parents: parentsPointers,
|
||||
parents: parents.map((e) => e.pointer).toList(),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -101,9 +99,10 @@ class Commit {
|
|||
|
||||
/// Get the tree pointed to by a commit.
|
||||
Tree get tree {
|
||||
final repo = bindings.owner(_commitPointer);
|
||||
final oid = bindings.tree(_commitPointer);
|
||||
return Tree(tree_bindings.lookup(repoPointer: repo, oidPointer: oid));
|
||||
return Tree(tree_bindings.lookup(
|
||||
repoPointer: bindings.owner(_commitPointer),
|
||||
oidPointer: bindings.tree(_commitPointer),
|
||||
));
|
||||
}
|
||||
|
||||
/// Releases memory allocated for commit object.
|
||||
|
|
|
@ -96,11 +96,9 @@ class Diff {
|
|||
int breakRewriteThreshold = 60,
|
||||
int renameLimit = 200,
|
||||
}) {
|
||||
final int flagsInt = flags.fold(0, (acc, e) => acc | e.value);
|
||||
|
||||
bindings.findSimilar(
|
||||
diffPointer: _diffPointer,
|
||||
flags: flagsInt,
|
||||
flags: flags.fold(0, (acc, e) => acc | e.value),
|
||||
renameThreshold: renameThreshold,
|
||||
copyThreshold: copyThreshold,
|
||||
renameFromRewriteThreshold: renameFromRewriteThreshold,
|
||||
|
@ -229,11 +227,9 @@ class DiffStats {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
String print({required Set<GitDiffStats> format, required int width}) {
|
||||
final int formatInt = format.fold(0, (acc, e) => acc | e.value);
|
||||
|
||||
return bindings.statsPrint(
|
||||
statsPointer: _diffStatsPointer,
|
||||
format: formatInt,
|
||||
format: format.fold(0, (acc, e) => acc | e.value),
|
||||
width: width,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -189,13 +189,10 @@ class Index with IterableMixin<IndexEntry> {
|
|||
int contextLines = 3,
|
||||
int interhunkLines = 0,
|
||||
}) {
|
||||
final repo = bindings.owner(_indexPointer);
|
||||
final int flagsInt = flags.fold(0, (acc, e) => acc | e.value);
|
||||
|
||||
return Diff(diff_bindings.indexToWorkdir(
|
||||
repoPointer: repo,
|
||||
repoPointer: bindings.owner(_indexPointer),
|
||||
indexPointer: _indexPointer,
|
||||
flags: flagsInt,
|
||||
flags: flags.fold(0, (acc, e) => acc | e.value),
|
||||
contextLines: contextLines,
|
||||
interhunkLines: interhunkLines,
|
||||
));
|
||||
|
@ -210,14 +207,11 @@ class Index with IterableMixin<IndexEntry> {
|
|||
int contextLines = 3,
|
||||
int interhunkLines = 0,
|
||||
}) {
|
||||
final repo = bindings.owner(_indexPointer);
|
||||
final int flagsInt = flags.fold(0, (acc, e) => acc | e.value);
|
||||
|
||||
return Diff(diff_bindings.treeToIndex(
|
||||
repoPointer: repo,
|
||||
repoPointer: bindings.owner(_indexPointer),
|
||||
treePointer: tree.pointer,
|
||||
indexPointer: _indexPointer,
|
||||
flags: flagsInt,
|
||||
flags: flags.fold(0, (acc, e) => acc | e.value),
|
||||
contextLines: contextLines,
|
||||
interhunkLines: interhunkLines,
|
||||
));
|
||||
|
@ -255,8 +249,9 @@ class IndexEntry {
|
|||
|
||||
/// Returns the UNIX file attributes of a index entry.
|
||||
GitFilemode get mode {
|
||||
final modeInt = _indexEntryPointer.ref.mode;
|
||||
return GitFilemode.values.singleWhere((mode) => modeInt == mode.value);
|
||||
return GitFilemode.values.singleWhere(
|
||||
(mode) => _indexEntryPointer.ref.mode == mode.value,
|
||||
);
|
||||
}
|
||||
|
||||
/// Sets the UNIX file attributes of a index entry.
|
||||
|
|
|
@ -241,8 +241,10 @@ class Reference {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
bool get hasLog {
|
||||
final owner = bindings.owner(_refPointer);
|
||||
return bindings.hasLog(repoPointer: owner, name: name);
|
||||
return bindings.hasLog(
|
||||
repoPointer: bindings.owner(_refPointer),
|
||||
name: name,
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns a [RefLog] object.
|
||||
|
|
|
@ -9,9 +9,10 @@ class RefLog with IterableMixin<RefLogEntry> {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
RefLog(Reference ref) {
|
||||
final repo = ref.owner;
|
||||
final name = ref.name;
|
||||
_reflogPointer = bindings.read(repoPointer: repo.pointer, name: name);
|
||||
_reflogPointer = bindings.read(
|
||||
repoPointer: ref.owner.pointer,
|
||||
name: ref.name,
|
||||
);
|
||||
}
|
||||
|
||||
/// Pointer to memory address for allocated reflog object.
|
||||
|
|
|
@ -207,13 +207,10 @@ class Repository {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
void setHead(String target) {
|
||||
late final Oid oid;
|
||||
|
||||
if (isValidShaHex(target)) {
|
||||
oid = Oid.fromSHA(repo: this, sha: target);
|
||||
bindings.setHeadDetached(
|
||||
repoPointer: _repoPointer,
|
||||
commitishPointer: oid.pointer,
|
||||
commitishPointer: this[target].pointer,
|
||||
);
|
||||
} else {
|
||||
bindings.setHead(repoPointer: _repoPointer, refname: target);
|
||||
|
@ -450,11 +447,10 @@ class Repository {
|
|||
required String sha,
|
||||
Set<GitSort> sorting = const {GitSort.none},
|
||||
}) {
|
||||
final oid = Oid.fromSHA(repo: this, sha: sha);
|
||||
final walker = RevWalk(this);
|
||||
|
||||
walker.sorting(sorting);
|
||||
walker.push(oid);
|
||||
walker.push(this[sha]);
|
||||
final result = walker.walk();
|
||||
|
||||
walker.free();
|
||||
|
@ -759,12 +755,10 @@ class Repository {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Oid mergeBase({required String a, required String b}) {
|
||||
final oidA = Oid.fromSHA(repo: this, sha: a);
|
||||
final oidB = Oid.fromSHA(repo: this, sha: b);
|
||||
return Oid(merge_bindings.mergeBase(
|
||||
repoPointer: _repoPointer,
|
||||
aPointer: oidA.pointer,
|
||||
bPointer: oidB.pointer,
|
||||
aPointer: this[a].pointer,
|
||||
bPointer: this[b].pointer,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -994,10 +988,9 @@ class Repository {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
void reset({required String target, required GitReset resetType}) {
|
||||
final oid = Oid.fromSHA(repo: this, sha: target);
|
||||
final object = object_bindings.lookup(
|
||||
repoPointer: _repoPointer,
|
||||
oidPointer: oid.pointer,
|
||||
oidPointer: this[target].pointer,
|
||||
type: GitObject.any.value,
|
||||
);
|
||||
|
||||
|
@ -1375,13 +1368,10 @@ class Repository {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
bool descendantOf({required String commitSHA, required String ancestorSHA}) {
|
||||
final commit = Oid.fromSHA(repo: this, sha: commitSHA);
|
||||
final ancestor = Oid.fromSHA(repo: this, sha: ancestorSHA);
|
||||
|
||||
return graph_bindings.descendantOf(
|
||||
repoPointer: _repoPointer,
|
||||
commitPointer: commit.pointer,
|
||||
ancestorPointer: ancestor.pointer,
|
||||
commitPointer: this[commitSHA].pointer,
|
||||
ancestorPointer: this[ancestorSHA].pointer,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1394,13 +1384,10 @@ class Repository {
|
|||
required String localSHA,
|
||||
required String upstreamSHA,
|
||||
}) {
|
||||
final local = Oid.fromSHA(repo: this, sha: localSHA);
|
||||
final upstream = Oid.fromSHA(repo: this, sha: upstreamSHA);
|
||||
|
||||
return graph_bindings.aheadBehind(
|
||||
repoPointer: _repoPointer,
|
||||
localPointer: local.pointer,
|
||||
upstreamPointer: upstream.pointer,
|
||||
localPointer: this[localSHA].pointer,
|
||||
upstreamPointer: this[upstreamSHA].pointer,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,10 +17,8 @@ class RevWalk {
|
|||
///
|
||||
/// Default sorting is reverse chronological order (default in git).
|
||||
List<Commit> walk() {
|
||||
final repoPointer = bindings.repository(_revWalkPointer);
|
||||
|
||||
final pointers = bindings.walk(
|
||||
repoPointer: repoPointer,
|
||||
repoPointer: bindings.repository(_revWalkPointer),
|
||||
walkerPointer: _revWalkPointer,
|
||||
);
|
||||
|
||||
|
|
|
@ -140,10 +140,8 @@ class Submodule {
|
|||
Set<GitSubmoduleStatus> status({
|
||||
GitSubmoduleIgnore ignore = GitSubmoduleIgnore.unspecified,
|
||||
}) {
|
||||
final repo = bindings.owner(_submodulePointer);
|
||||
|
||||
final resultInt = bindings.status(
|
||||
repoPointer: repo,
|
||||
repoPointer: bindings.owner(_submodulePointer),
|
||||
name: name,
|
||||
ignore: ignore.value,
|
||||
);
|
||||
|
@ -192,8 +190,11 @@ class Submodule {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
set url(String url) {
|
||||
final repo = bindings.owner(_submodulePointer);
|
||||
bindings.setUrl(repoPointer: repo, name: name, url: url);
|
||||
bindings.setUrl(
|
||||
repoPointer: bindings.owner(_submodulePointer),
|
||||
name: name,
|
||||
url: url,
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns the branch for the submodule.
|
||||
|
@ -206,8 +207,11 @@ class Submodule {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
set branch(String branch) {
|
||||
final repo = bindings.owner(_submodulePointer);
|
||||
bindings.setBranch(repoPointer: repo, name: name, branch: branch);
|
||||
bindings.setBranch(
|
||||
repoPointer: bindings.owner(_submodulePointer),
|
||||
name: name,
|
||||
branch: branch,
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns the [Oid] for the submodule in the current HEAD tree or
|
||||
|
@ -266,8 +270,11 @@ class Submodule {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
set updateRule(GitSubmoduleUpdate rule) {
|
||||
final repo = bindings.owner(_submodulePointer);
|
||||
bindings.setUpdateRule(repoPointer: repo, name: name, update: rule.value);
|
||||
bindings.setUpdateRule(
|
||||
repoPointer: bindings.owner(_submodulePointer),
|
||||
name: name,
|
||||
update: rule.value,
|
||||
);
|
||||
}
|
||||
|
||||
/// Releases memory allocated for submodule object.
|
||||
|
|
|
@ -52,6 +52,7 @@ class Tag {
|
|||
oidPointer: target.pointer,
|
||||
type: targetType.value,
|
||||
);
|
||||
|
||||
final result = bindings.create(
|
||||
repoPointer: repo.pointer,
|
||||
tagName: tagName,
|
||||
|
@ -62,6 +63,7 @@ class Tag {
|
|||
);
|
||||
|
||||
object_bindings.free(object);
|
||||
|
||||
return Oid(result);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue