diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt index 0f5517c91b..9762465647 100644 --- a/Documentation/rest-api-changes.txt +++ b/Documentation/rest-api-changes.txt @@ -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 diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/Revisions.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/Revisions.java index 3501351d54..2970852a19 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/Revisions.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/Revisions.java @@ -55,11 +55,18 @@ class Revisions implements ChildCollection { @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 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 { 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 find(ChangeResource change, String id) throws OrmException { ReviewDb db = dbProvider.get();