mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
feat(reference): add ability to compress references
This commit is contained in:
parent
f63808b4f8
commit
28c4eca573
4 changed files with 45 additions and 0 deletions
20
lib/src/bindings/refdb.dart
Normal file
20
lib/src/bindings/refdb.dart
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import 'dart:ffi';
|
||||||
|
import '../error.dart';
|
||||||
|
import 'libgit2_bindings.dart';
|
||||||
|
import '../util.dart';
|
||||||
|
|
||||||
|
/// Suggests that the given refdb compress or optimize its references.
|
||||||
|
/// This mechanism is implementation specific. For on-disk reference databases,
|
||||||
|
/// for example, this may pack all loose references.
|
||||||
|
///
|
||||||
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
|
void compress(Pointer<git_refdb> refdb) {
|
||||||
|
final error = libgit2.git_refdb_compress(refdb);
|
||||||
|
|
||||||
|
if (error < 0) {
|
||||||
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Close an open reference database to release memory.
|
||||||
|
void free(Pointer<git_refdb> refdb) => libgit2.git_refdb_free(refdb);
|
|
@ -4,6 +4,8 @@ import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'bindings/libgit2_bindings.dart';
|
import 'bindings/libgit2_bindings.dart';
|
||||||
import 'bindings/reference.dart' as bindings;
|
import 'bindings/reference.dart' as bindings;
|
||||||
import 'bindings/object.dart' as object_bindings;
|
import 'bindings/object.dart' as object_bindings;
|
||||||
|
import 'bindings/refdb.dart' as refdb_bindings;
|
||||||
|
import 'bindings/repository.dart' as repository_bindings;
|
||||||
import 'blob.dart';
|
import 'blob.dart';
|
||||||
import 'commit.dart';
|
import 'commit.dart';
|
||||||
import 'oid.dart';
|
import 'oid.dart';
|
||||||
|
@ -40,6 +42,17 @@ class References {
|
||||||
final refPointer = bindings.lookup(_repoPointer, name);
|
final refPointer = bindings.lookup(_repoPointer, name);
|
||||||
return Reference(_repoPointer, refPointer);
|
return Reference(_repoPointer, refPointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Suggests that the given refdb compress or optimize its references.
|
||||||
|
/// This mechanism is implementation specific. For on-disk reference databases,
|
||||||
|
/// for example, this may pack all loose references.
|
||||||
|
///
|
||||||
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
|
void compress() {
|
||||||
|
final refdb = repository_bindings.refdb(_repoPointer);
|
||||||
|
refdb_bindings.compress(refdb);
|
||||||
|
refdb_bindings.free(refdb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Reference {
|
class Reference {
|
||||||
|
|
|
@ -514,5 +514,17 @@ void main() {
|
||||||
tree.free();
|
tree.free();
|
||||||
ref.free();
|
ref.free();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('successfully compresses references', () {
|
||||||
|
final packedRefsFile = File('$tmpDir.git/packed-refs');
|
||||||
|
expect(packedRefsFile.existsSync(), false);
|
||||||
|
final oldRefs = repo.references.list();
|
||||||
|
|
||||||
|
repo.references.compress();
|
||||||
|
|
||||||
|
expect(packedRefsFile.existsSync(), true);
|
||||||
|
final newRefs = repo.references.list();
|
||||||
|
expect(newRefs, oldRefs);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue