mergeBase method

Future<List<GitCommit>> mergeBase(
  1. GitCommit a,
  2. GitCommit b
)

mergeBase mimics the behavior of git merge-base actual other, returning the best common ancestor between the actual and the passed one. The best common ancestors can not be reached from other common ancestors.

Implementation

Future<List<GitCommit>> mergeBase(GitCommit a, GitCommit b) async {
  var clist = [a, b];
  clist.sort(_commitDateDec);

  var newer = clist[0];
  var older = clist[1];

  var newerHistory = await allAncestors(newer, shouldNotContain: older);
  if (newerHistory == null) {
    return [older];
  }

  var inNewerHistory = (GitCommit c) => newerHistory.contains(c.hash);

  var results = <GitCommit>[];
  var iter = commitIteratorBFSFiltered(
    objStorage: objStorage,
    from: older,
    isValid: inNewerHistory,
    isLimit: inNewerHistory,
  );
  await for (var c in iter) {
    results.add(c);
  }

  return independents(results);
}