]> source.dussan.org Git - jgit.git/commitdiff
Optimize ref scanning 50/550/1
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Tue, 13 Apr 2010 21:00:53 +0000 (23:00 +0200)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Tue, 13 Apr 2010 21:00:53 +0000 (23:00 +0200)
We can avoid one stat call by trying to perform a directory
listing without checking if the reference File is a directory.
Attempting a directory listing is defined to return. The other
case for null returns from list is when an I/O error occcurs.

Both cases are now intepreted as a possible plain reference. I/O
errors when reading plain references will be handled (ignored)
in scanRef().

Change-Id: I9906ed8c42eab4d6029c781aab87b3b07c1a1d2c
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDirectory.java

index 90ac0bf47e6f9c888b9a7e1b8529ba2994a26495..faebbf67cc494faffe04abdbce0a2c2fd5aee482 100644 (file)
@@ -331,18 +331,19 @@ public class RefDirectory extends RefDatabase {
                        }
                }
 
-               private void scanTree(String prefix, File dir) {
+               private boolean scanTree(String prefix, File dir) {
                        final String[] entries = dir.list(LockFile.FILTER);
-                       if (entries != null && 0 < entries.length) {
+                       if (entries == null) // not a directory or an I/O error
+                               return false;
+                       if (0 < entries.length) {
                                Arrays.sort(entries);
                                for (String name : entries) {
                                        File e = new File(dir, name);
-                                       if (e.isDirectory())
-                                               scanTree(prefix + name + '/', e);
-                                       else
+                                       if (!scanTree(prefix + name + '/', e))
                                                scanOne(prefix + name);
                                }
                        }
+                       return true;
                }
 
                private void scanOne(String name) {