Merge lp:~thumper/launchpad/branch-distro-avoid-scan into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 11607
Proposed branch: lp:~thumper/launchpad/branch-distro-avoid-scan
Merge into: lp:launchpad
Prerequisite: lp:~thumper/launchpad/fix-branchChanged-scan-request
Diff against target: 138 lines (+65/-1)
3 files modified
database/schema/security.cfg (+2/-0)
lib/lp/codehosting/branchdistro.py (+23/-1)
lib/lp/codehosting/tests/test_branchdistro.py (+40/-0)
To merge this branch: bzr merge lp:~thumper/launchpad/branch-distro-avoid-scan
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+36103@code.launchpad.net

Commit message

Copy the branch revision and revision details for the branch during new branch creation when running branch-distro.py.

Description of the change

When branching the distro, we don't want to tie up the scanner for three days, like we have in the past. Given that we are just copying the details of one branch to the other, we can do that as we create the branches.

tests:
  lp.codehosting.tests.test_branchdistro

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

Nice! r=me.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg 2010-09-21 23:09:42 +0000
+++ database/schema/security.cfg 2010-09-22 08:59:46 +0000
@@ -629,6 +629,7 @@
629[branch-distro]629[branch-distro]
630type=user630type=user
631public.branch = SELECT, INSERT, UPDATE631public.branch = SELECT, INSERT, UPDATE
632public.branchrevision = SELECT, INSERT
632public.branchsubscription = SELECT, INSERT633public.branchsubscription = SELECT, INSERT
633public.distribution = SELECT634public.distribution = SELECT
634public.distroseries = SELECT635public.distroseries = SELECT
@@ -636,6 +637,7 @@
636public.karmaaction = SELECT637public.karmaaction = SELECT
637public.person = SELECT638public.person = SELECT
638public.product = SELECT639public.product = SELECT
640public.revision = SELECT
639public.seriessourcepackagebranch = SELECT, INSERT, DELETE641public.seriessourcepackagebranch = SELECT, INSERT, DELETE
640public.sourcepackagename = SELECT642public.sourcepackagename = SELECT
641public.teamparticipation = SELECT643public.teamparticipation = SELECT
642644
=== modified file 'lib/lp/codehosting/branchdistro.py'
--- lib/lp/codehosting/branchdistro.py 2010-09-21 03:47:19 +0000
+++ lib/lp/codehosting/branchdistro.py 2010-09-22 08:59:46 +0000
@@ -27,7 +27,7 @@
27from zope.component import getUtility27from zope.component import getUtility
2828
29from canonical.config import config29from canonical.config import config
30from canonical.launchpad.interfaces import ILaunchpadCelebrities30from canonical.launchpad.interfaces import ILaunchpadCelebrities, IMasterStore
31from lp.code.enums import BranchLifecycleStatus, BranchType31from lp.code.enums import BranchLifecycleStatus, BranchType
32from lp.code.errors import BranchExists32from lp.code.errors import BranchExists
33from lp.code.interfaces.branchcollection import IAllBranches33from lp.code.interfaces.branchcollection import IAllBranches
@@ -35,6 +35,7 @@
35from lp.code.interfaces.seriessourcepackagebranch import (35from lp.code.interfaces.seriessourcepackagebranch import (
36 IFindOfficialBranchLinks,36 IFindOfficialBranchLinks,
37 )37 )
38from lp.code.model.branchrevision import BranchRevision
38from lp.codehosting.vfs import branch_id_to_path39from lp.codehosting.vfs import branch_id_to_path
39from lp.registry.interfaces.distribution import IDistributionSet40from lp.registry.interfaces.distribution import IDistributionSet
40from lp.registry.interfaces.pocket import PackagePublishingPocket41from lp.registry.interfaces.pocket import PackagePublishingPocket
@@ -350,4 +351,25 @@
350 switch_branches(351 switch_branches(
351 config.codehosting.mirrored_branches_root,352 config.codehosting.mirrored_branches_root,
352 'lp-internal', old_db_branch, new_db_branch)353 'lp-internal', old_db_branch, new_db_branch)
354 # Directly copy the branch revisions from the old branch to the new branch.
355 store = IMasterStore(BranchRevision)
356 store.execute(
357 """
358 INSERT INTO BranchRevision (branch, revision, sequence)
359 SELECT %s, BranchRevision.revision, BranchRevision.sequence
360 FROM BranchRevision
361 WHERE branch = %s
362 """ % (new_db_branch.id, old_db_branch.id))
363
364 # Update the scanned details first, that way when hooking into
365 # branchChanged, it won't try to create a new scan job.
366 tip_revision = old_db_branch.getTipRevision()
367 new_db_branch.updateScannedDetails(
368 tip_revision, old_db_branch.revision_count)
369 new_db_branch.branchChanged(
370 '', tip_revision.revision_id,
371 old_db_branch.control_format,
372 old_db_branch.branch_format,
373 old_db_branch.repository_format)
374 transaction.commit()
353 return new_db_branch375 return new_db_branch
354376
=== modified file 'lib/lp/codehosting/tests/test_branchdistro.py'
--- lib/lp/codehosting/tests/test_branchdistro.py 2010-09-20 04:32:49 +0000
+++ lib/lp/codehosting/tests/test_branchdistro.py 2010-09-22 08:59:46 +0000
@@ -27,6 +27,8 @@
27from bzrlib.transport.chroot import ChrootServer27from bzrlib.transport.chroot import ChrootServer
28from lazr.uri import URI28from lazr.uri import URI
29import transaction29import transaction
30from zope.component import getUtility
31from zope.security.proxy import removeSecurityProxy
3032
31from canonical.config import config33from canonical.config import config
32from canonical.launchpad.scripts.logger import (34from canonical.launchpad.scripts.logger import (
@@ -35,6 +37,7 @@
35 )37 )
36from canonical.testing.layers import LaunchpadZopelessLayer38from canonical.testing.layers import LaunchpadZopelessLayer
37from lp.code.enums import BranchLifecycleStatus39from lp.code.enums import BranchLifecycleStatus
40from lp.code.interfaces.branchjob import IBranchScanJobSource
38from lp.codehosting.branchdistro import (41from lp.codehosting.branchdistro import (
39 DistroBrancher,42 DistroBrancher,
40 switch_branches,43 switch_branches,
@@ -127,6 +130,7 @@
127 """Make an official package branch with an underlying bzr branch."""130 """Make an official package branch with an underlying bzr branch."""
128 db_branch = self.factory.makePackageBranch(distroseries=distroseries)131 db_branch = self.factory.makePackageBranch(distroseries=distroseries)
129 db_branch.sourcepackage.setBranch(RELEASE, db_branch, db_branch.owner)132 db_branch.sourcepackage.setBranch(RELEASE, db_branch, db_branch.owner)
133 self.factory.makeRevisionsForBranch(db_branch, count=1)
130134
131 transaction.commit()135 transaction.commit()
132136
@@ -241,6 +245,42 @@
241 self.assertEqual(245 self.assertEqual(
242 BranchLifecycleStatus.MATURE, db_branch.lifecycle_status)246 BranchLifecycleStatus.MATURE, db_branch.lifecycle_status)
243247
248 def test_makeOneNewBranch_avoids_need_for_scan(self):
249 # makeOneNewBranch sets the appropriate properties of the new branch
250 # so a scan is unnecessary. This can be done because we are making a
251 # copy of the source branch.
252 db_branch = self.makeOfficialPackageBranch()
253 self.factory.makeRevisionsForBranch(db_branch, count=10)
254 tip_revision_id = db_branch.last_mirrored_id
255 self.assertIsNot(None, tip_revision_id)
256 # The makeRevisionsForBranch will create a scan job for the db_branch.
257 # We don't really care about that, but what we do care about is that
258 # no new jobs are created.
259 existing_scan_job_count = len(
260 list(getUtility(IBranchScanJobSource).iterReady()))
261
262 brancher = self.makeNewSeriesAndBrancher(db_branch.distroseries)
263 brancher.makeOneNewBranch(db_branch)
264 new_branch = brancher.new_distroseries.getSourcePackage(
265 db_branch.sourcepackage.name).getBranch(RELEASE)
266
267 self.assertEqual(tip_revision_id, new_branch.last_mirrored_id)
268 self.assertEqual(tip_revision_id, new_branch.last_scanned_id)
269 # Make sure that the branch revisions have been copied.
270 old_ancestry, old_history = removeSecurityProxy(
271 db_branch).getScannerData()
272 new_ancestry, new_history = removeSecurityProxy(
273 new_branch).getScannerData()
274 self.assertEqual(old_ancestry, new_ancestry)
275 self.assertEqual(old_history, new_history)
276 self.assertFalse(new_branch.pending_writes)
277 # The script doesn't have permission to create branch jobs, but just
278 # to be insanely paradoid.
279 transaction.commit()
280 self.layer.switchDbUser('launchpad')
281 scan_jobs = list(getUtility(IBranchScanJobSource).iterReady())
282 self.assertEqual(existing_scan_job_count, len(scan_jobs))
283
244 def test_makeOneNewBranch_inconsistent_branch(self):284 def test_makeOneNewBranch_inconsistent_branch(self):
245 # makeOneNewBranch skips over an inconsistent official package branch285 # makeOneNewBranch skips over an inconsistent official package branch
246 # (see `checkConsistentOfficialPackageBranch` for precisely what an286 # (see `checkConsistentOfficialPackageBranch` for precisely what an