List of usage examples for org.eclipse.jgit.lib RefUpdate getOldObjectId
public ObjectId getOldObjectId()
From source file:com.gitblit.git.PatchsetReceivePack.java
License:Apache License
private void updateReflog(RefUpdate ru) { if (ru == null) { return;/*from ww w. ja v a 2 s . c o m*/ } ReceiveCommand.Type type = null; switch (ru.getResult()) { case NEW: type = Type.CREATE; break; case FAST_FORWARD: type = Type.UPDATE; break; case FORCED: type = Type.UPDATE_NONFASTFORWARD; break; default: LOGGER.error( MessageFormat.format("unexpected ref update type {0} for {1}", ru.getResult(), ru.getName())); return; } ReceiveCommand cmd = new ReceiveCommand(ru.getOldObjectId(), ru.getNewObjectId(), ru.getName(), type); RefLogUtils.updateRefLog(user, getRepository(), Arrays.asList(cmd)); }
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;//from www . j a v a2 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.common.ChangeHookRunner.java
License:Apache License
@Override public void doRefUpdatedHook(Branch.NameKey refName, RefUpdate refUpdate, Account account) { doRefUpdatedHook(refName, refUpdate.getOldObjectId(), refUpdate.getNewObjectId(), account); }
From source file:com.google.gerrit.server.extensions.events.GitReferenceUpdated.java
License:Apache License
public void fire(Project.NameKey project, RefUpdate refUpdate, ReceiveCommand.Type type) { fire(project, refUpdate.getName(), refUpdate.getOldObjectId(), refUpdate.getNewObjectId(), type); }
From source file:com.google.gerrit.server.extensions.events.GitReferenceUpdated.java
License:Apache License
public void fire(Project.NameKey project, RefUpdate refUpdate) { fire(project, refUpdate.getName(), refUpdate.getOldObjectId(), refUpdate.getNewObjectId(), ReceiveCommand.Type.UPDATE); }
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 2s . c om*/ } 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.MergeOp.java
License:Apache License
private RefUpdate getPendingRefUpdate(Branch.NameKey destBranch) throws MergeException { if (pendingRefUpdates.containsKey(destBranch)) { logDebug("Access cached open branch {}: {}", destBranch.get(), openBranches.get(destBranch)); return pendingRefUpdates.get(destBranch); }// w ww . ja v a 2 s . com try { RefUpdate branchUpdate = repo.updateRef(destBranch.get()); CodeReviewCommit branchTip; if (branchUpdate.getOldObjectId() != null) { branchTip = rw.parseCommit(branchUpdate.getOldObjectId()); } else if (Objects.equals(repo.getFullBranch(), destBranch.get())) { branchTip = null; branchUpdate.setExpectedOldObjectId(ObjectId.zeroId()); } else { throw new MergeException("The destination branch " + destBranch.get() + " does not exist anymore."); } logDebug("Opened branch {}: {}", destBranch.get(), branchTip); pendingRefUpdates.put(destBranch, branchUpdate); openBranches.put(destBranch, branchTip); return branchUpdate; } catch (IOException e) { throw new MergeException("Cannot open branch", e); } }
From source file:com.google.gerrit.server.git.MergeOp.java
License:Apache License
private RefUpdate updateBranch(Branch.NameKey destBranch) throws MergeException { RefUpdate branchUpdate = getPendingRefUpdate(destBranch); CodeReviewCommit branchTip = getBranchTip(destBranch); MergeTip mergeTip = mergeTips.get(destBranch); CodeReviewCommit currentTip = mergeTip != null ? mergeTip.getCurrentTip() : null; if (Objects.equals(branchTip, currentTip)) { if (currentTip != null) { logDebug("Branch already at merge tip {}, no update to perform", currentTip.name()); } else {/* w w w . j av a 2s . c om*/ logDebug("Both branch and merge tip are nonexistent, no update"); } return null; } else if (currentTip == null) { logDebug("No merge tip, no update to perform"); return null; } if (RefNames.REFS_CONFIG.equals(branchUpdate.getName())) { logDebug("Loading new configuration from {}", RefNames.REFS_CONFIG); try { ProjectConfig cfg = new ProjectConfig(destProject.getProject().getNameKey()); cfg.load(repo, currentTip); } catch (Exception e) { throw new MergeException("Submit would store invalid" + " project configuration " + currentTip.name() + " for " + destProject.getProject().getName(), e); } } branchUpdate.setRefLogIdent(refLogIdent); branchUpdate.setForceUpdate(false); branchUpdate.setNewObjectId(currentTip); branchUpdate.setRefLogMessage("merged", true); try { RefUpdate.Result result = branchUpdate.update(rw); logDebug("Update of {}: {}..{} returned status {}", branchUpdate.getName(), branchUpdate.getOldObjectId(), branchUpdate.getNewObjectId(), result); switch (result) { case NEW: case FAST_FORWARD: if (branchUpdate.getResult() == RefUpdate.Result.FAST_FORWARD) { tagCache.updateFastForward(destBranch.getParentKey(), branchUpdate.getName(), branchUpdate.getOldObjectId(), currentTip); } if (RefNames.REFS_CONFIG.equals(branchUpdate.getName())) { Project p = destProject.getProject(); projectCache.evict(p); destProject = projectCache.get(p.getNameKey()); repoManager.setProjectDescription(p.getNameKey(), p.getDescription()); } return branchUpdate; case LOCK_FAILURE: throw new MergeException("Failed to lock " + branchUpdate.getName()); default: throw new IOException(branchUpdate.getResult().name() + '\n' + branchUpdate); } } catch (IOException e) { throw new MergeException("Cannot update " + branchUpdate.getName(), e); } }
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;// ww w. j ava 2 s.com } 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; } } }
From source file:com.google.gerrit.server.git.validators.RefOperationValidators.java
License:Apache License
public static ReceiveCommand getCommand(RefUpdate update, ReceiveCommand.Type type) { return new ReceiveCommand(update.getOldObjectId(), update.getNewObjectId(), update.getName(), type); }