feat(oid): add base bindings and api

This commit is contained in:
Aleksey Kulikov 2021-07-16 21:17:51 +03:00
parent 21001d170c
commit 2c28fddcec
3 changed files with 149 additions and 0 deletions

58
lib/src/oid.dart Normal file
View file

@ -0,0 +1,58 @@
import 'dart:ffi';
import 'bindings/libgit2_bindings.dart';
import 'bindings/oid.dart' as bindings;
import 'util.dart';
class Oid {
/// Initializes a new instance of [Oid] class from provided
/// hexadecimal [sha] string.
///
/// Throws a [LibGit2Error] if error occured.
Oid.fromSHA(String sha) {
libgit2.git_libgit2_init();
try {
_oidPointer = bindings.fromSHA(sha);
} catch (e) {
rethrow;
}
}
/// Pointer to memory address for allocated oid object.
late Pointer<git_oid> _oidPointer;
/// Returns hexadecimal SHA-1 string.
String get sha {
try {
return bindings.toSHA(_oidPointer);
} catch (e) {
rethrow;
}
}
@override
bool operator ==(other) {
return (other is Oid) &&
(bindings.compare(_oidPointer, other._oidPointer) == 0);
}
bool operator <(other) {
return (other is Oid) &&
(bindings.compare(_oidPointer, other._oidPointer) == -1);
}
bool operator <=(other) {
return (other is Oid) &&
(bindings.compare(_oidPointer, other._oidPointer) == -1);
}
bool operator >(other) {
return (other is Oid) &&
(bindings.compare(_oidPointer, other._oidPointer) == 1);
}
bool operator >=(other) {
return (other is Oid) &&
(bindings.compare(_oidPointer, other._oidPointer) == 1);
}
}