List of usage examples for org.eclipse.jgit.lib RefUpdate setRefLogMessage
public void setRefLogMessage(String msg, boolean appendStatus)
From source file:com.google.gerrit.httpd.rpc.project.AddBranch.java
License:Apache License
@Override public ListBranchesResult call() throws NoSuchProjectException, InvalidNameException, InvalidRevisionException, IOException, BranchCreationNotAllowedException { final ProjectControl projectControl = projectControlFactory.controlFor(projectName); String refname = branchName;//from w ww .j a va2s .c o m while (refname.startsWith("/")) { refname = refname.substring(1); } if (!refname.startsWith(Constants.R_REFS)) { refname = Constants.R_HEADS + refname; } if (!Repository.isValidRefName(refname)) { throw new InvalidNameException(); } if (refname.startsWith(ReceiveCommits.NEW_CHANGE)) { throw new BranchCreationNotAllowedException(ReceiveCommits.NEW_CHANGE); } final Branch.NameKey name = new Branch.NameKey(projectName, refname); final RefControl refControl = projectControl.controlForRef(name); final Repository repo = repoManager.openRepository(projectName); try { final ObjectId revid = parseStartingRevision(repo); final RevWalk rw = verifyConnected(repo, revid); RevObject object = rw.parseAny(revid); if (refname.startsWith(Constants.R_HEADS)) { // Ensure that what we start the branch from is a commit. If we // were given a tag, deference to the commit instead. // try { object = rw.parseCommit(object); } catch (IncorrectObjectTypeException notCommit) { throw new IllegalStateException(startingRevision + " not a commit"); } } if (!refControl.canCreate(rw, object)) { throw new IllegalStateException("Cannot create " + refname); } try { final RefUpdate u = repo.updateRef(refname); u.setExpectedOldObjectId(ObjectId.zeroId()); u.setNewObjectId(object.copy()); u.setRefLogIdent(identifiedUser.newRefLogIdent()); u.setRefLogMessage("created via web from " + startingRevision, false); final RefUpdate.Result result = u.update(rw); switch (result) { case FAST_FORWARD: case NEW: case NO_CHANGE: replication.scheduleUpdate(name.getParentKey(), refname); hooks.doRefUpdatedHook(name, u, identifiedUser.getAccount()); break; default: { throw new IOException(result.name()); } } } catch (IOException err) { log.error("Cannot create branch " + name, err); throw err; } } finally { repo.close(); } return listBranchesFactory.create(projectName).call(); }
From source file:com.google.gerrit.pgm.init.AllProjectsConfig.java
License:Apache License
private void updateRef(Repository repo, PersonIdent ident, ObjectId newRevision, String refLogMsg) throws IOException { RefUpdate ru = repo.updateRef(getRefName()); ru.setRefLogIdent(ident);/*ww w. java 2 s . c om*/ ru.setNewObjectId(newRevision); ru.setExpectedOldObjectId(revision); ru.setRefLogMessage(refLogMsg, false); RefUpdate.Result r = ru.update(); switch (r) { case FAST_FORWARD: case NEW: case NO_CHANGE: break; default: throw new IOException("Failed to update " + getRefName() + " of " + project + ": " + r.name()); } }
From source file:com.google.gerrit.pgm.init.api.VersionedMetaDataOnInit.java
License:Apache License
private void updateRef(Repository repo, PersonIdent ident, ObjectId newRevision, String refLogMsg) throws IOException { RefUpdate ru = repo.updateRef(getRefName()); ru.setRefLogIdent(ident);//from w w w . j av a2 s .com ru.setNewObjectId(newRevision); ru.setExpectedOldObjectId(revision); ru.setRefLogMessage(refLogMsg, false); RefUpdate.Result r = ru.update(); switch (r) { case FAST_FORWARD: case NEW: case NO_CHANGE: break; case FORCED: case IO_FAILURE: case LOCK_FAILURE: case NOT_ATTEMPTED: case REJECTED: case REJECTED_CURRENT_BRANCH: case RENAMED: default: throw new IOException("Failed to update " + getRefName() + " of " + project + ": " + r.name()); } }
From source file:com.google.gerrit.server.account.AccountsUpdate.java
License:Apache License
public static void createUserBranch(Repository repo, ObjectInserter oi, PersonIdent committerIdent, PersonIdent authorIdent, Account account) throws IOException { ObjectId id = createInitialEmptyCommit(oi, committerIdent, authorIdent, account.getRegisteredOn()); String refName = RefNames.refsUsers(account.getId()); RefUpdate ru = repo.updateRef(refName); ru.setExpectedOldObjectId(ObjectId.zeroId()); ru.setNewObjectId(id);//from w w w .j ava 2 s . com ru.setForceUpdate(true); ru.setRefLogIdent(committerIdent); ru.setRefLogMessage("Create Account", true); Result result = ru.update(); if (result != Result.NEW) { throw new IOException(String.format("Failed to update ref %s: %s", refName, result.name())); } }
From source file:com.google.gerrit.server.account.AccountsUpdate.java
License:Apache License
public static void deleteUserBranch(Repository repo, PersonIdent refLogIdent, Account.Id accountId) throws IOException { String refName = RefNames.refsUsers(accountId); Ref ref = repo.exactRef(refName); if (ref == null) { return;/*from www .ja v a2s. c om*/ } RefUpdate ru = repo.updateRef(refName); ru.setExpectedOldObjectId(ref.getObjectId()); ru.setNewObjectId(ObjectId.zeroId()); ru.setForceUpdate(true); ru.setRefLogIdent(refLogIdent); ru.setRefLogMessage("Delete Account", true); Result result = ru.delete(); if (result != Result.FORCED) { throw new IOException(String.format("Failed to delete ref %s: %s", refName, result.name())); } }
From source file:com.google.gerrit.server.account.externalids.ExternalIdsUpdate.java
License:Apache License
/** Commits updates to the external IDs. */ public static ObjectId commit(Repository repo, RevWalk rw, ObjectInserter ins, ObjectId rev, NoteMap noteMap, String commitMessage, PersonIdent committerIdent, PersonIdent authorIdent) throws IOException { CommitBuilder cb = new CommitBuilder(); cb.setMessage(commitMessage);// w w w . ja va2 s .c o m cb.setTreeId(noteMap.writeTree(ins)); cb.setAuthor(authorIdent); cb.setCommitter(committerIdent); if (!rev.equals(ObjectId.zeroId())) { cb.setParentId(rev); } else { cb.setParentIds(); // Ref is currently nonexistent, commit has no parents. } if (cb.getTreeId() == null) { if (rev.equals(ObjectId.zeroId())) { cb.setTreeId(emptyTree(ins)); // No parent, assume empty tree. } else { RevCommit p = rw.parseCommit(rev); cb.setTreeId(p.getTree()); // Copy tree from parent. } } ObjectId commitId = ins.insert(cb); ins.flush(); RefUpdate u = repo.updateRef(RefNames.REFS_EXTERNAL_IDS); u.setRefLogIdent(committerIdent); u.setRefLogMessage("Update external IDs", false); u.setExpectedOldObjectId(rev); u.setNewObjectId(commitId); RefUpdate.Result res = u.update(); switch (res) { case NEW: case FAST_FORWARD: case NO_CHANGE: case RENAMED: case FORCED: break; case LOCK_FAILURE: throw new LockFailureException("Updating external IDs failed with " + res); case IO_FAILURE: case NOT_ATTEMPTED: case REJECTED: case REJECTED_CURRENT_BRANCH: default: throw new IOException("Updating external IDs failed with " + res); } return rw.parseCommit(commitId); }
From source file:com.google.gerrit.server.change.ConsistencyChecker.java
License:Apache License
private void fixPatchSetRef(ProblemInfo p, PatchSet ps) { try {//from w ww . ja va 2 s . c om RefUpdate ru = repo.updateRef(ps.getId().toRefName()); ru.setForceUpdate(true); ru.setNewObjectId(ObjectId.fromString(ps.getRevision().get())); ru.setRefLogIdent(newRefLogIdent()); ru.setRefLogMessage("Repair patch set ref", true); RefUpdate.Result result = ru.update(); switch (result) { case NEW: case FORCED: case FAST_FORWARD: case NO_CHANGE: p.status = Status.FIXED; p.outcome = "Repaired patch set ref"; return; default: p.status = Status.FIX_FAILED; p.outcome = "Failed to update patch set ref: " + result; return; } } catch (IOException e) { String msg = "Error fixing patch set ref"; log.warn(msg + ' ' + ps.getId().toRefName(), e); p.status = Status.FIX_FAILED; p.outcome = msg; } }
From source file:com.google.gerrit.server.edit.ChangeEditModifier.java
License:Apache License
private RefUpdate.Result update(Repository repo, IdentifiedUser me, String refName, RevWalk rw, ObjectId oldObjectId, ObjectId newEdit) throws IOException { RefUpdate ru = repo.updateRef(refName); ru.setExpectedOldObjectId(oldObjectId); ru.setNewObjectId(newEdit);/*from ww w . j a v a2s. c o m*/ ru.setRefLogIdent(getRefLogIdent(me)); ru.setRefLogMessage("inline edit (amend)", false); ru.setForceUpdate(true); RefUpdate.Result res = ru.update(rw); if (res != RefUpdate.Result.NEW && res != RefUpdate.Result.FORCED) { throw new IOException("update failed: " + ru); } return res; }
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 {//from w w w .ja v a2 s. 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.SubmoduleOp.java
License:Apache License
/** * Update the submodules in one branch of one repository. * * @param subscriber the branch of the repository which should be changed. * @param updates submodule updates which should be updated to. * @throws SubmoduleException//from w w w. j a v a 2 s . c o m */ private void updateGitlinks(ReviewDb db, Branch.NameKey subscriber, Collection<SubmoduleSubscription> updates) throws SubmoduleException { PersonIdent author = null; StringBuilder msgbuf = new StringBuilder("Updated git submodules\n\n"); boolean sameAuthorForAll = true; try (Repository pdb = repoManager.openRepository(subscriber.getParentKey())) { if (pdb.getRef(subscriber.get()) == null) { throw new SubmoduleException("The branch was probably deleted from the subscriber repository"); } DirCache dc = readTree(pdb, pdb.getRef(subscriber.get())); DirCacheEditor ed = dc.editor(); for (SubmoduleSubscription s : updates) { try (Repository subrepo = repoManager.openRepository(s.getSubmodule().getParentKey()); RevWalk rw = CodeReviewCommit.newRevWalk(subrepo)) { Ref ref = subrepo.getRefDatabase().exactRef(s.getSubmodule().get()); if (ref == null) { ed.add(new DeletePath(s.getPath())); continue; } final ObjectId updateTo = ref.getObjectId(); RevCommit newCommit = rw.parseCommit(updateTo); if (author == null) { author = newCommit.getAuthorIdent(); } else if (!author.equals(newCommit.getAuthorIdent())) { sameAuthorForAll = false; } DirCacheEntry dce = dc.getEntry(s.getPath()); ObjectId oldId; if (dce != null) { if (!dce.getFileMode().equals(FileMode.GITLINK)) { log.error("Requested to update gitlink " + s.getPath() + " in " + s.getSubmodule().getParentKey().get() + " but entry " + "doesn't have gitlink file mode."); continue; } oldId = dce.getObjectId(); } else { // This submodule did not exist before. We do not want to add // the full submodule history to the commit message, so omit it. oldId = updateTo; } ed.add(new PathEdit(s.getPath()) { @Override public void apply(DirCacheEntry ent) { ent.setFileMode(FileMode.GITLINK); ent.setObjectId(updateTo); } }); if (verboseSuperProject) { msgbuf.append("Project: " + s.getSubmodule().getParentKey().get()); msgbuf.append(" " + s.getSubmodule().getShortName()); msgbuf.append(" " + updateTo.getName()); msgbuf.append("\n\n"); try { rw.markStart(newCommit); rw.markUninteresting(rw.parseCommit(oldId)); for (RevCommit c : rw) { msgbuf.append(c.getFullMessage() + "\n\n"); } } catch (IOException e) { logAndThrowSubmoduleException( "Could not perform a revwalk to " + "create superproject commit message", e); } } } } ed.finish(); if (!sameAuthorForAll || author == null) { author = myIdent; } ObjectInserter oi = pdb.newObjectInserter(); ObjectId tree = dc.writeTree(oi); ObjectId currentCommitId = pdb.getRef(subscriber.get()).getObjectId(); CommitBuilder commit = new CommitBuilder(); commit.setTreeId(tree); commit.setParentIds(new ObjectId[] { currentCommitId }); commit.setAuthor(author); commit.setCommitter(myIdent); commit.setMessage(msgbuf.toString()); oi.insert(commit); oi.flush(); ObjectId commitId = oi.idFor(Constants.OBJ_COMMIT, commit.build()); final RefUpdate rfu = pdb.updateRef(subscriber.get()); rfu.setForceUpdate(false); rfu.setNewObjectId(commitId); rfu.setExpectedOldObjectId(currentCommitId); rfu.setRefLogMessage("Submit to " + subscriber.getParentKey().get(), true); switch (rfu.update()) { case NEW: case FAST_FORWARD: gitRefUpdated.fire(subscriber.getParentKey(), rfu); changeHooks.doRefUpdatedHook(subscriber, rfu, account); // TODO since this is performed "in the background" no mail will be // sent to inform users about the updated branch break; default: throw new IOException(rfu.getResult().name()); } // Recursive call: update subscribers of the subscriber updateSuperProjects(db, Sets.newHashSet(subscriber)); } catch (IOException e) { throw new SubmoduleException("Cannot update gitlinks for " + subscriber.get(), e); } }