mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 12:49:08 -04:00
refactor: use ffi Arena for resource management
This commit is contained in:
parent
d0bb7aaa0f
commit
747996b40c
17 changed files with 629 additions and 582 deletions
|
@ -10,14 +10,16 @@ import '../util.dart';
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Pointer<git_commit> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) {
|
||||
final out = calloc<Pointer<git_commit>>();
|
||||
final error = libgit2.git_commit_lookup(out, repo, id);
|
||||
return using((Arena arena) {
|
||||
final out = arena<Pointer<git_commit>>();
|
||||
final error = libgit2.git_commit_lookup(out, repo, id);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
}
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Get the encoding for the message of a commit, as a string representing a standard encoding name.
|
||||
|
@ -26,6 +28,7 @@ Pointer<git_commit> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) {
|
|||
/// in that case UTF-8 is assumed.
|
||||
String messageEncoding(Pointer<git_commit> commit) {
|
||||
final result = libgit2.git_commit_message_encoding(commit);
|
||||
|
||||
if (result == nullptr) {
|
||||
return 'utf-8';
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue