]> source.dussan.org Git - jgit.git/commitdiff
Fix gc's usage of progress monitor 23/7423/1
authorMatthias Sohn <matthias.sohn@sap.com>
Sat, 25 Aug 2012 23:46:40 +0000 (01:46 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Sat, 25 Aug 2012 23:46:40 +0000 (01:46 +0200)
Change-Id: I8dcdf0b83e91e6132dc490e8ec53818220773c94
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java

index cb053c18a69502311cb067bc09b6aa91cd7e332d..60d9cd0c027fe75c833dc2762e52cce547c824ef 100644 (file)
@@ -137,6 +137,7 @@ public class GC {
         * @throws IOException
         */
        public Collection<PackFile> gc() throws IOException {
+               pm.start(6 /* tasks */);
                packRefs();
                // TODO: implement reflog_expire(pm, repo);
                Collection<PackFile> newPacks = repack();
@@ -262,34 +263,38 @@ public class GC {
                if (fanout != null && fanout.length > 0) {
                        pm.beginTask(JGitText.get().pruneLooseUnreferencedObjects,
                                        fanout.length);
-                       for (String d : fanout) {
-                               pm.update(1);
-                               if (d.length() != 2)
-                                       continue;
-                               File[] entries = new File(objects, d).listFiles();
-                               if (entries == null)
-                                       continue;
-                               for (File f : entries) {
-                                       String fName = f.getName();
-                                       if (fName.length() != Constants.OBJECT_ID_STRING_LENGTH - 2)
+                       try {
+                               for (String d : fanout) {
+                                       pm.update(1);
+                                       if (d.length() != 2)
                                                continue;
-                                       if (f.lastModified() >= expireDate)
+                                       File[] entries = new File(objects, d).listFiles();
+                                       if (entries == null)
                                                continue;
-                                       try {
-                                               ObjectId id = ObjectId.fromString(d + fName);
-                                               if (objectsToKeep.contains(id))
+                                       for (File f : entries) {
+                                               String fName = f.getName();
+                                               if (fName.length() != Constants.OBJECT_ID_STRING_LENGTH - 2)
                                                        continue;
-                                               if (indexObjects == null)
-                                                       indexObjects = listNonHEADIndexObjects();
-                                               if (indexObjects.contains(id))
+                                               if (f.lastModified() >= expireDate)
                                                        continue;
-                                               deletionCandidates.put(id, f);
-                                       } catch (IllegalArgumentException notAnObject) {
-                                               // ignoring the file that does not represent loose
-                                               // object
-                                               continue;
+                                               try {
+                                                       ObjectId id = ObjectId.fromString(d + fName);
+                                                       if (objectsToKeep.contains(id))
+                                                               continue;
+                                                       if (indexObjects == null)
+                                                               indexObjects = listNonHEADIndexObjects();
+                                                       if (indexObjects.contains(id))
+                                                               continue;
+                                                       deletionCandidates.put(id, f);
+                                               } catch (IllegalArgumentException notAnObject) {
+                                                       // ignoring the file that does not represent loose
+                                                       // object
+                                                       continue;
+                                               }
                                        }
                                }
+                       } finally {
+                               pm.endTask();
                        }
                }
                if (deletionCandidates.isEmpty())