comparison commitwatcher/store.py @ 31:3edb91cfd3c1

move to ABC
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 11 Oct 2013 10:19:47 -0700
parents 4c53f4cc6ffe
children 035368f84847
comparison
equal deleted inserted replaced
30:4c53f4cc6ffe 31:3edb91cfd3c1
35 while path: 35 while path:
36 paths.append(sep.join(path)) 36 paths.append(sep.join(path))
37 path.pop() 37 path.pop()
38 return paths 38 return paths
39 39
40 def paths(self, *commits):
41 """
42 return paths touched by commits
43 """
44
45 paths = set()
46 for commit in commits:
47 for f in commit.files:
48 paths.update(self.ancestry(f))
49 return paths
50
40 51
41 class MemoryStore(CommitStore): 52 class MemoryStore(CommitStore):
42 """store in volatile memory""" 53 """store in volatile memory"""
43 # volatile! 54 # volatile!
44 55
45 def __init__(self): 56 def __init__(self):
46 self.path_to_commit = {} 57 self.path_to_commit = {}
47 self._commits = [] 58 self._commits = []
48 59
49 def add(self, commit): 60 def store(self, commit):
61 paths = self.paths(commit)
62 for path in paths:
63 self.path_to_commit.set_default(path, []).append(commit)
50 raise NotImplementedError() 64 raise NotImplementedError()
51 65
52 def paths(self, *commits):
53 """
54 return paths touched by commits
55 """
56
57 paths = set()
58 for commit in commits:
59 for f in commit.files:
60 for path in self.ancestry(f):
61 self.path_to_commit.set_default(path, []).append(commit)
62 # TODO: worry about commit order
63