Merge "Accept /changes/*/revisions/current to mean current patch set"
This commit is contained in:
@@ -1429,6 +1429,7 @@ Identifier that uniquely identifies one revision of a change.
|
||||
|
||||
This can be:
|
||||
|
||||
* the literal `current` to name the current patch set/revision
|
||||
* a commit ID ("674ac754f91e64a0efb8087e59a176484bd534d1")
|
||||
* an abbreviated commit ID that uniquely identifies one revision of the
|
||||
change ("674ac754"), at least 4 digits are required
|
||||
|
@@ -55,11 +55,18 @@ class Revisions implements ChildCollection<ChangeResource, RevisionResource> {
|
||||
@Override
|
||||
public RevisionResource parse(ChangeResource change, IdString id)
|
||||
throws ResourceNotFoundException, OrmException {
|
||||
if (id.equals("current")) {
|
||||
PatchSet.Id p = change.getChange().currentPatchSetId();
|
||||
PatchSet ps = p != null ? dbProvider.get().patchSets().get(p) : null;
|
||||
if (ps != null && visible(change, ps)) {
|
||||
return new RevisionResource(change, ps);
|
||||
}
|
||||
throw new ResourceNotFoundException(id);
|
||||
}
|
||||
List<PatchSet> match = Lists.newArrayListWithExpectedSize(2);
|
||||
for (PatchSet ps : find(change, id.get())) {
|
||||
Change.Id changeId = ps.getId().getParentKey();
|
||||
if (changeId.equals(change.getChange().getId())
|
||||
&& change.getControl().isPatchVisible(ps, dbProvider.get())) {
|
||||
if (changeId.equals(change.getChange().getId()) && visible(change, ps)) {
|
||||
match.add(ps);
|
||||
}
|
||||
}
|
||||
@@ -69,6 +76,11 @@ class Revisions implements ChildCollection<ChangeResource, RevisionResource> {
|
||||
return new RevisionResource(change, match.get(0));
|
||||
}
|
||||
|
||||
private boolean visible(ChangeResource change, PatchSet ps)
|
||||
throws OrmException {
|
||||
return change.getControl().isPatchVisible(ps, dbProvider.get());
|
||||
}
|
||||
|
||||
private List<PatchSet> find(ChangeResource change, String id)
|
||||
throws OrmException {
|
||||
ReviewDb db = dbProvider.get();
|
||||
|
Reference in New Issue
Block a user