List of usage examples for org.eclipse.jgit.notes NoteMapMerger merge
public NoteMap merge(NoteMap base, NoteMap ours, NoteMap theirs) throws IOException
From source file:com.google.appraise.eclipse.core.client.git.AppraiseGitReviewClient.java
License:Open Source License
/** * Merges the notes from local and origin commits with the given merge base. *//*from w w w . j a v a2s .c o m*/ private void mergeNotesAndPush(RevWalk revWalk, String refName, RevCommit baseCommit, RevCommit localCommit, RevCommit originCommit) throws GitClientException { int remainingLockFailureCalls = JgitUtils.MAX_LOCK_FAILURE_CALLS; // Merge and commit. while (true) { try { NoteMap theirNoteMap = NoteMap.read(revWalk.getObjectReader(), originCommit); NoteMap ourNoteMap = NoteMap.read(revWalk.getObjectReader(), localCommit); NoteMap baseNoteMap; if (baseCommit != null) { baseNoteMap = NoteMap.read(revWalk.getObjectReader(), baseCommit); } else { baseNoteMap = NoteMap.newEmptyMap(); } NoteMapMerger merger = new NoteMapMerger(repo, new DefaultNoteMerger(), MergeStrategy.RESOLVE); NoteMap merged = merger.merge(baseNoteMap, ourNoteMap, theirNoteMap); try (ObjectInserter inserter = repo.newObjectInserter()) { RevCommit mergeCommit = createNotesCommit(merged, inserter, revWalk, "Merged note commits\n", localCommit, originCommit); RefUpdate update = JgitUtils.updateRef(repo, mergeCommit, localCommit, refName); Result result = update.update(); if (result == Result.LOCK_FAILURE) { if (--remainingLockFailureCalls > 0) { Thread.sleep(JgitUtils.SLEEP_ON_LOCK_FAILURE_MS); } else { throw new GitClientException("Failed to lock the ref: " + refName); } } else if (result == Result.REJECTED) { throw new GitClientException("Rejected update to " + refName + ", this is unexpected"); } else if (result == Result.IO_FAILURE) { throw new GitClientException("I/O failure merging notes"); } else { // OK. break; } } } catch (Exception e) { throw new GitClientException("Error merging notes commits", e); } } // And push. try { pushCommentsAndReviews(); } catch (Exception e) { throw new GitClientException("Error pushing merge commit", e); } }
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;/*w w w .j av a2s .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;/* www .java 2 s . co m*/ } 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; } } }
From source file:com.google.gerrit.server.git.NotesBranchUtil.java
License:Apache License
private void updateRef(String notesBranch) throws IOException, MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, ConcurrentRefUpdateException { 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 a v a 2 s . c o m } 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); break; } } }