Merge lp:~mwhudson/launchpad/no-hosted-area-fix-useBzrBranch-users into lp:launchpad/db-devel
- no-hosted-area-fix-useBzrBranch-users
- Merge into db-devel
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~mwhudson/launchpad/no-hosted-area-fix-useBzrBranch-users |
Merge into: | lp:launchpad/db-devel |
Prerequisite: | lp:~mwhudson/launchpad/no-hosted-area-fix-directbranchcommit |
Diff against target: |
1127 lines (+136/-160) 28 files modified
lib/canonical/buildd/tests/test_generate_translation_templates.py (+4/-4) lib/canonical/launchpad/scripts/tests/test_garbo.py (+0/-2) lib/lp/code/configure.zcml (+1/-1) lib/lp/code/interfaces/branch.py (+9/-7) lib/lp/code/interfaces/branchtarget.py (+4/-2) lib/lp/code/mail/codehandler.py (+1/-2) lib/lp/code/mail/tests/test_codehandler.py (+18/-50) lib/lp/code/model/branch.py (+3/-4) lib/lp/code/model/branchjob.py (+6/-5) lib/lp/code/model/branchmergeproposaljob.py (+4/-4) lib/lp/code/model/diff.py (+3/-4) lib/lp/code/model/directbranchcommit.py (+7/-1) lib/lp/code/model/tests/test_branch.py (+1/-1) lib/lp/code/model/tests/test_branchjob.py (+24/-26) lib/lp/code/model/tests/test_branchmergeproposaljobs.py (+4/-4) lib/lp/code/model/tests/test_diff.py (+12/-10) lib/lp/code/scripts/tests/test_create_merge_proposals.py (+4/-10) lib/lp/code/scripts/tests/test_scan_branches.py (+3/-4) lib/lp/code/scripts/tests/test_upgrade_branches.py (+4/-5) lib/lp/codehosting/inmemory.py (+2/-2) lib/lp/codehosting/scanner/bzrsync.py (+1/-2) lib/lp/codehosting/tests/test_branchdistro.py (+1/-1) lib/lp/codehosting/tests/test_jobs.py (+1/-1) lib/lp/codehosting/vfs/__init__.py (+3/-2) lib/lp/codehosting/vfs/branchfs.py (+4/-2) lib/lp/testing/__init__.py (+8/-1) lib/lp/testing/factory.py (+2/-2) lib/lp/translations/tests/test_translationtemplatesbuildjob.py (+2/-1) |
To merge this branch: | bzr merge lp:~mwhudson/launchpad/no-hosted-area-fix-useBzrBranch-users |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Penhey (community) | conditional | Approve | |
Review via email: mp+24096@code.launchpad.net |
Commit message
Description of the change
Hi Tim,
This branch is a bit of a mess of assorted test fixes. I hope it's not too deathly dull to read!
Cheers,
mwh
Michael Hudson-Doyle (mwhudson) wrote : | # |
On 26/04/10 20:58, Tim Penhey wrote:
> Review: Approve conditional
> I know that it is not worth it now, but in
> lib/lp/
> have just overridden the inherited useBzrBranches method
> to make it always specify direct_
Yeah, this aspect of things does smell a bit doesn't it?
> It may be an interesting count, but which is used more?
> direct_
It seems 43 of 64 calls use direct_
Part of my unease around this comes from the fact that what determines
whether to use direct_database or not basically depends on the layer --
if it's a appserver layer, don't use direct_database, otherwise do. I
don't know if tying it to the layer makes sense though.
What do you think?
> lib/lp/
> - you still have: raise AssertionError(
>
> removeSecurityP
> - is there a bzrlib constant we can use here?
Yes, but that line disappears in a later pipe anyway I think...
> And yes, it was a pretty boring branch to review. Great
> to see a consistent use of getInternalBzrUrl and getBzrBranch.
Yeah!
Cheers,
mwh
Preview Diff
1 | === modified file 'lib/canonical/buildd/tests/test_generate_translation_templates.py' |
2 | --- lib/canonical/buildd/tests/test_generate_translation_templates.py 2010-03-18 13:27:47 +0000 |
3 | +++ lib/canonical/buildd/tests/test_generate_translation_templates.py 2010-04-27 02:24:35 +0000 |
4 | @@ -57,7 +57,7 @@ |
5 | |
6 | :return: a fresh lp.code.model.Branch backed by a real bzr branch. |
7 | """ |
8 | - db_branch, tree = self.create_branch_and_tree(hosted=True) |
9 | + db_branch, tree = self.create_branch_and_tree() |
10 | populist = DirectBranchCommit(db_branch) |
11 | last_revision = populist.bzrbranch.last_revision() |
12 | db_branch.last_scanned_id = populist.last_scanned_id = last_revision |
13 | @@ -71,13 +71,13 @@ |
14 | |
15 | def test_getBranch_bzr(self): |
16 | # _getBranch can retrieve branch contents from a branch URL. |
17 | - self.useBzrBranches() |
18 | + self.useBzrBranches(direct_database=True) |
19 | marker_text = "Ceci n'est pas cet branch." |
20 | branch = self._createBranch({'marker.txt': marker_text}) |
21 | - branch_url = branch.getPullURL() |
22 | |
23 | generator = GenerateTranslationTemplates( |
24 | - branch_url, self.result_name, self.makeTemporaryDirectory()) |
25 | + branch.getInternalBzrUrl(), self.result_name, |
26 | + self.makeTemporaryDirectory()) |
27 | generator.branch_dir = self.makeTemporaryDirectory() |
28 | generator._getBranch() |
29 | |
30 | |
31 | === added directory 'lib/canonical/launchpad/apidoc' |
32 | === modified file 'lib/canonical/launchpad/scripts/tests/test_garbo.py' |
33 | --- lib/canonical/launchpad/scripts/tests/test_garbo.py 2010-04-14 13:14:00 +0000 |
34 | +++ lib/canonical/launchpad/scripts/tests/test_garbo.py 2010-04-27 02:24:35 +0000 |
35 | @@ -448,7 +448,6 @@ |
36 | |
37 | def test_BranchJobPruner(self): |
38 | # Garbo should remove jobs completed over 30 days ago. |
39 | - self.useBzrBranches() |
40 | LaunchpadZopelessLayer.switchDbUser('testadmin') |
41 | store = IMasterStore(Job) |
42 | |
43 | @@ -478,7 +477,6 @@ |
44 | def test_BranchJobPruner_doesnt_prune_recent_jobs(self): |
45 | # Check to make sure the garbo doesn't remove jobs that aren't more |
46 | # than thirty days old. |
47 | - self.useBzrBranches() |
48 | LaunchpadZopelessLayer.switchDbUser('testadmin') |
49 | store = IMasterStore(Job) |
50 | |
51 | |
52 | === modified file 'lib/lp/code/configure.zcml' |
53 | --- lib/lp/code/configure.zcml 2010-04-27 02:24:30 +0000 |
54 | +++ lib/lp/code/configure.zcml 2010-04-27 02:24:35 +0000 |
55 | @@ -471,7 +471,6 @@ |
56 | last_scanned |
57 | last_scanned_id |
58 | revision_count |
59 | - warehouse_url |
60 | bug_branches |
61 | linked_bugs |
62 | linkBug |
63 | @@ -519,6 +518,7 @@ |
64 | getNotificationRecipients |
65 | getScannerData |
66 | getPullURL |
67 | + getInternalBzrUrl |
68 | getBzrBranch |
69 | requestMirror |
70 | startMirroring |
71 | |
72 | === modified file 'lib/lp/code/interfaces/branch.py' |
73 | --- lib/lp/code/interfaces/branch.py 2010-04-27 02:24:30 +0000 |
74 | +++ lib/lp/code/interfaces/branch.py 2010-04-27 02:24:35 +0000 |
75 | @@ -596,12 +596,6 @@ |
76 | |
77 | stacked_on = Attribute('Stacked-on branch') |
78 | |
79 | - warehouse_url = Attribute( |
80 | - "URL for accessing the branch by ID. " |
81 | - "This is for in-datacentre services only and allows such services to " |
82 | - "be unaffected during branch renames. " |
83 | - "See doc/bazaar for more information about the branch warehouse.") |
84 | - |
85 | # Bug attributes |
86 | bug_branches = CollectionField( |
87 | title=_("The bug-branch link objects that link this branch " |
88 | @@ -1076,7 +1070,15 @@ |
89 | the corresponding BranchRevision rows for this branch. |
90 | """ |
91 | |
92 | - def getBzrBranch(self): |
93 | + def getInternalBzrUrl(): |
94 | + """Get the internal URL for this branch. |
95 | + |
96 | + It's generally better to use `getBzrBranch` to open the branch |
97 | + directly, as that method is safe against the branch unexpectedly being |
98 | + a branch reference or stacked on something mischievous. |
99 | + """ |
100 | + |
101 | + def getBzrBranch(): |
102 | """Return the BzrBranch for this database Branch. |
103 | |
104 | You can only call this if a server returned by `get_ro_server` or |
105 | |
106 | === modified file 'lib/lp/code/interfaces/branchtarget.py' |
107 | --- lib/lp/code/interfaces/branchtarget.py 2010-04-13 11:05:58 +0000 |
108 | +++ lib/lp/code/interfaces/branchtarget.py 2010-04-27 02:24:35 +0000 |
109 | @@ -34,7 +34,9 @@ |
110 | Branches that are *not* suitable include: |
111 | - remote branches |
112 | - branches the user cannot see |
113 | - - branches that have not yet been successfully processed by the puller. |
114 | + - branches that have no last revision information set (hosted branches |
115 | + where a push hasn't completed or a mirrored branch that hasn't been |
116 | + mirrored, etc). |
117 | |
118 | If the given branch is not suitable, return None. For convenience, also |
119 | returns None if passed None. Otherwise, return the branch. |
120 | @@ -47,7 +49,7 @@ |
121 | return None |
122 | if branch_type == BranchType.REMOTE: |
123 | return None |
124 | - if branch.last_mirrored is None: |
125 | + if branch.last_mirrored_id is None: |
126 | return None |
127 | return branch |
128 | |
129 | |
130 | === modified file 'lib/lp/code/mail/codehandler.py' |
131 | --- lib/lp/code/mail/codehandler.py 2010-03-18 20:53:36 +0000 |
132 | +++ lib/lp/code/mail/codehandler.py 2010-04-27 02:24:35 +0000 |
133 | @@ -21,7 +21,6 @@ |
134 | |
135 | from zope.component import getUtility |
136 | from zope.interface import implements |
137 | -from zope.security.proxy import removeSecurityProxy |
138 | |
139 | from lp.codehosting.bzrutils import is_branch_stackable |
140 | from lp.codehosting.vfs import get_lp_server |
141 | @@ -495,7 +494,7 @@ |
142 | # source branch - one that has *no* Bazaar data. Together these |
143 | # prevent users from using Launchpad disk space at a rate that is |
144 | # disproportionately greater than data uploaded. |
145 | - mirrored_bzr_target = removeSecurityProxy(db_target).getBzrBranch() |
146 | + mirrored_bzr_target = db_target.getBzrBranch() |
147 | if not is_branch_stackable(mirrored_bzr_target): |
148 | return db_source |
149 | assert db_source.branch_type == BranchType.HOSTED, ( |
150 | |
151 | === modified file 'lib/lp/code/mail/tests/test_codehandler.py' |
152 | --- lib/lp/code/mail/tests/test_codehandler.py 2010-04-27 02:24:30 +0000 |
153 | +++ lib/lp/code/mail/tests/test_codehandler.py 2010-04-27 02:24:35 +0000 |
154 | @@ -848,13 +848,6 @@ |
155 | transaction.commit() |
156 | LaunchpadZopelessLayer.switchDbUser(user) |
157 | |
158 | - def _mirror(self, db_branch, bzr_branch): |
159 | - # Ensure the directories containing the mirror branch exist. |
160 | - transport = get_transport(db_branch.warehouse_url) |
161 | - lp_mirror = BzrDir.create_branch_convenience(db_branch.warehouse_url) |
162 | - self.addCleanup(transport.delete_tree, '.') |
163 | - lp_mirror.pull(bzr_branch) |
164 | - |
165 | def _createTargetSourceAndBundle(self, format=None): |
166 | """Create a merge directive with a bundle and associated branches. |
167 | |
168 | @@ -909,7 +902,7 @@ |
169 | # branch that is created is an empty hosted branch. The new branch |
170 | # will not have a mirror requested as there are no revisions, and |
171 | # there is no branch created in the hosted area. |
172 | - self.useBzrBranches(real_server=True) |
173 | + self.useBzrBranches() |
174 | branch, source, message = self._createTargetSourceAndBundle( |
175 | format="pack-0.92") |
176 | bmp = self._processMergeDirective(message) |
177 | @@ -921,7 +914,7 @@ |
178 | # mirrored, the source branch that is created is an empty hosted |
179 | # branch. The new branch will not have a mirror requested as there |
180 | # are no revisions, and there is no branch created in the hosted area. |
181 | - self.useBzrBranches(real_server=True) |
182 | + self.useBzrBranches() |
183 | branch, source, message = self._createTargetSourceAndBundle( |
184 | format="1.9") |
185 | # Mark the target branch as "unmirrored", at least as far as the db is |
186 | @@ -936,7 +929,7 @@ |
187 | # branch that is created is a hosted branch stacked on the target |
188 | # branch. The source branch will have the revisions from the bundle, |
189 | # and a mirror will have been triggered. |
190 | - self.useBzrBranches(real_server=True) |
191 | + self.useBzrBranches() |
192 | branch, source, message = self._createTargetSourceAndBundle( |
193 | format="1.9") |
194 | bmp = self._processMergeDirective(message) |
195 | @@ -946,24 +939,10 @@ |
196 | self.assertEqual( |
197 | source.last_revision(), source_bzr_branch.last_revision()) |
198 | |
199 | - def test_correct_area(self): |
200 | - # When a branch is created for a merge directive, it is created in the |
201 | - # hosted area (getPullURL) not the mirrored area (warehouse_url). |
202 | - self.useBzrBranches(real_server=True) |
203 | - branch, source, message = self._createTargetSourceAndBundle( |
204 | - format="1.9") |
205 | - bmp = self._processMergeDirective(message) |
206 | - # The hosted location should be populated (open succeeds). |
207 | - self._openBazaarBranchAsClient(bmp.source_branch) |
208 | - # Not the mirror (open raises). |
209 | - self.assertRaises( |
210 | - bzr_errors.NotBranchError, Branch.open, |
211 | - bmp.source_branch.warehouse_url) |
212 | - |
213 | def test_branch_stacked(self): |
214 | # When a branch is created for a merge directive, it is created |
215 | # stacked on the target branch. |
216 | - self.useBzrBranches(real_server=True) |
217 | + self.useBzrBranches() |
218 | branch, source, message = self._createTargetSourceAndBundle( |
219 | format="1.9") |
220 | bmp = self._processMergeDirective(message) |
221 | @@ -983,7 +962,7 @@ |
222 | def test_source_not_newer(self): |
223 | # The source branch is created correctly when the source is not newer |
224 | # than the target, instead of raising DivergedBranches. |
225 | - self.useBzrBranches(real_server=True) |
226 | + self.useBzrBranches() |
227 | branch, source, message = self._createTargetSourceAndBundle( |
228 | format="1.9") |
229 | target_tree = WorkingTree.open('.') |
230 | @@ -998,20 +977,16 @@ |
231 | db_target_branch, target_tree = self.create_branch_and_tree( |
232 | 'target', format=target_format) |
233 | target_tree.branch.set_public_branch(db_target_branch.bzr_identity) |
234 | - target_tree.commit('rev1') |
235 | - # Make sure that the created branch has been mirrored. |
236 | - db_target_branch.startMirroring() |
237 | + revid = target_tree.commit('rev1') |
238 | removeSecurityProxy(db_target_branch).branchChanged( |
239 | - '', 'rev1', None, None, None) |
240 | + '', revid, None, None, None) |
241 | |
242 | db_source_branch, source_tree = self.create_branch_and_tree( |
243 | - 'lpsource', db_target_branch.product, hosted=True, |
244 | - format=source_format) |
245 | + 'lpsource', db_target_branch.product, format=source_format) |
246 | # The branch is not scheduled to be mirrorred. |
247 | self.assertIs(db_source_branch.next_mirror_time, None) |
248 | source_tree.pull(target_tree.branch) |
249 | source_tree.commit('rev2', rev_id='rev2') |
250 | - self._mirror(db_source_branch, source_tree.branch) |
251 | # bundle_tree is effectively behaving like a local copy of |
252 | # db_source_branch, and is used to create the merge directive. |
253 | bundle_tree = source_tree.bzrdir.sprout('source').open_workingtree() |
254 | @@ -1030,41 +1005,34 @@ |
255 | def test_existing_stacked_branch(self): |
256 | # A bundle can update an existing branch if they are both stackable, |
257 | # and the source branch is stacked. |
258 | - self.useBzrBranches(real_server=True) |
259 | + self.useBzrBranches() |
260 | lp_source, message = self._createPreexistingSourceAndMessage( |
261 | target_format="1.9", source_format="1.9", set_stacked=True) |
262 | bmp = self._processMergeDirective(message) |
263 | # The branch merge proposal should use the existing db branch. |
264 | self.assertEqual(lp_source, bmp.source_branch) |
265 | - # Now the branch is now scheduled to be mirrorred. |
266 | - self.assertIsNot(None, lp_source.next_mirror_time) |
267 | - mirror = removeSecurityProxy(bmp.source_branch).getBzrBranch() |
268 | - # The mirrored copy of the branch has not been updated. |
269 | - self.assertEqual('rev2', mirror.last_revision()) |
270 | - hosted = self._openBazaarBranchAsClient(bmp.source_branch) |
271 | - # The hosted copy of the branch has been updated. |
272 | - self.assertEqual('rev3', hosted.last_revision()) |
273 | + bzr_branch = self._openBazaarBranchAsClient(bmp.source_branch) |
274 | + # The branch has been updated. |
275 | + self.assertEqual('rev3', bzr_branch.last_revision()) |
276 | |
277 | def test_existing_unstacked_branch(self): |
278 | # Even if the source and target are stackable, if the source is not |
279 | # stacked, we don't support stacking something that wasn't stacked |
280 | # before (yet). |
281 | - self.useBzrBranches(real_server=True) |
282 | + self.useBzrBranches() |
283 | lp_source, message = self._createPreexistingSourceAndMessage( |
284 | target_format="1.9", source_format="1.9") |
285 | bmp = self._processMergeDirective(message) |
286 | # The branch merge proposal should use the existing db branch. |
287 | self.assertEqual(lp_source, bmp.source_branch) |
288 | - # Now the branch is not scheduled to be mirrorred. |
289 | - self.assertIs(None, lp_source.next_mirror_time) |
290 | - hosted = self._openBazaarBranchAsClient(bmp.source_branch) |
291 | + bzr_branch = self._openBazaarBranchAsClient(bmp.source_branch) |
292 | # The hosted copy of the branch has not been updated. |
293 | - self.assertEqual('rev2', hosted.last_revision()) |
294 | + self.assertEqual('rev2', bzr_branch.last_revision()) |
295 | |
296 | def test_existing_branch_nonstackable_target(self): |
297 | # If the target branch is not stackable, then we don't pull any |
298 | # revisions. |
299 | - self.useBzrBranches(real_server=True) |
300 | + self.useBzrBranches() |
301 | lp_source, message = self._createPreexistingSourceAndMessage( |
302 | target_format="pack-0.92", source_format="1.9") |
303 | bmp = self._processMergeDirective(message) |
304 | @@ -1079,7 +1047,7 @@ |
305 | def test_existing_branch_nonstackable_source(self): |
306 | # If the source branch is not stackable, then we don't pull any |
307 | # revisions. |
308 | - self.useBzrBranches(real_server=True) |
309 | + self.useBzrBranches() |
310 | lp_source, message = self._createPreexistingSourceAndMessage( |
311 | target_format="1.9", source_format="pack-0.92") |
312 | bmp = self._processMergeDirective(message) |
313 | @@ -1093,7 +1061,7 @@ |
314 | |
315 | def test_forbidden_target(self): |
316 | """Specifying a branch in a forbidden target generates email.""" |
317 | - self.useBzrBranches(real_server=True) |
318 | + self.useBzrBranches() |
319 | branch, source, message = self._createTargetSourceAndBundle( |
320 | format="pack-0.92") |
321 | branch.product.setBranchVisibilityTeamPolicy( |
322 | |
323 | === modified file 'lib/lp/code/model/branch.py' |
324 | --- lib/lp/code/model/branch.py 2010-04-27 02:24:30 +0000 |
325 | +++ lib/lp/code/model/branch.py 2010-04-27 02:24:35 +0000 |
326 | @@ -460,14 +460,13 @@ |
327 | "Private branch %s has no public URL." % self.unique_name) |
328 | return compose_public_url(scheme, self.unique_name) |
329 | |
330 | - @property |
331 | - def warehouse_url(self): |
332 | + def getInternalBzrUrl(self): |
333 | """See `IBranch`.""" |
334 | - return 'lp-mirrored:///%s' % self.unique_name |
335 | + return 'lp-internal:///' + self.unique_name |
336 | |
337 | def getBzrBranch(self): |
338 | """See `IBranch`.""" |
339 | - return safe_open('lp-internal', 'lp-internal:///' + self.unique_name) |
340 | + return safe_open('lp-internal', self.getInternalBzrUrl()) |
341 | |
342 | @property |
343 | def displayname(self): |
344 | |
345 | === modified file 'lib/lp/code/model/branchjob.py' |
346 | --- lib/lp/code/model/branchjob.py 2010-04-27 02:24:30 +0000 |
347 | +++ lib/lp/code/model/branchjob.py 2010-04-27 02:24:35 +0000 |
348 | @@ -51,8 +51,8 @@ |
349 | from lp.code.model.diff import StaticDiff |
350 | from lp.code.model.revision import RevisionSet |
351 | from lp.codehosting.scanner.bzrsync import BzrSync |
352 | -from lp.codehosting.vfs import (branch_id_to_path, get_multi_server, |
353 | - get_scanner_server) |
354 | +from lp.codehosting.vfs import ( |
355 | + branch_id_to_path, get_rw_server, get_ro_server) |
356 | from lp.services.job.model.job import Job |
357 | from lp.services.job.interfaces.job import JobStatus |
358 | from lp.services.job.runner import BaseRunnableJob |
359 | @@ -284,7 +284,7 @@ |
360 | def contextManager(cls): |
361 | """See `IBranchScanJobSource`.""" |
362 | errorlog.globalErrorUtility.configure('branchscanner') |
363 | - cls.server = get_scanner_server() |
364 | + cls.server = get_ro_server() |
365 | cls.server.start_server() |
366 | yield |
367 | cls.server.stop_server() |
368 | @@ -313,7 +313,7 @@ |
369 | def contextManager(): |
370 | """See `IBranchUpgradeJobSource`.""" |
371 | errorlog.globalErrorUtility.configure('upgrade_branches') |
372 | - server = get_multi_server(write_hosted=True) |
373 | + server = get_rw_server() |
374 | server.start_server() |
375 | yield |
376 | server.stop_server() |
377 | @@ -325,7 +325,8 @@ |
378 | try: |
379 | upgrade_transport = get_transport(upgrade_branch_path) |
380 | upgrade_transport.mkdir('.bzr') |
381 | - source_branch_transport = get_transport(self.branch.getPullURL()) |
382 | + source_branch_transport = get_transport( |
383 | + self.branch.getInternalBzrUrl()) |
384 | source_branch_transport.clone('.bzr').copy_tree_to_transport( |
385 | upgrade_transport.clone('.bzr')) |
386 | upgrade_branch = BzrBranch.open_from_transport(upgrade_transport) |
387 | |
388 | === modified file 'lib/lp/code/model/branchmergeproposaljob.py' |
389 | --- lib/lp/code/model/branchmergeproposaljob.py 2010-04-06 03:37:16 +0000 |
390 | +++ lib/lp/code/model/branchmergeproposaljob.py 2010-04-27 02:24:35 +0000 |
391 | @@ -69,7 +69,7 @@ |
392 | from lp.code.mail.codereviewcomment import CodeReviewCommentMailer |
393 | from lp.code.model.branchmergeproposal import BranchMergeProposal |
394 | from lp.code.model.diff import PreviewDiff |
395 | -from lp.codehosting.vfs import get_multi_server, get_scanner_server |
396 | +from lp.codehosting.vfs import get_ro_server, get_rw_server |
397 | from lp.registry.interfaces.person import IPersonSet |
398 | from lp.services.job.model.job import Job |
399 | from lp.services.job.interfaces.job import JobStatus |
400 | @@ -322,7 +322,7 @@ |
401 | def contextManager(): |
402 | """See `IUpdatePreviewDiffJobSource`.""" |
403 | errorlog.globalErrorUtility.configure('update_preview_diffs') |
404 | - server = get_scanner_server() |
405 | + server = get_ro_server() |
406 | server.start_server() |
407 | yield |
408 | server.stop_server() |
409 | @@ -403,7 +403,7 @@ |
410 | raise AssertionError('No principal found for %s' % email_addr) |
411 | setupInteraction(principal, email_addr) |
412 | |
413 | - server = get_multi_server(write_hosted=True) |
414 | + server = get_rw_server() |
415 | server.start_server() |
416 | try: |
417 | return CodeHandler().processMergeProposal(message) |
418 | @@ -635,7 +635,7 @@ |
419 | def contextManager(): |
420 | """See `IJobSource`.""" |
421 | errorlog.globalErrorUtility.configure('merge_proposal_jobs') |
422 | - server = get_scanner_server() |
423 | + server = get_ro_server() |
424 | server.start_server() |
425 | yield |
426 | server.stop_server() |
427 | |
428 | === modified file 'lib/lp/code/model/diff.py' |
429 | --- lib/lp/code/model/diff.py 2010-02-17 19:10:51 +0000 |
430 | +++ lib/lp/code/model/diff.py 2010-04-27 02:24:35 +0000 |
431 | @@ -322,16 +322,15 @@ |
432 | :param bmp: The `BranchMergeProposal` to generate a `PreviewDiff` for. |
433 | :return: A `PreviewDiff`. |
434 | """ |
435 | - source_branch = Branch.open(bmp.source_branch.warehouse_url) |
436 | + source_branch = bmp.source_branch.getBzrBranch() |
437 | source_revision = source_branch.last_revision() |
438 | - target_branch = Branch.open(bmp.target_branch.warehouse_url) |
439 | + target_branch = bmp.target_branch.getBzrBranch() |
440 | target_revision = target_branch.last_revision() |
441 | preview = cls() |
442 | preview.source_revision_id = source_revision.decode('utf-8') |
443 | preview.target_revision_id = target_revision.decode('utf-8') |
444 | if bmp.prerequisite_branch is not None: |
445 | - prerequisite_branch = Branch.open( |
446 | - bmp.prerequisite_branch.warehouse_url) |
447 | + prerequisite_branch = bmp.prerequisite_branch.getBzrBranch() |
448 | else: |
449 | prerequisite_branch = None |
450 | preview.diff, conflicts = Diff.mergePreviewFromBranches( |
451 | |
452 | === modified file 'lib/lp/code/model/directbranchcommit.py' |
453 | --- lib/lp/code/model/directbranchcommit.py 2010-04-27 02:24:30 +0000 |
454 | +++ lib/lp/code/model/directbranchcommit.py 2010-04-27 02:24:35 +0000 |
455 | @@ -47,7 +47,7 @@ |
456 | is_locked = False |
457 | commit_builder = None |
458 | |
459 | - def __init__(self, db_branch, committer=None): |
460 | + def __init__(self, db_branch, committer=None, no_race_check=False): |
461 | """Create context for direct commit to branch. |
462 | |
463 | Before constructing a `DirectBranchCommit`, set up a server that |
464 | @@ -66,6 +66,8 @@ |
465 | |
466 | :param db_branch: a Launchpad `Branch` object. |
467 | :param committer: the `Person` writing to the branch. |
468 | + :param no_race_check: don't check for other commits before committing |
469 | + our changes, for use in tests. |
470 | """ |
471 | self.db_branch = db_branch |
472 | |
473 | @@ -75,6 +77,8 @@ |
474 | committer = db_branch.owner |
475 | self.committer = committer |
476 | |
477 | + self.no_race_check = no_race_check |
478 | + |
479 | # Directories we create on the branch, and their ids. |
480 | self.path_ids = {} |
481 | |
482 | @@ -155,6 +159,8 @@ |
483 | If it does, raise `ConcurrentUpdateError`. |
484 | """ |
485 | assert self.is_locked, "Getting revision on un-locked branch." |
486 | + if self.no_race_check: |
487 | + return |
488 | last_revision = self.bzrbranch.last_revision() |
489 | if last_revision != self.last_scanned_id: |
490 | raise ConcurrentUpdateError( |
491 | |
492 | === modified file 'lib/lp/code/model/tests/test_branch.py' |
493 | --- lib/lp/code/model/tests/test_branch.py 2010-04-27 02:24:30 +0000 |
494 | +++ lib/lp/code/model/tests/test_branch.py 2010-04-27 02:24:35 +0000 |
495 | @@ -2370,7 +2370,7 @@ |
496 | |
497 | def setUp(self): |
498 | TestCaseWithFactory.setUp(self) |
499 | - self.useBzrBranches(real_server=True, direct_database=True) |
500 | + self.useBzrBranches(direct_database=True) |
501 | |
502 | def test_simple(self): |
503 | # safe_open returns the underlying bzr branch of a database branch in |
504 | |
505 | === modified file 'lib/lp/code/model/tests/test_branchjob.py' |
506 | --- lib/lp/code/model/tests/test_branchjob.py 2010-04-27 02:24:30 +0000 |
507 | +++ lib/lp/code/model/tests/test_branchjob.py 2010-04-27 02:24:35 +0000 |
508 | @@ -100,7 +100,7 @@ |
509 | |
510 | def test_run_revision_ids(self): |
511 | """Ensure that run calculates revision ids.""" |
512 | - self.useBzrBranches() |
513 | + self.useBzrBranches(direct_database=True) |
514 | branch, tree = self.create_branch_and_tree() |
515 | tree.commit('First commit', rev_id='rev1') |
516 | job = BranchDiffJob.create(branch, '0', '1') |
517 | @@ -110,7 +110,7 @@ |
518 | |
519 | def test_run_diff_content(self): |
520 | """Ensure that run generates expected diff.""" |
521 | - self.useBzrBranches() |
522 | + self.useBzrBranches(direct_database=True) |
523 | |
524 | tree_location = tempfile.mkdtemp() |
525 | self.addCleanup(lambda: shutil.rmtree(tree_location)) |
526 | @@ -134,7 +134,7 @@ |
527 | |
528 | def test_run_is_idempotent(self): |
529 | """Ensure running an equivalent job emits the same diff.""" |
530 | - self.useBzrBranches() |
531 | + self.useBzrBranches(direct_database=True) |
532 | branch, tree = self.create_branch_and_tree() |
533 | tree.commit('First commit') |
534 | job1 = BranchDiffJob.create(branch, '0', '1') |
535 | @@ -149,7 +149,7 @@ |
536 | This diff contains an add of a file called hello.txt, with contents |
537 | "Hello World\n". |
538 | """ |
539 | - self.useBzrBranches() |
540 | + self.useBzrBranches(direct_database=True) |
541 | branch, tree = self.create_branch_and_tree() |
542 | first_revision = 'rev-1' |
543 | tree_transport = tree.bzrdir.root_transport |
544 | @@ -197,7 +197,7 @@ |
545 | |
546 | def test_run(self): |
547 | """Ensure the job scans the branch.""" |
548 | - self.useBzrBranches() |
549 | + self.useBzrBranches(direct_database=True) |
550 | |
551 | db_branch, bzr_tree = self.create_branch_and_tree() |
552 | bzr_tree.commit('First commit', rev_id='rev1') |
553 | @@ -249,9 +249,8 @@ |
554 | |
555 | def test_upgrades_branch(self): |
556 | """Ensure that a branch with an outdated format is upgraded.""" |
557 | - self.useBzrBranches() |
558 | - db_branch, tree = self.create_branch_and_tree( |
559 | - hosted=True, format='knit') |
560 | + self.useBzrBranches(direct_database=True) |
561 | + db_branch, tree = self.create_branch_and_tree(format='knit') |
562 | db_branch.branch_format = BranchFormat.BZR_BRANCH_5 |
563 | db_branch.repository_format = RepositoryFormat.BZR_KNIT_1 |
564 | self.assertEqual( |
565 | @@ -278,14 +277,13 @@ |
566 | def test_existing_bzr_backup(self): |
567 | # If the target branch already has a backup.bzr dir, the upgrade copy |
568 | # should remove it. |
569 | - self.useBzrBranches() |
570 | - db_branch, tree = self.create_branch_and_tree( |
571 | - hosted=True, format='knit') |
572 | + self.useBzrBranches(direct_database=True) |
573 | + db_branch, tree = self.create_branch_and_tree(format='knit') |
574 | db_branch.branch_format = BranchFormat.BZR_BRANCH_5 |
575 | db_branch.repository_format = RepositoryFormat.BZR_KNIT_1 |
576 | |
577 | # Add a fake backup.bzr dir |
578 | - source_branch_transport = get_transport(db_branch.getPullURL()) |
579 | + source_branch_transport = get_transport(db_branch.getInternalBzrUrl()) |
580 | source_branch_transport.mkdir('backup.bzr') |
581 | source_branch_transport.clone('.bzr').copy_tree_to_transport( |
582 | source_branch_transport.clone('backup.bzr')) |
583 | @@ -354,7 +352,7 @@ |
584 | |
585 | def test_perform_diff_performs_diff(self): |
586 | """Ensure that a diff is generated when perform_diff is True.""" |
587 | - self.useBzrBranches() |
588 | + self.useBzrBranches(direct_database=True) |
589 | branch, tree = self.create_branch_and_tree() |
590 | tree.bzrdir.root_transport.put_bytes('foo', 'bar\n') |
591 | tree.add('foo') |
592 | @@ -366,7 +364,7 @@ |
593 | |
594 | def test_perform_diff_ignored_for_revno_0(self): |
595 | """For the null revision, no diff is generated.""" |
596 | - self.useBzrBranches() |
597 | + self.useBzrBranches(direct_database=True) |
598 | branch, tree = self.create_branch_and_tree() |
599 | job = RevisionMailJob.create( |
600 | branch, 0, 'from@example.com', 'hello', True, 'subject') |
601 | @@ -465,7 +463,7 @@ |
602 | |
603 | def test_iterAddedMainline(self): |
604 | """iterAddedMainline iterates through mainline revisions.""" |
605 | - self.useBzrBranches() |
606 | + self.useBzrBranches(direct_database=True) |
607 | branch, tree = self.create3CommitsBranch() |
608 | job = RevisionsAddedJob.create(branch, 'rev1', 'rev2', '') |
609 | job.bzr_branch.lock_read() |
610 | @@ -475,7 +473,7 @@ |
611 | |
612 | def test_iterAddedNonMainline(self): |
613 | """iterAddedMainline drops non-mainline revisions.""" |
614 | - self.useBzrBranches() |
615 | + self.useBzrBranches(direct_database=True) |
616 | branch, tree = self.create3CommitsBranch() |
617 | tree.pull(tree.branch, overwrite=True, stop_revision='rev2') |
618 | tree.add_parent_tree_id('rev3') |
619 | @@ -489,7 +487,7 @@ |
620 | |
621 | def test_iterAddedMainline_order(self): |
622 | """iterAddedMainline iterates in commit order.""" |
623 | - self.useBzrBranches() |
624 | + self.useBzrBranches(direct_database=True) |
625 | branch, tree = self.create3CommitsBranch() |
626 | job = RevisionsAddedJob.create(branch, 'rev1', 'rev3', '') |
627 | job.bzr_branch.lock_read() |
628 | @@ -528,7 +526,7 @@ |
629 | that merges the others. |
630 | :param include_ghost:If true, add revision 2c as a ghost revision. |
631 | """ |
632 | - self.useBzrBranches() |
633 | + self.useBzrBranches(direct_database=True) |
634 | branch, tree = self.create_branch_and_tree() |
635 | tree.branch.nick = 'nicholas' |
636 | tree.commit('rev1') |
637 | @@ -558,7 +556,7 @@ |
638 | |
639 | def test_findRelatedBMP(self): |
640 | """The related branch merge proposals can be identified.""" |
641 | - self.useBzrBranches() |
642 | + self.useBzrBranches(direct_database=True) |
643 | target_branch, tree = self.create_branch_and_tree('tree') |
644 | desired_proposal = self.factory.makeBranchMergeProposal( |
645 | target_branch=target_branch) |
646 | @@ -577,7 +575,7 @@ |
647 | """findRelatedBMP only returns the most recent proposal for any |
648 | particular source branch. |
649 | """ |
650 | - self.useBzrBranches() |
651 | + self.useBzrBranches(direct_database=True) |
652 | target_branch, tree = self.create_branch_and_tree('tree') |
653 | the_past = datetime.datetime(2009, 1, 1, tzinfo=pytz.UTC) |
654 | old_proposal = self.factory.makeBranchMergeProposal( |
655 | @@ -614,7 +612,7 @@ |
656 | |
657 | def test_getRevisionMessage(self): |
658 | """getRevisionMessage provides a correctly-formatted message.""" |
659 | - self.useBzrBranches() |
660 | + self.useBzrBranches(direct_database=True) |
661 | branch, tree = self.makeBranchWithCommit() |
662 | job = RevisionsAddedJob.create(branch, 'rev1', 'rev1', '') |
663 | message = job.getRevisionMessage('rev1', 1) |
664 | @@ -785,7 +783,7 @@ |
665 | |
666 | def test_email_format(self): |
667 | """Contents of the email are as expected.""" |
668 | - self.useBzrBranches() |
669 | + self.useBzrBranches(direct_database=True) |
670 | db_branch, tree = self.create_branch_and_tree() |
671 | first_revision = 'rev-1' |
672 | tree.bzrdir.root_transport.put_bytes('hello.txt', 'Hello World\n') |
673 | @@ -844,7 +842,7 @@ |
674 | |
675 | def test_message_encoding(self): |
676 | """Test handling of non-ASCII commit messages.""" |
677 | - self.useBzrBranches() |
678 | + self.useBzrBranches(direct_database=True) |
679 | db_branch, tree = self.create_branch_and_tree() |
680 | rev_id = 'rev-1' |
681 | tree.commit( |
682 | @@ -868,7 +866,7 @@ |
683 | |
684 | def test_getMailerForRevision(self): |
685 | """The mailer for the revision is as expected.""" |
686 | - self.useBzrBranches() |
687 | + self.useBzrBranches(direct_database=True) |
688 | branch, tree = self.makeBranchWithCommit() |
689 | revision = tree.branch.repository.get_revision('rev1') |
690 | job = RevisionsAddedJob.create(branch, 'rev1', 'rev1', '') |
691 | @@ -881,7 +879,7 @@ |
692 | def test_only_nodiff_subscribers_means_no_diff_generated(self): |
693 | """No diff is generated when no subscribers need it.""" |
694 | self.layer.switchDbUser('launchpad') |
695 | - self.useBzrBranches() |
696 | + self.useBzrBranches(direct_database=True) |
697 | branch, tree = self.create_branch_and_tree() |
698 | subscriptions = branch.getSubscriptionsByLevel( |
699 | [BranchSubscriptionNotificationLevel.FULL]) |
700 | @@ -911,7 +909,7 @@ |
701 | in which case an arbitrary unique string is used. |
702 | :returns: The revision of the first commit. |
703 | """ |
704 | - self.useBzrBranches() |
705 | + self.useBzrBranches(direct_database=True) |
706 | self.branch, self.tree = self.create_branch_and_tree() |
707 | return self._commitFilesToTree(files, 'First commit') |
708 | |
709 | |
710 | === modified file 'lib/lp/code/model/tests/test_branchmergeproposaljobs.py' |
711 | --- lib/lp/code/model/tests/test_branchmergeproposaljobs.py 2010-04-06 03:37:16 +0000 |
712 | +++ lib/lp/code/model/tests/test_branchmergeproposaljobs.py 2010-04-27 02:24:35 +0000 |
713 | @@ -102,7 +102,7 @@ |
714 | |
715 | def test_run_sends_email(self): |
716 | """MergeProposalCreationJob.run sends an email.""" |
717 | - self.useBzrBranches() |
718 | + self.useBzrBranches(direct_database=True) |
719 | bmp = self.createProposalWithEmptyBranches() |
720 | job = MergeProposalCreatedJob.create(bmp) |
721 | self.assertEqual([], pop_notifications()) |
722 | @@ -123,7 +123,7 @@ |
723 | |
724 | def test_MergeProposalCreateJob_with_sourcepackage_branch(self): |
725 | """Jobs for merge proposals with sourcepackage branches work.""" |
726 | - self.useBzrBranches() |
727 | + self.useBzrBranches(direct_database=True) |
728 | bmp = self.factory.makeBranchMergeProposal( |
729 | target_branch=self.factory.makePackageBranch()) |
730 | tree = self.create_branch_and_tree(db_branch=bmp.target_branch)[1] |
731 | @@ -145,7 +145,7 @@ |
732 | verifyObject(IUpdatePreviewDiffJobSource, UpdatePreviewDiffJob) |
733 | |
734 | def test_run(self): |
735 | - self.useBzrBranches() |
736 | + self.useBzrBranches(direct_database=True) |
737 | bmp = self.createExampleMerge()[0] |
738 | job = UpdatePreviewDiffJob.create(bmp) |
739 | self.factory.makeRevisionsForBranch(bmp.source_branch, count=1) |
740 | @@ -179,7 +179,7 @@ |
741 | email.get_payload(decode=True)) |
742 | |
743 | def test_10_minute_lease(self): |
744 | - self.useBzrBranches() |
745 | + self.useBzrBranches(direct_database=True) |
746 | bmp = self.createExampleMerge()[0] |
747 | job = UpdatePreviewDiffJob.create(bmp) |
748 | job.acquireLease() |
749 | |
750 | === modified file 'lib/lp/code/model/tests/test_diff.py' |
751 | --- lib/lp/code/model/tests/test_diff.py 2010-04-27 02:24:30 +0000 |
752 | +++ lib/lp/code/model/tests/test_diff.py 2010-04-27 02:24:35 +0000 |
753 | @@ -11,10 +11,12 @@ |
754 | import logging |
755 | from unittest import TestLoader |
756 | |
757 | -from bzrlib.branch import Branch |
758 | from bzrlib import trace |
759 | + |
760 | import transaction |
761 | |
762 | +from zope.security.proxy import removeSecurityProxy |
763 | + |
764 | from canonical.launchpad.interfaces.launchpad import NotFoundError |
765 | from canonical.launchpad.webapp import canonical_url, errorlog |
766 | from canonical.launchpad.webapp.testing import verifyObject |
767 | @@ -44,7 +46,7 @@ |
768 | |
769 | This will create or modify the file, as needed. |
770 | """ |
771 | - committer = DirectBranchCommit(branch) |
772 | + committer = DirectBranchCommit(branch, no_race_check=True) |
773 | committer.writeFile(path, contents) |
774 | try: |
775 | return committer.commit('committing') |
776 | @@ -53,7 +55,7 @@ |
777 | |
778 | def createExampleMerge(self): |
779 | """Create a merge proposal with conflicts and updates.""" |
780 | - self.useBzrBranches() |
781 | + self.useBzrBranches(direct_database=True) |
782 | bmp = self.factory.makeBranchMergeProposal() |
783 | # Make the branches of the merge proposal look good as far as the |
784 | # model is concerned. |
785 | @@ -81,7 +83,7 @@ |
786 | |
787 | def preparePrerequisiteMerge(self, bmp=None): |
788 | """Prepare a merge scenario with a prerequisite branch.""" |
789 | - self.useBzrBranches() |
790 | + self.useBzrBranches(direct_database=True) |
791 | if bmp is None: |
792 | target = self.factory.makeBranch() |
793 | prerequisite = self.factory.makeBranch() |
794 | @@ -159,8 +161,8 @@ |
795 | def test_mergePreviewFromBranches(self): |
796 | # mergePreviewFromBranches generates the correct diff. |
797 | bmp, source_rev_id, target_rev_id = self.createExampleMerge() |
798 | - source_branch = Branch.open(bmp.source_branch.warehouse_url) |
799 | - target_branch = Branch.open(bmp.target_branch.warehouse_url) |
800 | + source_branch = bmp.source_branch.getBzrBranch() |
801 | + target_branch = bmp.target_branch.getBzrBranch() |
802 | diff, conflicts = Diff.mergePreviewFromBranches( |
803 | source_branch, source_rev_id, target_branch) |
804 | transaction.commit() |
805 | @@ -280,7 +282,7 @@ |
806 | |
807 | def test_acquire_existing(self): |
808 | """Ensure that acquire returns the existing StaticDiff.""" |
809 | - self.useBzrBranches() |
810 | + self.useBzrBranches(direct_database=True) |
811 | branch, tree = self.create_branch_and_tree() |
812 | tree.commit('First commit', rev_id='rev1') |
813 | diff1 = StaticDiff.acquire('null:', 'rev1', tree.branch.repository) |
814 | @@ -289,7 +291,7 @@ |
815 | |
816 | def test_acquire_existing_different_repo(self): |
817 | """The existing object is used even if the repository is different.""" |
818 | - self.useBzrBranches() |
819 | + self.useBzrBranches(direct_database=True) |
820 | branch1, tree1 = self.create_branch_and_tree('tree1') |
821 | tree1.commit('First commit', rev_id='rev1') |
822 | branch2, tree2 = self.create_branch_and_tree('tree2') |
823 | @@ -300,7 +302,7 @@ |
824 | |
825 | def test_acquire_nonexisting(self): |
826 | """A new object is created if there is no existant matching object.""" |
827 | - self.useBzrBranches() |
828 | + self.useBzrBranches(direct_database=True) |
829 | branch, tree = self.create_branch_and_tree() |
830 | tree.commit('First commit', rev_id='rev1') |
831 | tree.commit('Next commit', rev_id='rev2') |
832 | @@ -428,7 +430,7 @@ |
833 | |
834 | def test_fromPreviewDiff_with_no_conflicts(self): |
835 | """Test fromPreviewDiff when no conflicts are present.""" |
836 | - self.useBzrBranches() |
837 | + self.useBzrBranches(direct_database=True) |
838 | bmp = self.factory.makeBranchMergeProposal() |
839 | bzr_target = self.createBzrBranch(bmp.target_branch) |
840 | self.commitFile(bmp.target_branch, 'foo', 'a\n') |
841 | |
842 | === modified file 'lib/lp/code/scripts/tests/test_create_merge_proposals.py' |
843 | --- lib/lp/code/scripts/tests/test_create_merge_proposals.py 2010-04-01 05:08:47 +0000 |
844 | +++ lib/lp/code/scripts/tests/test_create_merge_proposals.py 2010-04-27 02:24:35 +0000 |
845 | @@ -70,22 +70,16 @@ |
846 | 'INFO Creating lockfile: /var/lock/launchpad-create_merge_proposals.lock\n' |
847 | 'INFO Ran 1 CreateMergeProposalJobs.\n', stderr) |
848 | self.assertEqual('', stdout) |
849 | - # The hosted location should be populated, not the mirror. |
850 | bmp = branch.landing_candidates[0] |
851 | - self.assertRaises( |
852 | - bzr_errors.NotBranchError, Branch.open, |
853 | - bmp.source_branch.warehouse_url) |
854 | - local_source = Branch.open(bmp.source_branch.getPullURL()) |
855 | - # The hosted branch has the correct last revision. |
856 | + local_source = bmp.source_branch.getBzrBranch() |
857 | + # The branch has the correct last revision. |
858 | self.assertEqual( |
859 | source.branch.last_revision(), local_source.last_revision()) |
860 | - # A mirror should be scheduled. |
861 | - self.assertIsNot(None, bmp.source_branch.next_mirror_time) |
862 | |
863 | def disabled_test_merge_directive_with_bundle(self): |
864 | """Merge directives with bundles generate branches.""" |
865 | # XXX TimPenhey 2009-04-01 bug 352800 |
866 | - self.useBzrBranches(real_server=True) |
867 | + self.useBzrBranches() |
868 | branch, tree = self.create_branch_and_tree() |
869 | source = self.createJob(branch, tree) |
870 | self.jobOutputCheck(branch, source) |
871 | @@ -93,7 +87,7 @@ |
872 | def disabled_test_merge_directive_with_project(self): |
873 | """Bundles are handled when the target branch has a project.""" |
874 | # XXX TimPenhey 2009-04-01 bug 352800 |
875 | - self.useBzrBranches(real_server=True) |
876 | + self.useBzrBranches() |
877 | product = self.factory.makeProduct(project=self.factory.makeProject()) |
878 | branch, tree = self.create_branch_and_tree(product=product) |
879 | source = self.createJob(branch, tree) |
880 | |
881 | === modified file 'lib/lp/code/scripts/tests/test_scan_branches.py' |
882 | --- lib/lp/code/scripts/tests/test_scan_branches.py 2010-04-01 04:29:46 +0000 |
883 | +++ lib/lp/code/scripts/tests/test_scan_branches.py 2010-04-27 02:24:35 +0000 |
884 | @@ -26,8 +26,7 @@ |
885 | |
886 | def make_branch_with_commits_and_scan_job(self, db_branch): |
887 | """Create a branch from a db_branch, make commits and a scan job.""" |
888 | - target, target_tree = self.create_branch_and_tree( |
889 | - db_branch=db_branch) |
890 | + target, target_tree = self.create_branch_and_tree(db_branch=db_branch) |
891 | target_tree.commit('First commit', rev_id='rev1') |
892 | target_tree.commit('Second commit', rev_id='rev2') |
893 | target_tree.commit('Third commit', rev_id='rev3') |
894 | @@ -45,7 +44,7 @@ |
895 | |
896 | def test_scan_branch(self): |
897 | """Test that scan branches adds revisions to the database.""" |
898 | - self.useBzrBranches(real_server=True) |
899 | + self.useBzrBranches() |
900 | |
901 | db_branch = self.factory.makeAnyBranch() |
902 | self.make_branch_with_commits_and_scan_job(db_branch) |
903 | @@ -70,7 +69,7 @@ |
904 | |
905 | def test_scan_packagebranch(self): |
906 | """Test that scan_branches can scan package branches.""" |
907 | - self.useBzrBranches(real_server=True) |
908 | + self.useBzrBranches() |
909 | |
910 | db_branch = self.factory.makePackageBranch() |
911 | self.make_branch_with_commits_and_scan_job(db_branch) |
912 | |
913 | === modified file 'lib/lp/code/scripts/tests/test_upgrade_branches.py' |
914 | --- lib/lp/code/scripts/tests/test_upgrade_branches.py 2010-04-01 04:37:30 +0000 |
915 | +++ lib/lp/code/scripts/tests/test_upgrade_branches.py 2010-04-27 02:24:35 +0000 |
916 | @@ -22,9 +22,8 @@ |
917 | |
918 | def test_upgrade_branches(self): |
919 | """Test that upgrade_branches upgrades branches.""" |
920 | - self.useBzrBranches(real_server=True) |
921 | - target, target_tree = self.create_branch_and_tree( |
922 | - hosted=True, format='knit') |
923 | + self.useBzrBranches() |
924 | + target, target_tree = self.create_branch_and_tree(format='knit') |
925 | target.branch_format = BranchFormat.BZR_BRANCH_5 |
926 | target.repository_format = RepositoryFormat.BZR_KNIT_1 |
927 | |
928 | @@ -49,10 +48,10 @@ |
929 | |
930 | def test_upgrade_branches_packagebranch(self): |
931 | """Test that upgrade_branches can upgrade package branches.""" |
932 | - self.useBzrBranches(real_server=True) |
933 | + self.useBzrBranches() |
934 | package_branch = self.factory.makePackageBranch() |
935 | target, target_tree = self.create_branch_and_tree( |
936 | - db_branch=package_branch, hosted=True, format='knit') |
937 | + db_branch=package_branch, format='knit') |
938 | target.branch_format = BranchFormat.BZR_BRANCH_5 |
939 | target.repository_format = RepositoryFormat.BZR_KNIT_1 |
940 | |
941 | |
942 | === modified file 'lib/lp/codehosting/inmemory.py' |
943 | --- lib/lp/codehosting/inmemory.py 2010-04-27 02:24:30 +0000 |
944 | +++ lib/lp/codehosting/inmemory.py 2010-04-27 02:24:35 +0000 |
945 | @@ -433,7 +433,7 @@ |
946 | if branch is None: |
947 | branch = self.makeBranch(product=product) |
948 | product.development_focus.branch = branch |
949 | - branch.last_mirrored = 'rev1' |
950 | + branch.last_mirrored_id = 'rev1' |
951 | return branch |
952 | |
953 | def enableDefaultStackingForPackage(self, package, branch): |
954 | @@ -445,7 +445,7 @@ |
955 | """ |
956 | package.development_version.setBranch( |
957 | PackagePublishingPocket.RELEASE, branch, branch.owner) |
958 | - branch.last_mirrored = 'rev1' |
959 | + branch.last_mirrored_id = 'rev1' |
960 | return branch |
961 | |
962 | |
963 | |
964 | === modified file 'lib/lp/codehosting/scanner/bzrsync.py' |
965 | --- lib/lp/codehosting/scanner/bzrsync.py 2010-04-27 02:24:30 +0000 |
966 | +++ lib/lp/codehosting/scanner/bzrsync.py 2010-04-27 02:24:35 +0000 |
967 | @@ -79,8 +79,7 @@ |
968 | """Synchronize the database with a Bazaar branch, handling locking. |
969 | """ |
970 | if bzr_branch is None: |
971 | - bzr_branch = BranchMirrorer(WarehouseBranchPolicy()).open( |
972 | - self.db_branch.warehouse_url) |
973 | + bzr_branch = self.db_branch.getBzrBranch() |
974 | bzr_branch.lock_read() |
975 | try: |
976 | self.syncBranch(bzr_branch) |
977 | |
978 | === modified file 'lib/lp/codehosting/tests/test_branchdistro.py' |
979 | --- lib/lp/codehosting/tests/test_branchdistro.py 2010-04-27 02:24:30 +0000 |
980 | +++ lib/lp/codehosting/tests/test_branchdistro.py 2010-04-27 02:24:35 +0000 |
981 | @@ -108,7 +108,7 @@ |
982 | |
983 | def setUp(self): |
984 | TestCaseWithFactory.setUp(self) |
985 | - self.useBzrBranches(real_server=True, direct_database=True) |
986 | + self.useBzrBranches(direct_database=True) |
987 | |
988 | def makeOfficialPackageBranch(self, distroseries=None): |
989 | """Make an official package branch with an underlying bzr branch.""" |
990 | |
991 | === modified file 'lib/lp/codehosting/tests/test_jobs.py' |
992 | --- lib/lp/codehosting/tests/test_jobs.py 2009-06-30 16:56:07 +0000 |
993 | +++ lib/lp/codehosting/tests/test_jobs.py 2010-04-27 02:24:35 +0000 |
994 | @@ -25,7 +25,7 @@ |
995 | |
996 | def test_runJob_generates_diff(self): |
997 | """Ensure that a diff is actually generated in this environment.""" |
998 | - self.useBzrBranches() |
999 | + self.useBzrBranches(direct_database=True) |
1000 | branch, tree = self.create_branch_and_tree() |
1001 | branch.subscribe(branch.registrant, |
1002 | BranchSubscriptionNotificationLevel.FULL, |
1003 | |
1004 | === modified file 'lib/lp/codehosting/vfs/__init__.py' |
1005 | --- lib/lp/codehosting/vfs/__init__.py 2010-04-27 02:24:30 +0000 |
1006 | +++ lib/lp/codehosting/vfs/__init__.py 2010-04-27 02:24:35 +0000 |
1007 | @@ -10,6 +10,7 @@ |
1008 | 'BranchFileSystemClient', |
1009 | 'get_lp_server', |
1010 | 'get_multi_server', |
1011 | + 'get_ro_server', |
1012 | 'get_rw_server', |
1013 | 'get_scanner_server', |
1014 | 'LaunchpadServer', |
1015 | @@ -18,7 +19,7 @@ |
1016 | |
1017 | from lp.codehosting.vfs.branchfs import ( |
1018 | AsyncLaunchpadTransport, branch_id_to_path, get_lp_server, |
1019 | - get_multi_server, get_rw_server, get_scanner_server, LaunchpadServer, |
1020 | - make_branch_mirrorer) |
1021 | + get_multi_server, get_ro_server, get_rw_server, get_scanner_server, |
1022 | + LaunchpadServer, make_branch_mirrorer) |
1023 | from lp.codehosting.vfs.branchfsclient import ( |
1024 | BlockingProxy,BranchFileSystemClient) |
1025 | |
1026 | === modified file 'lib/lp/codehosting/vfs/branchfs.py' |
1027 | --- lib/lp/codehosting/vfs/branchfs.py 2010-04-27 02:24:30 +0000 |
1028 | +++ lib/lp/codehosting/vfs/branchfs.py 2010-04-27 02:24:35 +0000 |
1029 | @@ -55,6 +55,7 @@ |
1030 | 'DirectDatabaseLaunchpadServer', |
1031 | 'get_lp_server', |
1032 | 'get_multi_server', |
1033 | + 'get_ro_server', |
1034 | 'get_rw_server', |
1035 | 'get_scanner_server', |
1036 | 'make_branch_mirrorer', |
1037 | @@ -167,15 +168,16 @@ |
1038 | return absolute_path.endswith('/.bzr/branch/lock/held') |
1039 | |
1040 | |
1041 | -def get_scanner_server(): |
1042 | +def get_ro_server(): |
1043 | """Get a Launchpad internal server for scanning branches.""" |
1044 | proxy = xmlrpclib.ServerProxy(config.codehosting.codehosting_endpoint) |
1045 | codehosting_endpoint = BlockingProxy(proxy) |
1046 | branch_transport = get_readonly_transport( |
1047 | get_transport(config.codehosting.internal_branch_by_id_root)) |
1048 | return LaunchpadInternalServer( |
1049 | - 'lp-mirrored:///', codehosting_endpoint, branch_transport) |
1050 | + 'lp-internal:///', codehosting_endpoint, branch_transport) |
1051 | |
1052 | +get_scanner_server = get_ro_server |
1053 | |
1054 | def get_rw_server(direct_database=False): |
1055 | """Get a server that can write to the Launchpad branch vfs. |
1056 | |
1057 | === modified file 'lib/lp/testing/__init__.py' |
1058 | --- lib/lp/testing/__init__.py 2010-04-27 02:24:30 +0000 |
1059 | +++ lib/lp/testing/__init__.py 2010-04-27 02:24:35 +0000 |
1060 | @@ -412,6 +412,7 @@ |
1061 | from lp.testing.factory import LaunchpadObjectFactory |
1062 | self.factory = LaunchpadObjectFactory() |
1063 | self.direct_database_server = False |
1064 | + self._use_bzr_branch_called = False |
1065 | |
1066 | def getUserBrowser(self, url=None, user=None, password='test'): |
1067 | """Return a Browser logged in as a fresh user, maybe opened at `url`. |
1068 | @@ -478,9 +479,10 @@ |
1069 | :param db_branch: The database branch to create the branch for. |
1070 | :param parent: If supplied, the bzr branch to use as a parent. |
1071 | """ |
1072 | - bzr_branch = self.createBranchAtURL(db_branch.warehouse_url) |
1073 | + bzr_branch = self.createBranchAtURL(db_branch.getInternalBzrUrl()) |
1074 | if parent: |
1075 | bzr_branch.pull(parent) |
1076 | + removeSecurityProxy(db_branch).last_scanned_id = bzr_branch.last_revision() |
1077 | return bzr_branch |
1078 | |
1079 | @staticmethod |
1080 | @@ -537,6 +539,11 @@ |
1081 | :param direct_database: If true, translate branch locations by |
1082 | directly querying the database, not the internal XML-RPC server. |
1083 | """ |
1084 | + if self._use_bzr_branch_called: |
1085 | + if direct_database != self.direct_database_server: |
1086 | + raise AssertionError("XXX") |
1087 | + return |
1088 | + self._use_bzr_branch_called = True |
1089 | self.useTempBzrHome() |
1090 | self.direct_database_server = direct_database |
1091 | server = get_rw_server(direct_database=direct_database) |
1092 | |
1093 | === modified file 'lib/lp/testing/factory.py' |
1094 | --- lib/lp/testing/factory.py 2010-04-27 02:24:30 +0000 |
1095 | +++ lib/lp/testing/factory.py 2010-04-27 02:24:35 +0000 |
1096 | @@ -2284,8 +2284,8 @@ |
1097 | md = MergeDirective2.from_objects( |
1098 | source_branch.repository, source_branch.last_revision(), |
1099 | public_branch=source_branch.get_public_branch(), |
1100 | - target_branch=target_branch.warehouse_url, |
1101 | - local_target_branch=target_branch.warehouse_url, time=0, |
1102 | + target_branch=target_branch.getInternalBzrUrl(), |
1103 | + local_target_branch=target_branch.getInternalBzrUrl(), time=0, |
1104 | timezone=0) |
1105 | email = None |
1106 | if sender is not None: |
1107 | |
1108 | === modified file 'lib/lp/translations/tests/test_translationtemplatesbuildjob.py' |
1109 | --- lib/lp/translations/tests/test_translationtemplatesbuildjob.py 2010-04-27 02:24:30 +0000 |
1110 | +++ lib/lp/translations/tests/test_translationtemplatesbuildjob.py 2010-04-27 02:24:35 +0000 |
1111 | @@ -149,7 +149,7 @@ |
1112 | def _makeTranslationBranch(self, fake_pottery_compatible=None): |
1113 | """Create a branch that provides translations for a productseries.""" |
1114 | if fake_pottery_compatible is None: |
1115 | - self.useBzrBranches() |
1116 | + self.useBzrBranches(direct_database=True) |
1117 | branch, tree = self.create_branch_and_tree() |
1118 | else: |
1119 | branch = self.factory.makeAnyBranch() |
1120 | @@ -219,6 +219,7 @@ |
1121 | # If the feature is enabled, a TipChanged event for a branch that |
1122 | # generates templates will schedule a templates build. |
1123 | branch = self._makeTranslationBranch() |
1124 | + removeSecurityProxy(branch).last_scanned_id = 'null:' |
1125 | commit = DirectBranchCommit(branch) |
1126 | commit.writeFile('POTFILES.in', 'foo') |
1127 | commit.commit('message') |
I know that it is not worth it now, but in code/model/ tests/test_ branchjob. py you could database= True.
lib/lp/
have just overridden the inherited useBzrBranches method
to make it always specify direct_
It may be an interesting count, but which is used more? database= True or False?
direct_
lib/lp/ testing/ __init_ _.py "XXX")
- you still have: raise AssertionError(
removeSecurityP roxy(branch) .last_scanned_ id = 'null:'
- is there a bzrlib constant we can use here?
And yes, it was a pretty boring branch to review. Great
to see a consistent use of getInternalBzrUrl and getBzrBranch.