Drop the autogenerated commit if its diff is empty
[trackgit.git] / idcache.py
blob377214da24d07b391c33e722463c1022bdb3d90e
1 import sys
2 import shelve
4 from git import git
6 class PatchIDCache(object):
8 def __init__(self, dbfile):
9 self._db = shelve.open(dbfile)
11 def rebuild(self):
12 for line in git('rev-list', '--all', ret_pipe=True):
13 sha = line.strip()
14 self[sha]
16 def __getitem__(self, key):
17 if key in self._db:
18 return self._db[key]
19 patch = git('show', key+'^!')[0]
20 v = self._db[key] = git('patch-id', input=patch)[0].split()[0]
21 return v
23 def items(self):
24 return self._db.iteritems()
27 if __name__ == '__main__':
28 c = PatchIDCache(sys.argv[1])
29 c.rebuild()
30 for k,v in c.items():
31 print k, v