From: Avery Pennarun Date: Tue, 2 Feb 2010 02:30:59 +0000 (-0500) Subject: cmd-midx: correctly handle a tiny nonzero number of objects. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=11f86ebed112fa8305271388c71248a51740b644;p=packages%2Fb%2Fbup.git cmd-midx: correctly handle a tiny nonzero number of objects. 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. --- diff --git a/cmd-midx.py b/cmd-midx.py index 97d01de..c0f8324 100755 --- a/cmd-midx.py +++ b/cmd-midx.py @@ -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