feat(index): add binding and API method for git_index_new (#33)

This commit is contained in:
Aleksey Kulikov 2022-01-14 15:08:45 +03:00 committed by GitHub
parent 02ac220d46
commit cc78e7945f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View file

@ -5,6 +5,18 @@ import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
import 'package:libgit2dart/src/error.dart'; import 'package:libgit2dart/src/error.dart';
import 'package:libgit2dart/src/util.dart'; import 'package:libgit2dart/src/util.dart';
/// Create an in-memory index object.
///
/// This index object cannot be read/written to the filesystem, but may be
/// used to perform in-memory index operations.
///
/// The index must be freed once it's no longer in use.
Pointer<git_index> newInMemory() {
final out = calloc<Pointer<git_index>>();
libgit2.git_index_new(out);
return out.value;
}
/// Read index capabilities flags. /// Read index capabilities flags.
int capabilities(Pointer<git_index> index) => libgit2.git_index_caps(index); int capabilities(Pointer<git_index> index) => libgit2.git_index_caps(index);

View file

@ -14,6 +14,14 @@ class Index with IterableMixin<IndexEntry> {
/// **IMPORTANT**: Should be freed to release allocated memory. /// **IMPORTANT**: Should be freed to release allocated memory.
const Index(this._indexPointer); const Index(this._indexPointer);
/// Creates an in-memory index object.
///
/// This index object cannot be read/written to the filesystem, but may be
/// used to perform in-memory index operations.
///
/// **IMPORTANT**: Should be freed to release allocated memory.
Index.newInMemory() : _indexPointer = bindings.newInMemory();
final Pointer<git_index> _indexPointer; final Pointer<git_index> _indexPointer;
/// Pointer to memory address for allocated index object. /// Pointer to memory address for allocated index object.

View file

@ -29,6 +29,10 @@ void main() {
const fileSha = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'; const fileSha = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391';
const featureFileSha = '9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc'; const featureFileSha = '9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc';
test('creates new in memory index object', () {
expect(Index.newInMemory(), isA<Index>());
});
test('returns full path to the index file on disk', () { test('returns full path to the index file on disk', () {
expect(index.path, p.join(repo.path, 'index')); expect(index.path, p.join(repo.path, 'index'));
}); });