Merge lp:~dobey/tarmac/full-authors into lp:tarmac

Proposed by dobey on 2010-09-17
Status: Merged
Approved by: Paul Hummer on 2010-09-18
Approved revision: 356
Merged at revision: 357
Proposed branch: lp:~dobey/tarmac/full-authors
Merge into: lp:tarmac
Diff against target: 124 lines (+46/-18)
3 files modified
tarmac/bin/commands.py (+1/-1)
tarmac/branch.py (+34/-12)
tarmac/tests/test_branch.py (+11/-5)
To merge this branch: bzr merge lp:~dobey/tarmac/full-authors
Reviewer Review Type Date Requested Status
Paul Hummer 2010-09-17 Approve on 2010-09-18
Review via email: mp+35869@code.launchpad.net

Commit message

Get all the authors for all unique changes in the source branch

To post a comment you must log in.
Paul Hummer (rockstar) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tarmac/bin/commands.py'
2--- tarmac/bin/commands.py 2010-09-02 15:18:07 +0000
3+++ tarmac/bin/commands.py 2010-09-17 19:29:50 +0000
4@@ -143,7 +143,7 @@
5 u'Preparing to merge %(source_branch)s' % {
6 'source_branch': proposal.source_branch.bzr_identity})
7 source = Branch.create(
8- proposal.source_branch, self.config)
9+ proposal.source_branch, self.config, target)
10
11 try:
12 approved = proposal.reviewed_revid
13
14=== modified file 'tarmac/branch.py'
15--- tarmac/branch.py 2010-09-02 15:04:52 +0000
16+++ tarmac/branch.py 2010-09-17 19:29:50 +0000
17@@ -35,7 +35,7 @@
18
19 class Branch(object):
20
21- def __init__(self, lp_branch, config=False):
22+ def __init__(self, lp_branch, config=False, target=None):
23 self.lp_branch = lp_branch
24 self.bzr_branch = bzr_branch.Branch.open(self.lp_branch.bzr_identity)
25 if config:
26@@ -43,15 +43,14 @@
27 else:
28 self.config = None
29
30+ self.target = target
31 self.logger = logging.getLogger('tarmac')
32
33 @classmethod
34- def create(cls, lp_branch, config, create_tree=False):
35+ def create(cls, lp_branch, config, create_tree=False, target=None):
36+ clazz = cls(lp_branch, config, target)
37 if create_tree:
38- clazz = cls(lp_branch, config)
39 clazz.create_tree()
40- else:
41- clazz = cls(lp_branch)
42 return clazz
43
44 def create_tree(self):
45@@ -133,15 +132,38 @@
46
47 @property
48 def authors(self):
49- last_rev = self.bzr_branch.last_revision()
50 author_list = []
51
52- # Only query for authors if last_rev is not null:
53- if last_rev != 'null:':
54- rev = self.bzr_branch.repository.get_revision(last_rev)
55- apparent_authors = rev.get_apparent_authors()
56- author_list.extend(
57- [a.replace('\n', '') for a in apparent_authors])
58+ if self.target:
59+ self.bzr_branch.lock_read()
60+ self.target.bzr_branch.lock_read()
61+
62+ graph = self.bzr_branch.repository.get_graph(
63+ self.target.bzr_branch.repository)
64+
65+ unique_ids = graph.find_unique_ancestors(
66+ self.bzr_branch.last_revision(),
67+ [self.target.bzr_branch.last_revision()])
68+
69+ revs = self.bzr_branch.repository._iter_revisions(unique_ids)
70+ for rev in revs:
71+ apparent_authors = rev[1].get_apparent_authors()
72+ for author in apparent_authors:
73+ author.replace('\n', '')
74+ if author not in author_list:
75+ author_list.append(author)
76+
77+ self.target.bzr_branch.unlock()
78+ self.bzr_branch.unlock()
79+ else:
80+ last_rev = self.bzr_branch.last_revision()
81+ if last_rev != 'null:':
82+ rev = self.bzr_branch.repository.get_revision(last_rev)
83+ apparent_authors = rev.get_apparent_authors()
84+ author_list.extend(
85+ [a.replace('\n', '') for a in apparent_authors])
86+
87+
88 return author_list
89
90 @property
91
92=== modified file 'tarmac/tests/test_branch.py'
93--- tarmac/tests/test_branch.py 2010-09-14 16:53:54 +0000
94+++ tarmac/tests/test_branch.py 2010-09-17 19:29:50 +0000
95@@ -58,7 +58,8 @@
96 branch1.lp_branch.revision_count += 1
97
98 mock2 = MockLPBranch(branch2_dir, source_branch=branch1.lp_branch)
99- branch2 = branch.Branch.create(mock2, self.config, create_tree=True)
100+ branch2 = branch.Branch.create(mock2, self.config, create_tree=True,
101+ target=branch1)
102 branch2.commit('ABC...')
103
104 added_file = os.path.join(branch2.lp_branch.tree_dir, 'README')
105@@ -124,10 +125,15 @@
106 def test_merge_with_authors(self):
107 '''A merge from a branch with authors'''
108 authors = ['author1', 'author2']
109- self.branch1.commit('Authors test', authors=authors)
110- self.branch2.merge(self.branch1)
111- self.branch2.commit('Authors Merge test', authors=self.branch1.authors)
112- self.assertEqual(self.branch2.authors.sort(), authors.sort())
113+ self.branch2.commit('Authors test', authors=authors)
114+ self.branch2.commit('Another author', authors=['author3'])
115+ self.branch2.lp_branch.revision_count += 2
116+ orig_authors = self.branch2.authors
117+ self.branch1.merge(self.branch2)
118+ self.branch1.commit('Authors Merge test', authors=self.branch2.authors)
119+ self.branch1.lp_branch.revision_count += 1
120+ self.assertEqual(sorted(orig_authors),
121+ sorted(self.branch1.authors))
122
123 def test_merge_with_bugs(self):
124 '''A merge from a branch with authors'''

Subscribers

People subscribed via source and target branches