本文整理汇总了Java中com.google.gerrit.server.ChangeUtil.nextPatchSetId方法的典型用法代码示例。如果您正苦于以下问题:Java ChangeUtil.nextPatchSetId方法的具体用法?Java ChangeUtil.nextPatchSetId怎么用?Java ChangeUtil.nextPatchSetId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gerrit.server.ChangeUtil
的用法示例。
在下文中一共展示了ChangeUtil.nextPatchSetId方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertPatchSet
import com.google.gerrit.server.ChangeUtil; //导入方法依赖的package包/类
private Change.Id insertPatchSet(
BatchUpdate bu,
Repository git,
ChangeNotes destNotes,
CodeReviewCommit cherryPickCommit,
CherryPickInput input)
throws IOException, OrmException, BadRequestException, ConfigInvalidException {
Change destChange = destNotes.getChange();
PatchSet.Id psId = ChangeUtil.nextPatchSetId(git, destChange.currentPatchSetId());
PatchSetInserter inserter = patchSetInserterFactory.create(destNotes, psId, cherryPickCommit);
inserter
.setMessage("Uploaded patch set " + inserter.getPatchSetId().get() + ".")
.setNotify(input.notify)
.setAccountsToNotify(notifyUtil.resolveAccounts(input.notifyDetails));
bu.addOp(destChange.getId(), inserter);
return destChange.getId();
}
示例2: insertPatchSet
import com.google.gerrit.server.ChangeUtil; //导入方法依赖的package包/类
private void insertPatchSet(
BatchUpdate bu,
Repository git,
Change change,
RevCommit cherryPickCommit,
ChangeControl changeControl,
String pullRequestMessage)
throws IOException, UpdateException, RestApiException {
try (RevWalk revWalk = new RevWalk(git)) {
PatchSet.Id psId = ChangeUtil.nextPatchSetId(git, change.currentPatchSetId());
PatchSetInserter patchSetInserter =
patchSetInserterFactory.create(changeControl, psId, cherryPickCommit);
patchSetInserter.setMessage(pullRequestMessage);
patchSetInserter.setValidate(false);
bu.addOp(change.getId(), patchSetInserter);
bu.execute();
}
}
示例3: publish
import com.google.gerrit.server.ChangeUtil; //导入方法依赖的package包/类
/**
* Promote change edit to patch set, by squashing the edit into its parent.
*
* @param updateFactory factory for creating updates.
* @param notes the {@code ChangeNotes} of the change to which the change edit belongs
* @param user the current user
* @param edit change edit to publish
* @param notify Notify handling that defines to whom email notifications should be sent after the
* change edit is published.
* @param accountsToNotify Accounts that should be notified after the change edit is published.
* @throws IOException
* @throws OrmException
* @throws UpdateException
* @throws RestApiException
*/
public void publish(
BatchUpdate.Factory updateFactory,
ChangeNotes notes,
CurrentUser user,
final ChangeEdit edit,
NotifyHandling notify,
ListMultimap<RecipientType, Account.Id> accountsToNotify)
throws IOException, OrmException, RestApiException, UpdateException {
Change change = edit.getChange();
try (Repository repo = gitManager.openRepository(change.getProject());
ObjectInserter oi = repo.newObjectInserter();
ObjectReader reader = oi.newReader();
RevWalk rw = new RevWalk(reader)) {
PatchSet basePatchSet = edit.getBasePatchSet();
if (!basePatchSet.getId().equals(change.currentPatchSetId())) {
throw new ResourceConflictException("only edit for current patch set can be published");
}
RevCommit squashed = squashEdit(rw, oi, edit.getEditCommit(), basePatchSet);
PatchSet.Id psId = ChangeUtil.nextPatchSetId(repo, change.currentPatchSetId());
PatchSetInserter inserter =
patchSetInserterFactory
.create(notes, psId, squashed)
.setNotify(notify)
.setAccountsToNotify(accountsToNotify);
StringBuilder message =
new StringBuilder("Patch Set ").append(inserter.getPatchSetId().get()).append(": ");
// Previously checked that the base patch set is the current patch set.
ObjectId prior = ObjectId.fromString(basePatchSet.getRevision().get());
ChangeKind kind =
changeKindCache.getChangeKind(change.getProject(), rw, repo.getConfig(), prior, squashed);
if (kind == ChangeKind.NO_CODE_CHANGE) {
message.append("Commit message was updated.");
inserter.setDescription("Edit commit message");
} else {
message
.append("Published edit on patch set ")
.append(basePatchSet.getPatchSetId())
.append(".");
}
try (BatchUpdate bu =
updateFactory.create(db.get(), change.getProject(), user, TimeUtil.nowTs())) {
bu.setRepository(repo, rw, oi);
bu.addOp(change.getId(), inserter.setMessage(message.toString()));
bu.addOp(
change.getId(),
new BatchUpdateOp() {
@Override
public void updateRepo(RepoContext ctx) throws Exception {
ctx.addRefUpdate(edit.getEditCommit().copy(), ObjectId.zeroId(), edit.getRefName());
}
});
bu.execute();
}
}
}
示例4: applyImpl
import com.google.gerrit.server.ChangeUtil; //导入方法依赖的package包/类
@Override
protected Response<ChangeInfo> applyImpl(
BatchUpdate.Factory updateFactory, ChangeResource rsrc, MergePatchSetInput in)
throws OrmException, IOException, InvalidChangeOperationException, RestApiException,
UpdateException, PermissionBackendException {
rsrc.permissions().database(db).check(ChangePermission.ADD_PATCH_SET);
MergeInput merge = in.merge;
if (merge == null || Strings.isNullOrEmpty(merge.source)) {
throw new BadRequestException("merge.source must be non-empty");
}
in.baseChange = Strings.nullToEmpty(in.baseChange).trim();
PatchSet ps = psUtil.current(db.get(), rsrc.getNotes());
ProjectState projectState = projectCache.checkedGet(rsrc.getProject());
Change change = rsrc.getChange();
Project.NameKey project = change.getProject();
Branch.NameKey dest = change.getDest();
try (Repository git = gitManager.openRepository(project);
ObjectInserter oi = git.newObjectInserter();
ObjectReader reader = oi.newReader();
RevWalk rw = new RevWalk(reader)) {
RevCommit sourceCommit = MergeUtil.resolveCommit(git, rw, merge.source);
if (!commits.canRead(projectState, git, sourceCommit)) {
throw new ResourceNotFoundException(
"cannot find source commit: " + merge.source + " to merge.");
}
RevCommit currentPsCommit;
List<String> groups = null;
if (!in.inheritParent && !in.baseChange.isEmpty()) {
PatchSet basePS = findBasePatchSet(in.baseChange);
currentPsCommit = rw.parseCommit(ObjectId.fromString(basePS.getRevision().get()));
groups = basePS.getGroups();
} else {
currentPsCommit = rw.parseCommit(ObjectId.fromString(ps.getRevision().get()));
}
Timestamp now = TimeUtil.nowTs();
IdentifiedUser me = user.get().asIdentifiedUser();
PersonIdent author = me.newCommitterIdent(now, serverTimeZone);
RevCommit newCommit =
createMergeCommit(
in,
projectState,
dest,
git,
oi,
rw,
currentPsCommit,
sourceCommit,
author,
ObjectId.fromString(change.getKey().get().substring(1)));
PatchSet.Id nextPsId = ChangeUtil.nextPatchSetId(ps.getId());
PatchSetInserter psInserter =
patchSetInserterFactory.create(rsrc.getNotes(), nextPsId, newCommit);
try (BatchUpdate bu = updateFactory.create(db.get(), project, me, now)) {
bu.setRepository(git, rw, oi);
psInserter
.setMessage("Uploaded patch set " + nextPsId.get() + ".")
.setNotify(NotifyHandling.NONE)
.setCheckAddPatchSetPermission(false)
.setNotify(NotifyHandling.NONE);
if (groups != null) {
psInserter.setGroups(groups);
}
bu.addOp(rsrc.getId(), psInserter);
bu.execute();
}
ChangeJson json = jsonFactory.create(ListChangesOption.CURRENT_REVISION);
return Response.ok(json.format(psInserter.getChange()));
}
}
示例5: applyImpl
import com.google.gerrit.server.ChangeUtil; //导入方法依赖的package包/类
@Override
protected Response<String> applyImpl(
BatchUpdate.Factory updateFactory, ChangeResource resource, CommitMessageInput input)
throws IOException, UnchangedCommitMessageException, RestApiException, UpdateException,
PermissionBackendException, OrmException, ConfigInvalidException {
PatchSet ps = psUtil.current(db.get(), resource.getNotes());
if (ps == null) {
throw new ResourceConflictException("current revision is missing");
}
if (input == null) {
throw new BadRequestException("input cannot be null");
}
String sanitizedCommitMessage = CommitMessageUtil.checkAndSanitizeCommitMessage(input.message);
ensureCanEditCommitMessage(resource.getNotes());
ensureChangeIdIsCorrect(
projectCache.checkedGet(resource.getProject()).isRequireChangeID(),
resource.getChange().getKey().get(),
sanitizedCommitMessage);
NotifyHandling notify = input.notify;
if (notify == null) {
notify = resource.getChange().isWorkInProgress() ? NotifyHandling.OWNER : NotifyHandling.ALL;
}
try (Repository repository = repositoryManager.openRepository(resource.getProject());
RevWalk revWalk = new RevWalk(repository);
ObjectInserter objectInserter = repository.newObjectInserter()) {
RevCommit patchSetCommit = revWalk.parseCommit(ObjectId.fromString(ps.getRevision().get()));
String currentCommitMessage = patchSetCommit.getFullMessage();
if (input.message.equals(currentCommitMessage)) {
throw new ResourceConflictException("new and existing commit message are the same");
}
Timestamp ts = TimeUtil.nowTs();
try (BatchUpdate bu =
updateFactory.create(
db.get(), resource.getChange().getProject(), currentUserProvider.get(), ts)) {
// Ensure that BatchUpdate will update the same repo
bu.setRepository(repository, new RevWalk(objectInserter.newReader()), objectInserter);
PatchSet.Id psId = ChangeUtil.nextPatchSetId(repository, ps.getId());
ObjectId newCommit =
createCommit(objectInserter, patchSetCommit, sanitizedCommitMessage, ts);
PatchSetInserter inserter = psInserterFactory.create(resource.getNotes(), psId, newCommit);
inserter.setMessage(
String.format("Patch Set %s: Commit message was updated.", psId.getId()));
inserter.setDescription("Edit commit message");
inserter.setNotify(notify);
inserter.setAccountsToNotify(notifyUtil.resolveAccounts(input.notifyDetails));
bu.addOp(resource.getChange().getId(), inserter);
bu.execute();
}
}
return Response.ok("ok");
}
示例6: nextPatchSetId
import com.google.gerrit.server.ChangeUtil; //导入方法依赖的package包/类
private PatchSet.Id nextPatchSetId(ChangeNotes notes) throws Exception {
return ChangeUtil.nextPatchSetId(
testRepo.getRepository(), notes.getChange().currentPatchSetId());
}