]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/gc.py
index: fix -H option
[bup.git] / lib / bup / gc.py
index b23029d3b75477928dab1038f2e1035581c42d49..e663cc02889c8dad1ac4912681258fa4eb91db7a 100644 (file)
@@ -163,40 +163,39 @@ def sweep(live_objects, existing_count, cat_pipe, threshold, compression,
         if verbosity:
             qprogress('preserving live data (%d%% complete)\r'
                       % ((float(collect_count) / existing_count) * 100))
-        idx = git.open_idx(idx_name)
-
-        idx_live_count = 0
-        for sha in idx:
-            if live_objects.exists(sha):
-                idx_live_count += 1
+        with git.open_idx(idx_name) as idx:
+            idx_live_count = 0
+            for sha in idx:
+                if live_objects.exists(sha):
+                    idx_live_count += 1
+
+            collect_count += idx_live_count
+            if idx_live_count == 0:
+                if verbosity:
+                    log('deleting %s\n'
+                        % path_msg(git.repo_rel(basename(idx_name))))
+                ns.stale_files.append(idx_name)
+                ns.stale_files.append(idx_name[:-3] + b'pack')
+                continue
+
+            live_frac = idx_live_count / float(len(idx))
+            if live_frac > ((100 - threshold) / 100.0):
+                if verbosity:
+                    log('keeping %s (%d%% live)\n' % (git.repo_rel(basename(idx_name)),
+                                                    live_frac * 100))
+                continue
 
-        collect_count += idx_live_count
-        if idx_live_count == 0:
             if verbosity:
-                log('deleting %s\n'
-                    % path_msg(git.repo_rel(basename(idx_name))))
+                log('rewriting %s (%.2f%% live)\n' % (basename(idx_name),
+                                                    live_frac * 100))
+            for sha in idx:
+                if live_objects.exists(sha):
+                    item_it = cat_pipe.get(hexlify(sha))
+                    _, typ, _ = next(item_it)
+                    writer.just_write(sha, typ, b''.join(item_it))
+
             ns.stale_files.append(idx_name)
             ns.stale_files.append(idx_name[:-3] + b'pack')
-            continue
-
-        live_frac = idx_live_count / float(len(idx))
-        if live_frac > ((100 - threshold) / 100.0):
-            if verbosity:
-                log('keeping %s (%d%% live)\n' % (git.repo_rel(basename(idx_name)),
-                                                  live_frac * 100))
-            continue
-
-        if verbosity:
-            log('rewriting %s (%.2f%% live)\n' % (basename(idx_name),
-                                                  live_frac * 100))
-        for sha in idx:
-            if live_objects.exists(sha):
-                item_it = cat_pipe.get(hexlify(sha))
-                _, typ, _ = next(item_it)
-                writer.just_write(sha, typ, b''.join(item_it))
-
-        ns.stale_files.append(idx_name)
-        ns.stale_files.append(idx_name[:-3] + b'pack')
 
     if verbosity:
         progress('preserving live data (%d%% complete)\n'