]> arthur.barton.de Git - bup.git/commitdiff
Merge branch 'bl/bloomcheck' into ap/cleanups
authorAvery Pennarun <apenwarr@gmail.com>
Thu, 17 Feb 2011 02:34:36 +0000 (18:34 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Thu, 17 Feb 2011 02:59:26 +0000 (18:59 -0800)
* bl/bloomcheck:
  Bail out immediately instead of redownloading .idx
  Add a --check behavior to verify bloom
  Defines/preprocessor lengths > magic numbers

Conflicts:
cmd/bloom-cmd.py

1  2 
Documentation/bup-bloom.md
cmd/bloom-cmd.py
lib/bup/client.py

index b827b68051101cbafbfd01b566595080e90626b0,1501e2e0c517959afdc03ce39830157eb10f3f68..3d57c74ad0a7be81f09a91268a4da8ce545db59c
@@@ -32,9 -28,17 +32,17 @@@ updates or regenerates it as needed
  
  -k, --hashes=*hashes*
  :   number of hash functions to use only 4 and 5 are valid.
 -    defaults to 5 for repositories < 2TiB and 4 otherwise.
 -    see comments in git.py for more on this value.
 +    defaults to 5 for repositories < 2 TiB, or 4 otherwise.
 +    See comments in git.py for more on this value.
  
+ -c, --check=*idxfile*
+ :   checks the bloom file (counterintuitively outfile)
+     against the specified .idx file, first checks that the
+     bloom filter is claiming to contain the .idx, then
+     checks that it does actually contain all of the objects
+     in the .idx.  Does not write anything and ignores the
+     `-k` option.
  # BUP
  
  Part of the `bup`(1) suite.
index 5e3cd8689dbda1350d71d7cd6197492c8869bd76,81ee392fb2d77a778e8cd8e4dc08dbf32f695728..033ad85f190c8b1a4bce787bf96dc7a7e57a3ada
@@@ -6,22 -6,37 +6,43 @@@ from bup.helpers import 
  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
@@@ -100,12 -109,22 +121,22 @@@ o = options.Options(optspec
  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')
Simple merge