mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
fix: free pointers to pointers
This commit is contained in:
parent
2ceead3917
commit
dee3acb7c9
34 changed files with 621 additions and 289 deletions
|
@ -27,11 +27,14 @@ Pointer<git_annotated_commit> lookup({
|
|||
oidPointer,
|
||||
);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,11 +52,14 @@ Pointer<git_annotated_commit> fromRef({
|
|||
referencePointer,
|
||||
);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,13 +81,15 @@ Pointer<git_annotated_commit> fromRevSpec({
|
|||
revspecC,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(revspecC);
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,14 +113,16 @@ Pointer<git_annotated_commit> fromFetchHead({
|
|||
oid,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(branchNameC);
|
||||
calloc.free(remoteUrlC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,27 +19,25 @@ Object? getAttribute({
|
|||
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||
libgit2.git_attr_get(out, repoPointer, flags, pathC, nameC);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(pathC);
|
||||
calloc.free(nameC);
|
||||
|
||||
final attributeValue = libgit2.git_attr_value(out.value);
|
||||
final attributeValue = libgit2.git_attr_value(result);
|
||||
|
||||
if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_UNSPECIFIED) {
|
||||
calloc.free(out);
|
||||
return null;
|
||||
}
|
||||
if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_TRUE) {
|
||||
calloc.free(out);
|
||||
return true;
|
||||
}
|
||||
if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_FALSE) {
|
||||
calloc.free(out);
|
||||
return false;
|
||||
}
|
||||
if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_STRING) {
|
||||
final result = out.value.cast<Utf8>().toDartString();
|
||||
calloc.free(out);
|
||||
return result;
|
||||
return result.cast<Utf8>().toDartString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -47,14 +47,16 @@ Pointer<git_blame> file({
|
|||
|
||||
final error = libgit2.git_blame_file(out, repoPointer, pathC, options);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(pathC);
|
||||
calloc.free(options);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,13 +82,15 @@ Pointer<git_blame> buffer({
|
|||
buffer.length,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(bufferC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,14 @@ Pointer<git_blob> lookup({
|
|||
final out = calloc<Pointer<git_blob>>();
|
||||
final error = libgit2.git_blob_lookup(out, repoPointer, oidPointer);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +131,11 @@ Pointer<git_oid> createFromDisk({
|
|||
Pointer<git_blob> duplicate(Pointer<git_blob> source) {
|
||||
final out = calloc<Pointer<git_blob>>();
|
||||
libgit2.git_blob_dup(out, source);
|
||||
return out.value;
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Get a buffer with the filtered content of a blob.
|
||||
|
@ -156,15 +163,19 @@ String filterContent({
|
|||
|
||||
final error = libgit2.git_blob_filter(out, blobPointer, asPathC, opts);
|
||||
|
||||
late final String result;
|
||||
if (out.ref.ptr != nullptr) {
|
||||
result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
}
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
calloc.free(asPathC);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,13 +35,15 @@ List<Pointer<git_reference>> list({
|
|||
error = libgit2.git_branch_next(reference, refType, iterator.value);
|
||||
if (error == 0) {
|
||||
result.add(reference.value);
|
||||
calloc.free(refType);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
calloc.free(reference);
|
||||
calloc.free(refType);
|
||||
}
|
||||
|
||||
libgit2.git_branch_iterator_free(iterator.value);
|
||||
calloc.free(iterator);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -65,13 +67,15 @@ Pointer<git_reference> lookup({
|
|||
branchType,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(branchNameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,13 +107,15 @@ Pointer<git_reference> create({
|
|||
forceC,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(branchNameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,13 +198,14 @@ String name(Pointer<git_reference> ref) {
|
|||
final out = calloc<Pointer<Int8>>();
|
||||
final error = libgit2.git_branch_name(out, ref);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.value.cast<Utf8>().toDartString();
|
||||
calloc.free(out);
|
||||
return result;
|
||||
return result.cast<Utf8>().toDartString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,14 +225,15 @@ String remoteName({
|
|||
final branchNameC = branchName.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_branch_remote_name(out, repoPointer, branchNameC);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
calloc.free(branchNameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -240,11 +248,14 @@ Pointer<git_reference> getUpstream(Pointer<git_reference> branch) {
|
|||
final out = calloc<Pointer<git_reference>>();
|
||||
final error = libgit2.git_branch_upstream(out, branch);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,14 +297,15 @@ String upstreamName({
|
|||
final branchNameC = branchName.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_branch_upstream_name(out, repoPointer, branchNameC);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
calloc.free(branchNameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -316,14 +328,15 @@ String upstreamRemote({
|
|||
branchNameC,
|
||||
);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
calloc.free(branchNameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -346,12 +359,15 @@ String upstreamMerge({
|
|||
branchNameC,
|
||||
);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
calloc.free(branchNameC);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,11 +17,14 @@ Pointer<git_commit> lookup({
|
|||
final out = calloc<Pointer<git_commit>>();
|
||||
final error = libgit2.git_commit_lookup(out, repoPointer, oidPointer);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,17 +127,18 @@ String createBuffer({
|
|||
parentsC,
|
||||
);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
calloc.free(updateRefC);
|
||||
calloc.free(messageEncodingC);
|
||||
calloc.free(messageC);
|
||||
calloc.free(parentsC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -196,7 +200,12 @@ Pointer<git_oid> amend({
|
|||
Pointer<git_commit> duplicate(Pointer<git_commit> source) {
|
||||
final out = calloc<Pointer<git_commit>>();
|
||||
libgit2.git_commit_dup(out, source);
|
||||
return out.value;
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Get the encoding for the message of a commit, as a string representing a
|
||||
|
@ -254,14 +263,15 @@ String headerField({
|
|||
final fieldC = field.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_commit_header_field(out, commitPointer, fieldC);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
calloc.free(fieldC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -292,11 +302,14 @@ Pointer<git_commit> parent({
|
|||
final out = calloc<Pointer<git_commit>>();
|
||||
final error = libgit2.git_commit_parent(out, commitPointer, position);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -315,11 +328,14 @@ Pointer<git_commit> nthGenAncestor({
|
|||
final out = calloc<Pointer<git_commit>>();
|
||||
final error = libgit2.git_commit_nth_gen_ancestor(out, commitPointer, n);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -350,7 +366,12 @@ Pointer<git_oid> treeOid(Pointer<git_commit> commit) {
|
|||
Pointer<git_tree> tree(Pointer<git_commit> commit) {
|
||||
final out = calloc<Pointer<git_tree>>();
|
||||
libgit2.git_commit_tree(out, commit);
|
||||
return out.value;
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Reverts the given commit, producing changes in the index and working
|
||||
|
@ -393,13 +414,15 @@ Pointer<git_index> revertCommit({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,11 +29,14 @@ Pointer<git_config> openDefault() {
|
|||
final out = calloc<Pointer<git_config>>();
|
||||
final error = libgit2.git_config_open_default(out);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,12 +57,14 @@ String findGlobal() {
|
|||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_config_find_global(out);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -73,12 +78,14 @@ String findSystem() {
|
|||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_config_find_system(out);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -93,12 +100,14 @@ String findXdg() {
|
|||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_config_find_xdg(out);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +120,12 @@ String findXdg() {
|
|||
Pointer<git_config> snapshot(Pointer<git_config> config) {
|
||||
final out = calloc<Pointer<git_config>>();
|
||||
libgit2.git_config_snapshot(out, config);
|
||||
return out.value;
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Get the config entry of a config variable.
|
||||
|
@ -122,16 +136,18 @@ Pointer<git_config_entry> getEntry({
|
|||
required String variable,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_config_entry>>();
|
||||
final name = variable.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_config_get_entry(out, configPointer, name);
|
||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_config_get_entry(out, configPointer, nameC);
|
||||
|
||||
calloc.free(name);
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,10 +158,10 @@ void setBool({
|
|||
required String variable,
|
||||
required bool value,
|
||||
}) {
|
||||
final name = variable.toNativeUtf8().cast<Int8>();
|
||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
||||
final valueC = value ? 1 : 0;
|
||||
libgit2.git_config_set_bool(configPointer, name, valueC);
|
||||
calloc.free(name);
|
||||
libgit2.git_config_set_bool(configPointer, nameC, valueC);
|
||||
calloc.free(nameC);
|
||||
}
|
||||
|
||||
/// Set the value of an integer config variable in the config file with the
|
||||
|
@ -155,9 +171,9 @@ void setInt({
|
|||
required String variable,
|
||||
required int value,
|
||||
}) {
|
||||
final name = variable.toNativeUtf8().cast<Int8>();
|
||||
libgit2.git_config_set_int64(configPointer, name, value);
|
||||
calloc.free(name);
|
||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
||||
libgit2.git_config_set_int64(configPointer, nameC, value);
|
||||
calloc.free(nameC);
|
||||
}
|
||||
|
||||
/// Set the value of a string config variable in the config file with the
|
||||
|
@ -167,10 +183,10 @@ void setString({
|
|||
required String variable,
|
||||
required String value,
|
||||
}) {
|
||||
final name = variable.toNativeUtf8().cast<Int8>();
|
||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
||||
final valueC = value.toNativeUtf8().cast<Int8>();
|
||||
libgit2.git_config_set_string(configPointer, name, valueC);
|
||||
calloc.free(name);
|
||||
libgit2.git_config_set_string(configPointer, nameC, valueC);
|
||||
calloc.free(nameC);
|
||||
calloc.free(valueC);
|
||||
}
|
||||
|
||||
|
@ -178,7 +194,12 @@ void setString({
|
|||
Pointer<git_config_iterator> iterator(Pointer<git_config> cfg) {
|
||||
final out = calloc<Pointer<git_config_iterator>>();
|
||||
libgit2.git_config_iterator_new(out, cfg);
|
||||
return out.value;
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Delete a config variable from the config file with the highest level
|
||||
|
@ -189,10 +210,10 @@ void delete({
|
|||
required Pointer<git_config> configPointer,
|
||||
required String variable,
|
||||
}) {
|
||||
final name = variable.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_config_delete_entry(configPointer, name);
|
||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_config_delete_entry(configPointer, nameC);
|
||||
|
||||
calloc.free(name);
|
||||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
|
@ -208,7 +229,7 @@ List<String> multivarValues({
|
|||
required String variable,
|
||||
String? regexp,
|
||||
}) {
|
||||
final name = variable.toNativeUtf8().cast<Int8>();
|
||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
||||
final regexpC = regexp?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||
final iterator = calloc<Pointer<git_config_iterator>>();
|
||||
final entry = calloc<Pointer<git_config_entry>>();
|
||||
|
@ -216,7 +237,7 @@ List<String> multivarValues({
|
|||
libgit2.git_config_multivar_iterator_new(
|
||||
iterator,
|
||||
configPointer,
|
||||
name,
|
||||
nameC,
|
||||
regexpC,
|
||||
);
|
||||
|
||||
|
@ -232,8 +253,9 @@ List<String> multivarValues({
|
|||
}
|
||||
}
|
||||
|
||||
calloc.free(name);
|
||||
calloc.free(nameC);
|
||||
calloc.free(regexpC);
|
||||
libgit2.git_config_iterator_free(iterator.value);
|
||||
calloc.free(iterator);
|
||||
calloc.free(entry);
|
||||
|
||||
|
@ -250,13 +272,13 @@ void setMultivar({
|
|||
required String regexp,
|
||||
required String value,
|
||||
}) {
|
||||
final name = variable.toNativeUtf8().cast<Int8>();
|
||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
||||
final regexpC = regexp.toNativeUtf8().cast<Int8>();
|
||||
final valueC = value.toNativeUtf8().cast<Int8>();
|
||||
|
||||
libgit2.git_config_set_multivar(configPointer, name, regexpC, valueC);
|
||||
libgit2.git_config_set_multivar(configPointer, nameC, regexpC, valueC);
|
||||
|
||||
calloc.free(name);
|
||||
calloc.free(nameC);
|
||||
calloc.free(regexpC);
|
||||
calloc.free(valueC);
|
||||
}
|
||||
|
@ -270,12 +292,12 @@ void deleteMultivar({
|
|||
required String variable,
|
||||
required String regexp,
|
||||
}) {
|
||||
final name = variable.toNativeUtf8().cast<Int8>();
|
||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
||||
final regexpC = regexp.toNativeUtf8().cast<Int8>();
|
||||
|
||||
libgit2.git_config_delete_multivar(configPointer, name, regexpC);
|
||||
libgit2.git_config_delete_multivar(configPointer, nameC, regexpC);
|
||||
|
||||
calloc.free(name);
|
||||
calloc.free(nameC);
|
||||
calloc.free(regexpC);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,10 +15,13 @@ Pointer<git_credential> userPass({
|
|||
|
||||
libgit2.git_credential_userpass_plaintext_new(out, usernameC, passwordC);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(usernameC);
|
||||
calloc.free(passwordC);
|
||||
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Create a new passphrase-protected ssh key credential object.
|
||||
|
@ -42,12 +45,15 @@ Pointer<git_credential> sshKey({
|
|||
passPhraseC,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(usernameC);
|
||||
calloc.free(publicKeyC);
|
||||
calloc.free(privateKeyC);
|
||||
calloc.free(passPhraseC);
|
||||
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Create a new ssh key credential object used for querying an ssh-agent.
|
||||
|
@ -57,9 +63,12 @@ Pointer<git_credential> sshKeyFromAgent(String username) {
|
|||
|
||||
libgit2.git_credential_ssh_key_from_agent(out, usernameC);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(usernameC);
|
||||
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Create a new ssh key credential object reading the keys from memory.
|
||||
|
@ -83,10 +92,13 @@ Pointer<git_credential> sshKeyFromMemory({
|
|||
passPhraseC,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(usernameC);
|
||||
calloc.free(publicKeyC);
|
||||
calloc.free(privateKeyC);
|
||||
calloc.free(passPhraseC);
|
||||
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -32,13 +32,15 @@ Pointer<git_describe_result> commit({
|
|||
|
||||
final error = libgit2.git_describe_commit(out, commitPointer.cast(), opts);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,13 +70,15 @@ Pointer<git_describe_result> workdir({
|
|||
|
||||
final error = libgit2.git_describe_workdir(out, repo, opts);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,8 +110,9 @@ String format({
|
|||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
calloc.free(opts);
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -31,13 +31,15 @@ Pointer<git_diff> indexToIndex({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,9 +60,12 @@ Pointer<git_diff> indexToWorkdir({
|
|||
|
||||
libgit2.git_diff_index_to_workdir(out, repoPointer, indexPointer, opts);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Create a diff between a tree and repository index.
|
||||
|
@ -87,9 +92,12 @@ Pointer<git_diff> treeToIndex({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Create a diff between a tree and the working directory.
|
||||
|
@ -116,13 +124,15 @@ Pointer<git_diff> treeToWorkdir({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,13 +165,15 @@ Pointer<git_diff> treeToWorkdirWithIndex({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,13 +203,15 @@ Pointer<git_diff> treeToTree({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,9 +249,12 @@ Pointer<git_diff> parse(String content) {
|
|||
final contentC = content.toNativeUtf8().cast<Int8>();
|
||||
libgit2.git_diff_from_buffer(out, contentC, content.length);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(contentC);
|
||||
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Transform a diff marking file renames, copies, etc.
|
||||
|
@ -324,11 +341,14 @@ Pointer<git_diff_stats> stats(Pointer<git_diff> diff) {
|
|||
final out = calloc<Pointer<git_diff_stats>>();
|
||||
final error = libgit2.git_diff_get_stats(out, diff);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -355,12 +375,14 @@ String statsPrint({
|
|||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_diff_stats_to_buf(out, statsPointer, format, width);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -369,10 +391,14 @@ String statsPrint({
|
|||
String addToBuf(Pointer<git_diff> diff) {
|
||||
final out = calloc<git_buf>();
|
||||
libgit2.git_diff_to_buf(out, diff, git_diff_format_t.GIT_DIFF_FORMAT_PATCH);
|
||||
|
||||
final result = out.ref.ptr == nullptr
|
||||
? ''
|
||||
: out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -462,14 +488,16 @@ Pointer<git_index> applyToTree({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(payload);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,12 @@ import 'package:libgit2dart/src/util.dart';
|
|||
Pointer<git_index> newInMemory() {
|
||||
final out = calloc<Pointer<git_index>>();
|
||||
libgit2.git_index_new(out);
|
||||
return out.value;
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Read index capabilities flags.
|
||||
|
@ -266,6 +271,8 @@ void addFromBuffer({
|
|||
buffer.length,
|
||||
);
|
||||
|
||||
calloc.free(bufferC);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
@ -452,12 +459,12 @@ List<Map<String, Pointer<git_index_entry>>> conflictList(
|
|||
'our': ourOut.value,
|
||||
'their': theirOut.value,
|
||||
});
|
||||
calloc.free(ancestorOut);
|
||||
calloc.free(ourOut);
|
||||
calloc.free(theirOut);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
calloc.free(ancestorOut);
|
||||
calloc.free(ourOut);
|
||||
calloc.free(theirOut);
|
||||
}
|
||||
|
||||
libgit2.git_index_conflict_iterator_free(iterator.value);
|
||||
|
|
|
@ -13,7 +13,11 @@ Pointer<git_mailmap> init() {
|
|||
final out = calloc<Pointer<git_mailmap>>();
|
||||
libgit2.git_mailmap_new(out);
|
||||
|
||||
return out.value;
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Create a new mailmap instance containing a single mailmap file.
|
||||
|
@ -23,9 +27,12 @@ Pointer<git_mailmap> fromBuffer(String buffer) {
|
|||
|
||||
libgit2.git_mailmap_from_buffer(out, bufferC, buffer.length);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(bufferC);
|
||||
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Create a new mailmap instance from a repository, loading mailmap files based
|
||||
|
@ -43,11 +50,14 @@ Pointer<git_mailmap> fromRepository(Pointer<git_repository> repo) {
|
|||
final out = calloc<Pointer<git_mailmap>>();
|
||||
final error = libgit2.git_mailmap_from_repository(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +97,11 @@ Pointer<git_signature> resolveSignature({
|
|||
final out = calloc<Pointer<git_signature>>();
|
||||
libgit2.git_mailmap_resolve_signature(out, mailmapPointer, signaturePointer);
|
||||
|
||||
return out.value;
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Add a single entry to the given mailmap object. If the entry already exists,
|
||||
|
|
|
@ -234,12 +234,16 @@ String mergeFileFromIndex({
|
|||
nullptr,
|
||||
);
|
||||
|
||||
if (error < 0) {
|
||||
late final String result;
|
||||
if (out.ref.ptr != nullptr) {
|
||||
result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.len);
|
||||
}
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.len);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -275,13 +279,15 @@ Pointer<git_index> mergeCommits({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -318,13 +324,15 @@ Pointer<git_index> mergeTrees({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,15 +30,21 @@ List<Map<String, Pointer>> list(Pointer<git_repository> repo) {
|
|||
if (nextError >= 0) {
|
||||
final out = calloc<Pointer<git_note>>();
|
||||
libgit2.git_note_read(out, repo, notesRef, annotatedOid);
|
||||
calloc.free(noteOid);
|
||||
result.add({'note': out.value, 'annotatedOid': annotatedOid});
|
||||
|
||||
final note = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
result.add({'note': note, 'annotatedOid': annotatedOid});
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
calloc.free(noteOid);
|
||||
}
|
||||
|
||||
calloc.free(notesRef);
|
||||
libgit2.git_note_iterator_free(iterator.value);
|
||||
calloc.free(iterator);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -57,13 +63,15 @@ Pointer<git_note> lookup({
|
|||
final notesRefC = notesRef.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_note_read(out, repoPointer, notesRefC, oidPointer);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(notesRefC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,11 +26,14 @@ Pointer<git_object> lookup({
|
|||
final out = calloc<Pointer<git_object>>();
|
||||
final error = libgit2.git_object_lookup(out, repoPointer, oidPointer, type);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,12 @@ import 'package:libgit2dart/src/util.dart';
|
|||
Pointer<git_odb> create() {
|
||||
final out = calloc<Pointer<git_odb>>();
|
||||
libgit2.git_odb_new(out);
|
||||
return out.value;
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Add an on-disk alternate to an existing Object DB.
|
||||
|
@ -120,11 +125,14 @@ Pointer<git_odb_object> read({
|
|||
final out = calloc<Pointer<git_odb_object>>();
|
||||
final error = libgit2.git_odb_read(out, odbPointer, oidPointer);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,14 +193,15 @@ Pointer<git_oid> write({
|
|||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
final buffer = data.toNativeUtf8().cast<Int8>();
|
||||
libgit2.git_odb_stream_write(stream.value, buffer, data.length);
|
||||
final bufferC = data.toNativeUtf8().cast<Int8>();
|
||||
libgit2.git_odb_stream_write(stream.value, bufferC, data.length);
|
||||
|
||||
final out = calloc<git_oid>();
|
||||
libgit2.git_odb_stream_finalize_write(out, stream.value);
|
||||
|
||||
calloc.free(buffer);
|
||||
calloc.free(bufferC);
|
||||
libgit2.git_odb_stream_free(stream.value);
|
||||
calloc.free(stream);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
|
|
@ -7,10 +7,10 @@ import 'package:libgit2dart/src/util.dart';
|
|||
/// Parse N characters of a hex formatted object id into a git_oid.
|
||||
Pointer<git_oid> fromStrN(String hex) {
|
||||
final out = calloc<git_oid>();
|
||||
final str = hex.toNativeUtf8().cast<Int8>();
|
||||
libgit2.git_oid_fromstrn(out, str, hex.length);
|
||||
final hexC = hex.toNativeUtf8().cast<Int8>();
|
||||
libgit2.git_oid_fromstrn(out, hexC, hex.length);
|
||||
|
||||
calloc.free(str);
|
||||
calloc.free(hexC);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
@ -18,10 +18,10 @@ Pointer<git_oid> fromStrN(String hex) {
|
|||
/// Parse a hex formatted object id into a git_oid.
|
||||
Pointer<git_oid> fromSHA(String hex) {
|
||||
final out = calloc<git_oid>();
|
||||
final str = hex.toNativeUtf8().cast<Int8>();
|
||||
libgit2.git_oid_fromstr(out, str);
|
||||
final hexC = hex.toNativeUtf8().cast<Int8>();
|
||||
libgit2.git_oid_fromstr(out, hexC);
|
||||
|
||||
calloc.free(str);
|
||||
calloc.free(hexC);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
|
|
@ -12,11 +12,14 @@ Pointer<git_packbuilder> init(Pointer<git_repository> repo) {
|
|||
final out = calloc<Pointer<git_packbuilder>>();
|
||||
final error = libgit2.git_packbuilder_new(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,14 +42,17 @@ Pointer<git_patch> fromBuffers({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(oldAsPathC);
|
||||
calloc.free(newAsPathC);
|
||||
calloc.free(opts);
|
||||
// We are not freeing buffers because patch object does not have reference to
|
||||
// underlying buffers. So if the buffer is freed the patch text becomes
|
||||
// corrupted.
|
||||
// We are not freeing buffers `oldBufferC` and `newBufferC` because patch
|
||||
// object does not have reference to underlying buffers. So if the buffer is
|
||||
// freed the patch text becomes corrupted.
|
||||
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Directly generate a patch from the difference between two blobs.
|
||||
|
@ -83,11 +86,14 @@ Pointer<git_patch> fromBlobs({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(oldAsPathC);
|
||||
calloc.free(newAsPathC);
|
||||
calloc.free(opts);
|
||||
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Directly generate a patch from the difference between a blob and a buffer.
|
||||
|
@ -124,11 +130,17 @@ Pointer<git_patch> fromBlobAndBuffer({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(oldAsPathC);
|
||||
calloc.free(bufferAsPathC);
|
||||
calloc.free(opts);
|
||||
// We are not freeing buffer `bufferC` because patch object does not have
|
||||
// reference to underlying buffers. So if the buffer is freed the patch text
|
||||
// becomes corrupted.
|
||||
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Return a patch for an entry in the diff list.
|
||||
|
@ -145,11 +157,14 @@ Pointer<git_patch> fromDiff({
|
|||
final out = calloc<Pointer<git_patch>>();
|
||||
final error = libgit2.git_patch_from_diff(out, diffPointer, index);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,9 +187,13 @@ Map<String, Object> hunk({
|
|||
final linesInHunk = calloc<Int64>();
|
||||
libgit2.git_patch_get_hunk(out, linesInHunk.cast(), patchPointer, hunkIndex);
|
||||
|
||||
final hunk = out.value;
|
||||
final linesN = linesInHunk.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(linesInHunk);
|
||||
return {'hunk': out.value, 'linesN': linesN};
|
||||
|
||||
return {'hunk': hunk, 'linesN': linesN};
|
||||
}
|
||||
|
||||
/// Get line counts of each type in a patch.
|
||||
|
@ -211,7 +230,11 @@ Pointer<git_diff_line> lines({
|
|||
final out = calloc<Pointer<git_diff_line>>();
|
||||
libgit2.git_patch_get_line_in_hunk(out, patchPointer, hunkIndex, lineOfHunk);
|
||||
|
||||
return out.value;
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Get the content of a patch as a single diff text.
|
||||
|
@ -221,12 +244,14 @@ String text(Pointer<git_patch> patch) {
|
|||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_patch_to_buf(out, patch);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,13 +40,15 @@ Pointer<git_rebase> init({
|
|||
opts,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,11 +63,14 @@ Pointer<git_rebase> open(Pointer<git_repository> repo) {
|
|||
|
||||
final error = libgit2.git_rebase_open(out, repo, opts);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,11 +105,14 @@ Pointer<git_rebase_operation> next(Pointer<git_rebase> rebase) {
|
|||
final out = calloc<Pointer<git_rebase_operation>>();
|
||||
final error = libgit2.git_rebase_next(out, rebase);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,11 +33,14 @@ Pointer<git_reference> resolve(Pointer<git_reference> ref) {
|
|||
final out = calloc<Pointer<git_reference>>();
|
||||
final error = libgit2.git_reference_resolve(out, ref);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,13 +59,15 @@ Pointer<git_reference> lookup({
|
|||
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_reference_lookup(out, repoPointer, nameC);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,14 +115,16 @@ Pointer<git_reference> rename({
|
|||
logMessageC,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(newNameC);
|
||||
calloc.free(logMessageC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,10 +156,10 @@ bool hasLog({
|
|||
required Pointer<git_repository> repoPointer,
|
||||
required String name,
|
||||
}) {
|
||||
final refname = name.toNativeUtf8().cast<Int8>();
|
||||
final result = libgit2.git_reference_has_log(repoPointer, refname);
|
||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||
final result = libgit2.git_reference_has_log(repoPointer, nameC);
|
||||
|
||||
calloc.free(refname);
|
||||
calloc.free(nameC);
|
||||
|
||||
return result == 1 || false;
|
||||
}
|
||||
|
@ -244,14 +251,16 @@ Pointer<git_reference> createDirect({
|
|||
logMessageC,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
calloc.free(logMessageC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,15 +312,17 @@ Pointer<git_reference> createSymbolic({
|
|||
logMessageC,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
calloc.free(targetC);
|
||||
calloc.free(logMessageC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -348,13 +359,15 @@ Pointer<git_reference> setTarget({
|
|||
logMessageC,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(logMessageC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -386,14 +399,16 @@ Pointer<git_reference> setTargetSymbolic({
|
|||
logMessageC,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(targetC);
|
||||
calloc.free(logMessageC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -421,11 +436,14 @@ Pointer<git_object> peel({
|
|||
final out = calloc<Pointer<git_object>>();
|
||||
final error = libgit2.git_reference_peel(out, refPointer, type);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -433,7 +451,12 @@ Pointer<git_object> peel({
|
|||
Pointer<git_reference> duplicate(Pointer<git_reference> source) {
|
||||
final out = calloc<Pointer<git_reference>>();
|
||||
libgit2.git_reference_dup(out, source);
|
||||
return out.value;
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Free the given reference.
|
||||
|
|
|
@ -19,9 +19,12 @@ Pointer<git_reflog> read({
|
|||
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||
libgit2.git_reflog_read(out, repoPointer, nameC);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Write an existing in-memory reflog object back to disk using an atomic file
|
||||
|
|
|
@ -66,14 +66,15 @@ String transform({
|
|||
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_refspec_transform(out, refspecPointer, nameC);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -90,14 +91,15 @@ String rTransform({
|
|||
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_refspec_rtransform(out, refspecPointer, nameC);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,6 @@ import 'package:libgit2dart/src/oid.dart';
|
|||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Get a list of the configured remotes for a repo.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
List<String> list(Pointer<git_repository> repo) {
|
||||
final out = calloc<git_strarray>();
|
||||
libgit2.git_remote_list(out, repo);
|
||||
|
@ -38,13 +36,15 @@ Pointer<git_remote> lookup({
|
|||
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_remote_lookup(out, repoPointer, nameC);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,14 +62,16 @@ Pointer<git_remote> create({
|
|||
final urlC = url.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_remote_create(out, repoPointer, nameC, urlC);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
calloc.free(urlC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,15 +97,17 @@ Pointer<git_remote> createWithFetchSpec({
|
|||
fetchC,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
calloc.free(urlC);
|
||||
calloc.free(fetchC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,13 +19,15 @@ Pointer<git_repository> open(String path) {
|
|||
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_repository_open(out, pathC);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(pathC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +52,10 @@ String discover({
|
|||
calloc.free(ceilingDirsC);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -90,6 +95,9 @@ Pointer<git_repository> init({
|
|||
|
||||
final error = libgit2.git_repository_init_ext(out, pathC, opts);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(pathC);
|
||||
calloc.free(workdirPathC);
|
||||
calloc.free(descriptionC);
|
||||
|
@ -99,10 +107,9 @@ Pointer<git_repository> init({
|
|||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,6 +165,9 @@ Pointer<git_repository> clone({
|
|||
|
||||
final error = libgit2.git_clone(out, urlC, localPathC, cloneOptions);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(urlC);
|
||||
calloc.free(localPathC);
|
||||
calloc.free(checkoutBranchC);
|
||||
|
@ -166,10 +176,9 @@ Pointer<git_repository> clone({
|
|||
RemoteCallbacks.reset();
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,9 +221,9 @@ void setNamespace({
|
|||
required Pointer<git_repository> repoPointer,
|
||||
String? namespace,
|
||||
}) {
|
||||
final nmspace = namespace?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||
libgit2.git_repository_set_namespace(repoPointer, nmspace);
|
||||
calloc.free(nmspace);
|
||||
final namespaceC = namespace?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||
libgit2.git_repository_set_namespace(repoPointer, namespaceC);
|
||||
calloc.free(namespaceC);
|
||||
}
|
||||
|
||||
/// Check if a repository is bare or not.
|
||||
|
@ -248,11 +257,14 @@ Pointer<git_reference> head(Pointer<git_repository> repo) {
|
|||
final out = calloc<Pointer<git_reference>>();
|
||||
final error = libgit2.git_repository_head(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -338,7 +350,12 @@ Map<String, String> identity(Pointer<git_repository> repo) {
|
|||
Pointer<git_config> config(Pointer<git_repository> repo) {
|
||||
final out = calloc<Pointer<git_config>>();
|
||||
libgit2.git_repository_config(out, repo);
|
||||
return out.value;
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Get a snapshot of the repository's configuration.
|
||||
|
@ -352,7 +369,12 @@ Pointer<git_config> config(Pointer<git_repository> repo) {
|
|||
Pointer<git_config> configSnapshot(Pointer<git_repository> repo) {
|
||||
final out = calloc<Pointer<git_config>>();
|
||||
libgit2.git_repository_config_snapshot(out, repo);
|
||||
return out.value;
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Get the Index file for this repository.
|
||||
|
@ -364,7 +386,12 @@ Pointer<git_config> configSnapshot(Pointer<git_repository> repo) {
|
|||
Pointer<git_index> index(Pointer<git_repository> repo) {
|
||||
final out = calloc<Pointer<git_index>>();
|
||||
libgit2.git_repository_index(out, repo);
|
||||
return out.value;
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Determine if the repository was a shallow clone.
|
||||
|
@ -393,12 +420,14 @@ String message(Pointer<git_repository> repo) {
|
|||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_repository_message(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -420,11 +449,14 @@ Pointer<git_odb> odb(Pointer<git_repository> repo) {
|
|||
final out = calloc<Pointer<git_odb>>();
|
||||
final error = libgit2.git_repository_odb(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -441,11 +473,14 @@ Pointer<git_refdb> refdb(Pointer<git_repository> repo) {
|
|||
final out = calloc<Pointer<git_refdb>>();
|
||||
final error = libgit2.git_repository_refdb(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -517,15 +552,15 @@ void setWorkdir({
|
|||
required String path,
|
||||
required bool updateGitlink,
|
||||
}) {
|
||||
final workdir = path.toNativeUtf8().cast<Int8>();
|
||||
final workdirC = path.toNativeUtf8().cast<Int8>();
|
||||
final updateGitlinkC = updateGitlink ? 1 : 0;
|
||||
final error = libgit2.git_repository_set_workdir(
|
||||
repoPointer,
|
||||
workdir,
|
||||
workdirC,
|
||||
updateGitlinkC,
|
||||
);
|
||||
|
||||
calloc.free(workdir);
|
||||
calloc.free(workdirC);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
|
|
|
@ -46,13 +46,15 @@ Pointer<git_object> revParseSingle({
|
|||
|
||||
final error = libgit2.git_revparse_single(out, repoPointer, specC);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(specC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,18 +85,19 @@ List<Pointer> revParseExt({
|
|||
specC,
|
||||
);
|
||||
|
||||
calloc.free(specC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(objectOut);
|
||||
calloc.free(referenceOut);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = <Pointer>[];
|
||||
result.add(objectOut.value);
|
||||
if (referenceOut.value != nullptr) {
|
||||
result.add(referenceOut.value);
|
||||
}
|
||||
|
||||
calloc.free(objectOut);
|
||||
calloc.free(referenceOut);
|
||||
calloc.free(specC);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,11 +23,14 @@ Pointer<git_revwalk> create(Pointer<git_repository> repo) {
|
|||
final out = calloc<Pointer<git_revwalk>>();
|
||||
final error = libgit2.git_revwalk_new(out, repo);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,10 +155,10 @@ List<Pointer<git_commit>> walk({
|
|||
oidPointer: oid,
|
||||
);
|
||||
result.add(commit);
|
||||
calloc.free(oid);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
calloc.free(oid);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -22,14 +22,16 @@ Pointer<git_signature> create({
|
|||
final emailC = email.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_signature_new(out, nameC, emailC, time, offset);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
calloc.free(emailC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,14 +44,16 @@ Pointer<git_signature> now({required String name, required String email}) {
|
|||
final emailC = email.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_signature_now(out, nameC, emailC);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
calloc.free(emailC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,15 +65,23 @@ Pointer<git_signature> now({required String name, required String email}) {
|
|||
Pointer<git_signature> defaultSignature(Pointer<git_repository> repo) {
|
||||
final out = calloc<Pointer<git_signature>>();
|
||||
libgit2.git_signature_default(out, repo);
|
||||
return out.value;
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Create a copy of an existing signature.
|
||||
Pointer<git_signature> duplicate(Pointer<git_signature> sig) {
|
||||
final out = calloc<Pointer<git_signature>>();
|
||||
libgit2.git_signature_dup(out, sig);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,11 +13,14 @@ Pointer<git_status_list> listNew(Pointer<git_repository> repo) {
|
|||
final out = calloc<Pointer<git_status_list>>();
|
||||
final error = libgit2.git_status_list_new(out, repo, nullptr);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,14 +65,14 @@ int file({required Pointer<git_repository> repoPointer, required String path}) {
|
|||
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_status_file(out, repoPointer, pathC);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(pathC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = out.value;
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,13 +55,15 @@ Pointer<git_submodule> lookup({
|
|||
|
||||
final error = libgit2.git_submodule_lookup(out, repoPointer, nameC);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,11 +132,14 @@ Pointer<git_repository> open(Pointer<git_submodule> submodule) {
|
|||
final out = calloc<Pointer<git_repository>>();
|
||||
final error = libgit2.git_submodule_open(out, submodule);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,14 +170,16 @@ Pointer<git_submodule> addSetup({
|
|||
useGitlinkC,
|
||||
);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(urlC);
|
||||
calloc.free(pathC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,10 +236,11 @@ int status({
|
|||
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||
libgit2.git_submodule_status(out, repoPointer, nameC, ignore);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
|
||||
final result = out.value;
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,11 +36,14 @@ Pointer<git_tag> lookup({
|
|||
final out = calloc<Pointer<git_tag>>();
|
||||
final error = libgit2.git_tag_lookup(out, repoPointer, oidPointer);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,11 +57,14 @@ Pointer<git_object> target(Pointer<git_tag> tag) {
|
|||
final out = calloc<Pointer<git_object>>();
|
||||
final error = libgit2.git_tag_target(out, tag);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,11 +18,14 @@ Pointer<git_tree> lookup({
|
|||
final out = calloc<Pointer<git_tree>>();
|
||||
final error = libgit2.git_tree_lookup(out, repoPointer, oidPointer);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,13 +85,15 @@ Pointer<git_tree_entry> getByPath({
|
|||
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_tree_entry_bypath(out, rootPointer, pathC);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(pathC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,11 +24,14 @@ Pointer<git_treebuilder> create({
|
|||
final out = calloc<Pointer<git_treebuilder>>();
|
||||
final error = libgit2.git_treebuilder_new(out, repoPointer, sourcePointer);
|
||||
|
||||
if (error < 0) {
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,15 +33,17 @@ Pointer<git_worktree> create({
|
|||
|
||||
final error = libgit2.git_worktree_add(out, repoPointer, nameC, pathC, opts);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
calloc.free(pathC);
|
||||
calloc.free(opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,13 +58,15 @@ Pointer<git_worktree> lookup({
|
|||
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_worktree_lookup(out, repoPointer, nameC);
|
||||
|
||||
final result = out.value;
|
||||
|
||||
calloc.free(out);
|
||||
calloc.free(nameC);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +84,11 @@ bool isPrunable(Pointer<git_worktree> wt) {
|
|||
GIT_WORKTREE_PRUNE_OPTIONS_VERSION,
|
||||
);
|
||||
|
||||
return libgit2.git_worktree_is_prunable(wt, opts) > 0 || false;
|
||||
final result = libgit2.git_worktree_is_prunable(wt, opts);
|
||||
|
||||
calloc.free(opts);
|
||||
|
||||
return result > 0 || false;
|
||||
}
|
||||
|
||||
/// Prune working tree.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue