List of usage examples for org.eclipse.jgit.notes NoteMapMerger NoteMapMerger
public NoteMapMerger(Repository db)
From source file:com.google.appraise.eclipse.core.client.git.GitNoteWriter.java
License:Open Source License
private void updateRef() throws IOException, InterruptedException, RuntimeException, MissingObjectException, IncorrectObjectTypeException, CorruptObjectException { if (baseCommit != null && oursCommit.getTree().equals(baseCommit.getTree())) { // If the trees are identical, there is no change in the notes. // Avoid saving this commit as it has no new information. return;// ww w . j a v a 2 s .c o m } int remainingLockFailureCalls = JgitUtils.MAX_LOCK_FAILURE_CALLS; RefUpdate refUpdate = JgitUtils.updateRef(repo, oursCommit, baseCommit, ref); for (;;) { Result result = refUpdate.update(); if (result == Result.LOCK_FAILURE) { if (--remainingLockFailureCalls > 0) { Thread.sleep(JgitUtils.SLEEP_ON_LOCK_FAILURE_MS); } else { throw new RuntimeException("Failed to lock the ref: " + ref); } } else if (result == Result.REJECTED) { RevCommit theirsCommit = revWalk.parseCommit(refUpdate.getOldObjectId()); NoteMap theirs = NoteMap.read(revWalk.getObjectReader(), theirsCommit); NoteMapMerger merger = new NoteMapMerger(repo); NoteMap merged = merger.merge(base, ours, theirs); RevCommit mergeCommit = createCommit(merged, author, "Merged note records\n", theirsCommit, oursCommit); refUpdate = JgitUtils.updateRef(repo, mergeCommit, theirsCommit, ref); remainingLockFailureCalls = JgitUtils.MAX_LOCK_FAILURE_CALLS; } else if (result == Result.IO_FAILURE) { throw new RuntimeException("Couldn't create notes because of IO_FAILURE"); } else { break; } } }
From source file:com.google.gerrit.server.git.CreateCodeReviewNotes.java
License:Apache License
public void updateRef() throws IOException, InterruptedException, CodeReviewNoteCreationException, MissingObjectException, IncorrectObjectTypeException, CorruptObjectException { if (baseCommit != null && oursCommit.getTree().equals(baseCommit.getTree())) { // If the trees are identical, there is no change in the notes. // Avoid saving this commit as it has no new information. return;//from w w w . j av a 2 s. com } int remainingLockFailureCalls = MAX_LOCK_FAILURE_CALLS; RefUpdate refUpdate = createRefUpdate(oursCommit, baseCommit); for (;;) { Result result = refUpdate.update(); if (result == Result.LOCK_FAILURE) { if (--remainingLockFailureCalls > 0) { Thread.sleep(SLEEP_ON_LOCK_FAILURE_MS); } else { throw new CodeReviewNoteCreationException("Failed to lock the ref: " + REFS_NOTES_REVIEW); } } else if (result == Result.REJECTED) { RevCommit theirsCommit = revWalk.parseCommit(refUpdate.getOldObjectId()); NoteMap theirs = NoteMap.read(revWalk.getObjectReader(), theirsCommit); NoteMapMerger merger = new NoteMapMerger(db); NoteMap merged = merger.merge(base, ours, theirs); RevCommit mergeCommit = createCommit(merged, gerritIdent, "Merged note commits\n", theirsCommit, oursCommit); refUpdate = createRefUpdate(mergeCommit, theirsCommit); remainingLockFailureCalls = MAX_LOCK_FAILURE_CALLS; } else if (result == Result.IO_FAILURE) { throw new CodeReviewNoteCreationException( "Couldn't create code review notes because of IO_FAILURE"); } else { break; } } }