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
=== modified file 'lib/lp/code/bzr.py'
--- lib/lp/code/bzr.py 2012-03-22 23:21:24 +0000
+++ lib/lp/code/bzr.py 2012-06-26 14:13:33 +0000
@@ -56,6 +56,9 @@
56 RepositoryFormatKnitPack4,56 RepositoryFormatKnitPack4,
57 RepositoryFormatKnitPack5,57 RepositoryFormatKnitPack5,
58 )58 )
59from bzrlib.revision import (
60 NULL_REVISION,
61 )
59from bzrlib.repofmt.knitrepo import (62from bzrlib.repofmt.knitrepo import (
60 RepositoryFormatKnit1,63 RepositoryFormatKnit1,
61 RepositoryFormatKnit3,64 RepositoryFormatKnit3,
@@ -317,3 +320,24 @@
317 last_revision = bzr_branch.last_revision()320 last_revision = bzr_branch.last_revision()
318 formats = get_branch_formats(bzr_branch)321 formats = get_branch_formats(bzr_branch)
319 db_branch.branchChanged(stacked_on, last_revision, *formats)322 db_branch.branchChanged(stacked_on, last_revision, *formats)
323
324
325def branch_revision_history(branch):
326 """Find the revision history of a branch.
327
328 This is a compatibility wrapper for code that still requires
329 access to the full branch mainline and previously used
330 Branch.revision_history(), which is now deprecated.
331
332 :param branch: Branch object
333 :return: Revision ids on the main branch
334 """
335 branch.lock_read()
336 try:
337 graph = branch.repository.get_graph()
338 ret = list(graph.iter_lefthand_ancestry(
339 branch.last_revision(), (NULL_REVISION,)))
340 ret.reverse()
341 return ret
342 finally:
343 branch.unlock()
320344
=== modified file 'lib/lp/code/model/branchjob.py'
--- lib/lp/code/model/branchjob.py 2012-06-14 05:18:22 +0000
+++ lib/lp/code/model/branchjob.py 2012-06-26 14:13:33 +0000
@@ -56,7 +56,10 @@
56 implements,56 implements,
57 )57 )
5858
59from lp.code.bzr import get_branch_formats59from lp.code.bzr import (
60 branch_revision_history,
61 get_branch_formats,
62 )
60from lp.code.enums import (63from lp.code.enums import (
61 BranchMergeProposalStatus,64 BranchMergeProposalStatus,
62 BranchSubscriptionDiffSize,65 BranchSubscriptionDiffSize,
@@ -522,7 +525,7 @@
522 # Avoid hitting the database since bzrlib makes it easy to check.525 # Avoid hitting the database since bzrlib makes it easy to check.
523 # There are possibly more efficient ways to get the mainline526 # There are possibly more efficient ways to get the mainline
524 # revisions, but this is simple and it works.527 # revisions, but this is simple and it works.
525 history = self.bzr_branch.revision_history()528 history = branch_revision_history(self.bzr_branch)
526 for num, revid in enumerate(history):529 for num, revid in enumerate(history):
527 if revid in added_revisions:530 if revid in added_revisions:
528 yield repository.get_revision(revid), num + 1531 yield repository.get_revision(revid), num + 1
529532
=== modified file 'lib/lp/code/model/tests/test_branchjob.py'
--- lib/lp/code/model/tests/test_branchjob.py 2012-06-14 05:18:22 +0000
+++ lib/lp/code/model/tests/test_branchjob.py 2012-06-26 14:13:33 +0000
@@ -31,6 +31,7 @@
31from lp.code.bzr import (31from lp.code.bzr import (
32 BranchFormat,32 BranchFormat,
33 RepositoryFormat,33 RepositoryFormat,
34 branch_revision_history,
34 )35 )
35from lp.code.enums import (36from lp.code.enums import (
36 BranchMergeProposalStatus,37 BranchMergeProposalStatus,
@@ -380,7 +381,7 @@
380 job = RevisionsAddedJob.create(branch, 'rev1', 'rev2', '')381 job = RevisionsAddedJob.create(branch, 'rev1', 'rev2', '')
381 self.assertEqual([job], list(RevisionsAddedJob.iterReady()))382 self.assertEqual([job], list(RevisionsAddedJob.iterReady()))
382383
383 def updateDBRevisions(self, branch, bzr_branch, revision_ids=None):384 def updateDBRevisions(self, branch, bzr_branch, revision_ids):
384 """Update the database for the revisions.385 """Update the database for the revisions.
385386
386 :param branch: The database branch associated with the revisions.387 :param branch: The database branch associated with the revisions.
@@ -388,8 +389,6 @@
388 :param revision_ids: The ids of the revisions to update. If not389 :param revision_ids: The ids of the revisions to update. If not
389 supplied, the branch revision history is used.390 supplied, the branch revision history is used.
390 """391 """
391 if revision_ids is None:
392 revision_ids = bzr_branch.revision_history()
393 for bzr_revision in bzr_branch.repository.get_revisions(revision_ids):392 for bzr_revision in bzr_branch.repository.get_revisions(revision_ids):
394 existing = branch.getBranchRevision(393 existing = branch.getBranchRevision(
395 revision_id=bzr_revision.revision_id)394 revision_id=bzr_revision.revision_id)
@@ -777,7 +776,8 @@
777 committer="Joe Bloggs <joe@example.com>",776 committer="Joe Bloggs <joe@example.com>",
778 timestamp=1000100000.0, timezone=0)777 timestamp=1000100000.0, timezone=0)
779 switch_dbuser('branchscanner')778 switch_dbuser('branchscanner')
780 self.updateDBRevisions(db_branch, tree.branch)779 self.updateDBRevisions(db_branch, tree.branch,
780 branch_revision_history(tree.branch))
781 expected = (781 expected = (
782 u"-" * 60 + '\n'782 u"-" * 60 + '\n'
783 "revno: 1" '\n'783 "revno: 1" '\n'
@@ -820,7 +820,8 @@
820 committer=u"Non ASCII: \xed", timestamp=1000000000.0,820 committer=u"Non ASCII: \xed", timestamp=1000000000.0,
821 timezone=0)821 timezone=0)
822 switch_dbuser('branchscanner')822 switch_dbuser('branchscanner')
823 self.updateDBRevisions(db_branch, tree.branch)823 self.updateDBRevisions(db_branch, tree.branch,
824 branch_revision_history(tree.branch))
824 job = RevisionsAddedJob.create(db_branch, '', '', '')825 job = RevisionsAddedJob.create(db_branch, '', '', '')
825 message = job.getRevisionMessage(rev_id, 1)826 message = job.getRevisionMessage(rev_id, 1)
826 # The revision message must be a unicode object.827 # The revision message must be a unicode object.
827828
=== modified file 'lib/lp/code/tests/test_bzr.py'
--- lib/lp/code/tests/test_bzr.py 2010-08-20 20:31:18 +0000
+++ lib/lp/code/tests/test_bzr.py 2012-06-26 14:13:33 +0000
@@ -5,10 +5,14 @@
55
6__metaclass__ = type6__metaclass__ = type
77
8from bzrlib.tests import TestCaseInTempDir8from bzrlib.tests import (
9 TestCaseInTempDir,
10 TestCaseWithTransport,
11 )
912
10from lp.code.bzr import (13from lp.code.bzr import (
11 BranchFormat,14 BranchFormat,
15 branch_revision_history,
12 ControlFormat,16 ControlFormat,
13 get_branch_formats,17 get_branch_formats,
14 RepositoryFormat,18 RepositoryFormat,
@@ -69,3 +73,19 @@
69 self.assertEqual(ControlFormat.BZR_METADIR_1, formats[0])73 self.assertEqual(ControlFormat.BZR_METADIR_1, formats[0])
70 self.assertEqual(BranchFormat.BZR_BRANCH_5, formats[1])74 self.assertEqual(BranchFormat.BZR_BRANCH_5, formats[1])
71 self.assertEqual(RepositoryFormat.BZR_KNIT_1, formats[2])75 self.assertEqual(RepositoryFormat.BZR_KNIT_1, formats[2])
76
77
78class TestBranchRevisionHistory(TestCaseWithTransport):
79 """Tests for lp.code.bzr.branch_revision_history."""
80
81 def test_empty(self):
82 branch = self.make_branch('test')
83 self.assertEquals([], branch_revision_history(branch))
84
85 def test_some_commits(self):
86 branch = self.make_branch('test')
87 wt = branch.bzrdir.create_workingtree()
88 wt.commit('acommit', rev_id='A')
89 wt.commit('bcommit', rev_id='B')
90 wt.commit('ccommit', rev_id='C')
91 self.assertEquals(['A', 'B', 'C'], branch_revision_history(wt.branch))
7292
=== modified file 'lib/lp/codehosting/codeimport/tests/test_worker.py'
--- lib/lp/codehosting/codeimport/tests/test_worker.py 2012-06-25 15:34:46 +0000
+++ lib/lp/codehosting/codeimport/tests/test_worker.py 2012-06-26 14:13:33 +0000
@@ -899,8 +899,7 @@
899 source_details.branch_id)899 source_details.branch_id)
900 branch = Branch.open(branch_url)900 branch = Branch.open(branch_url)
901901
902 self.assertEqual(902 self.assertEqual(self.foreign_commit_count, branch.revno())
903 self.foreign_commit_count, len(branch.revision_history()))
904903
905 def test_script_exit_codes(self):904 def test_script_exit_codes(self):
906 # After a successful import that imports revisions, the worker exits905 # After a successful import that imports revisions, the worker exits
907906
=== modified file 'lib/lp/codehosting/scanner/bzrsync.py'
--- lib/lp/codehosting/scanner/bzrsync.py 2012-02-21 19:13:45 +0000
+++ lib/lp/codehosting/scanner/bzrsync.py 2012-06-26 14:13:33 +0000
@@ -24,6 +24,7 @@
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_history
27from lp.code.interfaces.branchjob import IRosettaUploadJobSource28from lp.code.interfaces.branchjob import IRosettaUploadJobSource
28from lp.code.interfaces.revision import IRevisionSet29from lp.code.interfaces.revision import IRevisionSet
29from lp.code.model.branchrevision import BranchRevision30from lp.code.model.branchrevision import BranchRevision
@@ -85,7 +86,7 @@
85 # Get the history and ancestry from the branch first, to fail early86 # Get the history and ancestry from the branch first, to fail early
86 # if something is wrong with the branch.87 # if something is wrong with the branch.
87 self.logger.info("Retrieving history from bzrlib.")88 self.logger.info("Retrieving history from bzrlib.")
88 bzr_history = bzr_branch.revision_history()89 bzr_history = branch_revision_history(bzr_branch)
89 # The BranchRevision, Revision and RevisionParent tables are only90 # The BranchRevision, Revision and RevisionParent tables are only
90 # written to by the branch-scanner, so they are not subject to91 # written to by the branch-scanner, so they are not subject to
91 # write-lock contention. Update them all in a single transaction to92 # write-lock contention. Update them all in a single transaction to
9293
=== modified file 'lib/lp/codehosting/scanner/tests/test_bzrsync.py'
--- lib/lp/codehosting/scanner/tests/test_bzrsync.py 2012-03-26 06:52:59 +0000
+++ lib/lp/codehosting/scanner/tests/test_bzrsync.py 2012-06-26 14:13:33 +0000
@@ -23,6 +23,7 @@
23from zope.component import getUtility23from zope.component import getUtility
24from zope.security.proxy import removeSecurityProxy24from zope.security.proxy import removeSecurityProxy
2525
26from lp.code.bzr import branch_revision_history
26from lp.code.interfaces.branchjob import IRosettaUploadJobSource27from lp.code.interfaces.branchjob import IRosettaUploadJobSource
27from lp.code.interfaces.branchlookup import IBranchLookup28from lp.code.interfaces.branchlookup import IBranchLookup
28from lp.code.interfaces.revision import IRevisionSet29from lp.code.interfaces.revision import IRevisionSet
@@ -469,7 +470,7 @@
469 # yield each revision along with a sequence number, starting at 1.470 # yield each revision along with a sequence number, starting at 1.
470 self.commitRevision(rev_id='rev-1')471 self.commitRevision(rev_id='rev-1')
471 bzrsync = self.makeBzrSync(self.db_branch)472 bzrsync = self.makeBzrSync(self.db_branch)
472 bzr_history = self.bzr_branch.revision_history()473 bzr_history = branch_revision_history(self.bzr_branch)
473 added_ancestry = bzrsync.getAncestryDelta(self.bzr_branch)[0]474 added_ancestry = bzrsync.getAncestryDelta(self.bzr_branch)[0]
474 result = bzrsync.revisionsToInsert(475 result = bzrsync.revisionsToInsert(
475 bzr_history, self.bzr_branch.revno(), added_ancestry)476 bzr_history, self.bzr_branch.revno(), added_ancestry)
@@ -481,7 +482,7 @@
481 (db_branch, bzr_tree), ignored = self.makeBranchWithMerge(482 (db_branch, bzr_tree), ignored = self.makeBranchWithMerge(
482 'base', 'trunk', 'branch', 'merge')483 'base', 'trunk', 'branch', 'merge')
483 bzrsync = self.makeBzrSync(db_branch)484 bzrsync = self.makeBzrSync(db_branch)
484 bzr_history = bzr_tree.branch.revision_history()485 bzr_history = branch_revision_history(bzr_tree.branch)
485 added_ancestry = bzrsync.getAncestryDelta(bzr_tree.branch)[0]486 added_ancestry = bzrsync.getAncestryDelta(bzr_tree.branch)[0]
486 expected = {'base': 1, 'trunk': 2, 'merge': 3, 'branch': None}487 expected = {'base': 1, 'trunk': 2, 'merge': 3, 'branch': None}
487 self.assertEqual(488 self.assertEqual(