]> source.dussan.org Git - jgit.git/commitdiff
Transport: load all refs only if push refspecs have wildcards 29/190729/2
authorThomas Wolf <thomas.wolf@paranor.ch>
Fri, 11 Feb 2022 16:18:20 +0000 (17:18 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Mon, 14 Feb 2022 09:45:15 +0000 (10:45 +0100)
There is no need to load all refs if there are no wildcard push
refspecs. Load them lazily on the first wildcard refspec encountered
instead of loading them up-front.

Change-Id: I6d0e981f9ed4997dbdefeb7f83f37ff4f33e06a5
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java

index 5b781ac25f28e84188ef2edc4d31907f88e70f7d..bfe26d9808474f489f1c5c8ff8663c66013fd973 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 2008, 2009 Google Inc.
  * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
  * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
- * Copyright (C) 2008, 2020 Shawn O. Pearce <spearce@spearce.org> and others
+ * Copyright (C) 2008, 2022 Shawn O. Pearce <spearce@spearce.org> and others
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -656,14 +656,18 @@ public abstract class Transport implements AutoCloseable {
        private static Collection<RefSpec> expandPushWildcardsFor(
                        final Repository db, final Collection<RefSpec> specs)
                        throws IOException {
-               final List<Ref> localRefs = db.getRefDatabase().getRefs();
                final Collection<RefSpec> procRefs = new LinkedHashSet<>();
 
+               List<Ref> localRefs = null;
                for (RefSpec spec : specs) {
                        if (spec.isWildcard()) {
+                               if (localRefs == null) {
+                                       localRefs = db.getRefDatabase().getRefs();
+                               }
                                for (Ref localRef : localRefs) {
-                                       if (spec.matchSource(localRef))
+                                       if (spec.matchSource(localRef)) {
                                                procRefs.add(spec.expandFromSource(localRef));
+                                       }
                                }
                        } else {
                                procRefs.add(spec);