Don't show SSH default port in download commands
If the default SSH port (22) is used there is no need to include it
into the download commands since all command-line utilities (e.g. ssh,
scp) will use this port by default.
Bug: Issue 4037
Change-Id: I023b884df1dd9599aaff927592e3ef1beb766f15
Signed-off-by: Edwin Kempin <ekempin@google.com>
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 948215b..f5ebef6 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/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;