mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 12:49:08 -04:00
feat(index): add ability to change attributes of index entry
This commit is contained in:
parent
5b8f089723
commit
06b44597d5
4 changed files with 48 additions and 7 deletions
|
@ -2,6 +2,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'bindings/libgit2_bindings.dart';
|
||||
import 'bindings/index.dart' as bindings;
|
||||
import 'oid.dart';
|
||||
import 'util.dart';
|
||||
|
||||
class Index {
|
||||
|
@ -116,18 +117,30 @@ class IndexEntry {
|
|||
/// Pointer to memory address for allocated index entry object.
|
||||
late final Pointer<git_index_entry> _indexEntryPointer;
|
||||
|
||||
/// Returns path to file.
|
||||
/// Unique identity of the index entry.
|
||||
Oid get id => Oid.fromSHA(sha);
|
||||
|
||||
set id(Oid oid) => _indexEntryPointer.ref.id = oid.pointer.ref;
|
||||
|
||||
/// Path of the index entry.
|
||||
String get path => _indexEntryPointer.ref.path.cast<Utf8>().toDartString();
|
||||
|
||||
/// Returns sha-1 of file.
|
||||
String get sha {
|
||||
set path(String path) =>
|
||||
_indexEntryPointer.ref.path = path.toNativeUtf8().cast<Int8>();
|
||||
|
||||
/// Returns id of the index entry as sha-1 hex.
|
||||
String get sha => _oidToHex(_indexEntryPointer.ref.id);
|
||||
|
||||
/// Mode of the index entry.
|
||||
int get mode => _indexEntryPointer.ref.mode;
|
||||
|
||||
set mode(int mode) => _indexEntryPointer.ref.mode = mode;
|
||||
|
||||
String _oidToHex(git_oid oid) {
|
||||
var hex = StringBuffer();
|
||||
for (var i = 0; i < 20; i++) {
|
||||
hex.write(_indexEntryPointer.ref.id.id[i].toRadixString(16));
|
||||
hex.write(oid.id[i].toRadixString(16));
|
||||
}
|
||||
return hex.toString();
|
||||
}
|
||||
|
||||
/// Returns mode of file.
|
||||
int get mode => _indexEntryPointer.ref.mode;
|
||||
}
|
||||
|
|
9
lib/src/types.dart
Normal file
9
lib/src/types.dart
Normal file
|
@ -0,0 +1,9 @@
|
|||
/// Valid modes for index and tree entries.
|
||||
abstract class GitFilemode {
|
||||
static const int unreadable = 0;
|
||||
static const int tree = 16384;
|
||||
static const int blob = 33188;
|
||||
static const int blobExecutable = 33261;
|
||||
static const int link = 40960;
|
||||
static const int commit = 57344;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue