Fix `repo download project nn/p` formatting

The download command wants change-id/patchset not refs/changes/ ref
style string as used by git fetch or pull. Break off the last two
path segments and pass this to repo download.

Move the repo download part of the command name into RepoCommand,
leaving RepoScheme to just return the project name. This better
matches the other types of commands and schemes where the scheme
names the project and the command supplies the invocation and
inserts the URL at the proper position.

Change-Id: I0473b61cccbc3bc1ef38c39aeaa4057ada63f3cc
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/RepoCommand.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/RepoCommand.java
index 5fa8118..2edfac3 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/RepoCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/RepoCommand.java
@@ -34,7 +34,23 @@
   @Override
   public String getCommand(DownloadScheme scheme, String project, String ref) {
     if (commandAllowed && scheme instanceof RepoScheme) {
-      return scheme.getUrl(project) + " " + ref;
+      String id = trim(ref);
+      if (id != null) {
+        return "repo download " + scheme.getUrl(project) + " " + id;
+      }
+    }
+    return null;
+  }
+
+  private static String trim(String ref) {
+    if (ref.startsWith("refs/changes/")) {
+      int s1 = ref.lastIndexOf('/');
+      if (s1 > 0) {
+        int s2 = ref.lastIndexOf('/', s1 - 1);
+        if (s2 > 0) {
+          return ref.substring(s2 + 1);
+        }
+      }
     }
     return null;
   }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/scheme/RepoScheme.java b/src/main/java/com/googlesource/gerrit/plugins/download/scheme/RepoScheme.java
index 388a7b4..9147d12 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/scheme/RepoScheme.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/scheme/RepoScheme.java
@@ -33,7 +33,7 @@
 
   @Override
   public String getUrl(String project) {
-    return "repo download " + project;
+    return project;
   }
 
   @Override