]> source.dussan.org Git - jgit.git/commitdiff
Remove use of deprecated getAllRefs() in UploadPack 78/182378/5
authorMatthias Sohn <matthias.sohn@sap.com>
Wed, 23 Jun 2021 08:38:50 +0000 (10:38 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Sat, 23 Oct 2021 11:31:08 +0000 (07:31 -0400)
Repository.getAllRefs() is deprecated and should not
be used anymore.

Bug: 534731
Change-Id: I037a9b901275bfa7952b4c79861d7639c9d42715

org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

index fa2448083fd27f3952cb8496d6efe28c00067f3d..6da6c133427d60d2f503f843b9b672658f986cb8 100644 (file)
@@ -57,6 +57,7 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
 import java.util.TreeMap;
+import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -406,14 +407,16 @@ public class UploadPack {
         *            were advertised.
         */
        public void setAdvertisedRefs(@Nullable Map<String, Ref> allRefs) {
-               if (allRefs != null)
+               if (allRefs != null) {
                        refs = allRefs;
-               else
-                       refs = db.getAllRefs();
-               if (refFilter == RefFilter.DEFAULT)
+               } else {
+                       refs = getAllRefs();
+               }
+               if (refFilter == RefFilter.DEFAULT) {
                        refs = transferConfig.getRefFilter().filter(refs);
-               else
+               } else {
                        refs = refFilter.filter(refs);
+               }
        }
 
        /**
@@ -864,6 +867,20 @@ public class UploadPack {
                return statistics;
        }
 
+       /**
+        * Extract the full list of refs from the ref-db.
+        *
+        * @return Map of all refname/ref
+        */
+       private Map<String, Ref> getAllRefs() {
+               try {
+                       return db.getRefDatabase().getRefs().stream().collect(
+                                       Collectors.toMap(Ref::getName, Function.identity()));
+               } catch (IOException e) {
+                       throw new UncheckedIOException(e);
+               }
+       }
+
        private Map<String, Ref> getAdvertisedOrDefaultRefs() throws IOException {
                if (refs != null) {
                        return refs;