mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
refactor: revert 'use ffi Arena for resource management'
This commit is contained in:
parent
6a097c1841
commit
a78c38d8e3
9 changed files with 588 additions and 620 deletions
|
@ -10,16 +10,14 @@ import '../util.dart';
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_commit> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) {
|
Pointer<git_commit> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_commit>>();
|
||||||
final out = arena<Pointer<git_commit>>();
|
final error = libgit2.git_commit_lookup(out, repo, id);
|
||||||
final error = libgit2.git_commit_lookup(out, repo, id);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the encoding for the message of a commit, as a string representing a standard encoding name.
|
/// Get the encoding for the message of a commit, as a string representing a standard encoding name.
|
||||||
|
|
|
@ -11,33 +11,31 @@ import '../util.dart';
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_config> newConfig() {
|
Pointer<git_config> newConfig() {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_config>>();
|
||||||
final out = arena<Pointer<git_config>>();
|
final error = libgit2.git_config_new(out);
|
||||||
final error = libgit2.git_config_new(out);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new config instance containing a single on-disk file
|
/// Create a new config instance containing a single on-disk file
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_config> open(String path) {
|
Pointer<git_config> open(String path) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_config>>();
|
||||||
final out = arena<Pointer<git_config>>();
|
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||||
final pathC = path.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_config_open_ondisk(out, pathC);
|
||||||
final error = libgit2.git_config_open_ondisk(out, pathC);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(pathC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
} else {
|
if (error < 0) {
|
||||||
return out.value;
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
} else {
|
||||||
});
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Open the global, XDG and system configuration files
|
/// Open the global, XDG and system configuration files
|
||||||
|
@ -48,16 +46,14 @@ Pointer<git_config> open(String path) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_config> openDefault() {
|
Pointer<git_config> openDefault() {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_config>>();
|
||||||
final out = arena<Pointer<git_config>>();
|
final error = libgit2.git_config_open_default(out);
|
||||||
final error = libgit2.git_config_open_default(out);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Locate the path to the global configuration file
|
/// Locate the path to the global configuration file
|
||||||
|
@ -74,17 +70,14 @@ Pointer<git_config> openDefault() {
|
||||||
///
|
///
|
||||||
/// Throws an error if file has not been found.
|
/// Throws an error if file has not been found.
|
||||||
String findGlobal() {
|
String findGlobal() {
|
||||||
return using((Arena arena) {
|
final out = calloc<git_buf>(sizeOf<git_buf>());
|
||||||
final out = arena<git_buf>(sizeOf<git_buf>());
|
final error = libgit2.git_config_find_global(out);
|
||||||
final error = libgit2.git_config_find_global(out);
|
|
||||||
final path = out.ref.ptr.cast<Utf8>().toDartString();
|
|
||||||
|
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
throw Error();
|
throw Error();
|
||||||
} else {
|
} else {
|
||||||
return path;
|
return out.ref.ptr.cast<Utf8>().toDartString();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Locate the path to the system configuration file
|
/// Locate the path to the system configuration file
|
||||||
|
@ -93,17 +86,14 @@ String findGlobal() {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
String findSystem() {
|
String findSystem() {
|
||||||
return using((Arena arena) {
|
final out = calloc<git_buf>();
|
||||||
final out = arena<git_buf>();
|
final error = libgit2.git_config_find_system(out);
|
||||||
final error = libgit2.git_config_find_system(out);
|
|
||||||
final path = out.ref.ptr.cast<Utf8>().toDartString();
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return path;
|
return out.ref.ptr.cast<Utf8>().toDartString();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Locate the path to the global xdg compatible configuration file
|
/// Locate the path to the global xdg compatible configuration file
|
||||||
|
@ -113,17 +103,14 @@ String findSystem() {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
String findXdg() {
|
String findXdg() {
|
||||||
return using((Arena arena) {
|
final out = calloc<git_buf>();
|
||||||
final out = arena<git_buf>();
|
final error = libgit2.git_config_find_xdg(out);
|
||||||
final error = libgit2.git_config_find_xdg(out);
|
|
||||||
final path = out.ref.ptr.cast<Utf8>().toDartString();
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return path;
|
return out.ref.ptr.cast<Utf8>().toDartString();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a snapshot of the configuration.
|
/// Create a snapshot of the configuration.
|
||||||
|
@ -134,33 +121,31 @@ String findXdg() {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_config> snapshot(Pointer<git_config> config) {
|
Pointer<git_config> snapshot(Pointer<git_config> config) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_config>>();
|
||||||
final out = arena<Pointer<git_config>>();
|
final error = libgit2.git_config_snapshot(out, config);
|
||||||
final error = libgit2.git_config_snapshot(out, config);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the value of a config variable.
|
/// Get the value of a config variable.
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
String getValue(Pointer<git_config> cfg, String variable) {
|
String getValue(Pointer<git_config> cfg, String variable) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_config_entry>>();
|
||||||
final out = arena<Pointer<git_config_entry>>();
|
final name = variable.toNativeUtf8().cast<Int8>();
|
||||||
final name = variable.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_config_get_entry(out, cfg, name);
|
||||||
final error = libgit2.git_config_get_entry(out, cfg, name);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(name);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
} else {
|
if (error < 0) {
|
||||||
return out.value.ref.value.cast<Utf8>().toDartString();
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
} else {
|
||||||
});
|
return out.value.ref.value.cast<Utf8>().toDartString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the value of a boolean config variable in the config file with the
|
/// Set the value of a boolean config variable in the config file with the
|
||||||
|
@ -168,15 +153,15 @@ String getValue(Pointer<git_config> cfg, String variable) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void setBool(Pointer<git_config> cfg, String variable, bool value) {
|
void setBool(Pointer<git_config> cfg, String variable, bool value) {
|
||||||
using((Arena arena) {
|
final name = variable.toNativeUtf8().cast<Int8>();
|
||||||
final name = variable.toNativeUtf8(allocator: arena).cast<Int8>();
|
final valueC = value ? 1 : 0;
|
||||||
final valueC = value ? 1 : 0;
|
final error = libgit2.git_config_set_bool(cfg, name, valueC);
|
||||||
final error = libgit2.git_config_set_bool(cfg, name, valueC);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(name);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
}
|
if (error < 0) {
|
||||||
});
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the value of an integer config variable in the config file with the
|
/// Set the value of an integer config variable in the config file with the
|
||||||
|
@ -184,14 +169,14 @@ void setBool(Pointer<git_config> cfg, String variable, bool value) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void setInt(Pointer<git_config> cfg, String variable, int value) {
|
void setInt(Pointer<git_config> cfg, String variable, int value) {
|
||||||
using((Arena arena) {
|
final name = variable.toNativeUtf8().cast<Int8>();
|
||||||
final name = variable.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_config_set_int64(cfg, name, value);
|
||||||
final error = libgit2.git_config_set_int64(cfg, name, value);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(name);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
}
|
if (error < 0) {
|
||||||
});
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the value of a string config variable in the config file with the
|
/// Set the value of a string config variable in the config file with the
|
||||||
|
@ -199,34 +184,36 @@ void setInt(Pointer<git_config> cfg, String variable, int value) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void setString(Pointer<git_config> cfg, String variable, String value) {
|
void setString(Pointer<git_config> cfg, String variable, String value) {
|
||||||
using((Arena arena) {
|
final name = variable.toNativeUtf8().cast<Int8>();
|
||||||
final name = variable.toNativeUtf8(allocator: arena).cast<Int8>();
|
final valueC = value.toNativeUtf8().cast<Int8>();
|
||||||
final valueC = value.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_config_set_string(cfg, name, valueC);
|
||||||
final error = libgit2.git_config_set_string(cfg, name, valueC);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(name);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
calloc.free(valueC);
|
||||||
}
|
|
||||||
});
|
if (error < 0) {
|
||||||
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate over all the config variables.
|
/// Iterate over all the config variables.
|
||||||
Map<String, String> getEntries(Pointer<git_config> cfg) {
|
Map<String, String> getEntries(Pointer<git_config> cfg) {
|
||||||
return using((Arena arena) {
|
final iterator = calloc<Pointer<git_config_iterator>>();
|
||||||
final iterator = arena<Pointer<git_config_iterator>>();
|
final entry = calloc<Pointer<git_config_entry>>();
|
||||||
final entry = arena<Pointer<git_config_entry>>();
|
libgit2.git_config_iterator_new(iterator, cfg);
|
||||||
libgit2.git_config_iterator_new(iterator, cfg);
|
var error = 0;
|
||||||
var error = 0;
|
final entries = <String, String>{};
|
||||||
final entries = <String, String>{};
|
|
||||||
|
|
||||||
while (error != -31) {
|
while (error != -31) {
|
||||||
error = libgit2.git_config_next(entry, iterator.value);
|
error = libgit2.git_config_next(entry, iterator.value);
|
||||||
entries[entry.value.ref.name.cast<Utf8>().toDartString()] =
|
entries[entry.value.ref.name.cast<Utf8>().toDartString()] =
|
||||||
entry.value.ref.value.cast<Utf8>().toDartString();
|
entry.value.ref.value.cast<Utf8>().toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return entries;
|
calloc.free(iterator);
|
||||||
});
|
calloc.free(entry);
|
||||||
|
|
||||||
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete a config variable from the config file with the highest level
|
/// Delete a config variable from the config file with the highest level
|
||||||
|
@ -234,14 +221,14 @@ Map<String, String> getEntries(Pointer<git_config> cfg) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void delete(Pointer<git_config> cfg, String variable) {
|
void delete(Pointer<git_config> cfg, String variable) {
|
||||||
using((Arena arena) {
|
final name = variable.toNativeUtf8().cast<Int8>();
|
||||||
final name = variable.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_config_delete_entry(cfg, name);
|
||||||
final error = libgit2.git_config_delete_entry(cfg, name);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(name);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
}
|
if (error < 0) {
|
||||||
});
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate over the values of a multivar
|
/// Iterate over the values of a multivar
|
||||||
|
@ -253,27 +240,29 @@ List<String> multivarValues(
|
||||||
String variable,
|
String variable,
|
||||||
String? regexp,
|
String? regexp,
|
||||||
) {
|
) {
|
||||||
return using((Arena arena) {
|
final name = variable.toNativeUtf8().cast<Int8>();
|
||||||
final name = variable.toNativeUtf8(allocator: arena).cast<Int8>();
|
final regexpC = regexp?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
final regexpC =
|
final iterator = calloc<Pointer<git_config_iterator>>();
|
||||||
regexp?.toNativeUtf8(allocator: arena).cast<Int8>() ?? nullptr;
|
final entry = calloc<Pointer<git_config_entry>>();
|
||||||
final iterator = arena<Pointer<git_config_iterator>>();
|
libgit2.git_config_multivar_iterator_new(iterator, cfg, name, regexpC);
|
||||||
final entry = arena<Pointer<git_config_entry>>();
|
var error = 0;
|
||||||
libgit2.git_config_multivar_iterator_new(iterator, cfg, name, regexpC);
|
final entries = <String>[];
|
||||||
var error = 0;
|
|
||||||
final entries = <String>[];
|
|
||||||
|
|
||||||
while (error == 0) {
|
while (error == 0) {
|
||||||
error = libgit2.git_config_next(entry, iterator.value);
|
error = libgit2.git_config_next(entry, iterator.value);
|
||||||
if (error != -31) {
|
if (error != -31) {
|
||||||
entries.add(entry.value.ref.value.cast<Utf8>().toDartString());
|
entries.add(entry.value.ref.value.cast<Utf8>().toDartString());
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return entries;
|
calloc.free(name);
|
||||||
});
|
calloc.free(regexpC);
|
||||||
|
calloc.free(iterator);
|
||||||
|
calloc.free(entry);
|
||||||
|
|
||||||
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the value of a multivar config variable in the config file with the
|
/// Set the value of a multivar config variable in the config file with the
|
||||||
|
@ -286,28 +275,27 @@ void setMultivar(
|
||||||
String regexp,
|
String regexp,
|
||||||
String value,
|
String value,
|
||||||
) {
|
) {
|
||||||
using((Arena arena) {
|
final name = variable.toNativeUtf8().cast<Int8>();
|
||||||
final name = variable.toNativeUtf8(allocator: arena).cast<Int8>();
|
final regexpC = regexp.toNativeUtf8().cast<Int8>();
|
||||||
final regexpC = regexp.toNativeUtf8(allocator: arena).cast<Int8>();
|
final valueC = value.toNativeUtf8().cast<Int8>();
|
||||||
final valueC = value.toNativeUtf8(allocator: arena).cast<Int8>();
|
libgit2.git_config_set_multivar(cfg, name, regexpC, valueC);
|
||||||
libgit2.git_config_set_multivar(cfg, name, regexpC, valueC);
|
|
||||||
});
|
calloc.free(name);
|
||||||
|
calloc.free(regexpC);
|
||||||
|
calloc.free(valueC);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deletes one or several values from a multivar in the config file
|
/// Deletes one or several values from a multivar in the config file
|
||||||
/// with the highest level (usually the local one).
|
/// with the highest level (usually the local one).
|
||||||
///
|
///
|
||||||
/// The regexp is applied case-sensitively on the value.
|
/// The regexp is applied case-sensitively on the value.
|
||||||
void deleteMultivar(
|
void deleteMultivar(Pointer<git_config> cfg, String variable, String regexp) {
|
||||||
Pointer<git_config> cfg,
|
final name = variable.toNativeUtf8().cast<Int8>();
|
||||||
String variable,
|
final regexpC = regexp.toNativeUtf8().cast<Int8>();
|
||||||
String regexp,
|
libgit2.git_config_delete_multivar(cfg, name, regexpC);
|
||||||
) {
|
|
||||||
using((Arena arena) {
|
calloc.free(name);
|
||||||
final name = variable.toNativeUtf8(allocator: arena).cast<Int8>();
|
calloc.free(regexpC);
|
||||||
final regexpC = regexp.toNativeUtf8(allocator: arena).cast<Int8>();
|
|
||||||
libgit2.git_config_delete_multivar(cfg, name, regexpC);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Free the configuration and its associated memory and files.
|
/// Free the configuration and its associated memory and files.
|
||||||
|
|
|
@ -62,12 +62,12 @@ Pointer<git_oid> writeTree(Pointer<git_index> index) {
|
||||||
|
|
||||||
/// Find the first position of any entries which point to given path in the Git index.
|
/// Find the first position of any entries which point to given path in the Git index.
|
||||||
bool find(Pointer<git_index> index, String path) {
|
bool find(Pointer<git_index> index, String path) {
|
||||||
return using((Arena arena) {
|
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||||
final pathC = path.toNativeUtf8(allocator: arena).cast<Int8>();
|
final result = libgit2.git_index_find(nullptr, index, pathC);
|
||||||
final result = libgit2.git_index_find(nullptr, index, pathC);
|
|
||||||
|
|
||||||
return result == git_error_code.GIT_ENOTFOUND ? false : true;
|
calloc.free(pathC);
|
||||||
});
|
|
||||||
|
return result == git_error_code.GIT_ENOTFOUND ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the count of entries currently in the index.
|
/// Get the count of entries currently in the index.
|
||||||
|
@ -98,16 +98,16 @@ Pointer<git_index_entry> getByPath(
|
||||||
String path,
|
String path,
|
||||||
int stage,
|
int stage,
|
||||||
) {
|
) {
|
||||||
return using((Arena arena) {
|
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||||
final pathC = path.toNativeUtf8(allocator: arena).cast<Int8>();
|
final result = libgit2.git_index_get_bypath(index, pathC, stage);
|
||||||
final result = libgit2.git_index_get_bypath(index, pathC, stage);
|
|
||||||
|
|
||||||
if (result == nullptr) {
|
calloc.free(pathC);
|
||||||
throw ArgumentError.value('$path was not found');
|
|
||||||
} else {
|
if (result == nullptr) {
|
||||||
return result;
|
throw ArgumentError.value('$path was not found');
|
||||||
}
|
} else {
|
||||||
});
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear the contents (all the entries) of an index object.
|
/// Clear the contents (all the entries) of an index object.
|
||||||
|
@ -152,14 +152,14 @@ void add(Pointer<git_index> index, Pointer<git_index_entry> sourceEntry) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void addByPath(Pointer<git_index> index, String path) {
|
void addByPath(Pointer<git_index> index, String path) {
|
||||||
using((Arena arena) {
|
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||||
final pathC = path.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_index_add_bypath(index, pathC);
|
||||||
final error = libgit2.git_index_add_bypath(index, pathC);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(pathC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
}
|
if (error < 0) {
|
||||||
});
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add or update index entries matching files in the working directory.
|
/// Add or update index entries matching files in the working directory.
|
||||||
|
@ -172,32 +172,35 @@ void addByPath(Pointer<git_index> index, String path) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void addAll(Pointer<git_index> index, List<String> pathspec) {
|
void addAll(Pointer<git_index> index, List<String> pathspec) {
|
||||||
using((Arena arena) {
|
var pathspecC = calloc<git_strarray>();
|
||||||
var pathspecC = arena<git_strarray>();
|
final List<Pointer<Int8>> pathPointers =
|
||||||
final List<Pointer<Int8>> pathPointers = pathspec
|
pathspec.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
|
||||||
.map((e) => e.toNativeUtf8(allocator: arena).cast<Int8>())
|
final Pointer<Pointer<Int8>> strArray = calloc(pathspec.length);
|
||||||
.toList();
|
|
||||||
final Pointer<Pointer<Int8>> strArray = arena(pathspec.length);
|
|
||||||
|
|
||||||
for (var i = 0; i < pathspec.length; i++) {
|
for (var i = 0; i < pathspec.length; i++) {
|
||||||
strArray[i] = pathPointers[i];
|
strArray[i] = pathPointers[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
pathspecC.ref.strings = strArray;
|
pathspecC.ref.strings = strArray;
|
||||||
pathspecC.ref.count = pathspec.length;
|
pathspecC.ref.count = pathspec.length;
|
||||||
|
|
||||||
final error = libgit2.git_index_add_all(
|
final error = libgit2.git_index_add_all(
|
||||||
index,
|
index,
|
||||||
pathspecC,
|
pathspecC,
|
||||||
0,
|
0,
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(pathspecC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
for (var p in pathPointers) {
|
||||||
}
|
calloc.free(p);
|
||||||
});
|
}
|
||||||
|
calloc.free(strArray);
|
||||||
|
|
||||||
|
if (error < 0) {
|
||||||
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write an existing index object from memory back to disk using an atomic file lock.
|
/// Write an existing index object from memory back to disk using an atomic file lock.
|
||||||
|
@ -215,45 +218,48 @@ void write(Pointer<git_index> index) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void remove(Pointer<git_index> index, String path, int stage) {
|
void remove(Pointer<git_index> index, String path, int stage) {
|
||||||
using((Arena arena) {
|
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||||
final pathC = path.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_index_remove(index, pathC, stage);
|
||||||
final error = libgit2.git_index_remove(index, pathC, stage);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(pathC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
}
|
if (error < 0) {
|
||||||
});
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove all matching index entries.
|
/// Remove all matching index entries.
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void removeAll(Pointer<git_index> index, List<String> pathspec) {
|
void removeAll(Pointer<git_index> index, List<String> pathspec) {
|
||||||
using((Arena arena) {
|
final pathspecC = calloc<git_strarray>();
|
||||||
final pathspecC = arena<git_strarray>();
|
final List<Pointer<Int8>> pathPointers =
|
||||||
final List<Pointer<Int8>> pathPointers = pathspec
|
pathspec.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
|
||||||
.map((e) => e.toNativeUtf8(allocator: arena).cast<Int8>())
|
final Pointer<Pointer<Int8>> strArray = calloc(pathspec.length);
|
||||||
.toList();
|
|
||||||
final Pointer<Pointer<Int8>> strArray = arena(pathspec.length);
|
|
||||||
|
|
||||||
for (var i = 0; i < pathspec.length; i++) {
|
for (var i = 0; i < pathspec.length; i++) {
|
||||||
strArray[i] = pathPointers[i];
|
strArray[i] = pathPointers[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
pathspecC.ref.strings = strArray;
|
pathspecC.ref.strings = strArray;
|
||||||
pathspecC.ref.count = pathspec.length;
|
pathspecC.ref.count = pathspec.length;
|
||||||
|
|
||||||
final error = libgit2.git_index_remove_all(
|
final error = libgit2.git_index_remove_all(
|
||||||
index,
|
index,
|
||||||
pathspecC,
|
pathspecC,
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(pathspecC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
for (var p in pathPointers) {
|
||||||
}
|
calloc.free(p);
|
||||||
});
|
}
|
||||||
|
calloc.free(strArray);
|
||||||
|
|
||||||
|
if (error < 0) {
|
||||||
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the repository this index relates to.
|
/// Get the repository this index relates to.
|
||||||
|
|
|
@ -42,17 +42,17 @@ Pointer<git_oid> fromSHA(String hex) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
String toSHA(Pointer<git_oid> id) {
|
String toSHA(Pointer<git_oid> id) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Int8>(40);
|
||||||
final out = arena<Int8>(40);
|
final error = libgit2.git_oid_fmt(out, id);
|
||||||
final error = libgit2.git_oid_fmt(out, id);
|
final result = out.cast<Utf8>().toDartString(length: 40);
|
||||||
final result = out.cast<Utf8>().toDartString(length: 40);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(out);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
} else {
|
if (error < 0) {
|
||||||
return result;
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
} else {
|
||||||
});
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compare two oid structures.
|
/// Compare two oid structures.
|
||||||
|
|
|
@ -35,16 +35,14 @@ Pointer<git_oid> target(Pointer<git_reference> ref) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_reference> resolve(Pointer<git_reference> ref) {
|
Pointer<git_reference> resolve(Pointer<git_reference> ref) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_reference>>();
|
||||||
final out = arena<Pointer<git_reference>>();
|
final error = libgit2.git_reference_resolve(out, ref);
|
||||||
final error = libgit2.git_reference_resolve(out, ref);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lookup a reference by name in a repository.
|
/// Lookup a reference by name in a repository.
|
||||||
|
@ -55,17 +53,17 @@ Pointer<git_reference> resolve(Pointer<git_reference> ref) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_reference> lookup(Pointer<git_repository> repo, String name) {
|
Pointer<git_reference> lookup(Pointer<git_repository> repo, String name) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_reference>>();
|
||||||
final out = arena<Pointer<git_reference>>();
|
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||||
final nameC = name.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_reference_lookup(out, repo, nameC);
|
||||||
final error = libgit2.git_reference_lookup(out, repo, nameC);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(nameC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
} else {
|
if (error < 0) {
|
||||||
return out.value;
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
} else {
|
||||||
});
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lookup a reference by DWIMing its short name.
|
/// Lookup a reference by DWIMing its short name.
|
||||||
|
@ -75,27 +73,25 @@ Pointer<git_reference> lookup(Pointer<git_repository> repo, String name) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_reference> lookupDWIM(Pointer<git_repository> repo, String name) {
|
Pointer<git_reference> lookupDWIM(Pointer<git_repository> repo, String name) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_reference>>();
|
||||||
final out = arena<Pointer<git_reference>>();
|
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||||
final nameC = name.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_reference_dwim(out, repo, nameC);
|
||||||
final error = libgit2.git_reference_dwim(out, repo, nameC);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(nameC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
} else {
|
if (error < 0) {
|
||||||
return out.value;
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
} else {
|
||||||
});
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the full name of a reference.
|
/// Get the full name of a reference.
|
||||||
String name(Pointer<git_reference> ref) {
|
String name(Pointer<git_reference> ref) {
|
||||||
return using((Arena arena) {
|
var result = calloc<Int8>();
|
||||||
var result = arena<Int8>();
|
result = libgit2.git_reference_name(ref);
|
||||||
result = libgit2.git_reference_name(ref);
|
|
||||||
|
|
||||||
return result.cast<Utf8>().toDartString();
|
return result.cast<Utf8>().toDartString();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the reference's short name.
|
/// Get the reference's short name.
|
||||||
|
@ -126,66 +122,64 @@ Pointer<git_reference> rename(
|
||||||
bool force,
|
bool force,
|
||||||
String? logMessage,
|
String? logMessage,
|
||||||
) {
|
) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_reference>>();
|
||||||
final out = arena<Pointer<git_reference>>();
|
final newNameC = newName.toNativeUtf8().cast<Int8>();
|
||||||
final newNameC = newName.toNativeUtf8(allocator: arena).cast<Int8>();
|
final forceC = force == true ? 1 : 0;
|
||||||
final forceC = force == true ? 1 : 0;
|
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final error = libgit2.git_reference_rename(
|
||||||
final error = libgit2.git_reference_rename(
|
out,
|
||||||
out,
|
ref,
|
||||||
ref,
|
newNameC,
|
||||||
newNameC,
|
forceC,
|
||||||
forceC,
|
logMessageC,
|
||||||
logMessageC,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(newNameC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
calloc.free(logMessageC);
|
||||||
} else {
|
|
||||||
return out.value;
|
if (error < 0) {
|
||||||
}
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
});
|
} else {
|
||||||
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fill a list with all the references that can be found in a repository.
|
/// Fill a list with all the references that can be found in a repository.
|
||||||
///
|
///
|
||||||
/// The string array will be filled with the names of all references;
|
|
||||||
/// these values are owned by the user and should be free'd manually when no longer needed.
|
|
||||||
///
|
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
List<String> list(Pointer<git_repository> repo) {
|
List<String> list(Pointer<git_repository> repo) {
|
||||||
return using((Arena arena) {
|
var array = calloc<git_strarray>();
|
||||||
var array = arena<git_strarray>();
|
final error = libgit2.git_reference_list(array, repo);
|
||||||
final error = libgit2.git_reference_list(array, repo);
|
var result = <String>[];
|
||||||
var result = <String>[];
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
for (var i = 0; i < array.ref.count; i++) {
|
for (var i = 0; i < array.ref.count; i++) {
|
||||||
result.add(
|
result.add(
|
||||||
array.ref.strings.elementAt(i).value.cast<Utf8>().toDartString());
|
array.ref.strings.elementAt(i).value.cast<Utf8>().toDartString());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
calloc.free(array);
|
||||||
});
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if a reflog exists for the specified reference.
|
/// Check if a reflog exists for the specified reference.
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
bool hasLog(Pointer<git_repository> repo, String name) {
|
bool hasLog(Pointer<git_repository> repo, String name) {
|
||||||
return using((Arena arena) {
|
final refname = name.toNativeUtf8().cast<Int8>();
|
||||||
final refname = name.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_reference_has_log(repo, refname);
|
||||||
final error = libgit2.git_reference_has_log(repo, refname);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(refname);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
} else {
|
if (error < 0) {
|
||||||
return error == 1 ? true : false;
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
} else {
|
||||||
});
|
return error == 1 ? true : false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if a reference is a local branch.
|
/// Check if a reference is a local branch.
|
||||||
|
@ -241,26 +235,27 @@ Pointer<git_reference> createDirect(
|
||||||
bool force,
|
bool force,
|
||||||
String? logMessage,
|
String? logMessage,
|
||||||
) {
|
) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_reference>>();
|
||||||
final out = arena<Pointer<git_reference>>();
|
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||||
final nameC = name.toNativeUtf8(allocator: arena).cast<Int8>();
|
final forceC = force == true ? 1 : 0;
|
||||||
final forceC = force == true ? 1 : 0;
|
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final error = libgit2.git_reference_create(
|
||||||
final error = libgit2.git_reference_create(
|
out,
|
||||||
out,
|
repo,
|
||||||
repo,
|
nameC,
|
||||||
nameC,
|
oid,
|
||||||
oid,
|
forceC,
|
||||||
forceC,
|
logMessageC,
|
||||||
logMessageC,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(nameC);
|
||||||
throw (LibGit2Error(libgit2.git_error_last()));
|
calloc.free(logMessageC);
|
||||||
} else {
|
|
||||||
return out.value;
|
if (error < 0) {
|
||||||
}
|
throw (LibGit2Error(libgit2.git_error_last()));
|
||||||
});
|
} else {
|
||||||
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new symbolic reference.
|
/// Create a new symbolic reference.
|
||||||
|
@ -292,27 +287,29 @@ Pointer<git_reference> createSymbolic(
|
||||||
bool force,
|
bool force,
|
||||||
String? logMessage,
|
String? logMessage,
|
||||||
) {
|
) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_reference>>();
|
||||||
final out = arena<Pointer<git_reference>>();
|
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||||
final nameC = name.toNativeUtf8(allocator: arena).cast<Int8>();
|
final targetC = target.toNativeUtf8().cast<Int8>();
|
||||||
final targetC = target.toNativeUtf8().cast<Int8>();
|
final forceC = force == true ? 1 : 0;
|
||||||
final forceC = force == true ? 1 : 0;
|
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final error = libgit2.git_reference_symbolic_create(
|
||||||
final error = libgit2.git_reference_symbolic_create(
|
out,
|
||||||
out,
|
repo,
|
||||||
repo,
|
nameC,
|
||||||
nameC,
|
targetC,
|
||||||
targetC,
|
forceC,
|
||||||
forceC,
|
logMessageC,
|
||||||
logMessageC,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(nameC);
|
||||||
throw (LibGit2Error(libgit2.git_error_last()));
|
calloc.free(targetC);
|
||||||
} else {
|
calloc.free(logMessageC);
|
||||||
return out.value;
|
|
||||||
}
|
if (error < 0) {
|
||||||
});
|
throw (LibGit2Error(libgit2.git_error_last()));
|
||||||
|
} else {
|
||||||
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete an existing reference.
|
/// Delete an existing reference.
|
||||||
|
@ -345,18 +342,17 @@ Pointer<git_reference> setTarget(
|
||||||
Pointer<git_oid> oid,
|
Pointer<git_oid> oid,
|
||||||
String? logMessage,
|
String? logMessage,
|
||||||
) {
|
) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_reference>>();
|
||||||
final out = arena<Pointer<git_reference>>();
|
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
final logMessageC =
|
final error = libgit2.git_reference_set_target(out, ref, oid, logMessageC);
|
||||||
logMessage?.toNativeUtf8(allocator: arena).cast<Int8>() ?? nullptr;
|
|
||||||
final error = libgit2.git_reference_set_target(out, ref, oid, logMessageC);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(logMessageC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
} else {
|
if (error < 0) {
|
||||||
return out.value;
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
} else {
|
||||||
});
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new reference with the same name as the given reference but a different
|
/// Create a new reference with the same name as the given reference but a different
|
||||||
|
@ -375,20 +371,20 @@ Pointer<git_reference> setTargetSymbolic(
|
||||||
String target,
|
String target,
|
||||||
String? logMessage,
|
String? logMessage,
|
||||||
) {
|
) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_reference>>();
|
||||||
final out = arena<Pointer<git_reference>>();
|
final targetC = target.toNativeUtf8().cast<Int8>();
|
||||||
final targetC = target.toNativeUtf8(allocator: arena).cast<Int8>();
|
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
final logMessageC =
|
final error =
|
||||||
logMessage?.toNativeUtf8(allocator: arena).cast<Int8>() ?? nullptr;
|
libgit2.git_reference_symbolic_set_target(out, ref, targetC, logMessageC);
|
||||||
final error = libgit2.git_reference_symbolic_set_target(
|
|
||||||
out, ref, targetC, logMessageC);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(targetC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
calloc.free(logMessageC);
|
||||||
} else {
|
|
||||||
return out.value;
|
if (error < 0) {
|
||||||
}
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
});
|
} else {
|
||||||
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compare two references.
|
/// Compare two references.
|
||||||
|
@ -407,12 +403,12 @@ bool compare(Pointer<git_reference> ref1, Pointer<git_reference> ref2) {
|
||||||
/// the characters '~', '^', ':', '\', '?', '[', and '*', and the sequences ".."
|
/// the characters '~', '^', ':', '\', '?', '[', and '*', and the sequences ".."
|
||||||
/// and "@{" which have special meaning to revparse.
|
/// and "@{" which have special meaning to revparse.
|
||||||
bool isValidName(String name) {
|
bool isValidName(String name) {
|
||||||
return using((Arena arena) {
|
final refname = name.toNativeUtf8().cast<Int8>();
|
||||||
final refname = name.toNativeUtf8(allocator: arena).cast<Int8>();
|
final result = libgit2.git_reference_is_valid_name(refname);
|
||||||
final result = libgit2.git_reference_is_valid_name(refname);
|
|
||||||
|
|
||||||
return result == 1 ? true : false;
|
calloc.free(refname);
|
||||||
});
|
|
||||||
|
return result == 1 ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Free the given reference.
|
/// Free the given reference.
|
||||||
|
|
|
@ -13,17 +13,17 @@ import '../util.dart';
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_reflog> read(Pointer<git_repository> repo, String name) {
|
Pointer<git_reflog> read(Pointer<git_repository> repo, String name) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_reflog>>();
|
||||||
final out = arena<Pointer<git_reflog>>();
|
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||||
final nameC = name.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_reflog_read(out, repo, nameC);
|
||||||
final error = libgit2.git_reflog_read(out, repo, nameC);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(nameC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
} else {
|
if (error < 0) {
|
||||||
return out.value;
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
} else {
|
||||||
});
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the number of log entries in a reflog.
|
/// Get the number of log entries in a reflog.
|
||||||
|
|
|
@ -10,17 +10,17 @@ import '../util.dart';
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_repository> open(String path) {
|
Pointer<git_repository> open(String path) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_repository>>();
|
||||||
final out = arena<Pointer<git_repository>>();
|
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||||
final pathC = path.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_repository_open(out, pathC);
|
||||||
final error = libgit2.git_repository_open(out, pathC);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(pathC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
} else {
|
if (error < 0) {
|
||||||
return out.value;
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
} else {
|
||||||
});
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempt to open an already-existing bare repository at [bare_path].
|
/// Attempt to open an already-existing bare repository at [bare_path].
|
||||||
|
@ -29,17 +29,17 @@ Pointer<git_repository> open(String path) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_repository> openBare(String barePath) {
|
Pointer<git_repository> openBare(String barePath) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_repository>>();
|
||||||
final out = arena<Pointer<git_repository>>();
|
final barePathC = barePath.toNativeUtf8().cast<Int8>();
|
||||||
final barePathC = barePath.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_repository_open_bare(out, barePathC);
|
||||||
final error = libgit2.git_repository_open_bare(out, barePathC);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(barePathC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
} else {
|
if (error < 0) {
|
||||||
return out.value;
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
} else {
|
||||||
});
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Look for a git repository and return its path. The lookup start from [startPath]
|
/// Look for a git repository and return its path. The lookup start from [startPath]
|
||||||
|
@ -50,40 +50,40 @@ Pointer<git_repository> openBare(String barePath) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
String discover(String startPath, String ceilingDirs) {
|
String discover(String startPath, String ceilingDirs) {
|
||||||
return using((Arena arena) {
|
final out = calloc<git_buf>(sizeOf<git_buf>());
|
||||||
final out = arena<git_buf>(sizeOf<git_buf>());
|
final startPathC = startPath.toNativeUtf8().cast<Int8>();
|
||||||
final startPathC = startPath.toNativeUtf8(allocator: arena).cast<Int8>();
|
final ceilingDirsC = ceilingDirs.toNativeUtf8().cast<Int8>();
|
||||||
final ceilingDirsC =
|
final error =
|
||||||
ceilingDirs.toNativeUtf8(allocator: arena).cast<Int8>();
|
libgit2.git_repository_discover(out, startPathC, 0, ceilingDirsC);
|
||||||
final error =
|
|
||||||
libgit2.git_repository_discover(out, startPathC, 0, ceilingDirsC);
|
|
||||||
|
|
||||||
if (error == git_error_code.GIT_ENOTFOUND) {
|
calloc.free(startPathC);
|
||||||
return '';
|
calloc.free(ceilingDirsC);
|
||||||
} else if (error < 0) {
|
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
if (error == git_error_code.GIT_ENOTFOUND) {
|
||||||
} else {
|
return '';
|
||||||
return out.ref.ptr.cast<Utf8>().toDartString();
|
} else if (error < 0) {
|
||||||
}
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
});
|
} else {
|
||||||
|
return out.ref.ptr.cast<Utf8>().toDartString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new Git repository in the given folder.
|
/// Creates a new Git repository in the given folder.
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_repository> init(String path, bool isBare) {
|
Pointer<git_repository> init(String path, bool isBare) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_repository>>();
|
||||||
final out = arena<Pointer<git_repository>>();
|
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||||
final pathC = path.toNativeUtf8(allocator: arena).cast<Int8>();
|
final isBareC = isBare ? 1 : 0;
|
||||||
final isBareC = isBare ? 1 : 0;
|
final error = libgit2.git_repository_init(out, pathC, isBareC);
|
||||||
final error = libgit2.git_repository_init(out, pathC, isBareC);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(pathC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
} else {
|
if (error < 0) {
|
||||||
return out.value;
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
} else {
|
||||||
});
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the path to the `.git` folder for normal repositories or the
|
/// Returns the path to the `.git` folder for normal repositories or the
|
||||||
|
@ -125,15 +125,14 @@ String getNamespace(Pointer<git_repository> repo) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void setNamespace(Pointer<git_repository> repo, String? namespace) {
|
void setNamespace(Pointer<git_repository> repo, String? namespace) {
|
||||||
using((Arena arena) {
|
final nmspace = namespace?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
final nmspace =
|
final error = libgit2.git_repository_set_namespace(repo, nmspace);
|
||||||
namespace?.toNativeUtf8(allocator: arena).cast<Int8>() ?? nullptr;
|
|
||||||
final error = libgit2.git_repository_set_namespace(repo, nmspace);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(nmspace);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
}
|
if (error < 0) {
|
||||||
});
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if a repository is bare or not.
|
/// Check if a repository is bare or not.
|
||||||
|
@ -165,16 +164,14 @@ bool isEmpty(Pointer<git_repository> repo) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_reference> head(Pointer<git_repository> repo) {
|
Pointer<git_reference> head(Pointer<git_repository> repo) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_reference>>();
|
||||||
final out = arena<Pointer<git_reference>>();
|
final error = libgit2.git_repository_head(out, repo);
|
||||||
final error = libgit2.git_repository_head(out, repo);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if a repository's HEAD is detached.
|
/// Check if a repository's HEAD is detached.
|
||||||
|
@ -213,32 +210,33 @@ bool isBranchUnborn(Pointer<git_repository> repo) {
|
||||||
/// If both are set, this name and email will be used to write to the reflog.
|
/// If both are set, this name and email will be used to write to the reflog.
|
||||||
/// Pass NULL to unset. When unset, the identity will be taken from the repository's configuration.
|
/// Pass NULL to unset. When unset, the identity will be taken from the repository's configuration.
|
||||||
void setIdentity(Pointer<git_repository> repo, String? name, String? email) {
|
void setIdentity(Pointer<git_repository> repo, String? name, String? email) {
|
||||||
using((Arena arena) {
|
final nameC = name?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
final nameC = name?.toNativeUtf8(allocator: arena).cast<Int8>() ?? nullptr;
|
final emailC = email?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
final emailC =
|
|
||||||
email?.toNativeUtf8(allocator: arena).cast<Int8>() ?? nullptr;
|
|
||||||
|
|
||||||
libgit2.git_repository_set_ident(repo, nameC, emailC);
|
libgit2.git_repository_set_ident(repo, nameC, emailC);
|
||||||
});
|
|
||||||
|
calloc.free(nameC);
|
||||||
|
calloc.free(emailC);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve the configured identity to use for reflogs.
|
/// Retrieve the configured identity to use for reflogs.
|
||||||
Map<String, String> identity(Pointer<git_repository> repo) {
|
Map<String, String> identity(Pointer<git_repository> repo) {
|
||||||
return using((Arena arena) {
|
final name = calloc<Pointer<Int8>>();
|
||||||
final name = arena<Pointer<Int8>>();
|
final email = calloc<Pointer<Int8>>();
|
||||||
final email = arena<Pointer<Int8>>();
|
libgit2.git_repository_ident(name, email, repo);
|
||||||
libgit2.git_repository_ident(name, email, repo);
|
var identity = <String, String>{};
|
||||||
var identity = <String, String>{};
|
|
||||||
|
|
||||||
if (name.value == nullptr && email.value == nullptr) {
|
|
||||||
return identity;
|
|
||||||
} else {
|
|
||||||
identity[name.value.cast<Utf8>().toDartString()] =
|
|
||||||
email.value.cast<Utf8>().toDartString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (name.value == nullptr && email.value == nullptr) {
|
||||||
return identity;
|
return identity;
|
||||||
});
|
} else {
|
||||||
|
identity[name.value.cast<Utf8>().toDartString()] =
|
||||||
|
email.value.cast<Utf8>().toDartString();
|
||||||
|
}
|
||||||
|
|
||||||
|
calloc.free(name);
|
||||||
|
calloc.free(email);
|
||||||
|
|
||||||
|
return identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the configuration file for this repository.
|
/// Get the configuration file for this repository.
|
||||||
|
@ -250,16 +248,14 @@ Map<String, String> identity(Pointer<git_repository> repo) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_config> config(Pointer<git_repository> repo) {
|
Pointer<git_config> config(Pointer<git_repository> repo) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_config>>();
|
||||||
final out = arena<Pointer<git_config>>();
|
final error = libgit2.git_repository_config(out, repo);
|
||||||
final error = libgit2.git_repository_config(out, repo);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a snapshot of the repository's configuration.
|
/// Get a snapshot of the repository's configuration.
|
||||||
|
@ -271,16 +267,14 @@ Pointer<git_config> config(Pointer<git_repository> repo) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_config> configSnapshot(Pointer<git_repository> repo) {
|
Pointer<git_config> configSnapshot(Pointer<git_repository> repo) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_config>>();
|
||||||
final out = arena<Pointer<git_config>>();
|
final error = libgit2.git_repository_config_snapshot(out, repo);
|
||||||
final error = libgit2.git_repository_config_snapshot(out, repo);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the Index file for this repository.
|
/// Get the Index file for this repository.
|
||||||
|
@ -292,16 +286,14 @@ Pointer<git_config> configSnapshot(Pointer<git_repository> repo) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_index> index(Pointer<git_repository> repo) {
|
Pointer<git_index> index(Pointer<git_repository> repo) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_index>>();
|
||||||
final out = arena<Pointer<git_index>>();
|
final error = libgit2.git_repository_index(out, repo);
|
||||||
final error = libgit2.git_repository_index(out, repo);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine if the repository was a shallow clone.
|
/// Determine if the repository was a shallow clone.
|
||||||
|
@ -328,16 +320,14 @@ bool isWorktree(Pointer<git_repository> repo) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
String message(Pointer<git_repository> repo) {
|
String message(Pointer<git_repository> repo) {
|
||||||
return using((Arena arena) {
|
final out = calloc<git_buf>(sizeOf<git_buf>());
|
||||||
final out = arena<git_buf>(sizeOf<git_buf>());
|
final error = libgit2.git_repository_message(out, repo);
|
||||||
final error = libgit2.git_repository_message(out, repo);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.ref.ptr.cast<Utf8>().toDartString();
|
return out.ref.ptr.cast<Utf8>().toDartString();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove git's prepared message.
|
/// Remove git's prepared message.
|
||||||
|
@ -354,16 +344,14 @@ void removeMessage(Pointer<git_repository> repo) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_odb> odb(Pointer<git_repository> repo) {
|
Pointer<git_odb> odb(Pointer<git_repository> repo) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_odb>>();
|
||||||
final out = arena<Pointer<git_odb>>();
|
final error = libgit2.git_repository_odb(out, repo);
|
||||||
final error = libgit2.git_repository_odb(out, repo);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the Reference Database Backend for this repository.
|
/// Get the Reference Database Backend for this repository.
|
||||||
|
@ -376,16 +364,14 @@ Pointer<git_odb> odb(Pointer<git_repository> repo) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_refdb> refdb(Pointer<git_repository> repo) {
|
Pointer<git_refdb> refdb(Pointer<git_repository> repo) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_refdb>>();
|
||||||
final out = arena<Pointer<git_refdb>>();
|
final error = libgit2.git_repository_refdb(out, repo);
|
||||||
final error = libgit2.git_repository_refdb(out, repo);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Make the repository HEAD point to the specified reference.
|
/// Make the repository HEAD point to the specified reference.
|
||||||
|
@ -401,14 +387,14 @@ Pointer<git_refdb> refdb(Pointer<git_repository> repo) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void setHead(Pointer<git_repository> repo, String ref) {
|
void setHead(Pointer<git_repository> repo, String ref) {
|
||||||
using((Arena arena) {
|
final refname = ref.toNativeUtf8().cast<Int8>();
|
||||||
final refname = ref.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_repository_set_head(repo, refname);
|
||||||
final error = libgit2.git_repository_set_head(repo, refname);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(refname);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
}
|
if (error < 0) {
|
||||||
});
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Make the repository HEAD directly point to the commit.
|
/// Make the repository HEAD directly point to the commit.
|
||||||
|
@ -462,16 +448,19 @@ void setWorkdir(
|
||||||
String path,
|
String path,
|
||||||
bool updateGitlink,
|
bool updateGitlink,
|
||||||
) {
|
) {
|
||||||
using((Arena arena) {
|
final workdir = path.toNativeUtf8().cast<Int8>();
|
||||||
final workdir = path.toNativeUtf8(allocator: arena).cast<Int8>();
|
final updateGitlinkC = updateGitlink ? 1 : 0;
|
||||||
final updateGitlinkC = updateGitlink ? 1 : 0;
|
final error = libgit2.git_repository_set_workdir(
|
||||||
final error =
|
repo,
|
||||||
libgit2.git_repository_set_workdir(repo, workdir, updateGitlinkC);
|
workdir,
|
||||||
|
updateGitlinkC,
|
||||||
|
);
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(workdir);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
}
|
if (error < 0) {
|
||||||
});
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines the status of a git repository - ie, whether an operation
|
/// Determines the status of a git repository - ie, whether an operation
|
||||||
|
@ -511,16 +500,14 @@ String workdir(Pointer<git_repository> repo) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_repository> wrapODB(Pointer<git_odb> odb) {
|
Pointer<git_repository> wrapODB(Pointer<git_odb> odb) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_repository>>();
|
||||||
final out = arena<Pointer<git_repository>>();
|
final error = libgit2.git_repository_wrap_odb(out, odb);
|
||||||
final error = libgit2.git_repository_wrap_odb(out, odb);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find a single object, as specified by a [spec] string.
|
/// Find a single object, as specified by a [spec] string.
|
||||||
|
@ -532,21 +519,21 @@ Pointer<git_object> revParseSingle(
|
||||||
Pointer<git_repository> repo,
|
Pointer<git_repository> repo,
|
||||||
String spec,
|
String spec,
|
||||||
) {
|
) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_object>>();
|
||||||
final out = arena<Pointer<git_object>>();
|
final specC = spec.toNativeUtf8().cast<Int8>();
|
||||||
final specC = spec.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_revparse_single(
|
||||||
final error = libgit2.git_revparse_single(
|
out,
|
||||||
out,
|
repo,
|
||||||
repo,
|
specC,
|
||||||
specC,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(specC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
|
||||||
} else {
|
if (error < 0) {
|
||||||
return out.value;
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
} else {
|
||||||
});
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Free a previously allocated repository.
|
/// Free a previously allocated repository.
|
||||||
|
|
|
@ -16,36 +16,38 @@ Pointer<git_signature> create(
|
||||||
int time,
|
int time,
|
||||||
int offset,
|
int offset,
|
||||||
) {
|
) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_signature>>();
|
||||||
final out = arena<Pointer<git_signature>>();
|
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||||
final nameC = name.toNativeUtf8(allocator: arena).cast<Int8>();
|
final emailC = email.toNativeUtf8().cast<Int8>();
|
||||||
final emailC = email.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_signature_new(out, nameC, emailC, time, offset);
|
||||||
final error = libgit2.git_signature_new(out, nameC, emailC, time, offset);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(nameC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
calloc.free(emailC);
|
||||||
} else {
|
|
||||||
return out.value;
|
if (error < 0) {
|
||||||
}
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
});
|
} else {
|
||||||
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new action signature with a timestamp of 'now'.
|
/// Create a new action signature with a timestamp of 'now'.
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_signature> now(String name, String email) {
|
Pointer<git_signature> now(String name, String email) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_signature>>();
|
||||||
final out = arena<Pointer<git_signature>>();
|
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||||
final nameC = name.toNativeUtf8(allocator: arena).cast<Int8>();
|
final emailC = email.toNativeUtf8().cast<Int8>();
|
||||||
final emailC = email.toNativeUtf8(allocator: arena).cast<Int8>();
|
final error = libgit2.git_signature_now(out, nameC, emailC);
|
||||||
final error = libgit2.git_signature_now(out, nameC, emailC);
|
|
||||||
|
|
||||||
if (error < 0) {
|
calloc.free(nameC);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
calloc.free(emailC);
|
||||||
} else {
|
|
||||||
return out.value;
|
if (error < 0) {
|
||||||
}
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
});
|
} else {
|
||||||
|
return out.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Free an existing signature.
|
/// Free an existing signature.
|
||||||
|
|
|
@ -11,16 +11,14 @@ Pointer<git_oid> id(Pointer<git_tree> tree) => libgit2.git_tree_id(tree);
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_tree> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) {
|
Pointer<git_tree> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_tree>>();
|
||||||
final out = arena<Pointer<git_tree>>();
|
final error = libgit2.git_tree_lookup(out, repo, id);
|
||||||
final error = libgit2.git_tree_lookup(out, repo, id);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lookup a tree object from the repository, given a prefix of its identifier (short id).
|
/// Lookup a tree object from the repository, given a prefix of its identifier (short id).
|
||||||
|
@ -31,22 +29,15 @@ Pointer<git_tree> lookupPrefix(
|
||||||
Pointer<git_oid> id,
|
Pointer<git_oid> id,
|
||||||
int len,
|
int len,
|
||||||
) {
|
) {
|
||||||
return using((Arena arena) {
|
final out = calloc<Pointer<git_tree>>();
|
||||||
final out = arena<Pointer<git_tree>>();
|
final error = libgit2.git_tree_lookup_prefix(out, repo, id, len);
|
||||||
final error = libgit2.git_tree_lookup_prefix(out, repo, id, len);
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Close an open tree.
|
/// Close an open tree to release memory.
|
||||||
///
|
|
||||||
/// You can no longer use the git_tree pointer after this call.
|
|
||||||
///
|
|
||||||
/// IMPORTANT: You MUST call this method when you stop using a tree to release memory.
|
|
||||||
/// Failure to do so will cause a memory leak.
|
|
||||||
void free(Pointer<git_tree> tree) => libgit2.git_tree_free(tree);
|
void free(Pointer<git_tree> tree) => libgit2.git_tree_free(tree);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue