/// <inheritdoc /> public ICommit FindMergeBase(IBranchHead branch, IBranchHead otherBranch) { var key = Tuple.Create(branch, otherBranch); if (_mergeBaseCache.ContainsKey(key)) { Logger.WriteDebug($"Cache hit for merge base between '{branch.Name}' and '{otherBranch.Name}'."); return(_mergeBaseCache[key].MergeBase); } using (Logger.IndentLog($"Finding merge base between '{branch.Name}' and '{otherBranch.Name}'.")) { var select = new HgLogQueryBuilder(); var findMergeBase = _repository .Log(select.CommonAncestorOf( select.ByBranch(branch.Name), select.ByBranch(branch.Name))) .FirstOrDefault(); // Store in cache. _mergeBaseCache.Add(key, new MergeBaseData(branch, otherBranch, _repository, findMergeBase)); Logger.WriteInfo($"Merge base of {branch.Name}' and '{otherBranch.Name} is {findMergeBase}"); return(findMergeBase); } }
/// <inheritdoc /> public ICommit FindCommitWasBranchedFrom(IBranchHead branch, params IBranchHead[] excludedBranches) { if (branch == null) { throw new ArgumentNullException(nameof(branch)); } using (Logger.IndentLog($"Finding branch source of '{branch.Name}'")) { var builder = new HgLogQueryBuilder(); var possibleBranches = _repository .Log(builder.ByBranch(branch.Name) .Limit(1) .Parents() .Except(excludedBranches.Select(b => b.Name).ToArray())) .ToList(); if (possibleBranches.Count > 1) { var first = possibleBranches.First(); Logger.WriteInfo( $"Multiple source branches have been found, picking the first one ({first.Branch}).\n" + "This may result in incorrect commit counting.\nOptions were:\n " + string.Join(", ", possibleBranches.Select(b => b.Branch))); return(first); } return(possibleBranches.SingleOrDefault()); } }