mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
refactor: use libgit free() functions instead of calloc()
This commit is contained in:
parent
4f851bc2e5
commit
2477b4efd8
14 changed files with 30 additions and 21 deletions
|
@ -9,8 +9,8 @@ void main() {
|
||||||
for (final entry in entries.entries) {
|
for (final entry in entries.entries) {
|
||||||
print('${entry.key}: ${entry.value}');
|
print('${entry.key}: ${entry.value}');
|
||||||
}
|
}
|
||||||
// .close should be called on object to free memory when done.
|
// free() should be called on object to free memory when done.
|
||||||
config.close();
|
config.free();
|
||||||
|
|
||||||
// Open config file at provided path.
|
// Open config file at provided path.
|
||||||
// Exception is thrown if file not found.
|
// Exception is thrown if file not found.
|
||||||
|
@ -31,7 +31,7 @@ void main() {
|
||||||
// Delete variable
|
// Delete variable
|
||||||
repoConfig.deleteEntry('core.variable');
|
repoConfig.deleteEntry('core.variable');
|
||||||
|
|
||||||
repoConfig.close();
|
repoConfig.free();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ void main() {
|
||||||
final userName = globalConfig.getValue('user.name');
|
final userName = globalConfig.getValue('user.name');
|
||||||
print('\nUser Name from global config: $userName');
|
print('\nUser Name from global config: $userName');
|
||||||
|
|
||||||
globalConfig.close();
|
globalConfig.free();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('\n$e');
|
print('\n$e');
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,5 +11,5 @@ void main() {
|
||||||
print('Reference full name: ${ref.name}');
|
print('Reference full name: ${ref.name}');
|
||||||
|
|
||||||
ref.free();
|
ref.free();
|
||||||
repo.close();
|
repo.free();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ void main() {
|
||||||
print('Is head detached: ${repo.isHeadDetached}');
|
print('Is head detached: ${repo.isHeadDetached}');
|
||||||
print('Repository refs: ${repo.references}');
|
print('Repository refs: ${repo.references}');
|
||||||
|
|
||||||
// close() should be called on object to free memory when done.
|
// free() should be called on object to free memory when done.
|
||||||
repo.close();
|
repo.free();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -284,3 +284,6 @@ void deleteMultivar(
|
||||||
calloc.free(name);
|
calloc.free(name);
|
||||||
calloc.free(regexpC);
|
calloc.free(regexpC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Free the configuration and its associated memory and files.
|
||||||
|
void free(Pointer<git_config> cfg) => libgit2.git_config_free(cfg);
|
||||||
|
|
|
@ -215,3 +215,6 @@ bool isValidName(String name) {
|
||||||
calloc.free(refname);
|
calloc.free(refname);
|
||||||
return result == 1 ? true : false;
|
return result == 1 ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Free the given reference.
|
||||||
|
void free(Pointer<git_reference> ref) => libgit2.git_reference_free(ref);
|
||||||
|
|
|
@ -446,3 +446,6 @@ Pointer<Pointer<git_object>> revParseSingle(
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Free a previously allocated repository.
|
||||||
|
void free(Pointer<git_repository> repo) => libgit2.git_repository_free(repo);
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Config {
|
||||||
/// [path] should point to single on-disk file; it's expected to be a native
|
/// [path] should point to single on-disk file; it's expected to be a native
|
||||||
/// Git config file following the default Git config syntax (see man git-config).
|
/// Git config file following the default Git config syntax (see man git-config).
|
||||||
///
|
///
|
||||||
/// [Config] object should be closed with [close] function to release allocated memory.
|
/// [Config] object should be closed with [free] function to release allocated memory.
|
||||||
Config.open({this.path}) {
|
Config.open({this.path}) {
|
||||||
libgit2.git_libgit2_init();
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
@ -145,8 +145,8 @@ class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Releases memory allocated for config object.
|
/// Releases memory allocated for config object.
|
||||||
void close() {
|
void free() {
|
||||||
calloc.free(_configPointer);
|
bindings.free(_configPointer);
|
||||||
libgit2.git_libgit2_shutdown();
|
libgit2.git_libgit2_shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ class Reference {
|
||||||
|
|
||||||
/// Releases memory allocated for reference object.
|
/// Releases memory allocated for reference object.
|
||||||
void free() {
|
void free() {
|
||||||
calloc.free(_refPointer);
|
bindings.free(_refPointer);
|
||||||
libgit2.git_libgit2_shutdown();
|
libgit2.git_libgit2_shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Repository {
|
||||||
/// or to the working directory. For a bare repository, [path] should directly
|
/// or to the working directory. For a bare repository, [path] should directly
|
||||||
/// point to the repository folder.
|
/// point to the repository folder.
|
||||||
///
|
///
|
||||||
/// [Repository] object should be close with [close] function to release allocated memory.
|
/// [Repository] object should be close with [free] function to release allocated memory.
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Repository.open(String path) {
|
Repository.open(String path) {
|
||||||
|
@ -237,8 +237,8 @@ class Repository {
|
||||||
String get workdir => bindings.workdir(_repoPointer);
|
String get workdir => bindings.workdir(_repoPointer);
|
||||||
|
|
||||||
/// Releases memory allocated for repository object.
|
/// Releases memory allocated for repository object.
|
||||||
void close() {
|
void free() {
|
||||||
calloc.free(_repoPointer);
|
bindings.free(_repoPointer);
|
||||||
libgit2.git_libgit2_shutdown();
|
libgit2.git_libgit2_shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() {
|
tearDown(() {
|
||||||
config.close();
|
config.free();
|
||||||
File('$tmpDir/$configFileName').deleteSync();
|
File('$tmpDir/$configFileName').deleteSync();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDownAll(() async {
|
tearDownAll(() async {
|
||||||
repo.close();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await Directory(tmpDir).delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDownAll(() async {
|
tearDownAll(() async {
|
||||||
repo.close();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await Directory(tmpDir).delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ void main() {
|
||||||
tearDownAll(() async {
|
tearDownAll(() async {
|
||||||
repo.head.free();
|
repo.head.free();
|
||||||
reflog.free();
|
reflog.free();
|
||||||
repo.close();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await Directory(tmpDir).delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() {
|
tearDown(() {
|
||||||
repo.close();
|
repo.free();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('opens successfully', () {
|
test('opens successfully', () {
|
||||||
|
@ -67,7 +67,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() {
|
tearDown(() {
|
||||||
repo.close();
|
repo.free();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('opens standart repository from working directory successfully',
|
test('opens standart repository from working directory successfully',
|
||||||
|
@ -144,7 +144,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDownAll(() async {
|
tearDownAll(() async {
|
||||||
repo.close();
|
repo.free();
|
||||||
await Directory(tmpDir).delete(recursive: true);
|
await Directory(tmpDir).delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue