From: Avery Pennarun Date: Sun, 28 Feb 2010 20:52:04 +0000 (-0500) Subject: bup index --check: detect broken index entries. X-Git-Tag: bup-0.12~6 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76c38a42144d0a7883765ae53c58b118de1e3296;p=bup.git bup index --check: detect broken index entries. 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. --- diff --git a/cmd-index.py b/cmd-index.py index 9ad3efa..fe1acb1 100755 --- a/cmd-index.py +++ b/cmd-index.py @@ -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)) diff --git a/index.py b/index.py index cfc42aa..536af8f 100644 --- 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