diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java index c11ddbee2..de4449f5e 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java @@ -174,8 +174,8 @@ private static LfsPointer loadLfsPointer(ObjectReader r, AnyObjectId obj) private void excludeRemoteRefs(ObjectWalk walk) throws IOException { RefDatabase refDatabase = getRepository().getRefDatabase(); - Map remoteRefs = refDatabase.getRefs(remote()); - for (Ref r : remoteRefs.values()) { + List remoteRefs = refDatabase.getRefsByPrefix(remote()); + for (Ref r : remoteRefs) { ObjectId oid = r.getPeeledObjectId(); if (oid == null) { oid = r.getObjectId(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java index 21adf738e..8ba533f13 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java @@ -49,7 +49,6 @@ 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 allRefs = db.getRefDatabase().getRefs(ALL); - for (final Ref r : allRefs.values()) { + List allRefs = db.getRefDatabase().getRefsByPrefix(ALL); + for (final Ref r : allRefs) { ObjectId objectId = r.getObjectId(); // getRefs skips dangling symrefs, so objectId should never be // null. diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java index 3fc91013a..f3714d8d7 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java @@ -47,7 +47,6 @@ 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 @@ else if (revLimiter.size() > 1) walk.setRevFilter(AndRevFilter.create(revLimiter)); if (all) { - Map refs = - db.getRefDatabase().getRefs(RefDatabase.ALL); - for (Ref a : refs.values()) { + List refs = + db.getRefDatabase().getRefsByPrefix(RefDatabase.ALL); + for (Ref a : refs) { ObjectId oid = a.getPeeledObjectId(); if (oid == null) oid = a.getObjectId(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java index 7b59d437a..2ed5de5c5 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java @@ -48,13 +48,11 @@ 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 @@ protected void run() throws Exception { } private Iterable getSortedRefs() throws Exception { - Map 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 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) diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java index 2e41eec7c..d7503ab29 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java @@ -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 @@ private void detachHead() throws IOException { private void deleteAllRefs() throws Exception { final RevWalk rw = new RevWalk(db); - Map refs = db.getRefDatabase().getRefs(ALL); - for (final Ref r : refs.values()) { + List refs = db.getRefDatabase().getRefsByPrefix(ALL); + for (final Ref r : refs) { if (Constants.HEAD.equals(r.getName())) continue; final RefUpdate u = db.updateRef(r.getName()); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java index 317248395..45fbc2cb3 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java @@ -154,7 +154,7 @@ private RefTree rebuild(RefDatabase refdb) throws IOException { 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; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java index fefccf314..5a2bd9c33 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java @@ -1271,7 +1271,7 @@ public void testRefsChangedStackOverflow() throws Exception { @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 void onRefsChanged(RefsChangedEvent event) { } } }); - refDb.getRefs("ref"); - refDb.getRefs("ref"); + refDb.getRefsByPrefix("ref"); + refDb.getRefsByPrefix("ref"); assertNull(error.get()); assertNull(exception.get()); assertEquals(1, changeCount.get()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java index 01fe4aa9e..7f1ed8c14 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java @@ -246,7 +246,8 @@ public String call() throws GitAPIException { if (target == null) setTarget(Constants.HEAD); - Collection tagList = repo.getRefDatabase().getRefs(R_TAGS).values(); + Collection tagList = repo.getRefDatabase() + .getRefsByPrefix(R_TAGS); Map> tags = tagList.stream() .collect(Collectors.groupingBy(this::getObjectIdFromRef)); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java index cdae782c6..28a27a90e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java @@ -187,6 +187,6 @@ public ListBranchCommand setContains(String containsCommitish) { } private Collection getRefs(String prefix) throws IOException { - return repo.getRefDatabase().getRefs(prefix).values(); + return repo.getRefDatabase().getRefsByPrefix(prefix); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ListTagCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ListTagCommand.java index 9161211d7..01c199184 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ListTagCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ListTagCommand.java @@ -47,7 +47,6 @@ 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 @@ protected ListTagCommand(Repository repo) { @Override public List call() throws GitAPIException { checkCallable(); - Map refList; List tags = new ArrayList<>(); try (RevWalk revWalk = new RevWalk(repo)) { - refList = repo.getRefDatabase().getRefs(Constants.R_TAGS); - for (Ref ref : refList.values()) { + List refList = repo.getRefDatabase() + .getRefsByPrefix(Constants.R_TAGS); + for (Ref ref : refList) { tags.add(ref); } } catch (IOException e) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java index fd6c1fa1b..19f26ff33 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java @@ -48,7 +48,6 @@ 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 LogCommand addRange(AnyObjectId since, AnyObjectId until) * the references could not be accessed */ public LogCommand all() throws IOException { - Map refs = getRepository().getRefDatabase().getRefs(ALL); - for (Ref ref : refs.values()) { + List refs = getRepository().getRefDatabase().getRefsByPrefix(ALL); + for (Ref ref : refs) { if(!ref.isPeeled()) ref = getRepository().peel(ref); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java index d6aafa3a1..a2b200706 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java @@ -278,7 +278,8 @@ public NameRevCommand addAnnotatedTags() { 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 @@ private void addPrefixes(Map nonCommits, private void addPrefix(String prefix, Map nonCommits, FIFORevQueue pending) throws IOException { - for (Ref ref : repo.getRefDatabase().getRefs(prefix).values()) + for (Ref ref : repo.getRefDatabase().getRefsByPrefix(prefix)) addRef(ref, nonCommits, pending); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java index 69989a451..6b227852e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java @@ -403,7 +403,7 @@ public boolean pack(ProgressMonitor pm) throws IOException { } private Collection getAllRefs() throws IOException { - Collection refs = refdb.getRefs(RefDatabase.ALL).values(); + Collection refs = refdb.getRefsByPrefix(RefDatabase.ALL); List addl = refdb.getAdditionalRefs(); if (!addl.isEmpty()) { List all = new ArrayList<>(refs.size() + addl.size()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java index 92776a6b2..f6b39e920 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java @@ -785,7 +785,8 @@ private static boolean equals(Ref r1, Ref r2) { * @throws java.io.IOException */ public void packRefs() throws IOException { - Collection refs = repo.getRefDatabase().getRefs(Constants.R_REFS).values(); + Collection refs = repo.getRefDatabase() + .getRefsByPrefix(Constants.R_REFS); List refsToBePacked = new ArrayList<>(refs.size()); pm.beginTask(JGitText.get().packRefs, refs.size()); try { @@ -1067,7 +1068,7 @@ private Set listRefLogObjects(Ref ref, long minTime) throws IOExceptio */ private Collection getAllRefs() throws IOException { RefDatabase refdb = repo.getRefDatabase(); - Collection refs = refdb.getRefs(RefDatabase.ALL).values(); + Collection refs = refdb.getRefsByPrefix(RefDatabase.ALL); List addl = refdb.getAdditionalRefs(); if (!addl.isEmpty()) { List all = new ArrayList<>(refs.size() + addl.size()); @@ -1375,7 +1376,7 @@ public RepoStatistics getStatistics() throws IOException { } 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++; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java index 183468fa3..27daaf0bb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java @@ -282,7 +282,7 @@ private static ObjectId idOf(@Nullable Ref src) { public List getAdditionalRefs() throws IOException { Collection 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) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java index c49013a8a..206e5b105 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java @@ -55,7 +55,6 @@ 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 @@ private int maxTimeWanted(final Collection wants) { private void markReachable(final Set have, final int maxTime) throws IOException { - Map 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(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java index 39efabf5d..48d8fa1e3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java @@ -254,13 +254,14 @@ private void verifyPrerequisites() throws TransportException { throw new MissingBundlePrerequisiteException(transport.uri, missing); - Map localRefs; + List 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) { 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 7625ba734..fdd0a5e0f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java @@ -689,12 +689,12 @@ public static Collection findRemoteRefUpdatesFor( private static Collection expandPushWildcardsFor( final Repository db, final Collection specs) throws IOException { - final Map localRefs = db.getRefDatabase().getRefs(ALL); + final List localRefs = db.getRefDatabase().getRefsByPrefix(ALL); final Collection 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)); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index 79c35e37e..33270e0ba 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -1582,7 +1582,8 @@ public void checkWants(UploadPack up, List wants) new ReachableCommitTipRequestValidator().checkWants(up, wants); else if (!wants.isEmpty()) { Set 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 static final class ReachableCommitTipRequestValidator public void checkWants(UploadPack up, List wants) throws PackProtocolException, IOException { checkNotAdvertisedWants(up, wants, - refIdSet(up.getRepository().getRefDatabase().getRefs(ALL).values())); + refIdSet(up.getRepository().getRefDatabase() + .getRefsByPrefix(ALL))); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java index 46fd5cf1d..406192849 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java @@ -58,7 +58,6 @@ 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 @@ private Collection expandOneAlternate( } private void markLocalRefsComplete(final Set have) throws TransportException { - Map refs; + List 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) {