summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChad Horohoe <chorohoe@wikimedia.org>2012-12-18 16:20:41 -0500
committerChad Horohoe <chorohoe@wikimedia.org>2012-12-19 09:10:28 -0500
commit5cef6e590f9dabe83a83c0bde28f78edf8a76f78 (patch)
tree2977fdd7ba6889ced2e63b249c5d6d7611c40263
parentbe37ad5cb0356dbd682fede1612acf46a4417ca1 (diff)
Add remote.NAME.remoteNameStyle
Github and Gitorious have naming conventions that do not allow for slashes in the repository name. This new option allows you to configure the replication plugin to replace slashes in the ${name} placeholder with dashes (-) or underscores (_). This option makes it much easier to replicate repositories from Gerrit to Github or Gitorious Change-Id: Ic4cd5ba6917412675342f6d1126f4b564c72a91a
-rw-r--r--src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java12
-rw-r--r--src/main/resources/Documentation/config.md13
2 files changed, 25 insertions, 0 deletions
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
index 7b8975e..a52050e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
@@ -14,6 +14,7 @@
package com.googlesource.gerrit.plugins.replication;
+import com.google.common.base.Objects;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
@@ -70,6 +71,7 @@ class Destination {
private final ProjectControl.Factory projectControlFactory;
private final GitRepositoryManager gitManager;
private final boolean replicatePermissions;
+ private final String remoteNameStyle;
private volatile WorkQueue.Executor pool;
private final PerThreadRequestScope.Scoper threadScoper;
@@ -91,6 +93,8 @@ class Destination {
poolName = "ReplicateTo-" + rc.getName();
replicatePermissions =
cfg.getBoolean("remote", rc.getName(), "replicatePermissions", true);
+ remoteNameStyle = Objects.firstNonNull(
+ cfg.getString("remote", rc.getName(), "remoteNameStyle"), "slash");
final CurrentUser remoteUser;
String[] authGroupNames = cfg.getStringList("remote", rc.getName(), "authGroup");
@@ -345,6 +349,14 @@ class Destination {
if (needsUrlEncoding(uri)) {
name = encode(name);
}
+ if (remoteNameStyle.equals("dash")) {
+ name = name.replace("/", "-");
+ } else if(remoteNameStyle.equals("underscore")) {
+ name = name.replace("/", "_");
+ } else if (!remoteNameStyle.equals("slash")) {
+ ReplicationQueue.log.debug(String.format(
+ "Unknown remoteNameStyle: %s, falling back to slash", remoteNameStyle));
+ }
String replacedPath = ReplicationQueue.replaceName(uri.getPath(), name);
if (replacedPath != null) {
uri = uri.setPath(replacedPath);
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index 4b8c6c6..fd90581 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -216,6 +216,19 @@ remote.NAME.mirror
By default, false, do not remove remote branches.
+remote.NAME.remoteNameStyle
+: Slashes in the `${name}` placeholder are replaced with either
+ dashes or underscores.
+
+ Github and Gitorious do not permit slashes "/" in repository
+ names and changes this to dashes "-" at repository creation
+ time. If set to "dash," this changes slashes to dashes in the
+ repository name. If set to "underscore", this changes slashes
+ to underscores in the repository name.
+
+ By default, "slash," remote name will contain slashes as they
+ do in Gerrit.
+
File `secure.config`
--------------------