]> source.dussan.org Git - jgit.git/commitdiff
RefDatabase: Introduce getAllRefs method 27/121827/2
authorDavid Pursehouse <david.pursehouse@gmail.com>
Fri, 27 Apr 2018 01:42:53 +0000 (10:42 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Fri, 27 Apr 2018 02:16:10 +0000 (11:16 +0900)
Currently to get all refs, callers must use:

  getRefsByPrefix(ALL)

Introduce getAllRefs, which does this, and migrate all existing
callers of getRefsByPrefix(ALL).

Change-Id: I7b1687c162c8ae836dc7db3ccc7ac847863f691d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
14 files changed:
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/src/org/eclipse/jgit/api/LogCommand.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/lib/RefDatabase.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 8ba533f1307b80dbcdde88afaa8041f11cb4a0ad..a52954307ea75b63d926ff6c0e90fe2bf79b5407 100644 (file)
@@ -45,8 +45,6 @@
 
 package org.eclipse.jgit.pgm;
 
-import static org.eclipse.jgit.lib.RefDatabase.ALL;
-
 import java.util.ArrayList;
 import java.util.List;
 
@@ -73,7 +71,7 @@ class RevParse extends TextBuiltin {
        @Override
        protected void run() throws Exception {
                if (all) {
-                       List<Ref> allRefs = db.getRefDatabase().getRefsByPrefix(ALL);
+                       List<Ref> allRefs = db.getRefDatabase().getAllRefs();
                        for (final Ref r : allRefs) {
                                ObjectId objectId = r.getObjectId();
                                // getRefs skips dangling symrefs, so objectId should never be
index f3714d8d75309dc0cb4987ed17f77cd7b62354bd..423887cc17ef2edbc3559d90f0059d82f01568f2 100644 (file)
@@ -53,7 +53,6 @@ import org.eclipse.jgit.errors.IncorrectObjectTypeException;
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.lib.RefDatabase;
 import org.eclipse.jgit.pgm.internal.CLIText;
 import org.eclipse.jgit.pgm.opt.PathTreeFilterHandler;
 import org.eclipse.jgit.revwalk.FollowFilter;
@@ -170,8 +169,7 @@ abstract class RevWalkTextBuiltin extends TextBuiltin {
                        walk.setRevFilter(AndRevFilter.create(revLimiter));
 
                if (all) {
-                       List<Ref> refs =
-                                       db.getRefDatabase().getRefsByPrefix(RefDatabase.ALL);
+                       List<Ref> refs = db.getRefDatabase().getAllRefs();
                        for (Ref a : refs) {
                                ObjectId oid = a.getPeeledObjectId();
                                if (oid == null)
index 2ed5de5c58104029a8d737e244221d6f7ca87588..f6384a2cea6410d3728306cc665ea9cd355f9d0c 100644 (file)
@@ -45,8 +45,6 @@
 
 package org.eclipse.jgit.pgm;
 
-import static org.eclipse.jgit.lib.RefDatabase.ALL;
-
 import java.io.IOException;
 import java.util.List;
 
@@ -67,7 +65,7 @@ class ShowRef extends TextBuiltin {
        }
 
        private Iterable<Ref> getSortedRefs() throws Exception {
-               List<Ref> all = db.getRefDatabase().getRefsByPrefix(ALL);
+               List<Ref> all = db.getRefDatabase().getAllRefs();
                // TODO(jrn) check if we can reintroduce fast-path by e.g. implementing
                // SortedList
                return RefComparator.sort(all);
index d7503ab297cd13f5ecf6320c0492565edb14c151..666fc34e268e973fcdc07aa54829b5641c8355bc 100644 (file)
@@ -43,8 +43,6 @@
 
 package org.eclipse.jgit.pgm.debug;
 
-import static org.eclipse.jgit.lib.RefDatabase.ALL;
-
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
@@ -117,7 +115,7 @@ class RebuildCommitGraph extends TextBuiltin {
        /** {@inheritDoc} */
        @Override
        protected void run() throws Exception {
-               if (!really && !db.getRefDatabase().getRefsByPrefix(ALL).isEmpty()) {
+               if (!really && !db.getRefDatabase().getAllRefs().isEmpty()) {
                        File directory = db.getDirectory();
                        String absolutePath = directory == null ? "null" //$NON-NLS-1$
                                        : directory.getAbsolutePath();
@@ -247,8 +245,7 @@ class RebuildCommitGraph extends TextBuiltin {
 
        private void deleteAllRefs() throws Exception {
                final RevWalk rw = new RevWalk(db);
-               List<Ref> refs = db.getRefDatabase().getRefsByPrefix(ALL);
-               for (final Ref r : refs) {
+               for (Ref r : db.getRefDatabase().getAllRefs()) {
                        if (Constants.HEAD.equals(r.getName()))
                                continue;
                        final RefUpdate u = db.updateRef(r.getName());
index 45fbc2cb3c05b39d3832b5b7f3724aff0bfaba97..6665ce7c1d11dc39e5e8af7b7a4fef92789d5d75 100644 (file)
@@ -154,7 +154,7 @@ class RebuildRefTree extends TextBuiltin {
                                        head));
                }
 
-               for (Ref r : refdb.getRefsByPrefix(RefDatabase.ALL)) {
+               for (Ref r : refdb.getAllRefs()) {
                        if (r.getName().equals(txnCommitted) || r.getName().equals(HEAD)
                                        || r.getName().startsWith(txnNamespace)) {
                                continue;
index 19f26ff33b0a04209ba0ff30e783388ece3e4d03..73433c18b8346cb41a837e00519e691697df338e 100644 (file)
@@ -42,8 +42,6 @@
  */
 package org.eclipse.jgit.api;
 
-import static org.eclipse.jgit.lib.RefDatabase.ALL;
-
 import java.io.IOException;
 import java.text.MessageFormat;
 import java.util.ArrayList;
@@ -274,8 +272,7 @@ public class LogCommand extends GitCommand<Iterable<RevCommit>> {
         *             the references could not be accessed
         */
        public LogCommand all() throws IOException {
-               List<Ref> refs = getRepository().getRefDatabase().getRefsByPrefix(ALL);
-               for (Ref ref : refs) {
+               for (Ref ref : getRepository().getRefDatabase().getAllRefs()) {
                        if(!ref.isPeeled())
                                ref = getRepository().peel(ref);
 
index 6b227852e01016be6ab4c7e6a67078b70b1637d4..30bcbf068b4b6ff23f6b182c36d910937bbea235 100644 (file)
@@ -403,7 +403,7 @@ public class DfsGarbageCollector {
        }
 
        private Collection<Ref> getAllRefs() throws IOException {
-               Collection<Ref> refs = refdb.getRefsByPrefix(RefDatabase.ALL);
+               Collection<Ref> refs = refdb.getAllRefs();
                List<Ref> addl = refdb.getAdditionalRefs();
                if (!addl.isEmpty()) {
                        List<Ref> all = new ArrayList<>(refs.size() + addl.size());
index f6b39e920d9ddf90719c346f8f743451280a2811..1ea686e7cdd753439d2acca7043ab406a5e95b75 100644 (file)
@@ -1068,7 +1068,7 @@ public class GC {
         */
        private Collection<Ref> getAllRefs() throws IOException {
                RefDatabase refdb = repo.getRefDatabase();
-               Collection<Ref> refs = refdb.getRefsByPrefix(RefDatabase.ALL);
+               Collection<Ref> refs = refdb.getAllRefs();
                List<Ref> addl = refdb.getAdditionalRefs();
                if (!addl.isEmpty()) {
                        List<Ref> all = new ArrayList<>(refs.size() + addl.size());
@@ -1376,7 +1376,7 @@ public class GC {
                }
 
                RefDatabase refDb = repo.getRefDatabase();
-               for (Ref r : refDb.getRefsByPrefix(RefDatabase.ALL)) {
+               for (Ref r : refDb.getAllRefs()) {
                        Storage storage = r.getStorage();
                        if (storage == Storage.LOOSE || storage == Storage.LOOSE_PACKED)
                                ret.numberOfLooseRefs++;
index 03888f8303e68d021e52766bb1b63b6412023365..bceb208292aea55434f9a5868c70a9de38ca0070 100644 (file)
@@ -391,6 +391,22 @@ public abstract class RefDatabase {
                return Collections.unmodifiableList(result);
        }
 
+       /**
+        * Returns all refs.
+        * <p>
+        * Callers interested in only a portion of the ref hierarchy can call
+        * {@link #getRefsByPrefix} instead.
+        *
+        * @return immutable list of all refs.
+        * @throws java.io.IOException
+        *             the reference space cannot be accessed.
+        * @since 5.0
+        */
+       @NonNull
+       public List<Ref> getAllRefs() throws IOException {
+               return getRefsByPrefix(ALL);
+       }
+
        /**
         * Get the additional reference-like entities from the repository.
         * <p>
index 206e5b105dbd91df17113eacb5af8e05ff840d29..a88918e7a125efa8f5bfee781c6ece0c0c1921c9 100644 (file)
@@ -45,8 +45,6 @@
 
 package org.eclipse.jgit.transport;
 
-import static org.eclipse.jgit.lib.RefDatabase.ALL;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -439,7 +437,7 @@ public abstract class BasePackFetchConnection extends BasePackConnection
 
        private void markReachable(final Set<ObjectId> have, final int maxTime)
                        throws IOException {
-               for (Ref r : local.getRefDatabase().getRefsByPrefix(ALL)) {
+               for (Ref r : local.getRefDatabase().getAllRefs()) {
                        ObjectId id = r.getPeeledObjectId();
                        if (id == null)
                                id = r.getObjectId();
index 48d8fa1e3ef2d4f8a856dad3db27fdbdac13f2b2..24f44cb46059cf8efc15dfa60947c85f6d666714 100644 (file)
@@ -47,8 +47,6 @@
 
 package org.eclipse.jgit.transport;
 
-import static org.eclipse.jgit.lib.RefDatabase.ALL;
-
 import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -256,8 +254,7 @@ class BundleFetchConnection extends BaseFetchConnection {
 
                        List<Ref> localRefs;
                        try {
-                               localRefs = transport.local.getRefDatabase()
-                                               .getRefsByPrefix(ALL);
+                               localRefs = transport.local.getRefDatabase().getAllRefs();
                        } catch (IOException e) {
                                throw new TransportException(transport.uri, e.getMessage(), e);
                        }
index fdd0a5e0fdbcbc7dbc94d76e913927491d813196..9ff5f7b91f2e54ab49593cc7c6dc590fe24d428e 100644 (file)
@@ -47,7 +47,6 @@
 package org.eclipse.jgit.transport;
 
 import static org.eclipse.jgit.lib.Constants.CHARSET;
-import static org.eclipse.jgit.lib.RefDatabase.ALL;
 
 import java.io.BufferedReader;
 import java.io.IOException;
@@ -689,7 +688,7 @@ 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().getRefsByPrefix(ALL);
+               final List<Ref> localRefs = db.getRefDatabase().getAllRefs();
                final Collection<RefSpec> procRefs = new LinkedHashSet<>();
 
                for (final RefSpec spec : specs) {
index 33270e0ba039e4f56a5443a405782449fe9eb8f5..2a1b2492e695a7a54cfe142ea4ba2c3888a6bd6a 100644 (file)
@@ -90,7 +90,6 @@ import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectReader;
 import org.eclipse.jgit.lib.ProgressMonitor;
 import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.lib.RefDatabase;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.AsyncRevObjectQueue;
 import org.eclipse.jgit.revwalk.BitmapWalker;
@@ -776,7 +775,7 @@ public class UploadPack {
 
        private Map<String, Ref> getAdvertisedOrDefaultRefs() throws IOException {
                if (refs == null)
-                       setAdvertisedRefs(db.getRefDatabase().getRefs(RefDatabase.ALL));
+                       setAdvertisedRefs(db.getRefDatabase().getRefs(ALL));
                return refs;
        }
 
@@ -1583,7 +1582,7 @@ public class UploadPack {
                        else if (!wants.isEmpty()) {
                                Set<ObjectId> refIds =
                                                refIdSet(up.getRepository().getRefDatabase()
-                                                               .getRefsByPrefix(ALL));
+                                                               .getAllRefs());
                                for (ObjectId obj : wants) {
                                        if (!refIds.contains(obj))
                                                throw new WantNotValidException(obj);
@@ -1603,8 +1602,7 @@ public class UploadPack {
                public void checkWants(UploadPack up, List<ObjectId> wants)
                                throws PackProtocolException, IOException {
                        checkNotAdvertisedWants(up, wants,
-                                       refIdSet(up.getRepository().getRefDatabase()
-                                                       .getRefsByPrefix(ALL)));
+                                       refIdSet(up.getRepository().getRefDatabase().getAllRefs()));
                }
        }
 
index 4061928498ad4ca321f13804f59a53e69d18ba68..c0ee28a2cde2659fce01d735250607db26d4471e 100644 (file)
@@ -44,8 +44,6 @@
 
 package org.eclipse.jgit.transport;
 
-import static org.eclipse.jgit.lib.RefDatabase.ALL;
-
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
@@ -691,7 +689,7 @@ class WalkFetchConnection extends BaseFetchConnection {
        private void markLocalRefsComplete(final Set<ObjectId> have) throws TransportException {
                List<Ref> refs;
                try {
-                       refs = local.getRefDatabase().getRefsByPrefix(ALL);
+                       refs = local.getRefDatabase().getAllRefs();
                } catch (IOException e) {
                        throw new TransportException(e.getMessage(), e);
                }