Merge lp:~mwhudson/launchpad/no-hosted-area-branchChanged-on-branch 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-branchChanged-on-branch
Merge into: lp:launchpad
Prerequisite: lp:~mwhudson/launchpad/no-hosted-area-one-codehosting-endpoint
Diff against target: 512 lines (+215/-130)
9 files modified
lib/lp/code/configure.zcml (+1/-1)
lib/lp/code/interfaces/branch.py (+17/-0)
lib/lp/code/interfaces/codehosting.py (+10/-4)
lib/lp/code/model/branch.py (+29/-0)
lib/lp/code/model/tests/test_branch.py (+107/-2)
lib/lp/code/xmlrpc/codehosting.py (+31/-39)
lib/lp/code/xmlrpc/tests/test_codehosting.py (+14/-80)
lib/lp/codehosting/inmemory.py (+3/-2)
lib/lp/codehosting/vfs/branchfsclient.py (+3/-2)
To merge this branch: bzr merge lp:~mwhudson/launchpad/no-hosted-area-branchChanged-on-branch
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+23803@code.launchpad.net

Description of the change

Hi,

This branch moves the guts of the branchChanged method from the endpoint implementation to a method on the branch itself.

Cheers,
mwh

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/configure.zcml'
--- lib/lp/code/configure.zcml 2010-04-27 02:17:46 +0000
+++ lib/lp/code/configure.zcml 2010-04-27 02:18:06 +0000
@@ -548,7 +548,7 @@
548 <require548 <require
549 permission="launchpad.Edit"549 permission="launchpad.Edit"
550 attributes="destroySelf destroySelfBreakReferences setPrivate550 attributes="destroySelf destroySelfBreakReferences setPrivate
551 setOwner setTarget requestUpgrade"551 setOwner setTarget requestUpgrade branchChanged"
552 set_attributes="name url mirror_status_message552 set_attributes="name url mirror_status_message
553 description lifecycle_status553 description lifecycle_status
554 last_mirrored last_mirrored_id last_mirror_attempt554 last_mirrored last_mirrored_id last_mirror_attempt
555555
=== modified file 'lib/lp/code/interfaces/branch.py'
--- lib/lp/code/interfaces/branch.py 2010-04-27 02:17:46 +0000
+++ lib/lp/code/interfaces/branch.py 2010-04-27 02:18:06 +0000
@@ -1088,6 +1088,23 @@
1088 def startMirroring():1088 def startMirroring():
1089 """Signal that this branch is being mirrored."""1089 """Signal that this branch is being mirrored."""
10901090
1091 def branchChanged(stacked_on_url, last_revision_id, control_format,
1092 branch_format, repository_format):
1093 """Record that a branch has been changed.
1094
1095 This method records the stacked on branch tip revision id and format
1096 or the branch and creates a scan job if the tip revision id has
1097 changed.
1098
1099 :param stacked_on_url: The unique name of the branch this branch is
1100 stacked on, or '' if this branch is not stacked.
1101 :param last_revision_id: The tip revision ID of the branch.
1102 :param control_format: The entry from ControlFormat for the branch.
1103 :param branch_format: The entry from BranchFormat for the branch.
1104 :param repository_format: The entry from RepositoryFormat for the
1105 branch.
1106 """
1107
1091 def mirrorComplete(last_revision_id):1108 def mirrorComplete(last_revision_id):
1092 """Signal that a mirror attempt has completed successfully.1109 """Signal that a mirror attempt has completed successfully.
10931110
10941111
=== modified file 'lib/lp/code/interfaces/codehosting.py'
--- lib/lp/code/interfaces/codehosting.py 2010-04-27 02:17:46 +0000
+++ lib/lp/code/interfaces/codehosting.py 2010-04-27 02:18:06 +0000
@@ -166,16 +166,22 @@
166 :param branchID: a branch ID.166 :param branchID: a branch ID.
167 """167 """
168168
169 def branchChanged(branch_id, stacked_on_url, last_revision_id):169 def branchChanged(login_id, branch_id, stacked_on_url, last_revision_id,
170 control_string, branch_string, repository_string):
170 """Record that a branch has been changed.171 """Record that a branch has been changed.
171172
172 This method records the stacked on branch and tip revision id of the173 See `IBranch.branchChanged`.
173 branch and creates a scan job if the tip revision id has changed.
174174
175 :param branchID: The database id of the branch to operate on.175 :param login_id: the person ID of the user changing the branch.
176 :param branch_id: The database id of the branch to operate on.
176 :param stacked_on_url: The unique name of the branch this branch is177 :param stacked_on_url: The unique name of the branch this branch is
177 stacked on, or '' if this branch is not stacked.178 stacked on, or '' if this branch is not stacked.
178 :param last_revision_id: The tip revision ID of the branch.179 :param last_revision_id: The tip revision ID of the branch.
180 :param control_string: The format string of the control directory of
181 the branch.
182 :param branch_string: The format string of the branch.
183 :param repository_string: The format string of the branch's
184 repository.
179 """185 """
180186
181 def translatePath(requester_id, path):187 def translatePath(requester_id, path):
182188
=== modified file 'lib/lp/code/model/branch.py'
--- lib/lp/code/model/branch.py 2010-04-27 02:17:46 +0000
+++ lib/lp/code/model/branch.py 2010-04-27 02:18:06 +0000
@@ -899,6 +899,35 @@
899 self.last_mirror_attempt = UTC_NOW899 self.last_mirror_attempt = UTC_NOW
900 self.next_mirror_time = None900 self.next_mirror_time = None
901901
902 def branchChanged(self, stacked_on_location, last_revision_id,
903 control_format, branch_format, repository_format):
904 """See `IBranch`."""
905 self.mirror_status_message = None
906 if stacked_on_location == '':
907 stacked_on_branch = None
908 else:
909 stacked_on_branch = getUtility(IBranchLookup).getByUniqueName(
910 stacked_on_location.strip('/'))
911 if stacked_on_branch is None:
912 self.mirror_status_message = (
913 'Invalid stacked on location: ' + stacked_on_location)
914 self.stacked_on = stacked_on_branch
915 self.last_mirrored = UTC_NOW
916 self.mirror_failures = 0
917 if (self.next_mirror_time is None
918 and self.branch_type == BranchType.MIRRORED):
919 # No mirror was requested since we started mirroring.
920 increment = getUtility(IBranchPuller).MIRROR_TIME_INCREMENT
921 self.next_mirror_time = (
922 datetime.datetime.now(pytz.timezone('UTC')) + increment)
923 if self.last_mirrored_id != last_revision_id:
924 self.last_mirrored_id = last_revision_id
925 from lp.code.model.branchjob import BranchScanJob
926 BranchScanJob.create(self)
927 self.control_format = control_format
928 self.branch_format = branch_format
929 self.repository_format = repository_format
930
902 def mirrorComplete(self, last_revision_id):931 def mirrorComplete(self, last_revision_id):
903 """See `IBranch`."""932 """See `IBranch`."""
904 if self.branch_type == BranchType.REMOTE:933 if self.branch_type == BranchType.REMOTE:
905934
=== modified file 'lib/lp/code/model/tests/test_branch.py'
--- lib/lp/code/model/tests/test_branch.py 2010-04-27 02:17:46 +0000
+++ lib/lp/code/model/tests/test_branch.py 2010-04-27 02:18:06 +0000
@@ -38,7 +38,7 @@
38 SpecificationBranch)38 SpecificationBranch)
39from lp.bugs.interfaces.bug import CreateBugParams, IBugSet39from lp.bugs.interfaces.bug import CreateBugParams, IBugSet
40from lp.bugs.model.bugbranch import BugBranch40from lp.bugs.model.bugbranch import BugBranch
41from lp.code.bzr import BranchFormat, RepositoryFormat41from lp.code.bzr import BranchFormat, ControlFormat, RepositoryFormat
42from lp.code.enums import (42from lp.code.enums import (
43 BranchLifecycleStatus, BranchSubscriptionNotificationLevel, BranchType,43 BranchLifecycleStatus, BranchSubscriptionNotificationLevel, BranchType,
44 BranchVisibilityRule, CodeReviewNotificationLevel)44 BranchVisibilityRule, CodeReviewNotificationLevel)
@@ -47,7 +47,8 @@
47 BranchCannotBePrivate, BranchCannotBePublic,47 BranchCannotBePrivate, BranchCannotBePublic,
48 BranchCreatorNotMemberOfOwnerTeam, BranchCreatorNotOwner,48 BranchCreatorNotMemberOfOwnerTeam, BranchCreatorNotOwner,
49 BranchTargetError, CannotDeleteBranch, DEFAULT_BRANCH_STATUS_IN_LISTING)49 BranchTargetError, CannotDeleteBranch, DEFAULT_BRANCH_STATUS_IN_LISTING)
50from lp.code.interfaces.branchjob import IBranchUpgradeJobSource50from lp.code.interfaces.branchjob import (
51 IBranchUpgradeJobSource, IBranchScanJobSource)
51from lp.code.interfaces.branchlookup import IBranchLookup52from lp.code.interfaces.branchlookup import IBranchLookup
52from lp.code.interfaces.branchnamespace import IBranchNamespaceSet53from lp.code.interfaces.branchnamespace import IBranchNamespaceSet
53from lp.code.interfaces.branchmergeproposal import (54from lp.code.interfaces.branchmergeproposal import (
@@ -94,6 +95,110 @@
94 self.assertEqual(None, branch.code_import)95 self.assertEqual(None, branch.code_import)
9596
9697
98class TestBranchChanged(TestCaseWithFactory):
99 """Tests for `IBranch.branchChanged`."""
100
101 layer = DatabaseFunctionalLayer
102
103 def setUp(self):
104 TestCaseWithFactory.setUp(self)
105 self.arbitrary_formats = (
106 ControlFormat.BZR_METADIR_1, BranchFormat.BZR_BRANCH_6,
107 RepositoryFormat.BZR_CHK_2A)
108
109 def test_branchChanged_sets_last_mirrored_id(self):
110 # branchChanged sets the last_mirrored_id attribute on the branch.
111 revid = self.factory.getUniqueString()
112 branch = self.factory.makeAnyBranch()
113 login_person(branch.owner)
114 branch.branchChanged('', revid, *self.arbitrary_formats)
115 self.assertEqual(revid, branch.last_mirrored_id)
116
117 def test_branchChanged_sets_stacked_on(self):
118 # branchChanged sets the stacked_on attribute based on the unique_name
119 # passed in.
120 branch = self.factory.makeAnyBranch()
121 stacked_on = self.factory.makeAnyBranch()
122 login_person(branch.owner)
123 branch.branchChanged(
124 stacked_on.unique_name, '', *self.arbitrary_formats)
125 self.assertEqual(stacked_on, branch.stacked_on)
126
127 def test_branchChanged_unsets_stacked_on(self):
128 # branchChanged clears the stacked_on attribute on the branch if '' is
129 # passed in as the stacked_on location.
130 branch = self.factory.makeAnyBranch()
131 removeSecurityProxy(branch).stacked_on = self.factory.makeAnyBranch()
132 login_person(branch.owner)
133 branch.branchChanged('', '', *self.arbitrary_formats)
134 self.assertIs(None, branch.stacked_on)
135
136 def test_branchChanged_sets_last_mirrored(self):
137 # branchChanged sets the last_mirrored attribute on the branch to the
138 # current time.
139 branch = self.factory.makeAnyBranch()
140 login_person(branch.owner)
141 branch.branchChanged('', '', *self.arbitrary_formats)
142 self.assertSqlAttributeEqualsDate(
143 branch, 'last_mirrored', UTC_NOW)
144
145 def test_branchChanged_records_bogus_stacked_on_url(self):
146 # If a bogus location is passed in as the stacked_on parameter,
147 # mirror_status_message is set to indicate the problem and stacked_on
148 # set to None.
149 branch = self.factory.makeAnyBranch()
150 login_person(branch.owner)
151 branch.branchChanged('~does/not/exist', '', *self.arbitrary_formats)
152 self.assertIs(None, branch.stacked_on)
153 self.assertTrue('~does/not/exist' in branch.mirror_status_message)
154
155 def test_branchChanged_clears_mirror_status_message_if_no_error(self):
156 # branchChanged() clears any error that's currently mentioned in
157 # mirror_status_message.
158 branch = self.factory.makeAnyBranch()
159 removeSecurityProxy(branch).mirror_status_message = 'foo'
160 login_person(branch.owner)
161 branch.branchChanged('', '', *self.arbitrary_formats)
162 self.assertIs(None, branch.mirror_status_message)
163
164 def test_branchChanged_creates_scan_job(self):
165 # branchChanged() creates a scan job for the branch.
166 branch = self.factory.makeAnyBranch()
167 login_person(branch.owner)
168 jobs = list(getUtility(IBranchScanJobSource).iterReady())
169 self.assertEqual(0, len(jobs))
170 branch.branchChanged('', 'rev1', *self.arbitrary_formats)
171 jobs = list(getUtility(IBranchScanJobSource).iterReady())
172 self.assertEqual(1, len(jobs))
173
174 def test_branchChanged_doesnt_create_scan_job_for_noop_change(self):
175 # branchChanged() doesn't create a scan job if the tip revision id
176 # hasn't changed.
177 branch = self.factory.makeAnyBranch()
178 login_person(branch.owner)
179 removeSecurityProxy(branch).last_mirrored_id = 'rev1'
180 jobs = list(getUtility(IBranchScanJobSource).iterReady())
181 self.assertEqual(0, len(jobs))
182 branch.branchChanged('', 'rev1', *self.arbitrary_formats)
183 jobs = list(getUtility(IBranchScanJobSource).iterReady())
184 self.assertEqual(0, len(jobs))
185
186 def test_branchChanged_packs_format(self):
187 # branchChanged sets the branch_format etc attributes to the passed in
188 # values.
189 branch = self.factory.makeAnyBranch()
190 login_person(branch.owner)
191 branch.branchChanged(
192 '', 'rev1', ControlFormat.BZR_METADIR_1,
193 BranchFormat.BZR_BRANCH_6, RepositoryFormat.BZR_KNITPACK_1)
194 login(ANONYMOUS)
195 self.assertEqual(
196 (ControlFormat.BZR_METADIR_1, BranchFormat.BZR_BRANCH_6,
197 RepositoryFormat.BZR_KNITPACK_1),
198 (branch.control_format, branch.branch_format,
199 branch.repository_format))
200
201
97class TestBranchGetRevision(TestCaseWithFactory):202class TestBranchGetRevision(TestCaseWithFactory):
98 """Make sure that `Branch.getBranchRevision` works as expected."""203 """Make sure that `Branch.getBranchRevision` works as expected."""
99204
100205
=== modified file 'lib/lp/code/xmlrpc/codehosting.py'
--- lib/lp/code/xmlrpc/codehosting.py 2010-04-27 02:17:46 +0000
+++ lib/lp/code/xmlrpc/codehosting.py 2010-04-27 02:18:06 +0000
@@ -22,7 +22,6 @@
22from zope.security.proxy import removeSecurityProxy22from zope.security.proxy import removeSecurityProxy
23from zope.security.management import endInteraction23from zope.security.management import endInteraction
2424
25from canonical.database.constants import UTC_NOW
26from canonical.launchpad.validators import LaunchpadValidationError25from canonical.launchpad.validators import LaunchpadValidationError
27from canonical.launchpad.webapp import LaunchpadXMLRPCView26from canonical.launchpad.webapp import LaunchpadXMLRPCView
28from canonical.launchpad.webapp.authorization import check_permission27from canonical.launchpad.webapp.authorization import check_permission
@@ -36,7 +35,6 @@
36from lp.code.bzr import BranchFormat, ControlFormat, RepositoryFormat35from lp.code.bzr import BranchFormat, ControlFormat, RepositoryFormat
37from lp.code.enums import BranchType36from lp.code.enums import BranchType
38from lp.code.interfaces.branch import BranchCreationException37from lp.code.interfaces.branch import BranchCreationException
39from lp.code.interfaces.branchjob import IBranchScanJobSource
40from lp.code.interfaces.branchlookup import IBranchLookup38from lp.code.interfaces.branchlookup import IBranchLookup
41from lp.code.interfaces.branchnamespace import (39from lp.code.interfaces.branchnamespace import (
42 InvalidNamespace, lookup_branch_namespace, split_unique_name)40 InvalidNamespace, lookup_branch_namespace, split_unique_name)
@@ -240,44 +238,38 @@
240 return True238 return True
241 return run_with_login(login_id, request_mirror)239 return run_with_login(login_id, request_mirror)
242240
243 def branchChanged(self, branch_id, stacked_on_location, last_revision_id,241 def branchChanged(self, login_id, branch_id, stacked_on_location,
244 control_string, branch_string, repository_string):242 last_revision_id, control_string, branch_string,
243 repository_string):
245 """See `ICodehostingAPI`."""244 """See `ICodehostingAPI`."""
246 branch_set = removeSecurityProxy(getUtility(IBranchLookup))245 def branch_changed(request_mirror):
247 branch = branch_set.get(branch_id)246 branch_set = getUtility(IBranchLookup)
248 if branch is None:247 branch = branch_set.get(branch_id)
249 return faults.NoBranchWithID(branch_id)248 if branch is None:
250 branch.mirror_status_message = None249 return faults.NoBranchWithID(branch_id)
251 if stacked_on_location == '':250
252 stacked_on_branch = None251 def match_title(enum, title, default):
253 else:252 for value in enum.items:
254 stacked_on_branch = branch_set.getByUniqueName(253 if value.title == title:
255 stacked_on_location.strip('/'))254 return value
256 if stacked_on_branch is None:255 else:
257 branch.mirror_status_message = (256 return default
258 'Invalid stacked on location: ' + stacked_on_location)257
259 branch.stacked_on = stacked_on_branch258 control_format = match_title(
260 branch.last_mirrored = UTC_NOW259 ControlFormat, control_string, ControlFormat.UNRECOGNIZED)
261 if branch.last_mirrored_id != last_revision_id:260 branch_format = match_title(
262 branch.last_mirrored_id = last_revision_id261 BranchFormat, branch_string, BranchFormat.UNRECOGNIZED)
263 getUtility(IBranchScanJobSource).create(branch)262 repository_format = match_title(
264263 RepositoryFormat, repository_string,
265 def match_title(enum, title, default):264 RepositoryFormat.UNRECOGNIZED)
266 for value in enum.items:265
267 if value.title == title:266 branch.branchChanged(
268 return value267 stacked_on_location, last_revision_id, control_format,
269 else:268 branch_format, repository_format)
270 return default269
271270 return True
272 branch.control_format = match_title(271
273 ControlFormat, control_string, ControlFormat.UNRECOGNIZED)272 return run_with_login(login_id, branch_changed)
274 branch.branch_format = match_title(
275 BranchFormat, branch_string, BranchFormat.UNRECOGNIZED)
276 branch.repository_format = match_title(
277 RepositoryFormat, repository_string,
278 RepositoryFormat.UNRECOGNIZED)
279
280 return True
281273
282 def _serializeBranch(self, requester, branch, trailing_path):274 def _serializeBranch(self, requester, branch, trailing_path):
283 if requester == LAUNCHPAD_SERVICES:275 if requester == LAUNCHPAD_SERVICES:
284276
=== modified file 'lib/lp/code/xmlrpc/tests/test_codehosting.py'
--- lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-04-27 02:17:46 +0000
+++ lib/lp/code/xmlrpc/tests/test_codehosting.py 2010-04-27 02:18:06 +0000
@@ -578,102 +578,34 @@
578 return self.getFormatStringsForFormatName('default')578 return self.getFormatStringsForFormatName('default')
579579
580 def test_branchChanged_sets_last_mirrored_id(self):580 def test_branchChanged_sets_last_mirrored_id(self):
581 # branchChanged sets the last_mirrored_id attribute on the branch.581 # branchChanged does many things but lets just check the setting of
582 # last_mirrored_id here. The other things are tested in unit tests.
582 revid = self.factory.getUniqueString()583 revid = self.factory.getUniqueString()
583 branch = self.factory.makeAnyBranch()584 branch = self.factory.makeAnyBranch()
584 self.codehosting_api.branchChanged(585 self.codehosting_api.branchChanged(
585 branch.id, '', revid, *self.arbitrary_format_strings)586 branch.owner.id, branch.id, '', revid,
587 *self.arbitrary_format_strings)
588 login(ANONYMOUS)
586 self.assertEqual(revid, branch.last_mirrored_id)589 self.assertEqual(revid, branch.last_mirrored_id)
587590
588 def test_branchChanged_sets_stacked_on(self):
589 # branchChanged sets the stacked_on attribute based on the unique_name
590 # passed in.
591 branch = self.factory.makeAnyBranch()
592 stacked_on = self.factory.makeAnyBranch()
593 self.codehosting_api.branchChanged(
594 branch.id, stacked_on.unique_name, '',
595 *self.arbitrary_format_strings)
596 self.assertEqual(stacked_on, branch.stacked_on)
597
598 def test_branchChanged_unsets_stacked_on(self):
599 # branchChanged clears the stacked_on attribute on the branch if '' is
600 # passed in as the stacked_on location.
601 branch = self.factory.makeAnyBranch()
602 removeSecurityProxy(branch).stacked_on = self.factory.makeAnyBranch()
603 self.codehosting_api.branchChanged(
604 branch.id, '', '', *self.arbitrary_format_strings)
605 self.assertIs(None, branch.stacked_on)
606
607 def test_branchChanged_sets_last_mirrored(self):
608 # branchChanged sets the last_mirrored attribute on the branch to the
609 # current time.
610 branch = self.factory.makeAnyBranch()
611 self.codehosting_api.branchChanged(
612 branch.id, '', '', *self.arbitrary_format_strings)
613 if self.frontend == LaunchpadDatabaseFrontend:
614 self.assertSqlAttributeEqualsDate(
615 branch, 'last_mirrored', UTC_NOW)
616 else:
617 self.assertIs(UTC_NOW, branch.last_mirrored)
618
619 def test_branchChanged_records_bogus_stacked_on_url(self):
620 # If a bogus location is passed in as the stacked_on parameter,
621 # mirror_status_message is set to indicate the problem and stacked_on
622 # set to None.
623 branch = self.factory.makeAnyBranch()
624 self.codehosting_api.branchChanged(
625 branch.id, '~does/not/exist', '', *self.arbitrary_format_strings)
626 self.assertIs(None, branch.stacked_on)
627 self.assertTrue('~does/not/exist' in branch.mirror_status_message)
628
629 def test_branchChanged_clears_mirror_status_message_if_no_error(self):
630 # branchChanged() clears any error that's currently mentioned in
631 # mirror_status_message.
632 branch = self.factory.makeAnyBranch()
633 removeSecurityProxy(branch).mirror_status_message = 'foo'
634 self.codehosting_api.branchChanged(
635 branch.id, '', '', *self.arbitrary_format_strings)
636 self.assertIs(None, branch.mirror_status_message)
637
638 def test_branchChanged_fault_on_unknown_id(self):591 def test_branchChanged_fault_on_unknown_id(self):
639 # If the id passed in doesn't match an existing branch, the fault592 # If the id passed in doesn't match an existing branch, the fault
640 # "NoBranchWithID" is returned.593 # "NoBranchWithID" is returned.
641 unused_id = -1594 unused_id = -1
642 expected_fault = faults.NoBranchWithID(unused_id)595 expected_fault = faults.NoBranchWithID(unused_id)
643 received_fault = self.codehosting_api.branchChanged(596 received_fault = self.codehosting_api.branchChanged(
644 unused_id, '', '', *self.arbitrary_format_strings)597 1, unused_id, '', '', *self.arbitrary_format_strings)
598 login(ANONYMOUS)
645 self.assertEqual(599 self.assertEqual(
646 (expected_fault.faultCode, expected_fault.faultString),600 (expected_fault.faultCode, expected_fault.faultString),
647 (received_fault.faultCode, received_fault.faultString))601 (received_fault.faultCode, received_fault.faultString))
648602
649 def test_branchChanged_creates_scan_job(self):
650 # branchChanged() creates a scan job for the branch.
651 if self.frontend != LaunchpadDatabaseFrontend:
652 return
653 branch = self.factory.makeAnyBranch()
654 jobs = list(getUtility(IBranchScanJobSource).iterReady())
655 self.assertEqual(0, len(jobs))
656 self.codehosting_api.branchChanged(
657 branch.id, '', 'rev1', *self.arbitrary_format_strings)
658 jobs = list(getUtility(IBranchScanJobSource).iterReady())
659 self.assertEqual(1, len(jobs))
660
661 def test_branchChanged_doesnt_create_scan_job_for_noop_change(self):
662 if self.frontend != LaunchpadDatabaseFrontend:
663 return
664 branch = self.factory.makeAnyBranch()
665 removeSecurityProxy(branch).last_mirrored_id = 'rev1'
666 jobs = list(getUtility(IBranchScanJobSource).iterReady())
667 self.assertEqual(0, len(jobs))
668 self.codehosting_api.branchChanged(
669 branch.id, '', 'rev1', *self.arbitrary_format_strings)
670 jobs = list(getUtility(IBranchScanJobSource).iterReady())
671 self.assertEqual(0, len(jobs))
672
673 def test_branchChanged_2a_format(self):603 def test_branchChanged_2a_format(self):
674 branch = self.factory.makeAnyBranch()604 branch = self.factory.makeAnyBranch()
675 self.codehosting_api.branchChanged(605 self.codehosting_api.branchChanged(
676 branch.id, '', 'rev1', *self.getFormatStringsForFormatName('2a'))606 branch.owner.id, branch.id, '', 'rev1',
607 *self.getFormatStringsForFormatName('2a'))
608 login(ANONYMOUS)
677 self.assertEqual(609 self.assertEqual(
678 (ControlFormat.BZR_METADIR_1, BranchFormat.BZR_BRANCH_7,610 (ControlFormat.BZR_METADIR_1, BranchFormat.BZR_BRANCH_7,
679 RepositoryFormat.BZR_CHK_2A),611 RepositoryFormat.BZR_CHK_2A),
@@ -683,8 +615,9 @@
683 def test_branchChanged_packs_format(self):615 def test_branchChanged_packs_format(self):
684 branch = self.factory.makeAnyBranch()616 branch = self.factory.makeAnyBranch()
685 self.codehosting_api.branchChanged(617 self.codehosting_api.branchChanged(
686 branch.id, '', 'rev1',618 branch.owner.id, branch.id, '', 'rev1',
687 *self.getFormatStringsForFormatName('pack-0.92'))619 *self.getFormatStringsForFormatName('pack-0.92'))
620 login(ANONYMOUS)
688 self.assertEqual(621 self.assertEqual(
689 (ControlFormat.BZR_METADIR_1, BranchFormat.BZR_BRANCH_6,622 (ControlFormat.BZR_METADIR_1, BranchFormat.BZR_BRANCH_6,
690 RepositoryFormat.BZR_KNITPACK_1),623 RepositoryFormat.BZR_KNITPACK_1),
@@ -694,8 +627,9 @@
694 def test_branchChanged_knits_format(self):627 def test_branchChanged_knits_format(self):
695 branch = self.factory.makeAnyBranch()628 branch = self.factory.makeAnyBranch()
696 self.codehosting_api.branchChanged(629 self.codehosting_api.branchChanged(
697 branch.id, '', 'rev1',630 branch.owner.id, branch.id, '', 'rev1',
698 *self.getFormatStringsForFormatName('knit'))631 *self.getFormatStringsForFormatName('knit'))
632 login(ANONYMOUS)
699 self.assertEqual(633 self.assertEqual(
700 (ControlFormat.BZR_METADIR_1, BranchFormat.BZR_BRANCH_5,634 (ControlFormat.BZR_METADIR_1, BranchFormat.BZR_BRANCH_5,
701 RepositoryFormat.BZR_KNIT_1),635 RepositoryFormat.BZR_KNIT_1),
702636
=== modified file 'lib/lp/codehosting/inmemory.py'
--- lib/lp/codehosting/inmemory.py 2010-04-27 02:17:46 +0000
+++ lib/lp/codehosting/inmemory.py 2010-04-27 02:18:06 +0000
@@ -614,8 +614,9 @@
614 def requestMirror(self, requester_id, branch_id):614 def requestMirror(self, requester_id, branch_id):
615 self._branch_set.get(branch_id).requestMirror()615 self._branch_set.get(branch_id).requestMirror()
616616
617 def branchChanged(self, branch_id, stacked_on_location, last_revision_id,617 def branchChanged(self, login_id, branch_id, stacked_on_location,
618 control_string, branch_string, repository_string):618 last_revision_id, control_string, branch_string,
619 repository_string):
619 branch = self._branch_set._find(id=branch_id)620 branch = self._branch_set._find(id=branch_id)
620 if branch is None:621 if branch is None:
621 return faults.NoBranchWithID(branch_id)622 return faults.NoBranchWithID(branch_id)
622623
=== modified file 'lib/lp/codehosting/vfs/branchfsclient.py'
--- lib/lp/codehosting/vfs/branchfsclient.py 2010-04-27 02:17:46 +0000
+++ lib/lp/codehosting/vfs/branchfsclient.py 2010-04-27 02:18:06 +0000
@@ -126,8 +126,9 @@
126 """126 """
127 return defer.maybeDeferred(127 return defer.maybeDeferred(
128 self._codehosting_endpoint.callRemote,128 self._codehosting_endpoint.callRemote,
129 'branchChanged', branch_id, stacked_on_url, last_revision_id,129 'branchChanged', self._user_id, branch_id, stacked_on_url,
130 control_string, branch_string, repository_string)130 last_revision_id, control_string, branch_string,
131 repository_string)
131132
132 def translatePath(self, path):133 def translatePath(self, path):
133 """Translate 'path'."""134 """Translate 'path'."""