]> arthur.barton.de Git - bup.git/commitdiff
cmd/midx, git.py: all else being equal, delete older midxes first.
authorAvery Pennarun <apenwarr@gmail.com>
Fri, 18 Feb 2011 09:15:47 +0000 (01:15 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Fri, 18 Feb 2011 09:18:28 +0000 (01:18 -0800)
Previous runs of 'bup midx -f' might have created invalid midx files with
exactly the same length as a newer run.  bup's "prune redundant midx" logic
would quasi-randomly choose one or the other to delete (based on
alphabetical order of filenames, basically) and sometimes that would be the
new one, not the old one, so the 'bup midx -f' results never actually kicked
in.

Now if the file sizes are equal we'll use the mtime as a tie breaker; newer
is better.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
cmd/midx-cmd.py
lib/bup/git.py
t/test.sh

index dfe346fed3ef1fdb78cea3ecfef6a41c6c1eb10e..8e8fbcac5b59e2d3285020f85a1267af61f97dba 100755 (executable)
@@ -160,9 +160,9 @@ def do_midx_dir(path):
             contents[mname] = [('%s/%s' % (path,i)) for i in m.idxnames]
             sizes[mname] = len(m)
                     
-        # sort the biggest midxes first, so that we can eliminate smaller
-        # redundant ones that come later in the list
-        midxs.sort(lambda x,y: -cmp(sizes[x], sizes[y]))
+        # sort the biggest+newest midxes first, so that we can eliminate
+        # smaller (or older) redundant ones that come later in the list
+        midxs.sort(key=lambda ix: (-sizes[ix], -os.stat(ix).st_mtime))
         
         for mname in midxs:
             any = 0
index ace4e4cb84118ee67682c998fa0956d48efc7042..6db392a2226fe5de78df7d4c15c44982a18bfdd2 100644 (file)
@@ -360,7 +360,8 @@ class PackIdxList:
                             unlink(full)
                         else:
                             midxl.append(mx)
-                midxl.sort(lambda x,y: -cmp(len(x),len(y)))
+                midxl.sort(key=lambda ix:
+                           (-len(ix), -os.stat(ix.name).st_mtime))
                 for ix in midxl:
                     any_needed = False
                     for sub in ix.idxnames:
index 0c523a6c017304dddca632ddba2359c0f20c8bbd..7186710c2ea6d6c38c8aa6b0e2624d5215f581ac 100755 (executable)
--- a/t/test.sh
+++ b/t/test.sh
@@ -148,6 +148,13 @@ WVPASS bup midx -o $BUP_DIR/objects/pack/test1.midx \
        $BUP_DIR/objects/pack/*.idx \
        $BUP_DIR/objects/pack/*.idx
 WVPASS bup midx --check -a
+all=$(echo $BUP_DIR/objects/pack/*.idx $BUP_DIR/objects/pack/*.midx)
+WVPASS bup midx -o $BUP_DIR/objects/pack/zzz.midx $all
+bup tick
+WVPASS bup midx -o $BUP_DIR/objects/pack/yyy.midx $all
+WVPASS bup midx -a
+WVPASSEQ "$(echo $BUP_DIR/objects/pack/*.midx)" \
+       "$BUP_DIR/objects/pack/yyy.midx"
 WVPASS bup margin
 WVPASS bup split -t t/testfile2 >tags2t.tmp
 WVPASS bup split -t t/testfile2 --fanout 3 >tags2tf.tmp