optspec = """
bup bloom [options...]
--
-o,output= output bloom filename (default: auto-generated)
-d,dir= input directory to look for idx files (default: auto-generated)
-k,hashes= number of hash functions to use (4 or 5) (default: auto-generated)
-c,check= an idx file to check against an existing bloom filter
+f,force ignore existing bloom file and regenerate it from scratch
+o,output= output bloom filename (default: auto)
+d,dir= input directory to look for idx files (default: auto)
+k,hashes= number of hash functions to use (4 or 5) (default: auto)
++c,check= check the given .idx file against the bloom filter
"""
- log("bloom: %s not found to check\n" % bloomfilename)
+ def check_bloom(path, bloomfilename, idx):
++ rbloomfilename = git.repo_rel(bloomfilename)
++ ridx = git.repo_rel(idx)
+ if not os.path.exists(bloomfilename):
- b = git.ShaBloom(bloomfilename)
++ log("bloom: %s: does not exist.\n" % rbloomfilename)
+ return
- log("bloom: %s could not be opened to check\n" % bloomfilename)
++ b = bloom.ShaBloom(bloomfilename)
+ if not b.valid():
- log("bloom: filter does not contain %s, nothing to check\n" % idx)
++ add_error("bloom: %r is invalid.\n" % rbloomfilename)
+ return
+ base = os.path.basename(idx)
+ if base not in b.idxnames:
- log("bloom: checking %s" % idx)
++ log("bloom: %s does not contain the idx.\n" % rbloomfilename)
+ return
+ if base == idx:
+ idx = os.path.join(path, idx)
- add_error("bloom: ERROR: %s missing from bloom"
++ log("bloom: bloom file: %s\n" % rbloomfilename)
++ log("bloom: checking %s\n" % ridx)
+ for objsha in git.open_idx(idx):
+ if not b.exists(objsha):
++ add_error("bloom: ERROR: object %s missing"
+ % str(objsha).encode('hex'))
+
+
+_first = None
def do_bloom(path, outfilename):
- if not outfilename:
- assert(path)
- outfilename = os.path.join(path, 'bup.bloom')
-
+ global _first
b = None
- if os.path.exists(outfilename):
- b = git.ShaBloom(outfilename)
+ if os.path.exists(outfilename) and not opt.force:
+ b = bloom.ShaBloom(outfilename)
if not b.valid():
debug1("bloom: Existing invalid bloom found, regenerating.\n")
b = None
if extra:
o.fatal('no positional parameters expected')
- if opt.k and opt.k not in (4,5):
- o.fatal('only k values of 4 and 5 are supported')
-
git.check_repo_or_die()
-bloompath = opt.dir or git.repo('objects/pack')
-if not opt.output:
- assert(bloompath)
-outfilename = opt.output or os.path.join(bloompath, 'bup.bloom')
++if not opt.check and opt.k and opt.k not in (4,5):
++ o.fatal('only k values of 4 and 5 are supported')
+
-if opt.check:
- check_bloom(bloompath, outfilename, opt.check)
-else:
- if opt.k and opt.k not in (4,5):
- o.fatal('only k values of 4 and 5 are supported')
-
- do_bloom(bloompath, outfilename)
+paths = opt.dir and [opt.dir] or git.all_packdirs()
+for path in paths:
+ debug1('bloom: scanning %s\n' % path)
- do_bloom(path, opt.output)
++ outfilename = opt.output or os.path.join(path, 'bup.bloom')
++ if opt.check:
++ check_bloom(path, outfilename, opt.check)
++ else:
++ do_bloom(path, outfilename)
+
+ if saved_errors:
+ log('WARNING: %d errors encountered during bloom.\n' % len(saved_errors))
+ sys.exit(1)
-
++elif opt.check:
++ log('all tests passed.\n')