]> arthur.barton.de Git - bup.git/blobdiff - cmd/bloom-cmd.py
do_bloom(): remove unused "count" variable
[bup.git] / cmd / bloom-cmd.py
index 02b0a106682633ed2163fc9c289523d8f3669d22..d74cce2704567597fc1fce934032dfd025041e55 100755 (executable)
@@ -81,14 +81,14 @@ def do_bloom(path, outfilename):
 
     if b:
         if len(b) != rest_count:
-            log("bloom: size %d != idx total %d, regenerating\n"
-                    % (len(b), rest_count))
+            debug1("bloom: size %d != idx total %d, regenerating\n"
+                   % (len(b), rest_count))
             b = None
         elif (b.bits < bloom.MAX_BLOOM_BITS and
               b.pfalse_positive(add_count) > bloom.MAX_PFALSE_POSITIVE):
-            log("bloom: regenerating: adding %d entries gives "
-                "%.2f%% false positives.\n"
-                    % (add_count, b.pfalse_positive(add_count)))
+            debug1("bloom: regenerating: adding %d entries gives "
+                   "%.2f%% false positives.\n"
+                   % (add_count, b.pfalse_positive(add_count)))
             b = None
         else:
             b = bloom.ShaBloom(outfilename, readwrite=True, expected=add_count)
@@ -101,7 +101,7 @@ def do_bloom(path, outfilename):
     msg = b is None and 'creating from' or 'adding'
     if not _first: _first = path
     dirprefix = (_first != path) and git.repo_rel(path)+': ' or ''
-    log('bloom: %s%s %d file%s (%d object%s).\n'
+    progress('bloom: %s%s %d file%s (%d object%s).\n'
         % (dirprefix, msg,
            len(add), len(add)!=1 and 's' or '',
            add_count, add_count!=1 and 's' or ''))
@@ -109,18 +109,20 @@ def do_bloom(path, outfilename):
     tfname = None
     if b is None:
         tfname = os.path.join(path, 'bup.tmp.bloom')
-        tf = open(tfname, 'w+')
-        b = bloom.create(tfname, f=tf, expected=add_count, k=opt.k)
-    count = 0
+        b = bloom.create(tfname, expected=add_count, k=opt.k)
+
     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)
 
+    # Currently, there's an open file object for tfname inside b.
+    # Make sure it's closed before rename.
+    b.close()
+
     if tfname:
         os.rename(tfname, outfilename)