Search in sources :

Example 11 with PatchSet

use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method expectedMergedCommitIsOldPatchSetOfSameChange.

@Test
public void expectedMergedCommitIsOldPatchSetOfSameChange() throws Exception {
    ChangeControl ctl = insertChange();
    PatchSet ps1 = psUtil.current(db, ctl.getNotes());
    String rev1 = ps1.getRevision().get();
    ctl = incrementPatchSet(ctl);
    PatchSet ps2 = psUtil.current(db, ctl.getNotes());
    testRepo.branch(ctl.getChange().getDest().get()).update(testRepo.getRevWalk().parseCommit(ObjectId.fromString(rev1)));
    FixInput fix = new FixInput();
    fix.expectMergedAs = rev1;
    assertProblems(ctl, fix, problem("No patch set found for merged commit " + rev1, FIXED, "Marked change as merged"), problem("Expected merge commit " + rev1 + " corresponds to patch set 1," + " not the current patch set 2", FIXED, "Deleted patch set"), problem("Expected merge commit " + rev1 + " corresponds to patch set 1," + " not the current patch set 2", FIXED, "Inserted as patch set 3"));
    ctl = reload(ctl);
    PatchSet.Id psId3 = new PatchSet.Id(ctl.getId(), 3);
    assertThat(ctl.getChange().currentPatchSetId()).isEqualTo(psId3);
    assertThat(ctl.getChange().getStatus()).isEqualTo(Change.Status.MERGED);
    assertThat(psUtil.byChangeAsMap(db, ctl.getNotes()).keySet()).containsExactly(ps2.getId(), psId3);
    assertThat(psUtil.get(db, ctl.getNotes(), psId3).getRevision().get()).isEqualTo(rev1);
}
Also used : ChangeControl(com.google.gerrit.server.project.ChangeControl) TestChanges.newPatchSet(com.google.gerrit.testutil.TestChanges.newPatchSet) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) FixInput(com.google.gerrit.extensions.api.changes.FixInput) ObjectId(org.eclipse.jgit.lib.ObjectId) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with PatchSet

use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.

the class ApprovalCopier method getPatchSets.

private static TreeMap<Integer, PatchSet> getPatchSets(ChangeData cd) throws OrmException {
    Collection<PatchSet> patchSets = cd.patchSets();
    TreeMap<Integer, PatchSet> result = new TreeMap<>();
    for (PatchSet ps : patchSets) {
        result.put(ps.getId().get(), ps);
    }
    return result;
}
Also used : PatchSet(com.google.gerrit.reviewdb.client.PatchSet) TreeMap(java.util.TreeMap)

Example 13 with PatchSet

use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.

the class CommentsUtil method publish.

public void publish(ChangeContext ctx, PatchSet.Id psId, Collection<Comment> drafts, @Nullable String tag) throws OrmException {
    ChangeNotes notes = ctx.getNotes();
    checkArgument(notes != null);
    if (drafts.isEmpty()) {
        return;
    }
    Map<PatchSet.Id, PatchSet> patchSets = psUtil.getAsMap(ctx.getDb(), notes, drafts.stream().map(d -> psId(notes, d)).collect(toSet()));
    for (Comment d : drafts) {
        PatchSet ps = patchSets.get(psId(notes, d));
        if (ps == null) {
            throw new OrmException("patch set " + ps + " not found");
        }
        d.writtenOn = ctx.getWhen();
        d.tag = tag;
        // Draft may have been created by a different real user; copy the current real user. (Only
        // applies to X-Gerrit-RunAs, since modifying drafts via on_behalf_of is not allowed.)
        ctx.getUser().updateRealAccountId(d::setRealAuthor);
        setCommentRevId(d, patchListCache, notes.getChange(), ps);
    }
    putComments(ctx.getDb(), ctx.getUpdate(psId), PUBLISHED, drafts);
}
Also used : PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) Comment(com.google.gerrit.reviewdb.client.Comment) RobotComment(com.google.gerrit.reviewdb.client.RobotComment) ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) GerritServerId(com.google.gerrit.server.config.GerritServerId) ObjectId(org.eclipse.jgit.lib.ObjectId) OrmException(com.google.gwtorm.server.OrmException) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) GerritServerId(com.google.gerrit.server.config.GerritServerId) ObjectId(org.eclipse.jgit.lib.ObjectId)

Example 14 with PatchSet

use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.

the class Mergeable method apply.

@Override
public MergeableInfo apply(RevisionResource resource) throws AuthException, ResourceConflictException, BadRequestException, OrmException, IOException {
    Change change = resource.getChange();
    PatchSet ps = resource.getPatchSet();
    MergeableInfo result = new MergeableInfo();
    if (!change.getStatus().isOpen()) {
        throw new ResourceConflictException("change is " + ChangeUtil.status(change));
    } else if (!ps.getId().equals(change.currentPatchSetId())) {
        // Only the current revision is mergeable. Others always fail.
        return result;
    }
    ChangeData cd = changeDataFactory.create(db.get(), resource.getControl());
    result.submitType = getSubmitType(cd, ps);
    try (Repository git = gitManager.openRepository(change.getProject())) {
        ObjectId commit = toId(ps);
        Ref ref = git.getRefDatabase().exactRef(change.getDest().get());
        ProjectState projectState = projectCache.get(change.getProject());
        String strategy = mergeUtilFactory.create(projectState).mergeStrategyName();
        result.strategy = strategy;
        result.mergeable = isMergable(git, change, commit, ref, result.submitType, strategy);
        if (otherBranches) {
            result.mergeableInto = new ArrayList<>();
            BranchOrderSection branchOrder = projectState.getBranchOrderSection();
            if (branchOrder != null) {
                int prefixLen = Constants.R_HEADS.length();
                String[] names = branchOrder.getMoreStable(ref.getName());
                Map<String, Ref> refs = git.getRefDatabase().exactRef(names);
                for (String n : names) {
                    Ref other = refs.get(n);
                    if (other == null) {
                        continue;
                    }
                    if (cache.get(commit, other, SubmitType.CHERRY_PICK, strategy, change.getDest(), git)) {
                        result.mergeableInto.add(other.getName().substring(prefixLen));
                    }
                }
            }
        }
    }
    return result;
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) BranchOrderSection(com.google.gerrit.server.git.BranchOrderSection) ChangeData(com.google.gerrit.server.query.change.ChangeData) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) MergeableInfo(com.google.gerrit.extensions.common.MergeableInfo) ProjectState(com.google.gerrit.server.project.ProjectState)

Example 15 with PatchSet

use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.

the class Rebase method getDescription.

@Override
public UiAction.Description getDescription(RevisionResource resource) {
    PatchSet patchSet = resource.getPatchSet();
    Change change = resource.getChange();
    Branch.NameKey dest = change.getDest();
    boolean visible = change.getStatus().isOpen() && resource.isCurrent() && resource.permissions().database(dbProvider).testOrFalse(ChangePermission.REBASE);
    boolean enabled = true;
    if (visible) {
        try (Repository repo = repoManager.openRepository(dest.getParentKey());
            RevWalk rw = new RevWalk(repo)) {
            visible = hasOneParent(rw, resource.getPatchSet());
            enabled = rebaseUtil.canRebase(patchSet, dest, repo, rw);
        } catch (IOException e) {
            log.error("Failed to check if patch set can be rebased: " + resource.getPatchSet(), e);
            visible = false;
        }
    }
    return new UiAction.Description().setLabel("Rebase").setTitle("Rebase onto tip of branch or parent change").setVisible(visible).setEnabled(enabled);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Branch(com.google.gerrit.reviewdb.client.Branch) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Aggregations

PatchSet (com.google.gerrit.reviewdb.client.PatchSet)124 Change (com.google.gerrit.reviewdb.client.Change)51 Test (org.junit.Test)44 ObjectId (org.eclipse.jgit.lib.ObjectId)35 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)27 RevCommit (org.eclipse.jgit.revwalk.RevCommit)26 Repository (org.eclipse.jgit.lib.Repository)21 RevId (com.google.gerrit.reviewdb.client.RevId)20 ChangeControl (com.google.gerrit.server.project.ChangeControl)20 ChangeData (com.google.gerrit.server.query.change.ChangeData)19 OrmException (com.google.gwtorm.server.OrmException)19 Timestamp (java.sql.Timestamp)18 RevWalk (org.eclipse.jgit.revwalk.RevWalk)15 Project (com.google.gerrit.reviewdb.client.Project)14 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)11 TestChanges.newPatchSet (com.google.gerrit.testutil.TestChanges.newPatchSet)11 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)10 Account (com.google.gerrit.reviewdb.client.Account)10