Add port to replication status and display path for local replication
Replication status was only displaying the hostname. It is impossible
to differentiate replication status when 2 urls use the same hostname
with different ports.
Replication status now displays host[:port] and if the replication
url does not have host(file:///), displays the path instead.
Here are some examples of replication url and the replication status
that is displayed:
-url = git://someHost.com/${name}.git
Replicate project1 to someHost, Succeeded!
-url = git://someHost:1234/${name}.git
Replicate project1 to someHost:1234, Succeeded!
-url = file:///somePath/git/${name}.git
Replicate project1 to /somePath/git/project1.git, Succeeded!
Change-Id: Ia86154cb9f26dfdcae37dc9993fe2cd0f7c37838
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java b/src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java
index 27c8b85..0452b69 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java
@@ -34,6 +34,20 @@
// Default doing nothing
}
+ private static String resolveNodeName(URIish uri) {
+ StringBuilder sb = new StringBuilder();
+ if (uri.isRemote()) {
+ sb.append(uri.getHost());
+ if (uri.getPort() != -1) {
+ sb.append(":");
+ sb.append(uri.getPort());
+ }
+ } else {
+ sb.append(uri.getPath());
+ }
+ return sb.toString();
+ }
+
public static class CommandProcessing extends PushResultProcessing {
private WeakReference<StartCommand> sshCommand;
private AtomicBoolean hasError = new AtomicBoolean();
@@ -49,11 +63,7 @@
sb.append("Replicate ");
sb.append(project);
sb.append(" to ");
- if (uri.getHost() != null) {
- sb.append(uri.getHost());
- } else {
- sb.append("localhost");
- }
+ sb.append(resolveNodeName(uri));
sb.append(", ");
switch (status) {
case SUCCEEDED: