mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
fix: release memory
This commit is contained in:
parent
a1481564b2
commit
0fe3fa9f23
3 changed files with 10 additions and 16 deletions
|
@ -27,10 +27,11 @@ Pointer<Pointer<git_repository>> open(String path) {
|
|||
/// The [bare_path] can point to only a bare repository.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Pointer<Pointer<git_repository>> openBare(String bare_path) {
|
||||
Pointer<Pointer<git_repository>> openBare(String barePath) {
|
||||
final out = calloc<Pointer<git_repository>>();
|
||||
final error = libgit2.git_repository_open_bare(
|
||||
out, bare_path.toNativeUtf8().cast<Int8>());
|
||||
final barePathC = barePath.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_repository_open_bare(out, barePathC);
|
||||
calloc.free(barePathC);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(error, libgit2.git_error_last());
|
||||
|
@ -75,11 +76,13 @@ Pointer<Pointer<git_object>> revParseSingle(
|
|||
String spec,
|
||||
) {
|
||||
final out = calloc<Pointer<git_object>>();
|
||||
final specC = spec.toNativeUtf8().cast<Int8>();
|
||||
final error = libgit2.git_revparse_single(
|
||||
out,
|
||||
repo,
|
||||
spec.toNativeUtf8().cast<Int8>(),
|
||||
specC,
|
||||
);
|
||||
calloc.free(specC);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(error, libgit2.git_error_last());
|
||||
|
|
|
@ -15,25 +15,18 @@ class Repository {
|
|||
Repository.open(String dir) {
|
||||
libgit2.git_libgit2_init();
|
||||
|
||||
_repoPointer = repository.open(dir);
|
||||
_head = repository.revParseSingle(_repoPointer.value, 'HEAD^{commit}');
|
||||
headCommit = libgit2
|
||||
.git_commit_message(_head.value.cast<git_commit>())
|
||||
.cast<Utf8>()
|
||||
.toDartString();
|
||||
final _repoPointer = repository.open(dir);
|
||||
path = repository.path(_repoPointer.value);
|
||||
namespace = repository.getNamespace(_repoPointer.value);
|
||||
isBare = repository.isBare(_repoPointer.value);
|
||||
|
||||
// free up neccessary pointers
|
||||
calloc.free(_repoPointer);
|
||||
calloc.free(_head);
|
||||
libgit2.git_libgit2_shutdown();
|
||||
}
|
||||
|
||||
late Pointer<Pointer<git_repository>> _repoPointer;
|
||||
late Pointer<Pointer<git_object>> _head;
|
||||
late String headCommit;
|
||||
/// Path to the `.git` folder for normal repositories
|
||||
/// or path to the repository itself for bare repositories.
|
||||
late String path;
|
||||
late String namespace;
|
||||
late bool isBare;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue