Mercurial > hg > CommitWatcher
annotate commitwatcher/store.py @ 32:630aaf102ce8
foo
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sun, 13 Oct 2013 12:28:25 -0700 |
parents | 3edb91cfd3c1 |
children | 035368f84847 |
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 |
30
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
10 def __init__(self, verbose=True): |
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
11 self.verbose = verbose |
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
12 |
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
|
13 @abstractmethod |
30
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
14 def __contains__(self, revision): |
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
15 """if a particular revision is already added""" |
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
16 |
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
17 @abstractmethod |
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
18 def store(self, commit): |
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
19 """store a commit""" |
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
20 |
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
|
21 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
|
22 """adds a commit to the store""" |
30
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
23 if commit.revision not in self: |
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
24 return |
4c53f4cc6ffe
commitwatcher/commit.py commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents:
24
diff
changeset
|
25 self.store(commit) |
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
|
26 |
5 | 27 @abstractmethod |
28 def paths(self, *commits): | |
29 """return all paths touched for a given commit""" | |
30 | |
20 | 31 def ancestry(self, path): |
32 sep = '/' # unix/url-style separators | |
33 path = path.split('/') | |
34 paths = [] | |
35 while path: | |
36 paths.append(sep.join(path)) | |
37 path.pop() | |
38 return paths | |
39 | |
31 | 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 | |
5 | 51 |
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
|
52 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
|
53 """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
|
54 # 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
|
55 |
20 | 56 def __init__(self): |
57 self.path_to_commit = {} | |
22 | 58 self._commits = [] |
20 | 59 |
31 | 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) | |
5 | 64 raise NotImplementedError() |
65 |