Merge lp:~jelmer/launchpad/no-revhistory-3 into lp:launchpad

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 15498
Proposed branch: lp:~jelmer/launchpad/no-revhistory-3
Merge into: lp:launchpad
Prerequisite: lp:~jelmer/launchpad/no-revhistory-2
Diff against target: 177 lines (+94/-8)
3 files modified
lib/lp/code/bzr.py (+36/-0)
lib/lp/code/tests/test_bzr.py (+53/-5)
lib/lp/codehosting/scanner/bzrsync.py (+5/-3)
To merge this branch: bzr merge lp:~jelmer/launchpad/no-revhistory-3
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+112123@code.launchpad.net

Commit message

Remove use of Repository.get_ancestry(), which is deprecated in bzr 2.5.

Description of the change

Remove use of Repository.get_ancestry(), which is deprecated in bzr 2.5.

Instead, this imports the get_ancestry() code into Launchpad, albeit a little bit simplified.

This is simpler than my previous attempt at getting rid of Repository.get_ancestry(), which tried to improve performance of the branch scanner at the same time by no longer having it look at the full ancestry but only those bits that were necessary.

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

Couple of nitpicks, nothing major:

[1]

104 + def test_missing_revision(self):

109 + def test_some(self):

122 + def test_children(self):

These all need leading comments or docstrings explaining the expected
behaviour for which they're testing, e.g.:

 def test_foo_bars(self):
    """When called, foo() returns bar."""
    ...

[2]

109 + def test_some(self):
110 + branch = self.make_branch('test')
111 + wt = branch.bzrdir.create_workingtree()
112 + wt.commit('msg a', rev_id='A')
113 + wt.commit('msg b', rev_id='B')
114 + wt.commit('msg c', rev_id='C')
115 + self.assertEqual(
116 + set(['A']), get_ancestry(branch.repository, 'A'))
117 + self.assertEqual(
118 + set(['A', 'B']), get_ancestry(branch.repository, 'B'))
119 + self.assertEqual(
120 + set(['A', 'B', 'C']), get_ancestry(branch.repository, 'C'))

s/wt/tree (or something meaningful). Same thing in test_children().

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/bzr.py'
2--- lib/lp/code/bzr.py 2012-06-26 14:49:27 +0000
3+++ lib/lp/code/bzr.py 2012-06-26 14:49:31 +0000
4@@ -10,6 +10,8 @@
5 'ControlFormat',
6 'CURRENT_BRANCH_FORMATS',
7 'CURRENT_REPOSITORY_FORMATS',
8+ 'branch_revision_history',
9+ 'get_ancestry',
10 'get_branch_formats',
11 'RepositoryFormat',
12 ]
13@@ -31,6 +33,7 @@
14 from bzrlib.bzrdir import BzrDirMetaFormat1
15 from bzrlib.errors import (
16 NotStacked,
17+ NoSuchRevision,
18 UnstackableBranchFormat,
19 )
20 from bzrlib.plugins.loom.branch import (
21@@ -57,6 +60,7 @@
22 RepositoryFormatKnitPack5,
23 )
24 from bzrlib.revision import (
25+ is_null,
26 NULL_REVISION,
27 )
28 from bzrlib.repofmt.knitrepo import (
29@@ -64,6 +68,7 @@
30 RepositoryFormatKnit3,
31 RepositoryFormatKnit4,
32 )
33+from bzrlib.tsort import topo_sort
34 from lazr.enum import (
35 DBEnumeratedType,
36 DBItem,
37@@ -341,3 +346,34 @@
38 return ret
39 finally:
40 branch.unlock()
41+
42+
43+def get_ancestry(repository, revision_id):
44+ """Return a list of revision-ids integrated by a revision.
45+
46+ The first element of the list is always None, indicating the origin
47+ revision. This might change when we have history horizons, or
48+ perhaps we should have a new API.
49+
50+ This is topologically sorted.
51+ """
52+ if is_null(revision_id):
53+ return set()
54+ if not repository.has_revision(revision_id):
55+ raise NoSuchRevision(repository, revision_id)
56+ repository.lock_read()
57+ try:
58+ graph = repository.get_graph()
59+ keys = set()
60+ search = graph._make_breadth_first_searcher([revision_id])
61+ while True:
62+ try:
63+ found, ghosts = search.next_with_ghosts()
64+ except StopIteration:
65+ break
66+ keys.update(found)
67+ if NULL_REVISION in keys:
68+ keys.remove(NULL_REVISION)
69+ finally:
70+ repository.unlock()
71+ return keys
72
73=== modified file 'lib/lp/code/tests/test_bzr.py'
74--- lib/lp/code/tests/test_bzr.py 2012-06-26 14:49:27 +0000
75+++ lib/lp/code/tests/test_bzr.py 2012-06-26 14:49:31 +0000
76@@ -5,6 +5,10 @@
77
78 __metaclass__ = type
79
80+from bzrlib.errors import (
81+ NoSuchRevision,
82+ )
83+from bzrlib.revision import NULL_REVISION
84 from bzrlib.tests import (
85 TestCaseInTempDir,
86 TestCaseWithTransport,
87@@ -14,6 +18,7 @@
88 BranchFormat,
89 branch_revision_history,
90 ControlFormat,
91+ get_ancestry,
92 get_branch_formats,
93 RepositoryFormat,
94 )
95@@ -84,8 +89,51 @@
96
97 def test_some_commits(self):
98 branch = self.make_branch('test')
99- wt = branch.bzrdir.create_workingtree()
100- wt.commit('acommit', rev_id='A')
101- wt.commit('bcommit', rev_id='B')
102- wt.commit('ccommit', rev_id='C')
103- self.assertEquals(['A', 'B', 'C'], branch_revision_history(wt.branch))
104+ tree = branch.bzrdir.create_workingtree()
105+ tree.commit('acommit', rev_id='A')
106+ tree.commit('bcommit', rev_id='B')
107+ tree.commit('ccommit', rev_id='C')
108+ self.assertEquals(
109+ ['A', 'B', 'C'], branch_revision_history(tree.branch))
110+
111+
112+class TestGetAncestry(TestCaseWithTransport):
113+ """Tests for lp.code.bzr.get_ancestry."""
114+
115+ def test_missing_revision(self):
116+ # If the revision does not exist, NoSuchRevision should be raised.
117+ branch = self.make_branch('test')
118+ self.assertRaises(
119+ NoSuchRevision, get_ancestry, branch.repository, 'orphan')
120+
121+ def test_some(self):
122+ # Verify ancestors are included.
123+ branch = self.make_branch('test')
124+ tree = branch.bzrdir.create_workingtree()
125+ tree.commit('msg a', rev_id='A')
126+ tree.commit('msg b', rev_id='B')
127+ tree.commit('msg c', rev_id='C')
128+ self.assertEqual(
129+ set(['A']), get_ancestry(branch.repository, 'A'))
130+ self.assertEqual(
131+ set(['A', 'B']), get_ancestry(branch.repository, 'B'))
132+ self.assertEqual(
133+ set(['A', 'B', 'C']), get_ancestry(branch.repository, 'C'))
134+
135+ def test_children(self):
136+ # Verify non-mainline children are included.
137+ branch = self.make_branch('test')
138+ tree = branch.bzrdir.create_workingtree()
139+ tree.commit('msg a', rev_id='A')
140+ branch.generate_revision_history(NULL_REVISION)
141+ tree.set_parent_ids([])
142+ tree.commit('msg b', rev_id='B')
143+ branch.generate_revision_history('A')
144+ tree.set_parent_ids(['A', 'B'])
145+ tree.commit('msg c', rev_id='C')
146+ self.assertEqual(
147+ set(['A']), get_ancestry(branch.repository, 'A'))
148+ self.assertEqual(
149+ set(['B']), get_ancestry(branch.repository, 'B'))
150+ self.assertEqual(
151+ set(['A', 'B', 'C']), get_ancestry(branch.repository, 'C'))
152
153=== modified file 'lib/lp/codehosting/scanner/bzrsync.py'
154--- lib/lp/codehosting/scanner/bzrsync.py 2012-06-26 14:49:27 +0000
155+++ lib/lp/codehosting/scanner/bzrsync.py 2012-06-26 14:49:31 +0000
156@@ -24,7 +24,10 @@
157 from zope.component import getUtility
158 from zope.event import notify
159
160-from lp.code.bzr import branch_revision_history
161+from lp.code.bzr import (
162+ branch_revision_history,
163+ get_ancestry,
164+ )
165 from lp.code.interfaces.branchjob import IRosettaUploadJobSource
166 from lp.code.interfaces.revision import IRevisionSet
167 from lp.code.model.branchrevision import BranchRevision
168@@ -155,8 +158,7 @@
169 bzr_last = bzr_branch.last_revision()
170 db_last = self.db_branch.last_scanned_id
171 if db_last is None:
172- added_ancestry = set(bzr_branch.repository.get_ancestry(bzr_last))
173- added_ancestry.discard(None)
174+ added_ancestry = get_ancestry(bzr_branch.repository, bzr_last)
175 removed_ancestry = set()
176 else:
177 graph = self._getRevisionGraph(bzr_branch, db_last)