]> arthur.ath.cx Git - bup.git/blobdiff - lib/bup/cmd/bloom.py
PackMidx.__del__: replace with context management
[bup.git] / lib / bup / cmd / bloom.py
index f9959642c0c1a7c0cf33b918224d9ffa45d16f4d..9963c438e7aca690c123a4dccf82ec2034e1f7ad 100755 (executable)
@@ -50,9 +50,10 @@ def check_bloom(path, bloomfilename, idx):
             idx = os.path.join(path, idx)
         log('bloom: bloom file: %s\n' % path_msg(rbloomfilename))
         log('bloom:   checking %s\n' % path_msg(ridx))
-        for objsha in git.open_idx(idx):
-            if not b.exists(objsha):
-                add_error('bloom: ERROR: object %s missing' % hexstr(objsha))
+        with git.open_idx(idx) as oids:
+            for oid in oids:
+                if not b.exists(oid):
+                    add_error('bloom: ERROR: object %s missing' % hexstr(oid))
 
 
 _first = None
@@ -74,14 +75,14 @@ def do_bloom(path, outfilename, k, force):
         rest_count = 0
         for i, name in enumerate(glob.glob(b'%s/*.idx' % path)):
             progress('bloom: counting: %d\r' % i)
-            ix = git.open_idx(name)
-            ixbase = os.path.basename(name)
-            if b and (ixbase in b.idxnames):
-                rest.append(name)
-                rest_count += len(ix)
-            else:
-                add.append(name)
-                add_count += len(ix)
+            with git.open_idx(name) as ix:
+                ixbase = os.path.basename(name)
+                if b and (ixbase in b.idxnames):
+                    rest.append(name)
+                    rest_count += len(ix)
+                else:
+                    add.append(name)
+                    add_count += len(ix)
 
         if not add:
             debug1("bloom: nothing to do.\n")
@@ -129,12 +130,12 @@ def do_bloom(path, outfilename, k, force):
         count = 0
         icount = 0
         for name in add:
-            ix = git.open_idx(name)
-            qprogress('bloom: writing %.2f%% (%d/%d objects)\r'
-                      % (icount*100.0/add_count, icount, add_count))
-            b.add_idx(ix)
-            count += 1
-            icount += len(ix)
+            with git.open_idx(name) as ix:
+                qprogress('bloom: writing %.2f%% (%d/%d objects)\r'
+                          % (icount*100.0/add_count, icount, add_count))
+                b.add_idx(ix)
+                count += 1
+                icount += len(ix)
 
     finally:  # This won't handle pending exceptions correctly in py2
         # Currently, there's an open file object for tfname inside b.