Merge lp:~mwhudson/launchpad/no-hosted-area-formats-from-codehosting 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-formats-from-codehosting
Merge into: lp:launchpad
Prerequisite: lp:~mwhudson/launchpad/no-hosted-area
Diff against target: 488 lines (+168/-40)
8 files modified
lib/lp/code/xmlrpc/codehosting.py (+19/-1)
lib/lp/code/xmlrpc/tests/test_codehosting.py (+65/-9)
lib/lp/codehosting/inmemory.py (+19/-1)
lib/lp/codehosting/scanner/tests/test_bzrsync.py (+1/-2)
lib/lp/codehosting/tests/test_acceptance.py (+11/-9)
lib/lp/codehosting/vfs/branchfs.py (+9/-1)
lib/lp/codehosting/vfs/branchfsclient.py (+4/-2)
lib/lp/codehosting/vfs/tests/test_branchfs.py (+40/-15)
To merge this branch: bzr merge lp:~mwhudson/launchpad/no-hosted-area-formats-from-codehosting
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+23644@code.launchpad.net

Description of the change

Hi Tim,

This branch changes the branchChanged endpoint to record the branch formats and the codehosting server to record them, so not creating scan jobs when the tip revision doesn't change doesn't mean a stale format showing in the UI.

Cheers,
mwh

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

I think it would be better for the branchChanged method to take
the format strings as three separate parameters rather than a tuple that
is unpacked.

We don't really need to test the branchChanged for packs and knits.

We should remove the code from the scanner that records the
formats as part of this (or the next pipe if you wish).

review: Needs Fixing
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

On 19/04/10 16:41, Tim Penhey wrote:
> Review: Needs Fixing
> I think it would be better for the branchChanged method to take
> the format strings as three separate parameters rather than a tuple that
> is unpacked.

Yeah, I think you're right.

> We don't really need to test the branchChanged for packs and knits.

OK.

> We should remove the code from the scanner that records the
> formats as part of this (or the next pipe if you wish).

I think we should do that after the pipe that records the formats from
the branch puller, which is a couple of pipes down the line yet...

Interdiff attached.

Cheers,
mwh

Revision history for this message
Tim Penhey (thumper) wrote :

Good now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/xmlrpc/codehosting.py'
--- lib/lp/code/xmlrpc/codehosting.py 2010-04-27 02:16:59 +0000
+++ lib/lp/code/xmlrpc/codehosting.py 2010-04-27 02:17:19 +0000
@@ -34,6 +34,7 @@
34from canonical.launchpad.xmlrpc.helpers import return_fault34from canonical.launchpad.xmlrpc.helpers import return_fault
3535
36from lp.code.errors import UnknownBranchTypeError36from lp.code.errors import UnknownBranchTypeError
37from lp.code.bzr import BranchFormat, ControlFormat, RepositoryFormat
37from lp.code.enums import BranchType38from lp.code.enums import BranchType
38from lp.code.interfaces.branch import BranchCreationException39from lp.code.interfaces.branch import BranchCreationException
39from lp.code.interfaces.branchjob import IBranchScanJobSource40from lp.code.interfaces.branchjob import IBranchScanJobSource
@@ -248,7 +249,8 @@
248 return True249 return True
249 return run_with_login(login_id, request_mirror)250 return run_with_login(login_id, request_mirror)
250251
251 def branchChanged(self, branch_id, stacked_on_location, last_revision_id):252 def branchChanged(self, branch_id, stacked_on_location, last_revision_id,
253 control_string, branch_string, repository_string):
252 """See `IBranchFileSystem`."""254 """See `IBranchFileSystem`."""
253 branch_set = removeSecurityProxy(getUtility(IBranchLookup))255 branch_set = removeSecurityProxy(getUtility(IBranchLookup))
254 branch = branch_set.get(branch_id)256 branch = branch_set.get(branch_id)
@@ -268,6 +270,22 @@
268 if branch.last_mirrored_id != last_revision_id:270 if branch.last_mirrored_id != last_revision_id:
269 branch.last_mirrored_id = last_revision_id271 branch.last_mirrored_id = last_revision_id
270 getUtility(IBranchScanJobSource).create(branch)272 getUtility(IBranchScanJobSource).create(branch)
273
274 def match_title(enum, title, default):
275 for value in enum.items:
276 if value.title == title:
277 return value
278 else:
279 return default
280
281 branch.control_format = match_title(
282 ControlFormat, control_string, ControlFormat.UNRECOGNIZED)
283 branch.branch_format = match_title(
284 BranchFormat, branch_string, BranchFormat.UNRECOGNIZED)
285 branch.repository_format = match_title(
286 RepositoryFormat, repository_string,
287 RepositoryFormat.UNRECOGNIZED)
288
271 return True289 return True
272290
273 def _serializeBranch(self, requester, branch, trailing_path):291 def _serializeBranch(self, requester, branch, trailing_path):
274292
=== modified file 'lib/lp/code/xmlrpc/tests/test_codehosting.py'
--- lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-04-27 02:16:59 +0000
+++ lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-04-27 02:17:19 +0000
@@ -9,6 +9,7 @@
9import pytz9import pytz
10import unittest10import unittest
1111
12from bzrlib import bzrdir
12from bzrlib.tests import multiply_tests13from bzrlib.tests import multiply_tests
13from bzrlib.urlutils import escape14from bzrlib.urlutils import escape
1415
@@ -28,6 +29,7 @@
28from canonical.launchpad.xmlrpc import faults29from canonical.launchpad.xmlrpc import faults
29from canonical.testing import DatabaseFunctionalLayer, FunctionalLayer30from canonical.testing import DatabaseFunctionalLayer, FunctionalLayer
3031
32from lp.code.bzr import BranchFormat, ControlFormat, RepositoryFormat
31from lp.code.enums import BranchType33from lp.code.enums import BranchType
32from lp.code.errors import UnknownBranchTypeError34from lp.code.errors import UnknownBranchTypeError
33from lp.code.interfaces.branch import BRANCH_NAME_VALIDATION_ERROR_MESSAGE35from lp.code.interfaces.branch import BRANCH_NAME_VALIDATION_ERROR_MESSAGE
@@ -712,11 +714,24 @@
712 self.assertSqlAttributeEqualsDate(714 self.assertSqlAttributeEqualsDate(
713 branch, 'next_mirror_time', UTC_NOW)715 branch, 'next_mirror_time', UTC_NOW)
714716
717 def getFormatStringsForFormatName(self, format_name):
718 default_format = bzrdir.format_registry.get(format_name)()
719 control_string = default_format.get_format_string()
720 branch_string = default_format.get_branch_format().get_format_string()
721 repository_string = \
722 default_format.repository_format.get_format_string()
723 return (control_string, branch_string, repository_string)
724
725 @property
726 def arbitrary_format_strings(self):
727 return self.getFormatStringsForFormatName('default')
728
715 def test_branchChanged_sets_last_mirrored_id(self):729 def test_branchChanged_sets_last_mirrored_id(self):
716 # branchChanged sets the last_mirrored_id attribute on the branch.730 # branchChanged sets the last_mirrored_id attribute on the branch.
717 revid = self.factory.getUniqueString()731 revid = self.factory.getUniqueString()
718 branch = self.factory.makeAnyBranch()732 branch = self.factory.makeAnyBranch()
719 self.branchfs.branchChanged(branch.id, '', revid)733 self.branchfs.branchChanged(
734 branch.id, '', revid, *self.arbitrary_format_strings)
720 self.assertEqual(revid, branch.last_mirrored_id)735 self.assertEqual(revid, branch.last_mirrored_id)
721736
722 def test_branchChanged_sets_stacked_on(self):737 def test_branchChanged_sets_stacked_on(self):
@@ -724,7 +739,9 @@
724 # passed in.739 # passed in.
725 branch = self.factory.makeAnyBranch()740 branch = self.factory.makeAnyBranch()
726 stacked_on = self.factory.makeAnyBranch()741 stacked_on = self.factory.makeAnyBranch()
727 self.branchfs.branchChanged(branch.id, stacked_on.unique_name, '')742 self.branchfs.branchChanged(
743 branch.id, stacked_on.unique_name, '',
744 *self.arbitrary_format_strings)
728 self.assertEqual(stacked_on, branch.stacked_on)745 self.assertEqual(stacked_on, branch.stacked_on)
729746
730 def test_branchChanged_unsets_stacked_on(self):747 def test_branchChanged_unsets_stacked_on(self):
@@ -732,14 +749,16 @@
732 # passed in as the stacked_on location.749 # passed in as the stacked_on location.
733 branch = self.factory.makeAnyBranch()750 branch = self.factory.makeAnyBranch()
734 removeSecurityProxy(branch).stacked_on = self.factory.makeAnyBranch()751 removeSecurityProxy(branch).stacked_on = self.factory.makeAnyBranch()
735 self.branchfs.branchChanged(branch.id, '', '')752 self.branchfs.branchChanged(
753 branch.id, '', '', *self.arbitrary_format_strings)
736 self.assertIs(None, branch.stacked_on)754 self.assertIs(None, branch.stacked_on)
737755
738 def test_branchChanged_sets_last_mirrored(self):756 def test_branchChanged_sets_last_mirrored(self):
739 # branchChanged sets the last_mirrored attribute on the branch to the757 # branchChanged sets the last_mirrored attribute on the branch to the
740 # current time.758 # current time.
741 branch = self.factory.makeAnyBranch()759 branch = self.factory.makeAnyBranch()
742 self.branchfs.branchChanged(branch.id, '', '')760 self.branchfs.branchChanged(
761 branch.id, '', '', *self.arbitrary_format_strings)
743 if self.frontend == LaunchpadDatabaseFrontend:762 if self.frontend == LaunchpadDatabaseFrontend:
744 self.assertSqlAttributeEqualsDate(763 self.assertSqlAttributeEqualsDate(
745 branch, 'last_mirrored', UTC_NOW)764 branch, 'last_mirrored', UTC_NOW)
@@ -751,7 +770,8 @@
751 # mirror_status_message is set to indicate the problem and stacked_on770 # mirror_status_message is set to indicate the problem and stacked_on
752 # set to None.771 # set to None.
753 branch = self.factory.makeAnyBranch()772 branch = self.factory.makeAnyBranch()
754 self.branchfs.branchChanged(branch.id, '~does/not/exist', '')773 self.branchfs.branchChanged(
774 branch.id, '~does/not/exist', '', *self.arbitrary_format_strings)
755 self.assertIs(None, branch.stacked_on)775 self.assertIs(None, branch.stacked_on)
756 self.assertTrue('~does/not/exist' in branch.mirror_status_message)776 self.assertTrue('~does/not/exist' in branch.mirror_status_message)
757777
@@ -760,7 +780,8 @@
760 # mirror_status_message.780 # mirror_status_message.
761 branch = self.factory.makeAnyBranch()781 branch = self.factory.makeAnyBranch()
762 removeSecurityProxy(branch).mirror_status_message = 'foo'782 removeSecurityProxy(branch).mirror_status_message = 'foo'
763 self.branchfs.branchChanged(branch.id, '', '')783 self.branchfs.branchChanged(
784 branch.id, '', '', *self.arbitrary_format_strings)
764 self.assertIs(None, branch.mirror_status_message)785 self.assertIs(None, branch.mirror_status_message)
765786
766 def test_branchChanged_fault_on_unknown_id(self):787 def test_branchChanged_fault_on_unknown_id(self):
@@ -768,7 +789,8 @@
768 # "NoBranchWithID" is returned.789 # "NoBranchWithID" is returned.
769 unused_id = -1790 unused_id = -1
770 expected_fault = faults.NoBranchWithID(unused_id)791 expected_fault = faults.NoBranchWithID(unused_id)
771 received_fault = self.branchfs.branchChanged(unused_id, '', '')792 received_fault = self.branchfs.branchChanged(
793 unused_id, '', '', *self.arbitrary_format_strings)
772 self.assertEqual(794 self.assertEqual(
773 (expected_fault.faultCode, expected_fault.faultString),795 (expected_fault.faultCode, expected_fault.faultString),
774 (received_fault.faultCode, received_fault.faultString))796 (received_fault.faultCode, received_fault.faultString))
@@ -780,7 +802,8 @@
780 branch = self.factory.makeAnyBranch()802 branch = self.factory.makeAnyBranch()
781 jobs = list(getUtility(IBranchScanJobSource).iterReady())803 jobs = list(getUtility(IBranchScanJobSource).iterReady())
782 self.assertEqual(0, len(jobs))804 self.assertEqual(0, len(jobs))
783 self.branchfs.branchChanged(branch.id, '', 'rev1')805 self.branchfs.branchChanged(
806 branch.id, '', 'rev1', *self.arbitrary_format_strings)
784 jobs = list(getUtility(IBranchScanJobSource).iterReady())807 jobs = list(getUtility(IBranchScanJobSource).iterReady())
785 self.assertEqual(1, len(jobs))808 self.assertEqual(1, len(jobs))
786809
@@ -791,10 +814,43 @@
791 removeSecurityProxy(branch).last_mirrored_id = 'rev1'814 removeSecurityProxy(branch).last_mirrored_id = 'rev1'
792 jobs = list(getUtility(IBranchScanJobSource).iterReady())815 jobs = list(getUtility(IBranchScanJobSource).iterReady())
793 self.assertEqual(0, len(jobs))816 self.assertEqual(0, len(jobs))
794 self.branchfs.branchChanged(branch.id, '', 'rev1')817 self.branchfs.branchChanged(
818 branch.id, '', 'rev1', *self.arbitrary_format_strings)
795 jobs = list(getUtility(IBranchScanJobSource).iterReady())819 jobs = list(getUtility(IBranchScanJobSource).iterReady())
796 self.assertEqual(0, len(jobs))820 self.assertEqual(0, len(jobs))
797821
822 def test_branchChanged_2a_format(self):
823 branch = self.factory.makeAnyBranch()
824 self.branchfs.branchChanged(
825 branch.id, '', 'rev1', *self.getFormatStringsForFormatName('2a'))
826 self.assertEqual(
827 (ControlFormat.BZR_METADIR_1, BranchFormat.BZR_BRANCH_7,
828 RepositoryFormat.BZR_CHK_2A),
829 (branch.control_format, branch.branch_format,
830 branch.repository_format))
831
832 def test_branchChanged_packs_format(self):
833 branch = self.factory.makeAnyBranch()
834 self.branchfs.branchChanged(
835 branch.id, '', 'rev1',
836 *self.getFormatStringsForFormatName('pack-0.92'))
837 self.assertEqual(
838 (ControlFormat.BZR_METADIR_1, BranchFormat.BZR_BRANCH_6,
839 RepositoryFormat.BZR_KNITPACK_1),
840 (branch.control_format, branch.branch_format,
841 branch.repository_format))
842
843 def test_branchChanged_knits_format(self):
844 branch = self.factory.makeAnyBranch()
845 self.branchfs.branchChanged(
846 branch.id, '', 'rev1',
847 *self.getFormatStringsForFormatName('knit'))
848 self.assertEqual(
849 (ControlFormat.BZR_METADIR_1, BranchFormat.BZR_BRANCH_5,
850 RepositoryFormat.BZR_KNIT_1),
851 (branch.control_format, branch.branch_format,
852 branch.repository_format))
853
798 def assertCannotTranslate(self, requester, path):854 def assertCannotTranslate(self, requester, path):
799 """Assert that we cannot translate 'path'."""855 """Assert that we cannot translate 'path'."""
800 fault = self.branchfs.translatePath(requester.id, path)856 fault = self.branchfs.translatePath(requester.id, path)
801857
=== modified file 'lib/lp/codehosting/inmemory.py'
--- lib/lp/codehosting/inmemory.py 2010-04-27 02:16:59 +0000
+++ lib/lp/codehosting/inmemory.py 2010-04-27 02:17:19 +0000
@@ -21,6 +21,7 @@
21from canonical.launchpad.validators import LaunchpadValidationError21from canonical.launchpad.validators import LaunchpadValidationError
22from canonical.launchpad.xmlrpc import faults22from canonical.launchpad.xmlrpc import faults
2323
24from lp.code.bzr import BranchFormat, ControlFormat, RepositoryFormat
24from lp.code.errors import UnknownBranchTypeError25from lp.code.errors import UnknownBranchTypeError
25from lp.code.model.branchnamespace import BranchNamespaceSet26from lp.code.model.branchnamespace import BranchNamespaceSet
26from lp.code.model.branchtarget import (27from lp.code.model.branchtarget import (
@@ -618,7 +619,8 @@
618 def requestMirror(self, requester_id, branch_id):619 def requestMirror(self, requester_id, branch_id):
619 self._branch_set.get(branch_id).requestMirror()620 self._branch_set.get(branch_id).requestMirror()
620621
621 def branchChanged(self, branch_id, stacked_on_location, last_revision_id):622 def branchChanged(self, branch_id, stacked_on_location, last_revision_id,
623 control_string, branch_string, repository_string):
622 branch = self._branch_set._find(id=branch_id)624 branch = self._branch_set._find(id=branch_id)
623 if branch is None:625 if branch is None:
624 return faults.NoBranchWithID(branch_id)626 return faults.NoBranchWithID(branch_id)
@@ -638,6 +640,22 @@
638 branch.last_mirrored = UTC_NOW640 branch.last_mirrored = UTC_NOW
639 if branch.last_mirrored_id != last_revision_id:641 if branch.last_mirrored_id != last_revision_id:
640 branch.last_mirrored_id = last_revision_id642 branch.last_mirrored_id = last_revision_id
643
644 def match_title(enum, title, default):
645 for value in enum.items:
646 if value.title == title:
647 return value
648 else:
649 return default
650
651 branch.control_format = match_title(
652 ControlFormat, control_string, ControlFormat.UNRECOGNIZED)
653 branch.branch_format = match_title(
654 BranchFormat, branch_string, BranchFormat.UNRECOGNIZED)
655 branch.repository_format = match_title(
656 RepositoryFormat, repository_string,
657 RepositoryFormat.UNRECOGNIZED)
658
641 return True659 return True
642660
643 def _canRead(self, person_id, branch):661 def _canRead(self, person_id, branch):
644662
=== modified file 'lib/lp/codehosting/scanner/tests/test_bzrsync.py'
--- lib/lp/codehosting/scanner/tests/test_bzrsync.py 2010-04-27 02:16:59 +0000
+++ lib/lp/codehosting/scanner/tests/test_bzrsync.py 2010-04-27 02:17:19 +0000
@@ -547,8 +547,7 @@
547 # We can scan a stacked branch that's stacked on a branch that has an547 # We can scan a stacked branch that's stacked on a branch that has an
548 # lp-mirrored:// URL.548 # lp-mirrored:// URL.
549 db_stacked_on_branch = self.factory.makeAnyBranch()549 db_stacked_on_branch = self.factory.makeAnyBranch()
550 stacked_on_tree = self.makeBzrBranchAndTree(550 self.makeBzrBranchAndTree(db_stacked_on_branch, format='1.6')
551 db_stacked_on_branch, format='1.6')
552 db_stacked_branch = self.factory.makeAnyBranch()551 db_stacked_branch = self.factory.makeAnyBranch()
553 stacked_tree = self.makeBzrBranchAndTree(552 stacked_tree = self.makeBzrBranchAndTree(
554 db_stacked_branch, format='1.6')553 db_stacked_branch, format='1.6')
555554
=== modified file 'lib/lp/codehosting/tests/test_acceptance.py'
--- lib/lp/codehosting/tests/test_acceptance.py 2010-04-27 02:16:59 +0000
+++ lib/lp/codehosting/tests/test_acceptance.py 2010-04-27 02:17:19 +0000
@@ -23,6 +23,7 @@
23from canonical.testing import ZopelessAppServerLayer23from canonical.testing import ZopelessAppServerLayer
24from canonical.testing.profiled import profiled24from canonical.testing.profiled import profiled
2525
26from lp.code.bzr import BranchFormat, ControlFormat, RepositoryFormat
26from lp.code.enums import BranchType27from lp.code.enums import BranchType
27from lp.code.interfaces.branch import IBranchSet28from lp.code.interfaces.branch import IBranchSet
28from lp.code.interfaces.branchnamespace import get_branch_namespace29from lp.code.interfaces.branchnamespace import get_branch_namespace
@@ -321,18 +322,19 @@
321 url=url)322 url=url)
322323
323 def test_push_to_new_branch(self):324 def test_push_to_new_branch(self):
324 """
325 The bzr client should be able to read and write to the codehosting
326 server just like another other server. This means that actions
327 like:
328 * `bzr push bzr+ssh://testinstance/somepath`
329 * `bzr log sftp://testinstance/somepath`
330 (and/or their bzrlib equivalents) and so on should work, so long as
331 the user has permission to read or write to those URLs.
332 """
333 remote_url = self.getTransportURL('~testuser/+junk/test-branch')325 remote_url = self.getTransportURL('~testuser/+junk/test-branch')
334 self.push(self.local_branch_path, remote_url)326 self.push(self.local_branch_path, remote_url)
335 self.assertBranchesMatch(self.local_branch_path, remote_url)327 self.assertBranchesMatch(self.local_branch_path, remote_url)
328 LaunchpadZopelessTestSetup().txn.begin()
329 db_branch = getUtility(IBranchSet).getByUniqueName(
330 '~testuser/+junk/test-branch')
331 self.assertEqual(
332 RepositoryFormat.BZR_CHK_2A, db_branch.repository_format)
333 self.assertEqual(
334 BranchFormat.BZR_BRANCH_7, db_branch.branch_format)
335 self.assertEqual(
336 ControlFormat.BZR_METADIR_1, db_branch.control_format)
337 LaunchpadZopelessTestSetup().txn.commit()
336338
337 def test_push_to_existing_branch(self):339 def test_push_to_existing_branch(self):
338 """Pushing to an existing branch must work."""340 """Pushing to an existing branch must work."""
339341
=== modified file 'lib/lp/codehosting/vfs/branchfs.py'
--- lib/lp/codehosting/vfs/branchfs.py 2010-04-27 02:16:59 +0000
+++ lib/lp/codehosting/vfs/branchfs.py 2010-04-27 02:17:19 +0000
@@ -675,13 +675,21 @@
675 ignore_fallbacks=True)675 ignore_fallbacks=True)
676 last_revision = branch.last_revision()676 last_revision = branch.last_revision()
677 stacked_on_url = self._normalize_stacked_on_url(branch)677 stacked_on_url = self._normalize_stacked_on_url(branch)
678 # XXX: Aaron Bentley 2008-06-13
679 # Bazaar does not provide a public API for learning about
680 # format markers. Fix this in Bazaar, then here.
681 control_string = branch.bzrdir._format.get_format_string()
682 branch_string = branch._format.get_format_string()
683 repository_string = \
684 branch.repository._format.get_format_string()
678 finally:685 finally:
679 if jail_info.transports:686 if jail_info.transports:
680 jail_info.transports.remove(transport)687 jail_info.transports.remove(transport)
681 if stacked_on_url is None:688 if stacked_on_url is None:
682 stacked_on_url = ''689 stacked_on_url = ''
683 return self._authserver.branchChanged(690 return self._authserver.branchChanged(
684 data['id'], stacked_on_url, last_revision)691 data['id'], stacked_on_url, last_revision,
692 control_string, branch_string, repository_string)
685693
686 # It gets really confusing if we raise an exception from this method694 # It gets really confusing if we raise an exception from this method
687 # (the branch remains locked, but this isn't obvious to the client) so695 # (the branch remains locked, but this isn't obvious to the client) so
688696
=== modified file 'lib/lp/codehosting/vfs/branchfsclient.py'
--- lib/lp/codehosting/vfs/branchfsclient.py 2010-04-27 02:16:59 +0000
+++ lib/lp/codehosting/vfs/branchfsclient.py 2010-04-27 02:17:19 +0000
@@ -115,14 +115,16 @@
115 self._branchfs_endpoint.callRemote, 'createBranch', self._user_id,115 self._branchfs_endpoint.callRemote, 'createBranch', self._user_id,
116 branch_path)116 branch_path)
117117
118 def branchChanged(self, branch_id, stacked_on_url, last_revision_id):118 def branchChanged(self, branch_id, stacked_on_url, last_revision_id,
119 control_string, branch_string, repository_string):
119 """Mark a branch as needing to be mirrored.120 """Mark a branch as needing to be mirrored.
120121
121 :param branch_id: The database ID of the branch.122 :param branch_id: The database ID of the branch.
122 """123 """
123 return defer.maybeDeferred(124 return defer.maybeDeferred(
124 self._branchfs_endpoint.callRemote,125 self._branchfs_endpoint.callRemote,
125 'branchChanged', branch_id, stacked_on_url, last_revision_id)126 'branchChanged', branch_id, stacked_on_url, last_revision_id,
127 control_string, branch_string, repository_string)
126128
127 def translatePath(self, path):129 def translatePath(self, path):
128 """Translate 'path'."""130 """Translate 'path'."""
129131
=== modified file 'lib/lp/codehosting/vfs/tests/test_branchfs.py'
--- lib/lp/codehosting/vfs/tests/test_branchfs.py 2010-04-27 02:16:59 +0000
+++ lib/lp/codehosting/vfs/tests/test_branchfs.py 2010-04-27 02:17:19 +0000
@@ -11,7 +11,7 @@
11import unittest11import unittest
1212
13from bzrlib import errors13from bzrlib import errors
14from bzrlib.bzrdir import BzrDir14from bzrlib.bzrdir import BzrDir, format_registry
15from bzrlib.tests import (15from bzrlib.tests import (
16 TestCase as BzrTestCase, TestCaseInTempDir, TestCaseWithTransport)16 TestCase as BzrTestCase, TestCaseInTempDir, TestCaseWithTransport)
17from bzrlib.transport import (17from bzrlib.transport import (
@@ -821,12 +821,17 @@
821 frontend = InMemoryFrontend()821 frontend = InMemoryFrontend()
822 self.factory = frontend.getLaunchpadObjectFactory()822 self.factory = frontend.getLaunchpadObjectFactory()
823 self.authserver = frontend.getFilesystemEndpoint()823 self.authserver = frontend.getFilesystemEndpoint()
824 self.authserver.branchChanged = (824 self.authserver.branchChanged = self._replacement_branchChanged
825 lambda *args: self._branch_changed_log.append(args))
826 self.requester = self.factory.makePerson()825 self.requester = self.factory.makePerson()
827 self.backing_transport = MemoryTransport()826 self.backing_transport = MemoryTransport()
828 self.disable_directory_isolation()827 self.disable_directory_isolation()
829828
829 def _replacement_branchChanged(self, branch_id, stacked_on_url,
830 last_revision, *format_strings):
831 self._branch_changed_log.append(dict(
832 branch_id=branch_id, stacked_on_url=stacked_on_url,
833 last_revision=last_revision, format_strings=format_strings))
834
830 def get_server(self):835 def get_server(self):
831 if self._server is None:836 if self._server is None:
832 self._server = LaunchpadServer(837 self._server = LaunchpadServer(
@@ -844,8 +849,7 @@
844 db_branch = self.factory.makeAnyBranch(849 db_branch = self.factory.makeAnyBranch(
845 branch_type=BranchType.HOSTED, owner=self.requester)850 branch_type=BranchType.HOSTED, owner=self.requester)
846 self.make_branch(db_branch.unique_name)851 self.make_branch(db_branch.unique_name)
847 self.assertEqual(852 self.assertEqual(1, len(self._branch_changed_log))
848 [(db_branch.id, '', 'null:')], self._branch_changed_log)
849853
850 def test_branch_unlock_calls_branchChanged(self):854 def test_branch_unlock_calls_branchChanged(self):
851 # Unlocking a branch calls branchChanged on the branch filesystem855 # Unlocking a branch calls branchChanged on the branch filesystem
@@ -856,8 +860,7 @@
856 del self._branch_changed_log[:]860 del self._branch_changed_log[:]
857 branch.lock_write()861 branch.lock_write()
858 branch.unlock()862 branch.unlock()
859 self.assertEqual(863 self.assertEqual(1, len(self._branch_changed_log))
860 [(db_branch.id, '', 'null:')], self._branch_changed_log)
861864
862 def test_branch_unlock_reports_stacked_on_url(self):865 def test_branch_unlock_reports_stacked_on_url(self):
863 # Unlocking a branch reports the stacked on URL to the branch866 # Unlocking a branch reports the stacked on URL to the branch
@@ -872,9 +875,10 @@
872 branch.lock_write()875 branch.lock_write()
873 branch.set_stacked_on_url('/' + db_branch1.unique_name)876 branch.set_stacked_on_url('/' + db_branch1.unique_name)
874 branch.unlock()877 branch.unlock()
878 self.assertEqual(1, len(self._branch_changed_log))
875 self.assertEqual(879 self.assertEqual(
876 [(db_branch2.id, '/' + db_branch1.unique_name, 'null:')],880 '/' + db_branch1.unique_name,
877 self._branch_changed_log)881 self._branch_changed_log[0]['stacked_on_url'])
878882
879 def test_branch_unlock_reports_last_revision(self):883 def test_branch_unlock_reports_last_revision(self):
880 # Unlocking a branch reports the tip revision of the branch to the884 # Unlocking a branch reports the tip revision of the branch to the
@@ -886,8 +890,10 @@
886 del self._branch_changed_log[:]890 del self._branch_changed_log[:]
887 branch.lock_write()891 branch.lock_write()
888 branch.unlock()892 branch.unlock()
893 self.assertEqual(1, len(self._branch_changed_log))
889 self.assertEqual(894 self.assertEqual(
890 [(db_branch.id, '', revid)], self._branch_changed_log)895 revid,
896 self._branch_changed_log[0]['last_revision'])
891897
892 def test_branch_unlock_relativizes_absolute_stacked_on_url(self):898 def test_branch_unlock_relativizes_absolute_stacked_on_url(self):
893 # When a branch that has been stacked on the absolute URL of another899 # When a branch that has been stacked on the absolute URL of another
@@ -904,9 +910,10 @@
904 'http://bazaar.launchpad.dev/~user/product/branch')910 'http://bazaar.launchpad.dev/~user/product/branch')
905 branch.unlock()911 branch.unlock()
906 self.assertEqual('/~user/product/branch', branch.get_stacked_on_url())912 self.assertEqual('/~user/product/branch', branch.get_stacked_on_url())
913 self.assertEqual(1, len(self._branch_changed_log))
907 self.assertEqual(914 self.assertEqual(
908 [(db_branch.id, '/~user/product/branch', 'null:')],915 '/~user/product/branch',
909 self._branch_changed_log)916 self._branch_changed_log[0]['stacked_on_url'])
910917
911 def test_branch_unlock_ignores_non_launchpad_stacked_url(self):918 def test_branch_unlock_ignores_non_launchpad_stacked_url(self):
912 # When a branch that has been stacked on the absolute URL of a branch919 # When a branch that has been stacked on the absolute URL of a branch
@@ -920,8 +927,9 @@
920 branch.get_config().set_user_option(927 branch.get_config().set_user_option(
921 'stacked_on_location', stacked_on_url)928 'stacked_on_location', stacked_on_url)
922 branch.unlock()929 branch.unlock()
930 self.assertEqual(1, len(self._branch_changed_log))
923 self.assertEqual(931 self.assertEqual(
924 [(db_branch.id, stacked_on_url, 'null:')], self._branch_changed_log)932 stacked_on_url, self._branch_changed_log[0]['stacked_on_url'])
925 self.assertEqual(stacked_on_url, branch.get_stacked_on_url())933 self.assertEqual(stacked_on_url, branch.get_stacked_on_url())
926934
927 def test_branch_unlock_ignores_odd_scheme_stacked_url(self):935 def test_branch_unlock_ignores_odd_scheme_stacked_url(self):
@@ -937,11 +945,28 @@
937 branch.get_config().set_user_option(945 branch.get_config().set_user_option(
938 'stacked_on_location', stacked_on_url)946 'stacked_on_location', stacked_on_url)
939 branch.unlock()947 branch.unlock()
948 self.assertEqual(1, len(self._branch_changed_log))
940 self.assertEqual(949 self.assertEqual(
941 [(db_branch.id, stacked_on_url, 'null:')],950 stacked_on_url, self._branch_changed_log[0]['stacked_on_url'])
942 self._branch_changed_log)
943 self.assertEqual(stacked_on_url, branch.get_stacked_on_url())951 self.assertEqual(stacked_on_url, branch.get_stacked_on_url())
944952
953 def assertFormatStringsPassed(self, branch):
954 self.assertEqual(1, len(self._branch_changed_log))
955 control_string = branch.bzrdir._format.get_format_string()
956 branch_string = branch._format.get_format_string()
957 repository_string = branch.repository._format.get_format_string()
958 self.assertEqual(
959 (control_string, branch_string, repository_string),
960 self._branch_changed_log[0]['format_strings'])
961
962 def test_format_2a(self):
963 # Creating a 2a branch reports the format to branchChanged.
964 db_branch = self.factory.makeAnyBranch(
965 branch_type=BranchType.HOSTED, owner=self.requester)
966 branch = self.make_branch(
967 db_branch.unique_name, format=format_registry.get('2a')())
968 self.assertFormatStringsPassed(branch)
969
945970
946class TestLaunchpadTransportReadOnly(TrialTestCase, BzrTestCase):971class TestLaunchpadTransportReadOnly(TrialTestCase, BzrTestCase):
947 """Tests for read-only operations on the LaunchpadTransport."""972 """Tests for read-only operations on the LaunchpadTransport."""