mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
feat(oid): add base bindings and api
This commit is contained in:
parent
21001d170c
commit
2c28fddcec
3 changed files with 149 additions and 0 deletions
58
lib/src/oid.dart
Normal file
58
lib/src/oid.dart
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue