final ObjectId baseCommit) throws IOException, InterruptedException,
MissingObjectException, IncorrectObjectTypeException,
CorruptObjectException, MergeException {
int remainingLockFailureCalls = MAX_LOCK_FAILURE_CALLS;
RefUpdate refUpdate = createRefUpdate(repo, oursCommit, baseCommit);
for (;;) {
final Result result = refUpdate.update();
if (result == Result.LOCK_FAILURE) {
if (--remainingLockFailureCalls > 0) {
Thread.sleep(SLEEP_ON_LOCK_FAILURE_MS);
} else {
throw new MergeException("Failed to lock the ref: "
+ REF_REJECT_COMMITS);
}
} else if (result == Result.REJECTED) {
final RevCommit theirsCommit =
revWalk.parseCommit(refUpdate.getOldObjectId());
final NoteMap theirNoteMap =
NoteMap.read(revWalk.getObjectReader(), theirsCommit);
final NoteMapMerger merger = new NoteMapMerger(repo);
final NoteMap merged =
merger.merge(baseNoteMap, ourNoteMap, theirNoteMap);