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
=== modified file 'lib/lp/code/bzr.py'
--- lib/lp/code/bzr.py 2012-06-26 14:49:27 +0000
+++ lib/lp/code/bzr.py 2012-06-26 14:49:31 +0000
@@ -10,6 +10,8 @@
10 'ControlFormat',10 'ControlFormat',
11 'CURRENT_BRANCH_FORMATS',11 'CURRENT_BRANCH_FORMATS',
12 'CURRENT_REPOSITORY_FORMATS',12 'CURRENT_REPOSITORY_FORMATS',
13 'branch_revision_history',
14 'get_ancestry',
13 'get_branch_formats',15 'get_branch_formats',
14 'RepositoryFormat',16 'RepositoryFormat',
15 ]17 ]
@@ -31,6 +33,7 @@
31from bzrlib.bzrdir import BzrDirMetaFormat133from bzrlib.bzrdir import BzrDirMetaFormat1
32from bzrlib.errors import (34from bzrlib.errors import (
33 NotStacked,35 NotStacked,
36 NoSuchRevision,
34 UnstackableBranchFormat,37 UnstackableBranchFormat,
35 )38 )
36from bzrlib.plugins.loom.branch import (39from bzrlib.plugins.loom.branch import (
@@ -57,6 +60,7 @@
57 RepositoryFormatKnitPack5,60 RepositoryFormatKnitPack5,
58 )61 )
59from bzrlib.revision import (62from bzrlib.revision import (
63 is_null,
60 NULL_REVISION,64 NULL_REVISION,
61 )65 )
62from bzrlib.repofmt.knitrepo import (66from bzrlib.repofmt.knitrepo import (
@@ -64,6 +68,7 @@
64 RepositoryFormatKnit3,68 RepositoryFormatKnit3,
65 RepositoryFormatKnit4,69 RepositoryFormatKnit4,
66 )70 )
71from bzrlib.tsort import topo_sort
67from lazr.enum import (72from lazr.enum import (
68 DBEnumeratedType,73 DBEnumeratedType,
69 DBItem,74 DBItem,
@@ -341,3 +346,34 @@
341 return ret346 return ret
342 finally:347 finally:
343 branch.unlock()348 branch.unlock()
349
350
351def get_ancestry(repository, revision_id):
352 """Return a list of revision-ids integrated by a revision.
353
354 The first element of the list is always None, indicating the origin
355 revision. This might change when we have history horizons, or
356 perhaps we should have a new API.
357
358 This is topologically sorted.
359 """
360 if is_null(revision_id):
361 return set()
362 if not repository.has_revision(revision_id):
363 raise NoSuchRevision(repository, revision_id)
364 repository.lock_read()
365 try:
366 graph = repository.get_graph()
367 keys = set()
368 search = graph._make_breadth_first_searcher([revision_id])
369 while True:
370 try:
371 found, ghosts = search.next_with_ghosts()
372 except StopIteration:
373 break
374 keys.update(found)
375 if NULL_REVISION in keys:
376 keys.remove(NULL_REVISION)
377 finally:
378 repository.unlock()
379 return keys
344380
=== modified file 'lib/lp/code/tests/test_bzr.py'
--- lib/lp/code/tests/test_bzr.py 2012-06-26 14:49:27 +0000
+++ lib/lp/code/tests/test_bzr.py 2012-06-26 14:49:31 +0000
@@ -5,6 +5,10 @@
55
6__metaclass__ = type6__metaclass__ = type
77
8from bzrlib.errors import (
9 NoSuchRevision,
10 )
11from bzrlib.revision import NULL_REVISION
8from bzrlib.tests import (12from bzrlib.tests import (
9 TestCaseInTempDir,13 TestCaseInTempDir,
10 TestCaseWithTransport,14 TestCaseWithTransport,
@@ -14,6 +18,7 @@
14 BranchFormat,18 BranchFormat,
15 branch_revision_history,19 branch_revision_history,
16 ControlFormat,20 ControlFormat,
21 get_ancestry,
17 get_branch_formats,22 get_branch_formats,
18 RepositoryFormat,23 RepositoryFormat,
19 )24 )
@@ -84,8 +89,51 @@
8489
85 def test_some_commits(self):90 def test_some_commits(self):
86 branch = self.make_branch('test')91 branch = self.make_branch('test')
87 wt = branch.bzrdir.create_workingtree()92 tree = branch.bzrdir.create_workingtree()
88 wt.commit('acommit', rev_id='A')93 tree.commit('acommit', rev_id='A')
89 wt.commit('bcommit', rev_id='B')94 tree.commit('bcommit', rev_id='B')
90 wt.commit('ccommit', rev_id='C')95 tree.commit('ccommit', rev_id='C')
91 self.assertEquals(['A', 'B', 'C'], branch_revision_history(wt.branch))96 self.assertEquals(
97 ['A', 'B', 'C'], branch_revision_history(tree.branch))
98
99
100class TestGetAncestry(TestCaseWithTransport):
101 """Tests for lp.code.bzr.get_ancestry."""
102
103 def test_missing_revision(self):
104 # If the revision does not exist, NoSuchRevision should be raised.
105 branch = self.make_branch('test')
106 self.assertRaises(
107 NoSuchRevision, get_ancestry, branch.repository, 'orphan')
108
109 def test_some(self):
110 # Verify ancestors are included.
111 branch = self.make_branch('test')
112 tree = branch.bzrdir.create_workingtree()
113 tree.commit('msg a', rev_id='A')
114 tree.commit('msg b', rev_id='B')
115 tree.commit('msg c', rev_id='C')
116 self.assertEqual(
117 set(['A']), get_ancestry(branch.repository, 'A'))
118 self.assertEqual(
119 set(['A', 'B']), get_ancestry(branch.repository, 'B'))
120 self.assertEqual(
121 set(['A', 'B', 'C']), get_ancestry(branch.repository, 'C'))
122
123 def test_children(self):
124 # Verify non-mainline children are included.
125 branch = self.make_branch('test')
126 tree = branch.bzrdir.create_workingtree()
127 tree.commit('msg a', rev_id='A')
128 branch.generate_revision_history(NULL_REVISION)
129 tree.set_parent_ids([])
130 tree.commit('msg b', rev_id='B')
131 branch.generate_revision_history('A')
132 tree.set_parent_ids(['A', 'B'])
133 tree.commit('msg c', rev_id='C')
134 self.assertEqual(
135 set(['A']), get_ancestry(branch.repository, 'A'))
136 self.assertEqual(
137 set(['B']), get_ancestry(branch.repository, 'B'))
138 self.assertEqual(
139 set(['A', 'B', 'C']), get_ancestry(branch.repository, 'C'))
92140
=== modified file 'lib/lp/codehosting/scanner/bzrsync.py'
--- lib/lp/codehosting/scanner/bzrsync.py 2012-06-26 14:49:27 +0000
+++ lib/lp/codehosting/scanner/bzrsync.py 2012-06-26 14:49:31 +0000
@@ -24,7 +24,10 @@
24from zope.component import getUtility24from zope.component import getUtility
25from zope.event import notify25from zope.event import notify
2626
27from lp.code.bzr import branch_revision_history27from lp.code.bzr import (
28 branch_revision_history,
29 get_ancestry,
30 )
28from lp.code.interfaces.branchjob import IRosettaUploadJobSource31from lp.code.interfaces.branchjob import IRosettaUploadJobSource
29from lp.code.interfaces.revision import IRevisionSet32from lp.code.interfaces.revision import IRevisionSet
30from lp.code.model.branchrevision import BranchRevision33from lp.code.model.branchrevision import BranchRevision
@@ -155,8 +158,7 @@
155 bzr_last = bzr_branch.last_revision()158 bzr_last = bzr_branch.last_revision()
156 db_last = self.db_branch.last_scanned_id159 db_last = self.db_branch.last_scanned_id
157 if db_last is None:160 if db_last is None:
158 added_ancestry = set(bzr_branch.repository.get_ancestry(bzr_last))161 added_ancestry = get_ancestry(bzr_branch.repository, bzr_last)
159 added_ancestry.discard(None)
160 removed_ancestry = set()162 removed_ancestry = set()
161 else:163 else:
162 graph = self._getRevisionGraph(bzr_branch, db_last)164 graph = self._getRevisionGraph(bzr_branch, db_last)