Search in sources :

Example 1 with Base

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());
}
Also used : Ref(org.eclipse.jgit.lib.Ref) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Branch(com.google.gerrit.reviewdb.client.Branch) AuthException(com.google.gerrit.extensions.restapi.AuthException) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) Base(com.google.gerrit.server.change.RebaseUtil.Base)

Example 2 with Base

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);
}
Also used : RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevId(com.google.gerrit.reviewdb.client.RevId) Base(com.google.gerrit.server.change.RebaseUtil.Base) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

Base (com.google.gerrit.server.change.RebaseUtil.Base)2 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 Branch (com.google.gerrit.reviewdb.client.Branch)1 Change (com.google.gerrit.reviewdb.client.Change)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 RevId (com.google.gerrit.reviewdb.client.RevId)1 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)1 Ref (org.eclipse.jgit.lib.Ref)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1