private MCommit TryFindFirstAncestorWithSameName(MCommit startCommit, BranchName branchName) { foreach (MCommit commit in startCommit.CommitAndFirstAncestors()) { BranchName commitBranchName = GetBranchName(commit); if (commitBranchName != null) { if (commitBranchName == branchName) { // Found an ancestor, which has branch name we are searching fore return(commit); } else { // Fond an ancestor with another different name break; } } if (commit != startCommit && commit.BranchTipBranches.Count == 1 && commit.BranchTipBranches[0].Name == branchName) { // Found a commit with a branch tip of a branch with same name, // this can happen for local/remote pairs. Lets assume the commit is the on that branch return(commit); } } // Could not find an ancestor with the branch name we a searching for return(null); }
private void SetActiveBranchCommits(MRepository repository) { IEnumerable <MSubBranch> branches = repository.SubBranches.Values .Where(b => b.TipCommit.BranchId == null && b.IsActive); foreach (MSubBranch branch in branches) { MCommit branchTip = branch.TipCommit; MCommit last = TryFindFirstAncestorWithSameName(branchTip, branch.Name); if (last == null) { // Could not find first ancestor commit with branch name continue; } foreach (MCommit current in branchTip.CommitAndFirstAncestors()) { current.SetBranchName(branch.Name); current.SubBranchId = branch.SubBranchId; if (current == last) { break; } } } }