ChangeNotes: Enforce project passed to factory matches change

In Ib164511e20 we started passing project to ChangeData.Factory
methods. Unfortunately during review we missed the fact that we're
passing the wrong project to the factory in
Submit#problemsForSubmittingChanges. This has subtle and unfortunate
consequences: using the wrong repository for the mergeability check
will always fail, since the commit to test does not belong to that
repository. The end result is that submitWholeTopic across projects
was intermittently broken, since we could never get the mergeability
check to pass on any change not in the same project as the one where
submit was clicked.

(Except that, maddeningly, when commits are shared between
projects using submitWholeTopic, as was the case before I71efad9d06,
the mergeability checks would succeed anyway, making tests pass when
they shouldn't have.)

Add a sanity check in this factory method. Fix the issue in Submit by
just using the existing ChangeData from the ChangeSet, which it's
unclear why we weren't doing that in the first place. To do so we also
need to teach MergeSuperSet to prepopulate the ChangeControls with the
right user, which are used for visibility checks later.

Change-Id: I3fa88121dde5b5eaaf72ead916466cf6d3e3c9f1
This commit is contained in:
Dave Borowitz
2016-02-18 20:49:54 -05:00
parent 1a245bda61
commit 3e4b231afc
7 changed files with 41 additions and 30 deletions

View File

@@ -23,6 +23,7 @@ import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.change.WalkSorter.PatchSetData;
import com.google.gerrit.server.git.ChangeSet;
import com.google.gerrit.server.git.MergeSuperSet;
@@ -74,7 +75,7 @@ public class SubmittedTogether implements RestReadView<ChangeResource> {
Change c = resource.getChange();
List<ChangeData> cds;
if (c.getStatus().isOpen()) {
cds = getForOpenChange(c);
cds = getForOpenChange(c, resource.getControl().getUser());
} else if (c.getStatus().asChangeStatus() == ChangeStatus.MERGED) {
cds = getForMergedChange(c);
} else {
@@ -99,9 +100,9 @@ public class SubmittedTogether implements RestReadView<ChangeResource> {
}
}
private List<ChangeData> getForOpenChange(Change c)
private List<ChangeData> getForOpenChange(Change c, CurrentUser user)
throws OrmException, IOException {
ChangeSet cs = mergeSuperSet.completeChangeSet(dbProvider.get(), c);
ChangeSet cs = mergeSuperSet.completeChangeSet(dbProvider.get(), c, user);
return cs.changes().asList();
}