Merge branch 'stable-2.12' into stable-2.13

* stable-2.12:
  CloneWithCommitMsgHook: Fix HTTP clone command inconsistency

Change-Id: I8a86b8cc56834933391afd56fc93d4ece67a4401
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/CheckoutCommand.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/CheckoutCommand.java
index 65ca417..79efede 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/CheckoutCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/CheckoutCommand.java
@@ -14,7 +14,7 @@
 
 package com.googlesource.gerrit.plugins.download.command;
 
-import static com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand.CHECKOUT;
+import static com.google.gerrit.extensions.client.GeneralPreferencesInfo.DownloadCommand.CHECKOUT;
 
 import com.google.gerrit.server.config.DownloadConfig;
 import com.google.gerrit.server.config.GerritServerConfig;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/CherryPickCommand.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/CherryPickCommand.java
index cde5a26..f0916d2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/CherryPickCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/CherryPickCommand.java
@@ -14,7 +14,7 @@
 
 package com.googlesource.gerrit.plugins.download.command;
 
-import static com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand.CHERRY_PICK;
+import static com.google.gerrit.extensions.client.GeneralPreferencesInfo.DownloadCommand.CHERRY_PICK;
 
 import com.google.gerrit.server.config.DownloadConfig;
 import com.google.gerrit.server.config.GerritServerConfig;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHook.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHook.java
index 02f3394..dcf7503 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHook.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHook.java
@@ -65,11 +65,15 @@
     }
 
     if (scheme instanceof SshScheme) {
-      return new StringBuilder()
+      StringBuilder b = new StringBuilder()
           .append(super.getCommand(scheme, project))
-          .append(" && scp -p -P ")
-          .append(sshScheme.getSshdPort())
-          .append(" ")
+          .append(" && scp -p");
+
+      if (sshScheme.getSshdPort() != 22) {
+        b.append(" -P ").append(sshScheme.getSshdPort());
+      }
+
+      b.append(" ")
           .append(username)
           .append("@")
           .append(sshScheme.getSshdHost())
@@ -77,8 +81,9 @@
           .append(HOOK)
           .append(" ")
           .append(projectName)
-          .append("/.git/hooks/")
-          .toString();
+          .append("/.git/hooks/");
+
+      return b.toString();
     }
 
     if (scheme instanceof HttpScheme || scheme instanceof AnonymousHttpScheme) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/FormatPatchCommand.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/FormatPatchCommand.java
index 57dfe25..6a120ff 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/FormatPatchCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/FormatPatchCommand.java
@@ -14,7 +14,7 @@
 
 package com.googlesource.gerrit.plugins.download.command;
 
-import static com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand.FORMAT_PATCH;
+import static com.google.gerrit.extensions.client.GeneralPreferencesInfo.DownloadCommand.FORMAT_PATCH;
 
 import com.google.gerrit.server.config.DownloadConfig;
 import com.google.gerrit.server.config.GerritServerConfig;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/GitDownloadCommand.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/GitDownloadCommand.java
index 59742ca..03b817d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/GitDownloadCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/GitDownloadCommand.java
@@ -14,9 +14,9 @@
 
 package com.googlesource.gerrit.plugins.download.command;
 
+import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
 import com.google.gerrit.extensions.config.DownloadCommand;
 import com.google.gerrit.extensions.config.DownloadScheme;
-import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
 import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.reviewdb.client.RefNames;
 import com.google.gerrit.server.config.DownloadConfig;
@@ -54,7 +54,7 @@
 
   GitDownloadCommand(@GerritServerConfig Config cfg,
       DownloadConfig downloadConfig,
-      AccountGeneralPreferences.DownloadCommand cmd,
+      GeneralPreferencesInfo.DownloadCommand cmd,
       GitRepositoryManager repoManager) {
     this.commandAllowed = downloadConfig.getDownloadCommands().contains(cmd);
     this.repoManager = repoManager;
@@ -109,14 +109,12 @@
         ObjectId id = repo.resolve(ref);
         if (id != null) {
           return id.name();
-        } else {
-          log.error(String.format("Cannot resolve ref %s in project %s.", ref,
-              project));
-          return null;
         }
-      } else {
-        return ref;
+        log.error(String.format("Cannot resolve ref %s in project %s.", ref,
+            project));
+        return null;
       }
+      return ref;
     } catch (RepositoryNotFoundException e) {
       log.error(String.format("Missing project: %s",  project), e);
       return null;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/PullCommand.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/PullCommand.java
index b16211a..309f5b2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/PullCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/PullCommand.java
@@ -14,7 +14,7 @@
 
 package com.googlesource.gerrit.plugins.download.command;
 
-import static com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand.PULL;
+import static com.google.gerrit.extensions.client.GeneralPreferencesInfo.DownloadCommand.PULL;
 
 import com.google.gerrit.server.config.DownloadConfig;
 import com.google.gerrit.server.config.GerritServerConfig;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SshScheme.java b/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SshScheme.java
index d85732d..43b3cc2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SshScheme.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SshScheme.java
@@ -50,23 +50,26 @@
         // ignore, then this scheme will be disabled
       }
     }
-    this.sshdAddress = sshAddr;
 
     int port = 29418;
-    String host = sshdAddress;
-    if (sshdAddress != null) {
-      int p = sshdAddress.indexOf(":");
+    String host = sshAddr;
+    if (sshAddr != null) {
+      int p = sshAddr.indexOf(":");
       if (p > 0) {
-        host = sshdAddress.substring(0, p);
+        host = sshAddr.substring(0, p);
         try {
-          port = Integer.parseInt(sshdAddress.substring(p + 1));
+          port = Integer.parseInt(sshAddr.substring(p + 1));
         } catch (NumberFormatException e) {
           // use default port
         }
+        if (port == 22) {
+          sshAddr = host;
+        }
       } else {
-        host = sshdAddress;
+        host = sshAddr;
       }
     }
+    this.sshdAddress = sshAddr;
     this.sshdHost = host;
     this.sshdPort = port;