Fix the default logic in managing refs-filter The refs-filter logic was inherently broken, by considering an empty list of patterns as matching any string, potentially blocking processing of ref-updates. Align the logic between ExcludedRefsFilter and SyncRefsFilter giving the same common logic of how to manage defaults. Bug: Issue 15424 Change-Id: I7347555b30aafe94ae747440477f2a66ae71f34f
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/filter/ExcludedRefsFilter.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/filter/ExcludedRefsFilter.java index f2e4ab3..63755b4 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/filter/ExcludedRefsFilter.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/filter/ExcludedRefsFilter.java
@@ -24,21 +24,8 @@ @Singleton public class ExcludedRefsFilter extends RefsFilter { - @Inject - public ExcludedRefsFilter(ReplicationConfig replicationConfig) { - super(replicationConfig); - } - - @Override - protected List<String> getRefNamePatterns(Config cfg) { - return ImmutableList.<String>builder() - .addAll(getDefaultExcludeRefPatterns()) - .addAll(ImmutableList.copyOf(cfg.getStringList("replication", null, "excludeRefs"))) - .build(); - } - - private List<String> getDefaultExcludeRefPatterns() { - return ImmutableList.of( + public static String[] DEFAULT_REPLICATION_EXCLUDE_REFS = + new String[] { RefNames.REFS_USERS + "*", RefNames.REFS_CONFIG, RefNames.REFS_SEQUENCES + "*", @@ -46,6 +33,20 @@ RefNames.REFS_GROUPS + "*", RefNames.REFS_GROUPNAMES, RefNames.REFS_CACHE_AUTOMERGE + "*", - RefNames.REFS_STARRED_CHANGES + "*"); + RefNames.REFS_STARRED_CHANGES + "*" + }; + + @Inject + public ExcludedRefsFilter(ReplicationConfig replicationConfig) { + super(replicationConfig); + } + + @Override + protected List<String> getRefNamePatterns(Config cfg) { + String[] replicationExcludeRefs = cfg.getStringList("replication", null, "excludeRefs"); + if (replicationExcludeRefs.length == 0) { + replicationExcludeRefs = DEFAULT_REPLICATION_EXCLUDE_REFS; + } + return ImmutableList.copyOf(replicationExcludeRefs); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/filter/RefsFilter.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/filter/RefsFilter.java index 7ec19ea..7ab44f9 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/filter/RefsFilter.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/filter/RefsFilter.java
@@ -48,9 +48,6 @@ throw new IllegalArgumentException( String.format("Ref name cannot be null or empty, but was %s", refName)); } - if (refsPatterns.isEmpty()) { - return true; - } for (String pattern : refsPatterns) { if (matchesPattern(refName, pattern)) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/filter/SyncRefsFilter.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/filter/SyncRefsFilter.java index a069935..7d004f5 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/filter/SyncRefsFilter.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/filter/SyncRefsFilter.java
@@ -30,6 +30,10 @@ @Override protected List<String> getRefNamePatterns(Config cfg) { - return ImmutableList.copyOf(cfg.getStringList("replication", null, "syncRefs")); + String[] replicationSyncRefs = cfg.getStringList("replication", null, "syncRefs"); + if (replicationSyncRefs.length == 0) { + replicationSyncRefs = new String[] {"*"}; + } + return ImmutableList.copyOf(replicationSyncRefs); } }
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md index 68c9001..b2470a4 100644 --- a/src/main/resources/Documentation/config.md +++ b/src/main/resources/Documentation/config.md
@@ -169,7 +169,7 @@ treated as single ref matches. So `foo/bar` matches only the ref `foo/bar`, but no other refs. - Following refs are always excluded from the git fetch calls: + By default, the following refs are excluded from the git fetch calls: - refs/users/* - refs/meta/config - refs/sequences/* @@ -179,8 +179,6 @@ - refs/cache-automerge/* - refs/starred-changes/* - By default, all other refs are included. - Note that if you are using @PLUGIN@ together with multi-site, you should explicitly exclude `refs/multi-site/version` from being replicated.