forked from aspiers/git-explode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopics.py
More file actions
53 lines (41 loc) · 1.42 KB
/
topics.py
File metadata and controls
53 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class TopicManager(object):
"""Acts as a factory for topic branch names, and a registry for
mapping both individual commits and merges of commits to topic
branch names.
This ensures we always know onto which topic branch to explode
(cherry-pick) a new commit.
"""
i = 0
topics = {}
commits = {}
def __init__(self, template, logger):
self.template = template
self.logger = logger
def lookup(self, *commits):
name = self._name_for(*commits)
return self.topics.get(name)
def register(self, *commits):
new = self.next()
self.assign(new, *commits)
return new
def _assign(self, topic, *commits):
name = self._name_for(*commits)
self.topics[name] = topic
self.commits[topic] = name
self.logger.debug(" Assigned %s to %s" % (topic, name))
def assign(self, topic, *commits):
old_commits = self.commits.get(topic)
if old_commits:
self.unassign(topic, old_commits)
self._assign(topic, *commits)
def unassign(self, topic, commits):
del self.topics[commits]
del self.commits[topic]
self.logger.debug(" Unassigned %s from %s" % (topic, commits))
def _name_for(self, *commits):
return ' '.join(sorted(commits))
def next(self):
self.i += 1
return self.template % self.i