Mercurial > hg > CommitWatcher
annotate commitwatcher/store.py @ 25:a5b4025f2455
commitwatcher/web.py
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 02 Oct 2013 18:41:59 -0700 |
parents | 60a67934c64e |
children | 4c53f4cc6ffe |
rev | line source |
---|---|
2
4cb3971d9d9d
commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 from abc import abstractmethod |
4cb3971d9d9d
commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 |
6
883c88b13142
commitwatcher/agent.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
3 __all__ = ['CommitStore', 'MemoryStore'] |
883c88b13142
commitwatcher/agent.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
5
diff
changeset
|
4 |
2
4cb3971d9d9d
commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 class CommitStore(object): |
5 | 6 """ |
7 ABC for commits | |
8 """ | |
2
4cb3971d9d9d
commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 |
4cb3971d9d9d
commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 @abstractmethod |
4cb3971d9d9d
commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 def add(self, commit): |
4cb3971d9d9d
commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 """adds a commit to the store""" |
4cb3971d9d9d
commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 |
5 | 14 @abstractmethod |
15 def paths(self, *commits): | |
16 """return all paths touched for a given commit""" | |
17 | |
20 | 18 def ancestry(self, path): |
19 sep = '/' # unix/url-style separators | |
20 path = path.split('/') | |
21 paths = [] | |
22 while path: | |
23 paths.append(sep.join(path)) | |
24 path.pop() | |
25 return paths | |
26 | |
5 | 27 |
2
4cb3971d9d9d
commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
28 class MemoryStore(CommitStore): |
4cb3971d9d9d
commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
29 """store in volatile memory""" |
4cb3971d9d9d
commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
30 # volatile! |
4cb3971d9d9d
commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
31 |
20 | 32 def __init__(self): |
33 self.path_to_commit = {} | |
22 | 34 self._commits = [] |
20 | 35 |
2
4cb3971d9d9d
commitwatcher/__init__.py commitwatcher/agent.py commitwatcher/main.py setup.py commitwatcher/commit.py commitwatcher/store.py mozbasewatcher.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
36 def add(self, commit): |
5 | 37 raise NotImplementedError() |
38 | |
39 def paths(self, *commits): | |
40 """ | |
21 | 41 return paths touched by commits |
5 | 42 """ |
20 | 43 |
44 paths = set() | |
45 for commit in commits: | |
46 for f in commit.files: | |
23 | 47 for path in self.ancestry(f): |
48 self.path_to_commit.set_default(path, []).append(commit) | |
49 # TODO: worry about commit order | |
24 | 50 |