Restrict /changes/{id}/revisions/{commit} one change

If the same commit SHA-1 is pushed to multiple changes
(e.g.  different projects) the /revisions/ collection
was failing to match by SHA-1 due to duplicate results.

The parent ChangeResource provides a way to filter to
more narrow result set, a revision is only valid if it
is known to the parent change.

Change-Id: I76607e31b38a373f0d23447f638ccb242a4083ac
This commit is contained in:
Shawn Pearce
2015-01-06 20:23:30 -08:00
parent 817c2abd54
commit 04c4f09378

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server.change;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Lists;
import com.google.gerrit.extensions.registration.DynamicMap;
@@ -170,8 +171,14 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
private static List<RevisionResource> toResources(final ChangeResource change,
Iterable<PatchSet> patchSets) {
final Change.Id changeId = change.getChange().getId();
return FluentIterable.from(patchSets)
.transform(new Function<PatchSet, RevisionResource>() {
.filter(new Predicate<PatchSet>() {
@Override
public boolean apply(PatchSet in) {
return changeId.equals(in.getId().getParentKey());
}
}).transform(new Function<PatchSet, RevisionResource>() {
@Override
public RevisionResource apply(PatchSet in) {
return new RevisionResource(change, in);