refactor(repository)!: use Finalizer to automatically free allocated memory (#51)

BREAKING CHANGE: Return value of identity getter changed from Map<String, String> to Identity
This commit is contained in:
Aleksey Kulikov 2022-05-02 15:33:31 +03:00 committed by GitHub
parent aef440e345
commit 4e55d0f06c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 109 additions and 151 deletions

View file

@ -6,6 +6,8 @@ import 'package:libgit2dart/src/bindings/credentials.dart'
as credentials_bindings;
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
import 'package:libgit2dart/src/bindings/remote.dart' as remote_bindings;
import 'package:libgit2dart/src/bindings/repository.dart'
as repository_bindings;
import 'package:libgit2dart/src/util.dart';
class RemoteCallbacks {
@ -112,17 +114,25 @@ class RemoteCallbacks {
int bare,
Pointer<Void> payload,
) {
final repoPointer = Repository.init(
var flagsInt = repositoryCbData!.flags.fold(
0,
(int acc, e) => acc | e.value,
);
if (repositoryCbData!.bare) {
flagsInt |= GitRepositoryInit.bare.value;
}
final repoPointer = repository_bindings.init(
path: repositoryCbData!.path,
bare: repositoryCbData!.bare,
flags: repositoryCbData!.flags,
flags: flagsInt,
mode: repositoryCbData!.mode,
workdirPath: repositoryCbData!.workdirPath,
description: repositoryCbData!.description,
templatePath: repositoryCbData!.templatePath,
initialHead: repositoryCbData!.initialHead,
originUrl: repositoryCbData!.originUrl,
).pointer;
);
repo[0] = repoPointer;

View file

@ -321,17 +321,19 @@ void setIdentity({
}
/// Retrieve the configured identity to use for reflogs.
Map<String, String> identity(Pointer<git_repository> repo) {
///
/// Returns list with name and email respectively.
List<String> identity(Pointer<git_repository> repo) {
final name = calloc<Pointer<Int8>>();
final email = calloc<Pointer<Int8>>();
libgit2.git_repository_ident(name, email, repo);
final identity = <String, String>{};
final identity = <String>[];
if (name.value == nullptr && email.value == nullptr) {
return identity;
} else {
identity[name.value.cast<Utf8>().toDartString()] =
email.value.cast<Utf8>().toDartString();
identity.add(name.value.cast<Utf8>().toDartString());
identity.add(email.value.cast<Utf8>().toDartString());
}
calloc.free(name);