use of org.eclipse.jgit.notes.NoteMapMerger in project gerrit by GerritCodeReview.
the class NotesBranchUtil method updateRef.
private void updateRef(String notesBranch) throws IOException, MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, ConcurrentRefUpdateException {
if (baseCommit != null && oursCommit.getTree().equals(baseCommit.getTree())) {
// Avoid saving this commit as it has no new information.
return;
}
int remainingLockFailureCalls = MAX_LOCK_FAILURE_CALLS;
RefUpdate refUpdate = createRefUpdate(notesBranch, oursCommit, baseCommit);
for (; ; ) {
Result result = refUpdate.update();
if (result == Result.LOCK_FAILURE) {
if (--remainingLockFailureCalls > 0) {
try {
Thread.sleep(SLEEP_ON_LOCK_FAILURE_MS);
} catch (InterruptedException e) {
// ignore
}
} else {
throw new ConcurrentRefUpdateException("Failed to lock the ref: " + notesBranch, refUpdate.getRef(), result);
}
} else if (result == Result.REJECTED) {
RevCommit theirsCommit = revWalk.parseCommit(refUpdate.getOldObjectId());
NoteMap theirs = NoteMap.read(revWalk.getObjectReader(), theirsCommit);
NoteMapMerger merger = new NoteMapMerger(db, getNoteMerger(), MergeStrategy.RESOLVE);
NoteMap merged = merger.merge(base, ours, theirs);
RevCommit mergeCommit = createCommit(merged, gerritIdent, "Merged note commits\n", theirsCommit, oursCommit);
refUpdate = createRefUpdate(notesBranch, mergeCommit, theirsCommit);
remainingLockFailureCalls = MAX_LOCK_FAILURE_CALLS;
} else if (result == Result.IO_FAILURE) {
throw new IOException("Couldn't update " + notesBranch + ". " + result.name());
} else {
gitRefUpdated.fire(project, refUpdate, null);
break;
}
}
}
Aggregations