use of com.google.gerrit.server.change.RebaseUtil.Base in project gerrit by GerritCodeReview.
the class Rebase method findBaseRev.
private ObjectId findBaseRev(Repository repo, RevWalk rw, RevisionResource rsrc, RebaseInput input) throws RestApiException, OrmException, IOException, NoSuchChangeException {
Branch.NameKey destRefKey = rsrc.getChange().getDest();
if (input == null || input.base == null) {
return rebaseUtil.findBaseRevision(rsrc.getPatchSet(), destRefKey, repo, rw);
}
Change change = rsrc.getChange();
String str = input.base.trim();
if (str.equals("")) {
// Remove existing dependency to other patch set.
Ref destRef = repo.exactRef(destRefKey.get());
if (destRef == null) {
throw new ResourceConflictException("can't rebase onto tip of branch " + destRefKey.get() + "; branch doesn't exist");
}
return destRef.getObjectId();
}
@SuppressWarnings("resource") ReviewDb db = dbProvider.get();
Base base = rebaseUtil.parseBase(rsrc, str);
if (base == null) {
throw new ResourceConflictException("base revision is missing: " + str);
}
PatchSet.Id baseId = base.patchSet().getId();
if (!base.control().isPatchVisible(base.patchSet(), db)) {
throw new AuthException("base revision not accessible: " + str);
} else if (change.getId().equals(baseId.getParentKey())) {
throw new ResourceConflictException("cannot rebase change onto itself");
}
Change baseChange = base.control().getChange();
if (!baseChange.getProject().equals(change.getProject())) {
throw new ResourceConflictException("base change is in wrong project: " + baseChange.getProject());
} else if (!baseChange.getDest().equals(change.getDest())) {
throw new ResourceConflictException("base change is targeting wrong branch: " + baseChange.getDest());
} else if (baseChange.getStatus() == Status.ABANDONED) {
throw new ResourceConflictException("base change is abandoned: " + baseChange.getKey());
} else if (isMergedInto(rw, rsrc.getPatchSet(), base.patchSet())) {
throw new ResourceConflictException("base change " + baseChange.getKey() + " is a descendant of the current change - recursion not allowed");
}
return ObjectId.fromString(base.patchSet().getRevision().get());
}
use of com.google.gerrit.server.change.RebaseUtil.Base in project gerrit by GerritCodeReview.
the class RebaseChangeOp method updateRepo.
@Override
public void updateRepo(RepoContext ctx) throws MergeConflictException, InvalidChangeOperationException, RestApiException, IOException, OrmException, NoSuchChangeException, PermissionBackendException {
// Ok that originalPatchSet was not read in a transaction, since we just
// need its revision.
RevId oldRev = originalPatchSet.getRevision();
RevWalk rw = ctx.getRevWalk();
RevCommit original = rw.parseCommit(ObjectId.fromString(oldRev.get()));
rw.parseBody(original);
RevCommit baseCommit = rw.parseCommit(baseCommitId);
String newCommitMessage;
if (detailedCommitMessage) {
rw.parseBody(baseCommit);
newCommitMessage = newMergeUtil().createCommitMessageOnSubmit(original, baseCommit, ctl, originalPatchSet.getId());
} else {
newCommitMessage = original.getFullMessage();
}
rebasedCommit = rebaseCommit(ctx, original, baseCommit, newCommitMessage);
Base base = rebaseUtil.parseBase(new RevisionResource(changeResourceFactory.create(ctl), originalPatchSet), baseCommitId.name());
rebasedPatchSetId = ChangeUtil.nextPatchSetIdFromChangeRefsMap(ctx.getRepoView().getRefs(originalPatchSet.getId().getParentKey().toRefPrefix()), ctl.getChange().currentPatchSetId());
patchSetInserter = patchSetInserterFactory.create(ctl, rebasedPatchSetId, rebasedCommit).setDescription("Rebase").setDraft(originalPatchSet.isDraft()).setNotify(NotifyHandling.NONE).setFireRevisionCreated(fireRevisionCreated).setCopyApprovals(copyApprovals).setCheckAddPatchSetPermission(checkAddPatchSetPermission).setValidate(validate);
if (postMessage) {
patchSetInserter.setMessage("Patch Set " + rebasedPatchSetId.get() + ": Patch Set " + originalPatchSet.getId().get() + " was rebased");
}
if (base != null) {
patchSetInserter.setGroups(base.patchSet().getGroups());
}
patchSetInserter.updateRepo(ctx);
}
Aggregations