annotate commitwatcher/store.py @ 28:f82331d875f0

wip
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 05 Oct 2013 15:38:32 -0700
parents 60a67934c64e
children 4c53f4cc6ffe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
6 """
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
7 ABC for commits
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
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
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
14 @abstractmethod
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
15 def paths(self, *commits):
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
16 """return all paths touched for a given commit"""
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
17
20
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
18 def ancestry(self, path):
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
19 sep = '/' # unix/url-style separators
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
20 path = path.split('/')
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
21 paths = []
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
22 while path:
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
23 paths.append(sep.join(path))
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
24 path.pop()
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
25 return paths
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
26
5
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
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
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
32 def __init__(self):
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
33 self.path_to_commit = {}
22
f82d43bcb24e commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
34 self._commits = []
20
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
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
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
37 raise NotImplementedError()
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
38
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
39 def paths(self, *commits):
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
40 """
21
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
41 return paths touched by commits
5
d85093ba9f45 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
42 """
20
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
43
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
44 paths = set()
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
45 for commit in commits:
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
46 for f in commit.files:
23
e65090645a18 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
47 for path in self.ancestry(f):
e65090645a18 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
48 self.path_to_commit.set_default(path, []).append(commit)
e65090645a18 commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
49 # TODO: worry about commit order
24
60a67934c64e commitwatcher/store.py
Jeff Hammel <jhammel@mozilla.com>
parents: 23
diff changeset
50