]> arthur.barton.de Git - bup.git/commitdiff
bup index --check: detect broken index entries.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 28 Feb 2010 20:52:04 +0000 (15:52 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 28 Feb 2010 22:49:10 +0000 (17:49 -0500)
Entries with invalid gitmode or sha1 are actually invalid, so if
IX_HASHVALID is set, that's a bug.  Detect it right away when it happens.

Also clean up a bit of log output related to checking and status.

cmd-index.py
index.py

index 9ad3efaeceb112dc9b39da408569e21e952801f1..fe1acb1d20b6b02f3332cb9c089e40bee2ef401d 100755 (executable)
@@ -31,11 +31,16 @@ def check_index(reader):
         d = {}
         for e in reader.forward_iter():
             if e.children_n:
-                log('%08x+%-4d %r\n' % (e.children_ofs, e.children_n, e.name))
+                if opt.verbose:
+                    log('%08x+%-4d %r\n' % (e.children_ofs, e.children_n,
+                                            e.name))
                 assert(e.children_ofs)
                 assert(e.name.endswith('/'))
                 assert(not d.get(e.children_ofs))
                 d[e.children_ofs] = 1
+            if e.flags & index.IX_HASHVALID:
+                assert(e.sha != index.EMPTY_SHA)
+                assert(e.gitmode)
         assert(not e or e.name == '/')  # last entry is *always* /
         log('check: checking normal iteration...\n')
         last = None
@@ -156,22 +161,22 @@ if opt['print'] or opt.status or opt.modified:
             continue
         line = ''
         if opt.status:
-            if not ent.flags & index.IX_EXISTS:
+            if ent.is_deleted():
                 line += 'D '
-            elif not ent.flags & index.IX_HASHVALID:
+            elif not ent.is_valid():
                 if ent.sha == index.EMPTY_SHA:
                     line += 'A '
                 else:
                     line += 'M '
             else:
                 line += '  '
-        if opt.long:
-            line += "%7s %7s " % (oct(ent.mode), oct(ent.gitmode))
         if opt.hash:
             line += ent.sha.encode('hex') + ' '
+        if opt.long:
+            line += "%7s %7s " % (oct(ent.mode), oct(ent.gitmode))
         print line + (name or './')
 
-if opt.check:
+if opt.check and (opt['print'] or opt.status or opt.modified or opt.update):
     log('check: starting final check.\n')
     check_index(index.Reader(indexfile))
 
index cfc42aa0fbe4e756fde2f9408c12df7fa2740d9a..536af8f494bab6082537c2a589bb9b208e4b12ad 100644 (file)
--- a/index.py
+++ b/index.py
@@ -68,10 +68,11 @@ class Entry:
         self.children_n = 0
 
     def __repr__(self):
-        return ("(%s,0x%04x,%d,%d,%d,%d,%d,0x%04x,0x%08x/%d)" 
+        return ("(%s,0x%04x,%d,%d,%d,%d,%d,%s/%s,0x%04x,0x%08x/%d)" 
                 % (self.name, self.dev,
                    self.ctime, self.mtime, self.uid, self.gid,
-                   self.size, self.flags, self.children_ofs, self.children_n))
+                   self.size, oct(self.mode), oct(self.gitmode),
+                   self.flags, self.children_ofs, self.children_n))
 
     def packed(self):
         return struct.pack(INDEX_SIG,
@@ -106,6 +107,7 @@ class Entry:
 
     def validate(self, gitmode, sha):
         assert(sha)
+        assert(gitmode)
         self.gitmode = gitmode
         self.sha = sha
         self.flags |= IX_HASHVALID|IX_EXISTS