if (baseCommits.isEmpty())
return null;
if (baseCommits.size() == 1)
return baseCommits.get(0);
if (baseCommits.size() >= MAX_BASES)
throw new NoMergeBaseException(NoMergeBaseException.MergeBaseFailureReason.TOO_MANY_MERGE_BASES, MessageFormat.format(
JGitText.get().mergeRecursiveTooManyMergeBasesFor,
Integer.valueOf(MAX_BASES), a.name(), b.name(),
Integer.valueOf(baseCommits.size())));
// We know we have more than one base commit. We have to do merges now
// to determine a single base commit. We don't want to spoil the current
// dircache and working tree with the results of this intermediate
// merges. Therefore set the dircache to a new in-memory dircache and
// disable that we update the working-tree. We set this back to the
// original values once a single base commit is created.
RevCommit currentBase = baseCommits.get(0);
DirCache oldDircache = dircache;
boolean oldIncore = inCore;
WorkingTreeIterator oldWTreeIt = workingTreeIterator;
workingTreeIterator = null;
try {
dircache = dircacheFromTree(currentBase.getTree());
inCore = true;
List<RevCommit> parents = new ArrayList<RevCommit>();
parents.add(currentBase);
for (int commitIdx = 1; commitIdx < baseCommits.size(); commitIdx++) {
RevCommit nextBase = baseCommits.get(commitIdx);
if (commitIdx >= MAX_BASES)
throw new NoMergeBaseException(
NoMergeBaseException.MergeBaseFailureReason.TOO_MANY_MERGE_BASES,
MessageFormat.format(
JGitText.get().mergeRecursiveTooManyMergeBasesFor,
Integer.valueOf(MAX_BASES), a.name(), b.name(),
Integer.valueOf(baseCommits.size())));
parents.add(nextBase);
if (mergeTrees(
openTree(getBaseCommit(currentBase, nextBase,
callDepth + 1).getTree()),
currentBase.getTree(), nextBase.getTree(), true))
currentBase = createCommitForTree(resultTree, parents);
else
throw new NoMergeBaseException(
NoMergeBaseException.MergeBaseFailureReason.CONFLICTS_DURING_MERGE_BASE_CALCULATION,
MessageFormat.format(
JGitText.get().mergeRecursiveConflictsWhenMergingCommonAncestors,
currentBase.getName(), nextBase.getName()));
}