Merge lp:~mwhudson/launchpad/no-hosted-area-fix-directbranchcommit into lp:launchpad

Proposed by Michael Hudson-Doyle
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 10828
Proposed branch: lp:~mwhudson/launchpad/no-hosted-area-fix-directbranchcommit
Merge into: lp:launchpad
Prerequisite: lp:~mwhudson/launchpad/no-hosted-area-safe-getBzrBranch
Diff against target: 305 lines (+26/-82)
7 files modified
lib/lp/code/model/directbranchcommit.py (+2/-19)
lib/lp/code/model/tests/test_diff.py (+1/-1)
lib/lp/code/tests/test_directbranchcommit.py (+3/-21)
lib/lp/testing/__init__.py (+12/-32)
lib/lp/translations/scripts/tests/test_translations_to_branch.py (+5/-6)
lib/lp/translations/scripts/translations_to_branch.py (+2/-2)
lib/lp/translations/tests/test_translationtemplatesbuildjob.py (+1/-1)
To merge this branch: bzr merge lp:~mwhudson/launchpad/no-hosted-area-fix-directbranchcommit
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+23980@code.launchpad.net

Description of the change

Hi Tim,

This branch simplifies DirectBranchCommit and makes it work with in the new world.

It changes the behaviour of the useBzrBranches() test helper some, which will probably break lots of tests that I'll fix in the next few pipes...

Cheers,
mwh

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Looks like a great change.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/model/directbranchcommit.py'
--- lib/lp/code/model/directbranchcommit.py 2010-04-27 02:23:05 +0000
+++ lib/lp/code/model/directbranchcommit.py 2010-04-27 02:23:25 +0000
@@ -12,13 +12,11 @@
1212
13import os.path13import os.path
1414
15from bzrlib.branch import Branch
16from bzrlib.generate_ids import gen_file_id15from bzrlib.generate_ids import gen_file_id
17from bzrlib.revision import NULL_REVISION16from bzrlib.revision import NULL_REVISION
18from bzrlib.transform import TransformPreview, ROOT_PARENT17from bzrlib.transform import TransformPreview, ROOT_PARENT
1918
20from canonical.launchpad.interfaces import IMasterObject19from canonical.launchpad.interfaces import IMasterObject
21from lp.codehosting.vfs import make_branch_mirrorer
2220
2321
24class ConcurrentUpdateError(Exception):22class ConcurrentUpdateError(Exception):
@@ -49,7 +47,7 @@
49 is_locked = False47 is_locked = False
50 commit_builder = None48 commit_builder = None
5149
52 def __init__(self, db_branch, committer=None, to_mirror=False):50 def __init__(self, db_branch, committer=None):
53 """Create context for direct commit to branch.51 """Create context for direct commit to branch.
5452
55 Before constructing a `DirectBranchCommit`, set up a server that53 Before constructing a `DirectBranchCommit`, set up a server that
@@ -68,11 +66,8 @@
6866
69 :param db_branch: a Launchpad `Branch` object.67 :param db_branch: a Launchpad `Branch` object.
70 :param committer: the `Person` writing to the branch.68 :param committer: the `Person` writing to the branch.
71 :param to_mirror: If True, write to the mirrored copy of the branch
72 instead of the hosted copy. (Mainly useful for tests)
73 """69 """
74 self.db_branch = db_branch70 self.db_branch = db_branch
75 self.to_mirror = to_mirror
7671
77 self.last_scanned_id = self.db_branch.last_scanned_id72 self.last_scanned_id = self.db_branch.last_scanned_id
7873
@@ -83,15 +78,7 @@
83 # Directories we create on the branch, and their ids.78 # Directories we create on the branch, and their ids.
84 self.path_ids = {}79 self.path_ids = {}
8580
86 if to_mirror:81 self.bzrbranch = self.db_branch.getBzrBranch()
87 self.bzrbranch = Branch.open(self.db_branch.warehouse_url)
88 else:
89 # Have the opening done through a branch mirrorer. It will
90 # pick the right policy. In case we're writing to a hosted
91 # branch stacked on a mirrored branch, the mirrorer knows
92 # how to do the right thing.
93 mirrorer = make_branch_mirrorer(self.db_branch.branch_type)
94 self.bzrbranch = mirrorer.open(self.db_branch.getPullURL())
9582
96 self.bzrbranch.lock_write()83 self.bzrbranch.lock_write()
97 self.is_locked = True84 self.is_locked = True
@@ -167,10 +154,6 @@
167154
168 If it does, raise `ConcurrentUpdateError`.155 If it does, raise `ConcurrentUpdateError`.
169 """156 """
170 # A different last_scanned_id does not indicate a race for mirrored
171 # branches -- last_scanned_id is a proxy for the mirrored branch.
172 if self.to_mirror:
173 return
174 assert self.is_locked, "Getting revision on un-locked branch."157 assert self.is_locked, "Getting revision on un-locked branch."
175 last_revision = self.bzrbranch.last_revision()158 last_revision = self.bzrbranch.last_revision()
176 if last_revision != self.last_scanned_id:159 if last_revision != self.last_scanned_id:
177160
=== modified file 'lib/lp/code/model/tests/test_diff.py'
--- lib/lp/code/model/tests/test_diff.py 2010-04-27 02:23:05 +0000
+++ lib/lp/code/model/tests/test_diff.py 2010-04-27 02:23:25 +0000
@@ -44,7 +44,7 @@
4444
45 This will create or modify the file, as needed.45 This will create or modify the file, as needed.
46 """46 """
47 committer = DirectBranchCommit(branch, to_mirror=True)47 committer = DirectBranchCommit(branch)
48 committer.writeFile(path, contents)48 committer.writeFile(path, contents)
49 try:49 try:
50 return committer.commit('committing')50 return committer.commit('committing')
5151
=== modified file 'lib/lp/code/tests/test_directbranchcommit.py'
--- lib/lp/code/tests/test_directbranchcommit.py 2009-11-18 14:34:45 +0000
+++ lib/lp/code/tests/test_directbranchcommit.py 2010-04-27 02:23:25 +0000
@@ -20,10 +20,10 @@
2020
21 def setUp(self):21 def setUp(self):
22 super(DirectBranchCommitTestCase, self).setUp()22 super(DirectBranchCommitTestCase, self).setUp()
23 self.useBzrBranches()23 self.useBzrBranches(direct_database=True)
2424
25 self.series = self.factory.makeProductSeries()25 self.series = self.factory.makeProductSeries()
26 self.db_branch, self.tree = self.create_branch_and_tree(hosted=True)26 self.db_branch, self.tree = self.create_branch_and_tree()
2727
28 self.series.translations_branch = self.db_branch28 self.series.translations_branch = self.db_branch
2929
@@ -46,7 +46,7 @@
4646
47 def _getContents(self):47 def _getContents(self):
48 """Return branch contents as dict mapping filenames to contents."""48 """Return branch contents as dict mapping filenames to contents."""
49 return map_branch_contents(self.committer.db_branch.getPullURL())49 return map_branch_contents(self.committer.db_branch.getBzrBranch())
5050
5151
52class TestDirectBranchCommit(DirectBranchCommitTestCase):52class TestDirectBranchCommit(DirectBranchCommitTestCase):
@@ -229,23 +229,5 @@
229 self.assertEqual(dir_id, self.committer._getDir('foo/bar'))229 self.assertEqual(dir_id, self.committer._getDir('foo/bar'))
230230
231231
232class TestDirectBranchCommitMirror(TestCaseWithFactory):
233
234 layer = ZopelessDatabaseLayer
235
236 def test_direct_branch_commit_respects_to_mirror(self):
237 # The "to_mirror" argument causes the commit to apply to the mirrored
238 # copy of the branch.
239 self.useBzrBranches()
240 branch = self.factory.makeBranch()
241 bzr_branch = self.createBzrBranch(branch)
242 dbc = DirectBranchCommit(branch, to_mirror=True)
243 try:
244 dbc.writeFile('path', 'contents')
245 dbc.commit('making commit to mirrored area.')
246 finally:
247 dbc.unlock()
248
249
250def test_suite():232def test_suite():
251 return TestLoader().loadTestsFromName(__name__)233 return TestLoader().loadTestsFromName(__name__)
252234
=== modified file 'lib/lp/testing/__init__.py'
--- lib/lp/testing/__init__.py 2010-04-27 02:23:05 +0000
+++ lib/lp/testing/__init__.py 2010-04-27 02:23:25 +0000
@@ -411,7 +411,7 @@
411 self.addCleanup(logout)411 self.addCleanup(logout)
412 from lp.testing.factory import LaunchpadObjectFactory412 from lp.testing.factory import LaunchpadObjectFactory
413 self.factory = LaunchpadObjectFactory()413 self.factory = LaunchpadObjectFactory()
414 self.real_bzr_server = False414 self.direct_database_server = False
415415
416 def getUserBrowser(self, url=None, user=None, password='test'):416 def getUserBrowser(self, url=None, user=None, password='test'):
417 """Return a Browser logged in as a fresh user, maybe opened at `url`.417 """Return a Browser logged in as a fresh user, maybe opened at `url`.
@@ -443,11 +443,6 @@
443 """443 """
444 if format is not None and isinstance(format, basestring):444 if format is not None and isinstance(format, basestring):
445 format = format_registry.get(format)()445 format = format_registry.get(format)()
446 transport = get_transport(branch_url)
447 if not self.real_bzr_server:
448 # for real bzr servers, the prefix always exists.
449 transport.create_prefix()
450 self.addCleanup(transport.delete_tree, '.')
451 return BzrDir.create_branch_convenience(446 return BzrDir.create_branch_convenience(
452 branch_url, format=format)447 branch_url, format=format)
453448
@@ -468,7 +463,7 @@
468 else:463 else:
469 db_branch = self.factory.makeProductBranch(product, **kwargs)464 db_branch = self.factory.makeProductBranch(product, **kwargs)
470 branch_url = 'lp-internal:///' + db_branch.unique_name465 branch_url = 'lp-internal:///' + db_branch.unique_name
471 if self.real_bzr_server:466 if not self.direct_database_server:
472 transaction.commit()467 transaction.commit()
473 bzr_branch = self.createBranchAtURL(branch_url, format=format)468 bzr_branch = self.createBranchAtURL(branch_url, format=format)
474 if tree_location is None:469 if tree_location is None:
@@ -533,34 +528,20 @@
533 os.environ['BZR_HOME'] = os.getcwd()528 os.environ['BZR_HOME'] = os.getcwd()
534 self.addCleanup(restore_bzr_home)529 self.addCleanup(restore_bzr_home)
535530
536 def useBzrBranches(self, real_server=False, direct_database=False):531 def useBzrBranches(self, direct_database=False):
537 """Prepare for using bzr branches.532 """Prepare for using bzr branches.
538533
539 This sets up support for lp-hosted and lp-mirrored URLs,534 This sets up support for lp-internal URLs, changes to a temp
540 changes to a temp directory, and overrides the bzr home directory.535 directory, and overrides the bzr home directory.
541536
542 :param real_server: If true, use the "real" code hosting server,537 :param direct_database: If true, translate branch locations by
543 using an xmlrpc server, etc.538 directly querying the database, not the internal XML-RPC server.
544 """539 """
545 from lp.codehosting.scanner.tests.test_bzrsync import (
546 FakeTransportServer)
547 self.useTempBzrHome()540 self.useTempBzrHome()
548 self.real_bzr_server = real_server541 self.direct_database_server = direct_database
549 if real_server:542 server = get_rw_server(direct_database=direct_database)
550 server = get_rw_server(543 server.start_server()
551 direct_database=direct_database)544 self.addCleanup(server.destroy)
552 server.start_server()
553 self.addCleanup(server.destroy)
554 else:
555 os.mkdir('lp-mirrored')
556 mirror_server = FakeTransportServer(get_transport('lp-mirrored'))
557 mirror_server.start_server()
558 self.addCleanup(mirror_server.stop_server)
559 os.mkdir('lp-hosted')
560 hosted_server = FakeTransportServer(
561 get_transport('lp-hosted'), url_prefix='lp-hosted:///')
562 hosted_server.start_server()
563 self.addCleanup(hosted_server.stop_server)
564545
565546
566class BrowserTestCase(TestCaseWithFactory):547class BrowserTestCase(TestCaseWithFactory):
@@ -855,7 +836,7 @@
855836
856# XXX: This doesn't seem to be a generically useful testing function. Perhaps837# XXX: This doesn't seem to be a generically useful testing function. Perhaps
857# it should go into a sub-module? -- jml838# it should go into a sub-module? -- jml
858def map_branch_contents(branch_url):839def map_branch_contents(branch):
859 """Return all files in branch at `branch_url`.840 """Return all files in branch at `branch_url`.
860841
861 :param branch_url: the URL for an accessible branch.842 :param branch_url: the URL for an accessible branch.
@@ -863,7 +844,6 @@
863 files are included.844 files are included.
864 """845 """
865 contents = {}846 contents = {}
866 branch = BzrBranch.open(branch_url)
867 tree = branch.basis_tree()847 tree = branch.basis_tree()
868 tree.lock_read()848 tree.lock_read()
869 try:849 try:
870850
=== modified file 'lib/lp/translations/scripts/tests/test_translations_to_branch.py'
--- lib/lp/translations/scripts/tests/test_translations_to_branch.py 2010-04-27 02:23:05 +0000
+++ lib/lp/translations/scripts/tests/test_translations_to_branch.py 2010-04-27 02:23:25 +0000
@@ -40,7 +40,7 @@
40 # End-to-end test of the script doing its work.40 # End-to-end test of the script doing its work.
4141
42 # Set up a server for hosted branches.42 # Set up a server for hosted branches.
43 self.useBzrBranches(real_server=True)43 self.useBzrBranches(direct_database=False)
4444
45 # Set up a product and translatable series.45 # Set up a product and translatable series.
46 product = self.factory.makeProduct(name='committobranch')46 product = self.factory.makeProduct(name='committobranch')
@@ -48,8 +48,7 @@
48 series = product.getSeries('trunk')48 series = product.getSeries('trunk')
4949
50 # Set up a translations_branch for the series.50 # Set up a translations_branch for the series.
51 db_branch, tree = self.create_branch_and_tree(51 db_branch, tree = self.create_branch_and_tree(product=product)
52 hosted=True, product=product)
53 removeSecurityProxy(db_branch).last_scanned_id = 'null:'52 removeSecurityProxy(db_branch).last_scanned_id = 'null:'
54 product.official_rosetta = True53 product.official_rosetta = True
55 series.translations_branch = db_branch54 series.translations_branch = db_branch
@@ -87,7 +86,7 @@
8786
88 # The branch now contains a snapshot of the translation. (Only87 # The branch now contains a snapshot of the translation. (Only
89 # one file: the Dutch translation we set up earlier).88 # one file: the Dutch translation we set up earlier).
90 branch_contents = map_branch_contents(db_branch.getPullURL())89 branch_contents = map_branch_contents(db_branch.getBzrBranch())
91 expected_contents = {90 expected_contents = {
92 'po/nl.po': """91 'po/nl.po': """
93 # Dutch translation for .*92 # Dutch translation for .*
@@ -163,11 +162,11 @@
163 self.useBzrBranches()162 self.useBzrBranches()
164163
165 base_branch, base_tree = self.create_branch_and_tree(164 base_branch, base_tree = self.create_branch_and_tree(
166 'base', name='base', hosted=True)165 'base', name='base')
167 self._setUpBranch(base_branch, base_tree, "Base branch.")166 self._setUpBranch(base_branch, base_tree, "Base branch.")
168167
169 stacked_branch, stacked_tree = self.create_branch_and_tree(168 stacked_branch, stacked_tree = self.create_branch_and_tree(
170 'stacked', name='stacked', hosted=True)169 'stacked', name='stacked')
171 stacked_tree.branch.set_stacked_on_url('/' + base_branch.unique_name)170 stacked_tree.branch.set_stacked_on_url('/' + base_branch.unique_name)
172 stacked_branch.stacked_on = base_branch171 stacked_branch.stacked_on = base_branch
173 self._setUpBranch(stacked_branch, stacked_tree, "Stacked branch.")172 self._setUpBranch(stacked_branch, stacked_tree, "Stacked branch.")
174173
=== modified file 'lib/lp/translations/scripts/translations_to_branch.py'
--- lib/lp/translations/scripts/translations_to_branch.py 2010-03-08 19:46:02 +0000
+++ lib/lp/translations/scripts/translations_to_branch.py 2010-04-27 02:23:25 +0000
@@ -17,7 +17,7 @@
17from storm.expr import Join, SQL17from storm.expr import Join, SQL
1818
19from canonical.launchpad.helpers import shortlist19from canonical.launchpad.helpers import shortlist
20from lp.codehosting.vfs import get_multi_server20from lp.codehosting.vfs import get_rw_server
21from lp.translations.interfaces.potemplate import IPOTemplateSet21from lp.translations.interfaces.potemplate import IPOTemplateSet
22from canonical.launchpad.webapp.interfaces import (22from canonical.launchpad.webapp.interfaces import (
23 IStoreSelector, MAIN_STORE, SLAVE_FLAVOR)23 IStoreSelector, MAIN_STORE, SLAVE_FLAVOR)
@@ -270,7 +270,7 @@
270 # testing.270 # testing.
271 productseries = productseries.order_by(ProductSeries.id)271 productseries = productseries.order_by(ProductSeries.id)
272272
273 bzrserver = get_multi_server(write_hosted=True)273 bzrserver = get_rw_server()
274 bzrserver.start_server()274 bzrserver.start_server()
275 try:275 try:
276 self._exportToBranches(productseries)276 self._exportToBranches(productseries)
277277
=== modified file 'lib/lp/translations/tests/test_translationtemplatesbuildjob.py'
--- lib/lp/translations/tests/test_translationtemplatesbuildjob.py 2010-04-16 13:31:48 +0000
+++ lib/lp/translations/tests/test_translationtemplatesbuildjob.py 2010-04-27 02:23:25 +0000
@@ -219,7 +219,7 @@
219 # If the feature is enabled, a TipChanged event for a branch that219 # If the feature is enabled, a TipChanged event for a branch that
220 # generates templates will schedule a templates build.220 # generates templates will schedule a templates build.
221 branch = self._makeTranslationBranch()221 branch = self._makeTranslationBranch()
222 commit = DirectBranchCommit(branch, to_mirror=True)222 commit = DirectBranchCommit(branch)
223 commit.writeFile('POTFILES.in', 'foo')223 commit.writeFile('POTFILES.in', 'foo')
224 commit.commit('message')224 commit.commit('message')
225 notify(events.TipChanged(branch, None, False))225 notify(events.TipChanged(branch, None, False))