countTillAncestor method
Implementation
Future<int?> countTillAncestor(GitHash from, GitHash ancestor) async {
var seen = <GitHash>{};
var parents = <GitHash>[];
parents.add(from);
while (parents.isNotEmpty) {
var sha = parents[0];
if (sha == ancestor) {
break;
}
parents.removeAt(0);
seen.add(sha);
GitCommit? commit;
try {
var res = await objStorage.readCommit(sha);
commit = res.get();
} catch (e) {
print(e);
return null;
}
for (var p in commit.parents) {
if (seen.contains(p)) continue;
parents.add(p);
}
}
return parents.isEmpty ? null : seen.length;
}