Fix PushOne toString() to show the right refs and hidden number
Include all refs without applying any limit when `maxRefsToShow`
is set to 0 and limit the displayed refs to the specified maximum
when `maxRefsToShow` is greater than 0. Previously, the method
always limited the number of refs to `maxRefsToShow`, and
`maxRefsToShow` was updated to the batch count when initially
set to 0.
Remove the calculation of hidden refs to avoid performance
issues with millions of refs.
Bug: Issue 375798125
Release-Notes: skip
Change-Id: I30aae0cebf4fe28309542808baeeb316e1e7fb52
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
index a648845..c9b9994 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
@@ -69,6 +69,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.eclipse.jgit.errors.NoRemoteRepositoryException;
import org.eclipse.jgit.errors.NotSupportedException;
import org.eclipse.jgit.errors.RemoteRepositoryException;
@@ -246,18 +247,14 @@
protected String getLimitedRefs() {
Set<ImmutableSet<String>> refs = getRefs();
int maxRefsToShow = replConfig.getMaxRefsToShow();
- if (maxRefsToShow == 0) {
- maxRefsToShow = refs.size();
- }
- String refsString =
- refs.stream()
- .flatMap(Collection::stream)
- .limit(maxRefsToShow)
- .collect(Collectors.joining(" "));
- int hiddenRefs = refs.size() - maxRefsToShow;
- if (hiddenRefs > 0) {
- refsString += " (+" + hiddenRefs + ")";
- }
+
+ Stream<String> refsStream = refs.stream().flatMap(Collection::stream);
+
+ Stream<String> refsFiltered =
+ (maxRefsToShow == 0) ? refsStream : refsStream.limit(maxRefsToShow);
+
+ String refsString = refsFiltered.collect(Collectors.joining(" "));
+
return "[" + refsString + "]";
}