launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #09222
[Merge] lp:~jelmer/launchpad/no-revhistory-2 into lp:launchpad
Jelmer Vernooij has proposed merging lp:~jelmer/launchpad/no-revhistory-2 into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jelmer/launchpad/no-revhistory-2/+merge/112119
Remove last uses of Branch.revision_history, which is deprecated in bzr 2.5.
--
https://code.launchpad.net/~jelmer/launchpad/no-revhistory-2/+merge/112119
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jelmer/launchpad/no-revhistory-2 into lp:launchpad.
=== 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 @@
RepositoryFormatKnitPack4,
RepositoryFormatKnitPack5,
)
+from bzrlib.revision import (
+ NULL_REVISION,
+ )
from bzrlib.repofmt.knitrepo import (
RepositoryFormatKnit1,
RepositoryFormatKnit3,
@@ -317,3 +320,24 @@
last_revision = bzr_branch.last_revision()
formats = get_branch_formats(bzr_branch)
db_branch.branchChanged(stacked_on, last_revision, *formats)
+
+
+def branch_revision_history(branch):
+ """Find the revision history of a branch.
+
+ This is a compatibility wrapper for code that still requires
+ access to the full branch mainline and previously used
+ Branch.revision_history(), which is now deprecated.
+
+ :param branch: Branch object
+ :return: Revision ids on the main branch
+ """
+ branch.lock_read()
+ try:
+ graph = branch.repository.get_graph()
+ ret = list(graph.iter_lefthand_ancestry(
+ branch.last_revision(), (NULL_REVISION,)))
+ ret.reverse()
+ return ret
+ finally:
+ branch.unlock()
=== 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 @@
implements,
)
-from lp.code.bzr import get_branch_formats
+from lp.code.bzr import (
+ branch_revision_history,
+ get_branch_formats,
+ )
from lp.code.enums import (
BranchMergeProposalStatus,
BranchSubscriptionDiffSize,
@@ -522,7 +525,7 @@
# Avoid hitting the database since bzrlib makes it easy to check.
# There are possibly more efficient ways to get the mainline
# revisions, but this is simple and it works.
- history = self.bzr_branch.revision_history()
+ history = branch_revision_history(self.bzr_branch)
for num, revid in enumerate(history):
if revid in added_revisions:
yield repository.get_revision(revid), num + 1
=== 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 @@
from lp.code.bzr import (
BranchFormat,
RepositoryFormat,
+ branch_revision_history,
)
from lp.code.enums import (
BranchMergeProposalStatus,
@@ -380,7 +381,7 @@
job = RevisionsAddedJob.create(branch, 'rev1', 'rev2', '')
self.assertEqual([job], list(RevisionsAddedJob.iterReady()))
- def updateDBRevisions(self, branch, bzr_branch, revision_ids=None):
+ def updateDBRevisions(self, branch, bzr_branch, revision_ids):
"""Update the database for the revisions.
:param branch: The database branch associated with the revisions.
@@ -388,8 +389,6 @@
:param revision_ids: The ids of the revisions to update. If not
supplied, the branch revision history is used.
"""
- if revision_ids is None:
- revision_ids = bzr_branch.revision_history()
for bzr_revision in bzr_branch.repository.get_revisions(revision_ids):
existing = branch.getBranchRevision(
revision_id=bzr_revision.revision_id)
@@ -777,7 +776,8 @@
committer="Joe Bloggs <joe@xxxxxxxxxxx>",
timestamp=1000100000.0, timezone=0)
switch_dbuser('branchscanner')
- self.updateDBRevisions(db_branch, tree.branch)
+ self.updateDBRevisions(db_branch, tree.branch,
+ branch_revision_history(tree.branch))
expected = (
u"-" * 60 + '\n'
"revno: 1" '\n'
@@ -820,7 +820,8 @@
committer=u"Non ASCII: \xed", timestamp=1000000000.0,
timezone=0)
switch_dbuser('branchscanner')
- self.updateDBRevisions(db_branch, tree.branch)
+ self.updateDBRevisions(db_branch, tree.branch,
+ branch_revision_history(tree.branch))
job = RevisionsAddedJob.create(db_branch, '', '', '')
message = job.getRevisionMessage(rev_id, 1)
# The revision message must be a unicode object.
=== 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 @@
__metaclass__ = type
-from bzrlib.tests import TestCaseInTempDir
+from bzrlib.tests import (
+ TestCaseInTempDir,
+ TestCaseWithTransport,
+ )
from lp.code.bzr import (
BranchFormat,
+ branch_revision_history,
ControlFormat,
get_branch_formats,
RepositoryFormat,
@@ -69,3 +73,19 @@
self.assertEqual(ControlFormat.BZR_METADIR_1, formats[0])
self.assertEqual(BranchFormat.BZR_BRANCH_5, formats[1])
self.assertEqual(RepositoryFormat.BZR_KNIT_1, formats[2])
+
+
+class TestBranchRevisionHistory(TestCaseWithTransport):
+ """Tests for lp.code.bzr.branch_revision_history."""
+
+ def test_empty(self):
+ branch = self.make_branch('test')
+ self.assertEquals([], branch_revision_history(branch))
+
+ def test_some_commits(self):
+ branch = self.make_branch('test')
+ wt = branch.bzrdir.create_workingtree()
+ wt.commit('acommit', rev_id='A')
+ wt.commit('bcommit', rev_id='B')
+ wt.commit('ccommit', rev_id='C')
+ self.assertEquals(['A', 'B', 'C'], branch_revision_history(wt.branch))
=== 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 @@
source_details.branch_id)
branch = Branch.open(branch_url)
- self.assertEqual(
- self.foreign_commit_count, len(branch.revision_history()))
+ self.assertEqual(self.foreign_commit_count, branch.revno())
def test_script_exit_codes(self):
# After a successful import that imports revisions, the worker exits
=== 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 @@
from zope.component import getUtility
from zope.event import notify
+from lp.code.bzr import branch_revision_history
from lp.code.interfaces.branchjob import IRosettaUploadJobSource
from lp.code.interfaces.revision import IRevisionSet
from lp.code.model.branchrevision import BranchRevision
@@ -85,7 +86,7 @@
# Get the history and ancestry from the branch first, to fail early
# if something is wrong with the branch.
self.logger.info("Retrieving history from bzrlib.")
- bzr_history = bzr_branch.revision_history()
+ bzr_history = branch_revision_history(bzr_branch)
# The BranchRevision, Revision and RevisionParent tables are only
# written to by the branch-scanner, so they are not subject to
# write-lock contention. Update them all in a single transaction to
=== 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 @@
from zope.component import getUtility
from zope.security.proxy import removeSecurityProxy
+from lp.code.bzr import branch_revision_history
from lp.code.interfaces.branchjob import IRosettaUploadJobSource
from lp.code.interfaces.branchlookup import IBranchLookup
from lp.code.interfaces.revision import IRevisionSet
@@ -469,7 +470,7 @@
# yield each revision along with a sequence number, starting at 1.
self.commitRevision(rev_id='rev-1')
bzrsync = self.makeBzrSync(self.db_branch)
- bzr_history = self.bzr_branch.revision_history()
+ bzr_history = branch_revision_history(self.bzr_branch)
added_ancestry = bzrsync.getAncestryDelta(self.bzr_branch)[0]
result = bzrsync.revisionsToInsert(
bzr_history, self.bzr_branch.revno(), added_ancestry)
@@ -481,7 +482,7 @@
(db_branch, bzr_tree), ignored = self.makeBranchWithMerge(
'base', 'trunk', 'branch', 'merge')
bzrsync = self.makeBzrSync(db_branch)
- bzr_history = bzr_tree.branch.revision_history()
+ bzr_history = branch_revision_history(bzr_tree.branch)
added_ancestry = bzrsync.getAncestryDelta(bzr_tree.branch)[0]
expected = {'base': 1, 'trunk': 2, 'merge': 3, 'branch': None}
self.assertEqual(
Follow ups