From 9091ccf6f1a4ed0feccb77ea249ef91a35a85f5f Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Thu, 11 Sep 2014 15:52:16 +0200 Subject: [PATCH] Handle edits in GetRelated GetRelated collects all patch sets of all open changes, but was not including the edit itself. Change-Id: Iff6389a11ea1befd998d6b21616661f14e2665e2 --- .../server/change/GetRelatedIT.java | 48 ++++++++++++++++++- .../client/change/RelatedChangesTab.java | 2 +- .../gerrit/server/change/GetRelated.java | 10 ++-- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/change/GetRelatedIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/change/GetRelatedIT.java index 1456086c95..4a577ccd82 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/change/GetRelatedIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/change/GetRelatedIT.java @@ -28,7 +28,10 @@ import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.server.change.GetRelated.ChangeAndCommit; import com.google.gerrit.server.change.GetRelated.RelatedInfo; +import com.google.gerrit.server.edit.ChangeEditModifier; +import com.google.gerrit.server.edit.ChangeEditUtil; import com.google.gwtorm.server.OrmException; +import com.google.inject.Inject; import org.eclipse.jgit.api.ResetCommand.ResetType; import org.eclipse.jgit.api.errors.GitAPIException; @@ -38,6 +41,11 @@ import java.io.IOException; import java.util.List; public class GetRelatedIT extends AbstractDaemonTest { + @Inject + private ChangeEditUtil editUtil; + + @Inject + private ChangeEditModifier editModifier; @Test public void getRelatedNoResult() throws GitAPIException, @@ -139,15 +147,51 @@ public class GetRelatedIT extends AbstractDaemonTest { } } + @Test + public void getRelatedEdit() throws Exception { + add(git, "a.txt", "1"); + Commit c1 = createCommit(git, admin.getIdent(), "subject: 1"); + add(git, "b.txt", "2"); + Commit c2 = createCommit(git, admin.getIdent(), "subject: 2"); + add(git, "b.txt", "3"); + Commit c3 = createCommit(git, admin.getIdent(), "subject: 3"); + pushHead(git, "refs/for/master", false); + + Change ch2 = getChange(c2); + editModifier.createEdit(ch2, getPatchSet(ch2)); + String editRev = editUtil.byChange(ch2).get().getRevision().get(); + + List related = getRelated(ch2.getId(), 0); + assertEquals(3, related.size()); + assertEquals("related to " + c2.getChangeId(), c3.getChangeId(), related.get(0).changeId); + assertEquals("related to " + c2.getChangeId(), c2.getChangeId(), related.get(1).changeId); + assertEquals("has edit revision number", 0, related.get(1)._revisionNumber.intValue()); + assertEquals("has edit revision " + editRev, editRev, related.get(1).commit.commit); + assertEquals("related to " + c2.getChangeId(), c1.getChangeId(), related.get(2).changeId); + } + private List getRelated(PatchSet.Id ps) throws IOException { + return getRelated(ps.getParentKey(), ps.get()); + } + + private List getRelated(Change.Id changeId, int ps) + throws IOException { String url = String.format("/changes/%d/revisions/%d/related", - ps.getParentKey().get(), ps.get()); + changeId.get(), ps); return newGson().fromJson(adminSession.get(url).getReader(), RelatedInfo.class).changes; } private PatchSet.Id getPatchSetId(Commit c) throws OrmException { + return getChange(c).currentPatchSetId(); + } + + private PatchSet getPatchSet(Change c) throws OrmException { + return db.patchSets().get(c.currentPatchSetId()); + } + + private Change getChange(Commit c) throws OrmException { return Iterables.getOnlyElement( - db.changes().byKey(new Change.Key(c.getChangeId()))).currentPatchSetId(); + db.changes().byKey(new Change.Key(c.getChangeId()))); } } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/RelatedChangesTab.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/RelatedChangesTab.java index e1ce99d014..4717ad01e5 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/RelatedChangesTab.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/RelatedChangesTab.java @@ -311,7 +311,7 @@ class RelatedChangesTab implements IsWidget { PatchSet.Id id = info.patch_set_id(); return "#" + PageLinks.toChange( id.getParentKey(), - String.valueOf(id.get())); + id.getId()); } GitwebLink gw = Gerrit.getGitwebLink(); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/GetRelated.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/GetRelated.java index fd727c4fb1..48349500e2 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/GetRelated.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/GetRelated.java @@ -91,7 +91,7 @@ public class GetRelated implements RestReadView { private List walk(RevisionResource rsrc, RevWalk rw, Ref ref) throws OrmException, IOException { Map changes = allOpenChanges(rsrc); - Map patchSets = allPatchSets(changes.keySet()); + Map patchSets = allPatchSets(rsrc, changes.keySet()); Map commits = Maps.newHashMap(); for (PatchSet p : patchSets.values()) { @@ -143,8 +143,8 @@ public class GetRelated implements RestReadView { db.changes().byBranchOpenAll(rsrc.getChange().getDest())); } - private Map allPatchSets(Collection ids) - throws OrmException { + private Map allPatchSets(RevisionResource rsrc, + Collection ids) throws OrmException { int n = ids.size(); ReviewDb db = dbProvider.get(); List> t = Lists.newArrayListWithCapacity(n); @@ -158,6 +158,10 @@ public class GetRelated implements RestReadView { r.put(p.getId(), p); } } + + if (rsrc.getEdit().isPresent()) { + r.put(rsrc.getPatchSet().getId(), rsrc.getPatchSet()); + } return r; }