]> source.dussan.org Git - jgit.git/commitdiff
RefDatabase: add hasRefs convenience method 02/121902/2
authorDavid Pursehouse <david.pursehouse@gmail.com>
Fri, 27 Apr 2018 12:49:08 +0000 (21:49 +0900)
committerMatthias Sohn <matthias.sohn@sap.com>
Sun, 29 Apr 2018 20:03:07 +0000 (22:03 +0200)
Callers can now say:

 db.getRefDatabase().hasRefs()

rather than the more verbose:

 !db.getRefDatabase().getAllRefs().isEmpty()

The default implementation simply uses getAllRefs().isEmpty(), but a
derived class could possibly override the method with a more efficient
implementation.

Change-Id: I5244520708a1a7d9adb351f10e43fc39d98e22a1
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java

index 666fc34e268e973fcdc07aa54829b5641c8355bc..19d94eadef40752fbd9ba9b216d24c349037f961 100644 (file)
@@ -115,7 +115,7 @@ class RebuildCommitGraph extends TextBuiltin {
        /** {@inheritDoc} */
        @Override
        protected void run() throws Exception {
-               if (!really && !db.getRefDatabase().getAllRefs().isEmpty()) {
+               if (!really && db.getRefDatabase().hasRefs()) {
                        File directory = db.getDirectory();
                        String absolutePath = directory == null ? "null" //$NON-NLS-1$
                                        : directory.getAbsolutePath();
index bceb208292aea55434f9a5868c70a9de38ca0070..0ae14d13045f7a44d64d6ad0e38e8b6b93f0ed1f 100644 (file)
@@ -407,6 +407,18 @@ public abstract class RefDatabase {
                return getRefsByPrefix(ALL);
        }
 
+       /**
+        * Check if any refs exist in the ref database.
+        *
+        * @return true if the database has refs.
+        * @throws java.io.IOException
+        *             the reference space cannot be accessed.
+        * @since 5.0
+        */
+       public boolean hasRefs() throws IOException {
+               return !getAllRefs().isEmpty();
+       }
+
        /**
         * Get the additional reference-like entities from the repository.
         * <p>