]> arthur.barton.de Git - bup.git/commitdiff
Oops, 'bup save /' produced an invalid tree. bup-0.04
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 10 Jan 2010 07:12:47 +0000 (02:12 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 10 Jan 2010 07:13:52 +0000 (02:13 -0500)
Add a bunch of assertions to make sure that never happens.

cmd-save.py
git.py
t/test.sh

index 67cb30c2b4db06c38ea936e3214eee5844ed6c5f..c707b0222fc0a878504de585494d94499388982a 100755 (executable)
@@ -56,6 +56,7 @@ parts = ['']
 shalists = [[]]
 
 def _push(part):
+    assert(part)
     parts.append(part)
     shalists.append([])
 
@@ -90,8 +91,9 @@ for (transname,ent) in index.Reader(git.repo('bupindex')).filter(extra):
     dirp = dir.split('/')
     while parts > dirp:
         _pop()
-    for part in dirp[len(parts):]:
-        _push(part)
+    if dir != '/':
+        for part in dirp[len(parts):]:
+            _push(part)
 
     if not file:
         # directory already handled.
diff --git a/git.py b/git.py
index 5aa7933a520373f717ece351bd1472eaa6984797..f79fa3dfe931ddcb8309b9ccf2c82a7a1c3aa49e 100644 (file)
--- a/git.py
+++ b/git.py
@@ -200,8 +200,13 @@ class PackWriter:
 
     def new_tree(self, shalist):
         shalist = sorted(shalist, key = _shalist_sort_key)
-        l = ['%s %s\0%s' % (mode,name,bin) 
-             for (mode,name,bin) in shalist]
+        l = []
+        for (mode,name,bin) in shalist:
+            assert(mode)
+            assert(mode[0] != '0')
+            assert(name)
+            assert(len(bin) == 20)
+            l.append('%s %s\0%s' % (mode,name,bin))
         return self.maybe_write('tree', ''.join(l))
 
     def _new_commit(self, tree, parent, author, adate, committer, cdate, msg):
index 7e994c14bff7e0b5579358ee56451db7c15a8f59..4472956a58b6fb3d14a7d7a0800120b48dd607ca 100755 (executable)
--- a/t/test.sh
+++ b/t/test.sh
@@ -94,7 +94,7 @@ WVSTART "save/fsck"
     cd "$BUP_DIR" || exit 1
     #git repack -Ad
     #git prune
-    (cd "$TOP/t/sampledata" && WVPASS bup save -vvn master .) || WVFAIL
+    (cd "$TOP/t/sampledata" && WVPASS bup save -vvn master /) || WVFAIL
     n=$(git fsck --full --strict 2>&1 | 
          egrep -v 'dangling (commit|tree)' |
          tee -a /dev/stderr |