Handle edits in GetRelated
GetRelated collects all patch sets of all open changes, but was not including the edit itself. Change-Id: Iff6389a11ea1befd998d6b21616661f14e2665e2
This commit is contained in:
parent
59039f507d
commit
9091ccf6f1
@ -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<ChangeAndCommit> 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<ChangeAndCommit> getRelated(PatchSet.Id ps) throws IOException {
|
||||
return getRelated(ps.getParentKey(), ps.get());
|
||||
}
|
||||
|
||||
private List<ChangeAndCommit> 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())));
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -91,7 +91,7 @@ public class GetRelated implements RestReadView<RevisionResource> {
|
||||
private List<ChangeAndCommit> walk(RevisionResource rsrc, RevWalk rw, Ref ref)
|
||||
throws OrmException, IOException {
|
||||
Map<Change.Id, Change> changes = allOpenChanges(rsrc);
|
||||
Map<PatchSet.Id, PatchSet> patchSets = allPatchSets(changes.keySet());
|
||||
Map<PatchSet.Id, PatchSet> patchSets = allPatchSets(rsrc, changes.keySet());
|
||||
|
||||
Map<String, PatchSet> commits = Maps.newHashMap();
|
||||
for (PatchSet p : patchSets.values()) {
|
||||
@ -143,8 +143,8 @@ public class GetRelated implements RestReadView<RevisionResource> {
|
||||
db.changes().byBranchOpenAll(rsrc.getChange().getDest()));
|
||||
}
|
||||
|
||||
private Map<PatchSet.Id, PatchSet> allPatchSets(Collection<Change.Id> ids)
|
||||
throws OrmException {
|
||||
private Map<PatchSet.Id, PatchSet> allPatchSets(RevisionResource rsrc,
|
||||
Collection<Change.Id> ids) throws OrmException {
|
||||
int n = ids.size();
|
||||
ReviewDb db = dbProvider.get();
|
||||
List<ResultSet<PatchSet>> t = Lists.newArrayListWithCapacity(n);
|
||||
@ -158,6 +158,10 @@ public class GetRelated implements RestReadView<RevisionResource> {
|
||||
r.put(p.getId(), p);
|
||||
}
|
||||
}
|
||||
|
||||
if (rsrc.getEdit().isPresent()) {
|
||||
r.put(rsrc.getPatchSet().getId(), rsrc.getPatchSet());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user