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

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 15497
Proposed branch: lp:~jelmer/launchpad/no-revhistory-2
Merge into: lp:launchpad
Diff against target: 218 lines (+62/-13)
7 files modified
lib/lp/code/bzr.py (+24/-0)
lib/lp/code/model/branchjob.py (+5/-2)
lib/lp/code/model/tests/test_branchjob.py (+6/-5)
lib/lp/code/tests/test_bzr.py (+21/-1)
lib/lp/codehosting/codeimport/tests/test_worker.py (+1/-2)
lib/lp/codehosting/scanner/bzrsync.py (+2/-1)
lib/lp/codehosting/scanner/tests/test_bzrsync.py (+3/-2)
To merge this branch: bzr merge lp:~jelmer/launchpad/no-revhistory-2
Reviewer Review Type Date Requested Status
Graham Binns (community) Approve
Review via email: mp+112119@code.launchpad.net

Commit message

Remove last uses of Branch.revision_history, which is deprecated in bzr 2.5.

Description of the change

Remove last uses of Branch.revision_history, which is deprecated in bzr 2.5.

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

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-03-22 23:21:24 +0000
3+++ lib/lp/code/bzr.py 2012-06-26 14:13:33 +0000
4@@ -56,6 +56,9 @@
5 RepositoryFormatKnitPack4,
6 RepositoryFormatKnitPack5,
7 )
8+from bzrlib.revision import (
9+ NULL_REVISION,
10+ )
11 from bzrlib.repofmt.knitrepo import (
12 RepositoryFormatKnit1,
13 RepositoryFormatKnit3,
14@@ -317,3 +320,24 @@
15 last_revision = bzr_branch.last_revision()
16 formats = get_branch_formats(bzr_branch)
17 db_branch.branchChanged(stacked_on, last_revision, *formats)
18+
19+
20+def branch_revision_history(branch):
21+ """Find the revision history of a branch.
22+
23+ This is a compatibility wrapper for code that still requires
24+ access to the full branch mainline and previously used
25+ Branch.revision_history(), which is now deprecated.
26+
27+ :param branch: Branch object
28+ :return: Revision ids on the main branch
29+ """
30+ branch.lock_read()
31+ try:
32+ graph = branch.repository.get_graph()
33+ ret = list(graph.iter_lefthand_ancestry(
34+ branch.last_revision(), (NULL_REVISION,)))
35+ ret.reverse()
36+ return ret
37+ finally:
38+ branch.unlock()
39
40=== modified file 'lib/lp/code/model/branchjob.py'
41--- lib/lp/code/model/branchjob.py 2012-06-14 05:18:22 +0000
42+++ lib/lp/code/model/branchjob.py 2012-06-26 14:13:33 +0000
43@@ -56,7 +56,10 @@
44 implements,
45 )
46
47-from lp.code.bzr import get_branch_formats
48+from lp.code.bzr import (
49+ branch_revision_history,
50+ get_branch_formats,
51+ )
52 from lp.code.enums import (
53 BranchMergeProposalStatus,
54 BranchSubscriptionDiffSize,
55@@ -522,7 +525,7 @@
56 # Avoid hitting the database since bzrlib makes it easy to check.
57 # There are possibly more efficient ways to get the mainline
58 # revisions, but this is simple and it works.
59- history = self.bzr_branch.revision_history()
60+ history = branch_revision_history(self.bzr_branch)
61 for num, revid in enumerate(history):
62 if revid in added_revisions:
63 yield repository.get_revision(revid), num + 1
64
65=== modified file 'lib/lp/code/model/tests/test_branchjob.py'
66--- lib/lp/code/model/tests/test_branchjob.py 2012-06-14 05:18:22 +0000
67+++ lib/lp/code/model/tests/test_branchjob.py 2012-06-26 14:13:33 +0000
68@@ -31,6 +31,7 @@
69 from lp.code.bzr import (
70 BranchFormat,
71 RepositoryFormat,
72+ branch_revision_history,
73 )
74 from lp.code.enums import (
75 BranchMergeProposalStatus,
76@@ -380,7 +381,7 @@
77 job = RevisionsAddedJob.create(branch, 'rev1', 'rev2', '')
78 self.assertEqual([job], list(RevisionsAddedJob.iterReady()))
79
80- def updateDBRevisions(self, branch, bzr_branch, revision_ids=None):
81+ def updateDBRevisions(self, branch, bzr_branch, revision_ids):
82 """Update the database for the revisions.
83
84 :param branch: The database branch associated with the revisions.
85@@ -388,8 +389,6 @@
86 :param revision_ids: The ids of the revisions to update. If not
87 supplied, the branch revision history is used.
88 """
89- if revision_ids is None:
90- revision_ids = bzr_branch.revision_history()
91 for bzr_revision in bzr_branch.repository.get_revisions(revision_ids):
92 existing = branch.getBranchRevision(
93 revision_id=bzr_revision.revision_id)
94@@ -777,7 +776,8 @@
95 committer="Joe Bloggs <joe@example.com>",
96 timestamp=1000100000.0, timezone=0)
97 switch_dbuser('branchscanner')
98- self.updateDBRevisions(db_branch, tree.branch)
99+ self.updateDBRevisions(db_branch, tree.branch,
100+ branch_revision_history(tree.branch))
101 expected = (
102 u"-" * 60 + '\n'
103 "revno: 1" '\n'
104@@ -820,7 +820,8 @@
105 committer=u"Non ASCII: \xed", timestamp=1000000000.0,
106 timezone=0)
107 switch_dbuser('branchscanner')
108- self.updateDBRevisions(db_branch, tree.branch)
109+ self.updateDBRevisions(db_branch, tree.branch,
110+ branch_revision_history(tree.branch))
111 job = RevisionsAddedJob.create(db_branch, '', '', '')
112 message = job.getRevisionMessage(rev_id, 1)
113 # The revision message must be a unicode object.
114
115=== modified file 'lib/lp/code/tests/test_bzr.py'
116--- lib/lp/code/tests/test_bzr.py 2010-08-20 20:31:18 +0000
117+++ lib/lp/code/tests/test_bzr.py 2012-06-26 14:13:33 +0000
118@@ -5,10 +5,14 @@
119
120 __metaclass__ = type
121
122-from bzrlib.tests import TestCaseInTempDir
123+from bzrlib.tests import (
124+ TestCaseInTempDir,
125+ TestCaseWithTransport,
126+ )
127
128 from lp.code.bzr import (
129 BranchFormat,
130+ branch_revision_history,
131 ControlFormat,
132 get_branch_formats,
133 RepositoryFormat,
134@@ -69,3 +73,19 @@
135 self.assertEqual(ControlFormat.BZR_METADIR_1, formats[0])
136 self.assertEqual(BranchFormat.BZR_BRANCH_5, formats[1])
137 self.assertEqual(RepositoryFormat.BZR_KNIT_1, formats[2])
138+
139+
140+class TestBranchRevisionHistory(TestCaseWithTransport):
141+ """Tests for lp.code.bzr.branch_revision_history."""
142+
143+ def test_empty(self):
144+ branch = self.make_branch('test')
145+ self.assertEquals([], branch_revision_history(branch))
146+
147+ def test_some_commits(self):
148+ branch = self.make_branch('test')
149+ wt = branch.bzrdir.create_workingtree()
150+ wt.commit('acommit', rev_id='A')
151+ wt.commit('bcommit', rev_id='B')
152+ wt.commit('ccommit', rev_id='C')
153+ self.assertEquals(['A', 'B', 'C'], branch_revision_history(wt.branch))
154
155=== modified file 'lib/lp/codehosting/codeimport/tests/test_worker.py'
156--- lib/lp/codehosting/codeimport/tests/test_worker.py 2012-06-25 15:34:46 +0000
157+++ lib/lp/codehosting/codeimport/tests/test_worker.py 2012-06-26 14:13:33 +0000
158@@ -899,8 +899,7 @@
159 source_details.branch_id)
160 branch = Branch.open(branch_url)
161
162- self.assertEqual(
163- self.foreign_commit_count, len(branch.revision_history()))
164+ self.assertEqual(self.foreign_commit_count, branch.revno())
165
166 def test_script_exit_codes(self):
167 # After a successful import that imports revisions, the worker exits
168
169=== modified file 'lib/lp/codehosting/scanner/bzrsync.py'
170--- lib/lp/codehosting/scanner/bzrsync.py 2012-02-21 19:13:45 +0000
171+++ lib/lp/codehosting/scanner/bzrsync.py 2012-06-26 14:13:33 +0000
172@@ -24,6 +24,7 @@
173 from zope.component import getUtility
174 from zope.event import notify
175
176+from lp.code.bzr import branch_revision_history
177 from lp.code.interfaces.branchjob import IRosettaUploadJobSource
178 from lp.code.interfaces.revision import IRevisionSet
179 from lp.code.model.branchrevision import BranchRevision
180@@ -85,7 +86,7 @@
181 # Get the history and ancestry from the branch first, to fail early
182 # if something is wrong with the branch.
183 self.logger.info("Retrieving history from bzrlib.")
184- bzr_history = bzr_branch.revision_history()
185+ bzr_history = branch_revision_history(bzr_branch)
186 # The BranchRevision, Revision and RevisionParent tables are only
187 # written to by the branch-scanner, so they are not subject to
188 # write-lock contention. Update them all in a single transaction to
189
190=== modified file 'lib/lp/codehosting/scanner/tests/test_bzrsync.py'
191--- lib/lp/codehosting/scanner/tests/test_bzrsync.py 2012-03-26 06:52:59 +0000
192+++ lib/lp/codehosting/scanner/tests/test_bzrsync.py 2012-06-26 14:13:33 +0000
193@@ -23,6 +23,7 @@
194 from zope.component import getUtility
195 from zope.security.proxy import removeSecurityProxy
196
197+from lp.code.bzr import branch_revision_history
198 from lp.code.interfaces.branchjob import IRosettaUploadJobSource
199 from lp.code.interfaces.branchlookup import IBranchLookup
200 from lp.code.interfaces.revision import IRevisionSet
201@@ -469,7 +470,7 @@
202 # yield each revision along with a sequence number, starting at 1.
203 self.commitRevision(rev_id='rev-1')
204 bzrsync = self.makeBzrSync(self.db_branch)
205- bzr_history = self.bzr_branch.revision_history()
206+ bzr_history = branch_revision_history(self.bzr_branch)
207 added_ancestry = bzrsync.getAncestryDelta(self.bzr_branch)[0]
208 result = bzrsync.revisionsToInsert(
209 bzr_history, self.bzr_branch.revno(), added_ancestry)
210@@ -481,7 +482,7 @@
211 (db_branch, bzr_tree), ignored = self.makeBranchWithMerge(
212 'base', 'trunk', 'branch', 'merge')
213 bzrsync = self.makeBzrSync(db_branch)
214- bzr_history = bzr_tree.branch.revision_history()
215+ bzr_history = branch_revision_history(bzr_tree.branch)
216 added_ancestry = bzrsync.getAncestryDelta(bzr_tree.branch)[0]
217 expected = {'base': 1, 'trunk': 2, 'merge': 3, 'branch': None}
218 self.assertEqual(