feat(repository): add ability to lookup different types of git objects with []

This commit is contained in:
Aleksey Kulikov 2021-09-04 12:04:28 +03:00
parent f19a34a768
commit 2cf974c624
14 changed files with 124 additions and 67 deletions

View file

@ -15,14 +15,20 @@ class Oid {
/// in the ODB of [repository] with provided hexadecimal [sha] string that is 40 characters
/// long or shorter.
///
/// Throws [ArgumentError] if provided [sha] hex string is not valid.
///
/// Throws a [LibGit2Error] if error occured.
Oid.fromSHA(Repository repository, String sha) {
if (sha.length == 40) {
_oidPointer = bindings.fromSHA(sha);
if (isValidShaHex(sha)) {
if (sha.length == 40) {
_oidPointer = bindings.fromSHA(sha);
} else {
final odb = repository.odb;
_oidPointer = odb.existsPrefix(bindings.fromStrN(sha), sha.length);
odb.free();
}
} else {
final odb = repository.odb;
_oidPointer = odb.existsPrefix(bindings.fromStrN(sha), sha.length);
odb.free();
throw ArgumentError.value('$sha is not a valid sha hex string');
}
}