From: Thomas Wolf Date: Fri, 11 Feb 2022 16:18:20 +0000 (+0100) Subject: Transport: load all refs only if push refspecs have wildcards X-Git-Tag: v6.1.0.202202221755-m3~6 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=63c1c6e4d84105f3cc41d6b0e32cb9e6e2f6f82e;p=jgit.git Transport: load all refs only if push refspecs have wildcards 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 --- diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java index 5b781ac25f..bfe26d9808 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java @@ -2,7 +2,7 @@ * Copyright (C) 2008, 2009 Google Inc. * Copyright (C) 2008, Marek Zawirski * Copyright (C) 2008, Robin Rosenberg - * Copyright (C) 2008, 2020 Shawn O. Pearce and others + * Copyright (C) 2008, 2022 Shawn O. Pearce 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 expandPushWildcardsFor( final Repository db, final Collection specs) throws IOException { - final List localRefs = db.getRefDatabase().getRefs(); final Collection procRefs = new LinkedHashSet<>(); + List 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);