]> source.dussan.org Git - jgit.git/commitdiff
Remove trivial cases of using deprecated RefDatabase.getRefs() 99/121699/2
authorMatthias Sohn <matthias.sohn@sap.com>
Tue, 24 Apr 2018 23:44:43 +0000 (01:44 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 25 Apr 2018 01:28:51 +0000 (03:28 +0200)
Change-Id: I2d3e426a3391923f8a690ac68fcc33851f3eb419
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
20 files changed:
org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java
org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/api/ListTagCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java

index c11ddbee25265a649defc923b1c994bf57659b4b..de4449f5e3a573eaa1eb8ebd8de35eb328b2ed5a 100644 (file)
@@ -174,8 +174,8 @@ public class LfsPrePushHook extends PrePushHook {
 
        private void excludeRemoteRefs(ObjectWalk walk) throws IOException {
                RefDatabase refDatabase = getRepository().getRefDatabase();
-               Map<String, Ref> remoteRefs = refDatabase.getRefs(remote());
-               for (Ref r : remoteRefs.values()) {
+               List<Ref> remoteRefs = refDatabase.getRefsByPrefix(remote());
+               for (Ref r : remoteRefs) {
                        ObjectId oid = r.getPeeledObjectId();
                        if (oid == null) {
                                oid = r.getObjectId();
index 21adf738e05d1fa1c727c2cd8fe25c7c938b2b77..8ba533f1307b80dbcdde88afaa8041f11cb4a0ad 100644 (file)
@@ -49,7 +49,6 @@ import static org.eclipse.jgit.lib.RefDatabase.ALL;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.Ref;
@@ -74,8 +73,8 @@ class RevParse extends TextBuiltin {
        @Override
        protected void run() throws Exception {
                if (all) {
-                       Map<String, Ref> allRefs = db.getRefDatabase().getRefs(ALL);
-                       for (final Ref r : allRefs.values()) {
+                       List<Ref> allRefs = db.getRefDatabase().getRefsByPrefix(ALL);
+                       for (final Ref r : allRefs) {
                                ObjectId objectId = r.getObjectId();
                                // getRefs skips dangling symrefs, so objectId should never be
                                // null.
index 3fc91013acee0ae2b0caf4e69703e38b6307b131..f3714d8d75309dc0cb4987ed17f77cd7b62354bd 100644 (file)
@@ -47,7 +47,6 @@ import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
-import java.util.Map;
 
 import org.eclipse.jgit.diff.DiffConfig;
 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
@@ -171,9 +170,9 @@ abstract class RevWalkTextBuiltin extends TextBuiltin {
                        walk.setRevFilter(AndRevFilter.create(revLimiter));
 
                if (all) {
-                       Map<String, Ref> refs =
-                               db.getRefDatabase().getRefs(RefDatabase.ALL);
-                       for (Ref a : refs.values()) {
+                       List<Ref> refs =
+                                       db.getRefDatabase().getRefsByPrefix(RefDatabase.ALL);
+                       for (Ref a : refs) {
                                ObjectId oid = a.getPeeledObjectId();
                                if (oid == null)
                                        oid = a.getObjectId();
index 7b59d437ac60ef483c5c510e972b38bb6084f4e0..2ed5de5c58104029a8d737e244221d6f7ca87588 100644 (file)
@@ -48,13 +48,11 @@ package org.eclipse.jgit.pgm;
 import static org.eclipse.jgit.lib.RefDatabase.ALL;
 
 import java.io.IOException;
-import java.util.Map;
-import java.util.SortedMap;
+import java.util.List;
 
 import org.eclipse.jgit.lib.AnyObjectId;
 import org.eclipse.jgit.lib.Ref;
 import org.eclipse.jgit.lib.RefComparator;
-import org.eclipse.jgit.util.RefMap;
 
 @Command(usage = "usage_ShowRef")
 class ShowRef extends TextBuiltin {
@@ -69,11 +67,10 @@ class ShowRef extends TextBuiltin {
        }
 
        private Iterable<Ref> getSortedRefs() throws Exception {
-               Map<String, Ref> all = db.getRefDatabase().getRefs(ALL);
-               if (all instanceof RefMap
-                               || (all instanceof SortedMap && ((SortedMap) all).comparator() == null))
-                       return all.values();
-               return RefComparator.sort(all.values());
+               List<Ref> all = db.getRefDatabase().getRefsByPrefix(ALL);
+               // TODO(jrn) check if we can reintroduce fast-path by e.g. implementing
+               // SortedList
+               return RefComparator.sort(all);
        }
 
        private void show(final AnyObjectId id, final String name)
index 2e41eec7cb421cc4302bb7dad1104b43455798b4..d7503ab297cd13f5ecf6320c0492565edb14c151 100644 (file)
@@ -117,7 +117,7 @@ class RebuildCommitGraph extends TextBuiltin {
        /** {@inheritDoc} */
        @Override
        protected void run() throws Exception {
-               if (!really && !db.getRefDatabase().getRefs(ALL).isEmpty()) {
+               if (!really && !db.getRefDatabase().getRefsByPrefix(ALL).isEmpty()) {
                        File directory = db.getDirectory();
                        String absolutePath = directory == null ? "null" //$NON-NLS-1$
                                        : directory.getAbsolutePath();
@@ -247,8 +247,8 @@ class RebuildCommitGraph extends TextBuiltin {
 
        private void deleteAllRefs() throws Exception {
                final RevWalk rw = new RevWalk(db);
-               Map<String, Ref> refs = db.getRefDatabase().getRefs(ALL);
-               for (final Ref r : refs.values()) {
+               List<Ref> refs = db.getRefDatabase().getRefsByPrefix(ALL);
+               for (final Ref r : refs) {
                        if (Constants.HEAD.equals(r.getName()))
                                continue;
                        final RefUpdate u = db.updateRef(r.getName());
index 31724839531e77d896fe5a2b16bc9cef3953244a..45fbc2cb3c05b39d3832b5b7f3724aff0bfaba97 100644 (file)
@@ -154,7 +154,7 @@ class RebuildRefTree extends TextBuiltin {
                                        head));
                }
 
-               for (Ref r : refdb.getRefs(RefDatabase.ALL).values()) {
+               for (Ref r : refdb.getRefsByPrefix(RefDatabase.ALL)) {
                        if (r.getName().equals(txnCommitted) || r.getName().equals(HEAD)
                                        || r.getName().startsWith(txnNamespace)) {
                                continue;
index fefccf314f46c0df3ce9c586b7c4da175d5bcab1..5a2bd9c3330078054732913743de0de0f8b946ba 100644 (file)
@@ -1271,7 +1271,7 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
                                        @Override
                                        public void onRefsChanged(RefsChangedEvent event) {
                                                try {
-                                                       refDb.getRefs("ref");
+                                                       refDb.getRefsByPrefix("ref");
                                                        changeCount.incrementAndGet();
                                                } catch (StackOverflowError soe) {
                                                        error.set(soe);
@@ -1280,8 +1280,8 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
                                                }
                                        }
                                });
-               refDb.getRefs("ref");
-               refDb.getRefs("ref");
+               refDb.getRefsByPrefix("ref");
+               refDb.getRefsByPrefix("ref");
                assertNull(error.get());
                assertNull(exception.get());
                assertEquals(1, changeCount.get());
index 01fe4aa9ee898e6c0a7ca7127412b3a55f2c26be..7f1ed8c14859f15d91011a50f8ff55588bc57893 100644 (file)
@@ -246,7 +246,8 @@ public class DescribeCommand extends GitCommand<String> {
                        if (target == null)
                                setTarget(Constants.HEAD);
 
-                       Collection<Ref> tagList = repo.getRefDatabase().getRefs(R_TAGS).values();
+                       Collection<Ref> tagList = repo.getRefDatabase()
+                                       .getRefsByPrefix(R_TAGS);
                        Map<ObjectId, List<Ref>> tags = tagList.stream()
                                        .collect(Collectors.groupingBy(this::getObjectIdFromRef));
 
index cdae782c6c5ab8369741a3a84d0e0f64ad69c440..28a27a90e04ee0e9d4b9c7ff0f2c13277ec9d332 100644 (file)
@@ -187,6 +187,6 @@ public class ListBranchCommand extends GitCommand<List<Ref>> {
        }
 
        private Collection<Ref> getRefs(String prefix) throws IOException {
-               return repo.getRefDatabase().getRefs(prefix).values();
+               return repo.getRefDatabase().getRefsByPrefix(prefix);
        }
 }
index 9161211d7f9b5e6857f1a3b2e57f9fe05742caf6..01c1991846b640f4b9872046f2be71a3762ed171 100644 (file)
@@ -47,7 +47,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
-import java.util.Map;
 
 import org.eclipse.jgit.api.errors.GitAPIException;
 import org.eclipse.jgit.api.errors.JGitInternalException;
@@ -78,11 +77,11 @@ public class ListTagCommand extends GitCommand<List<Ref>> {
        @Override
        public List<Ref> call() throws GitAPIException {
                checkCallable();
-               Map<String, Ref> refList;
                List<Ref> tags = new ArrayList<>();
                try (RevWalk revWalk = new RevWalk(repo)) {
-                       refList = repo.getRefDatabase().getRefs(Constants.R_TAGS);
-                       for (Ref ref : refList.values()) {
+                       List<Ref> refList = repo.getRefDatabase()
+                                       .getRefsByPrefix(Constants.R_TAGS);
+                       for (Ref ref : refList) {
                                tags.add(ref);
                        }
                } catch (IOException e) {
index fd6c1fa1be19eb63612483b9571b1f4fdf5d5163..19f26ff33b0a04209ba0ff30e783388ece3e4d03 100644 (file)
@@ -48,7 +48,6 @@ import java.io.IOException;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
 import org.eclipse.jgit.api.errors.GitAPIException;
 import org.eclipse.jgit.api.errors.JGitInternalException;
@@ -275,8 +274,8 @@ public class LogCommand extends GitCommand<Iterable<RevCommit>> {
         *             the references could not be accessed
         */
        public LogCommand all() throws IOException {
-               Map<String, Ref> refs = getRepository().getRefDatabase().getRefs(ALL);
-               for (Ref ref : refs.values()) {
+               List<Ref> refs = getRepository().getRefDatabase().getRefsByPrefix(ALL);
+               for (Ref ref : refs) {
                        if(!ref.isPeeled())
                                ref = getRepository().peel(ref);
 
index d6aafa3a12d433e6df09f7d653f86dba94eeeb49..a2b200706b1436c6b643224461716974f0654c44 100644 (file)
@@ -278,7 +278,8 @@ public class NameRevCommand extends GitCommand<Map<ObjectId, String>> {
                if (refs == null)
                        refs = new ArrayList<>();
                try {
-                       for (Ref ref : repo.getRefDatabase().getRefs(Constants.R_TAGS).values()) {
+                       for (Ref ref : repo.getRefDatabase()
+                                       .getRefsByPrefix(Constants.R_TAGS)) {
                                ObjectId id = ref.getObjectId();
                                if (id != null && (walk.parseAny(id) instanceof RevTag))
                                        addRef(ref);
@@ -324,7 +325,7 @@ public class NameRevCommand extends GitCommand<Map<ObjectId, String>> {
 
        private void addPrefix(String prefix, Map<ObjectId, String> nonCommits,
                        FIFORevQueue pending) throws IOException {
-               for (Ref ref : repo.getRefDatabase().getRefs(prefix).values())
+               for (Ref ref : repo.getRefDatabase().getRefsByPrefix(prefix))
                        addRef(ref, nonCommits, pending);
        }
 
index 69989a451e8453e9746eedb55886ceaaeaa7fa35..6b227852e01016be6ab4c7e6a67078b70b1637d4 100644 (file)
@@ -403,7 +403,7 @@ public class DfsGarbageCollector {
        }
 
        private Collection<Ref> getAllRefs() throws IOException {
-               Collection<Ref> refs = refdb.getRefs(RefDatabase.ALL).values();
+               Collection<Ref> refs = refdb.getRefsByPrefix(RefDatabase.ALL);
                List<Ref> addl = refdb.getAdditionalRefs();
                if (!addl.isEmpty()) {
                        List<Ref> all = new ArrayList<>(refs.size() + addl.size());
index 92776a6b28087d7cf7ae37a2fdfcc04328ab2f3e..f6b39e920d9ddf90719c346f8f743451280a2811 100644 (file)
@@ -785,7 +785,8 @@ public class GC {
         * @throws java.io.IOException
         */
        public void packRefs() throws IOException {
-               Collection<Ref> refs = repo.getRefDatabase().getRefs(Constants.R_REFS).values();
+               Collection<Ref> refs = repo.getRefDatabase()
+                               .getRefsByPrefix(Constants.R_REFS);
                List<String> refsToBePacked = new ArrayList<>(refs.size());
                pm.beginTask(JGitText.get().packRefs, refs.size());
                try {
@@ -1067,7 +1068,7 @@ public class GC {
         */
        private Collection<Ref> getAllRefs() throws IOException {
                RefDatabase refdb = repo.getRefDatabase();
-               Collection<Ref> refs = refdb.getRefs(RefDatabase.ALL).values();
+               Collection<Ref> refs = refdb.getRefsByPrefix(RefDatabase.ALL);
                List<Ref> addl = refdb.getAdditionalRefs();
                if (!addl.isEmpty()) {
                        List<Ref> all = new ArrayList<>(refs.size() + addl.size());
@@ -1375,7 +1376,7 @@ public class GC {
                }
 
                RefDatabase refDb = repo.getRefDatabase();
-               for (Ref r : refDb.getRefs(RefDatabase.ALL).values()) {
+               for (Ref r : refDb.getRefsByPrefix(RefDatabase.ALL)) {
                        Storage storage = r.getStorage();
                        if (storage == Storage.LOOSE || storage == Storage.LOOSE_PACKED)
                                ret.numberOfLooseRefs++;
index 183468fa3537b31f8d2ea9b84f70fca61df98f92..27daaf0bb207b66f1f3bd1adf6bc519ac9f29a3c 100644 (file)
@@ -282,7 +282,7 @@ public class RefTreeDatabase extends RefDatabase {
        public List<Ref> getAdditionalRefs() throws IOException {
                Collection<Ref> txnRefs;
                if (txnNamespace != null) {
-                       txnRefs = bootstrap.getRefs(txnNamespace).values();
+                       txnRefs = bootstrap.getRefsByPrefix(txnNamespace);
                } else {
                        Ref r = bootstrap.exactRef(txnCommitted);
                        if (r != null && r.getObjectId() != null) {
index c49013a8a17b8a328bb9faada780bbb349686e40..206e5b105dbd91df17113eacb5af8e05ff840d29 100644 (file)
@@ -55,7 +55,6 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.Set;
 
 import org.eclipse.jgit.errors.PackProtocolException;
@@ -440,8 +439,7 @@ public abstract class BasePackFetchConnection extends BasePackConnection
 
        private void markReachable(final Set<ObjectId> have, final int maxTime)
                        throws IOException {
-               Map<String, Ref> refs = local.getRefDatabase().getRefs(ALL);
-               for (final Ref r : refs.values()) {
+               for (Ref r : local.getRefDatabase().getRefsByPrefix(ALL)) {
                        ObjectId id = r.getPeeledObjectId();
                        if (id == null)
                                id = r.getObjectId();
index 39efabf5d8dccc033ff7567d2f264c65bd62fd4f..48d8fa1e3ef2d4f8a856dad3db27fdbdac13f2b2 100644 (file)
@@ -254,13 +254,14 @@ class BundleFetchConnection extends BaseFetchConnection {
                                throw new MissingBundlePrerequisiteException(transport.uri,
                                                missing);
 
-                       Map<String, Ref> localRefs;
+                       List<Ref> localRefs;
                        try {
-                               localRefs = transport.local.getRefDatabase().getRefs(ALL);
+                               localRefs = transport.local.getRefDatabase()
+                                               .getRefsByPrefix(ALL);
                        } catch (IOException e) {
                                throw new TransportException(transport.uri, e.getMessage(), e);
                        }
-                       for (final Ref r : localRefs.values()) {
+                       for (final Ref r : localRefs) {
                                try {
                                        rw.markStart(rw.parseCommit(r.getObjectId()));
                                } catch (IOException readError) {
index 7625ba734635bdc4fa2bcaa3ea4e3eaebe8c42b1..fdd0a5e0fdbcbc7dbc94d76e913927491d813196 100644 (file)
@@ -689,12 +689,12 @@ public abstract class Transport implements AutoCloseable {
        private static Collection<RefSpec> expandPushWildcardsFor(
                        final Repository db, final Collection<RefSpec> specs)
                        throws IOException {
-               final Map<String, Ref> localRefs = db.getRefDatabase().getRefs(ALL);
+               final List<Ref> localRefs = db.getRefDatabase().getRefsByPrefix(ALL);
                final Collection<RefSpec> procRefs = new LinkedHashSet<>();
 
                for (final RefSpec spec : specs) {
                        if (spec.isWildcard()) {
-                               for (final Ref localRef : localRefs.values()) {
+                               for (final Ref localRef : localRefs) {
                                        if (spec.matchSource(localRef))
                                                procRefs.add(spec.expandFromSource(localRef));
                                }
index 79c35e37e04557926b4735ca81679fd41e4b918d..33270e0ba039e4f56a5443a405782449fe9eb8f5 100644 (file)
@@ -1582,7 +1582,8 @@ public class UploadPack {
                                new ReachableCommitTipRequestValidator().checkWants(up, wants);
                        else if (!wants.isEmpty()) {
                                Set<ObjectId> refIds =
-                                       refIdSet(up.getRepository().getRefDatabase().getRefs(ALL).values());
+                                               refIdSet(up.getRepository().getRefDatabase()
+                                                               .getRefsByPrefix(ALL));
                                for (ObjectId obj : wants) {
                                        if (!refIds.contains(obj))
                                                throw new WantNotValidException(obj);
@@ -1602,7 +1603,8 @@ public class UploadPack {
                public void checkWants(UploadPack up, List<ObjectId> wants)
                                throws PackProtocolException, IOException {
                        checkNotAdvertisedWants(up, wants,
-                                       refIdSet(up.getRepository().getRefDatabase().getRefs(ALL).values()));
+                                       refIdSet(up.getRepository().getRefDatabase()
+                                                       .getRefsByPrefix(ALL)));
                }
        }
 
index 46fd5cf1d6ffe0c8bf732f4718c5a2a875f77fdd..4061928498ad4ca321f13804f59a53e69d18ba68 100644 (file)
@@ -58,7 +58,6 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import org.eclipse.jgit.errors.CompoundException;
@@ -690,13 +689,13 @@ class WalkFetchConnection extends BaseFetchConnection {
        }
 
        private void markLocalRefsComplete(final Set<ObjectId> have) throws TransportException {
-               Map<String, Ref> refs;
+               List<Ref> refs;
                try {
-                       refs = local.getRefDatabase().getRefs(ALL);
+                       refs = local.getRefDatabase().getRefsByPrefix(ALL);
                } catch (IOException e) {
                        throw new TransportException(e.getMessage(), e);
                }
-               for (final Ref r : refs.values()) {
+               for (final Ref r : refs) {
                        try {
                                markLocalObjComplete(revWalk.parseAny(r.getObjectId()));
                        } catch (IOException readError) {