]> git.michaelhowe.org Git - packages/b/bup.git/commitdiff
cmd-midx: correctly handle a tiny nonzero number of objects.
authorAvery Pennarun <apenwarr@gmail.com>
Tue, 2 Feb 2010 02:30:59 +0000 (21:30 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Tue, 2 Feb 2010 02:30:59 +0000 (21:30 -0500)
If all the sha1sums would have fit in a single page, the number of bits in
the table would be negative, with odd results.  Now we just refuse to create
the midx if there are too few objects *and* too few files, since it would be
useless anyway.

We're still willing to create a very small midx if it allows us to merge
several indexes into one, however small, since that will still speed up
searching.

cmd-midx.py

index 97d01de887be84b4f089549237088c751d2174d9..c0f832488d9d46db69cb238a3656369d78c9b586 100755 (executable)
@@ -29,15 +29,15 @@ def do_midx(outdir, outfilename, infilenames):
         inp.append(ix)
         total += len(ix)
 
-    if not total:
-        log('%s: no new .idx files: nothing to do.\n' % outdir)
+    log('Merging %d indexes (%d objects).\n' % (len(infilenames), total))
+    if total < 1024 and len(infilenames) < 3:
+        log('%s: not enough objects for a .midx to be useful.\n' % outdir)
         return
 
-    log('Merging %d indexes (%d objects).\n' % (len(infilenames), total))
-    pages = total/SHA_PER_PAGE
+    pages = int(total/SHA_PER_PAGE) or 1
     bits = int(math.ceil(math.log(pages, 2)))
     entries = 2**bits
-    log('table size: %d (%d bits)\n' % (entries*8, bits))
+    log('Table size: %d (%d bits)\n' % (entries*4, bits))
     
     table = [0]*entries