Merge lp:~jelmer/launchpad/auto-upgrade into lp:launchpad

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 13219
Proposed branch: lp:~jelmer/launchpad/auto-upgrade
Merge into: lp:launchpad
Diff against target: 198 lines (+78/-57)
3 files modified
lib/lp/code/browser/branch.py (+0/-2)
lib/lp/codehosting/codeimport/tests/test_worker.py (+46/-46)
lib/lp/codehosting/codeimport/worker.py (+32/-9)
To merge this branch: bzr merge lp:~jelmer/launchpad/auto-upgrade
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+64398@code.launchpad.net

Commit message

[r=benji][bug=432217] Reintroduce automatic upgrades of code imports.

Description of the change

Reintroduce automatic upgrades of code imports.

Automatic upgrades of code imports were disabled in September 2009 because they were much too slow. In particular because the upgrade from knits to 2a was very slow and memory hogging.

Bazaar is now much faster at doing upgrades.

This branch also fixes the worker to no longer do the upgrade on the remote branch. Instead, the worker upgrades its local branch and then replaces the remote branch with that.

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

This branch looks good.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/browser/branch.py'
2--- lib/lp/code/browser/branch.py 2011-05-27 21:12:25 +0000
3+++ lib/lp/code/browser/branch.py 2011-06-13 12:40:06 +0000
4@@ -118,7 +118,6 @@
5 from lp.bugs.interfaces.bug import IBugSet
6 from lp.bugs.interfaces.bugbranch import IBugBranch
7 from lp.bugs.interfaces.bugtask import UNRESOLVED_BUGTASK_STATUSES
8-from lp.buildmaster.interfaces.buildfarmjob import IBuildFarmJobSet
9 from lp.code.browser.branchmergeproposal import (
10 latest_proposals_for_each_branch,
11 )
12@@ -126,7 +125,6 @@
13 from lp.code.browser.decorations import DecoratedBranch
14 from lp.code.browser.sourcepackagerecipelisting import HasRecipesMenuMixin
15 from lp.code.enums import (
16- BranchLifecycleStatus,
17 BranchType,
18 CodeImportResultStatus,
19 CodeImportReviewStatus,
20
21=== modified file 'lib/lp/codehosting/codeimport/tests/test_worker.py'
22--- lib/lp/codehosting/codeimport/tests/test_worker.py 2011-06-01 15:52:13 +0000
23+++ lib/lp/codehosting/codeimport/tests/test_worker.py 2011-06-13 12:40:06 +0000
24@@ -29,7 +29,6 @@
25 from bzrlib.tests import TestCaseWithTransport
26 from bzrlib import trace
27 from bzrlib.transport import get_transport
28-from bzrlib.upgrade import upgrade
29 from bzrlib.urlutils import (
30 join as urljoin,
31 local_path_from_url,
32@@ -204,51 +203,52 @@
33 self.arbitrary_branch_id, self.temp_dir, default_format, True)
34 self.assertTrue(new_branch.bzrdir.has_workingtree())
35
36- # XXX Tim Penhey 2009-09-18 bug 432217 Automatic upgrade of import
37- # branches disabled. Need an orderly upgrade process.
38- def disabled_test_pullUpgradesFormat(self):
39- # A branch should always be in the most up-to-date format before a
40- # pull is performed.
41- store = self.makeBranchStore()
42- target_url = store._getMirrorURL(self.arbitrary_branch_id)
43- knit_format = format_registry.get('knit')()
44- create_branch_with_one_revision(target_url, format=knit_format)
45- default_format = BzrDirFormat.get_default_format()
46-
47- # The fetched branch is in the default format.
48- new_tree = store.pull(
49- self.arbitrary_branch_id, self.temp_dir, default_format)
50- self.assertEqual(
51- default_format, new_tree.branch.bzrdir._format)
52-
53- # In addition. the remote branch has been upgraded as well.
54- new_branch = Branch.open(target_url)
55- self.assertEqual(
56- default_format.get_branch_format(), new_branch._format)
57-
58- # XXX Tim Penhey 2009-09-18 bug 432217 Automatic upgrade of import
59- # branches disabled. Need an orderly upgrade process.
60- def disabled_test_pullUpgradesFormatWithBackupDirPresent(self):
61- # pull can upgrade the remote branch even if there is a backup.bzr
62- # directory from a previous upgrade.
63- store = self.makeBranchStore()
64- target_url = store._getMirrorURL(self.arbitrary_branch_id)
65- knit_format = format_registry.get('knit')()
66- create_branch_with_one_revision(target_url, format=knit_format)
67- upgrade(target_url, format_registry.get('dirstate-tags')())
68- self.failUnless(get_transport(target_url).has('backup.bzr'))
69- default_format = BzrDirFormat.get_default_format()
70-
71- # The fetched branch is in the default format.
72- new_tree = store.pull(
73- self.arbitrary_branch_id, self.temp_dir, default_format)
74- self.assertEqual(
75- default_format, new_tree.branch.bzrdir._format)
76-
77- # In addition. the remote branch has been upgraded as well.
78- new_branch = Branch.open(target_url)
79- self.assertEqual(
80- default_format.get_branch_format(), new_branch._format)
81+ def test_pullUpgradesFormat(self):
82+ # A branch should always be in the most up-to-date format before a
83+ # pull is performed.
84+ store = self.makeBranchStore()
85+ target_url = store._getMirrorURL(self.arbitrary_branch_id)
86+ knit_format = format_registry.get('knit')()
87+ create_branch_with_one_revision(target_url, format=knit_format)
88+ default_format = BzrDirFormat.get_default_format()
89+
90+ # The fetched branch is in the default format.
91+ new_branch = store.pull(
92+ self.arbitrary_branch_id, self.temp_dir, default_format)
93+ self.assertEqual(
94+ default_format, new_branch.bzrdir._format)
95+
96+ def test_pushUpgradesFormat(self):
97+ # A branch should always be in the most up-to-date format before a
98+ # pull is performed.
99+ store = self.makeBranchStore()
100+ target_url = store._getMirrorURL(self.arbitrary_branch_id)
101+ knit_format = format_registry.get('knit')()
102+ create_branch_with_one_revision(target_url, format=knit_format)
103+ default_format = BzrDirFormat.get_default_format()
104+
105+ # The fetched branch is in the default format.
106+ new_branch = store.pull(
107+ self.arbitrary_branch_id, self.temp_dir, default_format)
108+ self.assertEqual(
109+ default_format, new_branch.bzrdir._format)
110+
111+ # The remote branch is still in the old format at this point.
112+ target_branch = Branch.open(target_url)
113+ self.assertEqual(
114+ knit_format.get_branch_format(),
115+ target_branch._format)
116+
117+ store.push(self.arbitrary_branch_id, new_branch, default_format)
118+
119+ # The remote branch is now in the new format.
120+ target_branch = Branch.open(target_url)
121+ self.assertEqual(
122+ default_format.get_branch_format(),
123+ target_branch._format)
124+ self.assertEquals(
125+ target_branch.last_revision_info(),
126+ new_branch.last_revision_info())
127
128 def test_pushTwiceThenPull(self):
129 # We can push up a branch to the store twice and then pull it from the
130
131=== modified file 'lib/lp/codehosting/codeimport/worker.py'
132--- lib/lp/codehosting/codeimport/worker.py 2011-06-01 15:59:45 +0000
133+++ lib/lp/codehosting/codeimport/worker.py 2011-06-13 12:40:06 +0000
134@@ -95,15 +95,6 @@
135 if needs_tree:
136 local_branch.bzrdir.create_workingtree()
137 return local_branch
138- # XXX Tim Penhey 2009-09-18 bug 432217 Automatic upgrade of import
139- # branches disabled. Need an orderly upgrade process.
140- if False and remote_bzr_dir.needs_format_conversion(
141- format=required_format):
142- try:
143- remote_bzr_dir.root_transport.delete_tree('backup.bzr')
144- except NoSuchFile:
145- pass
146- upgrade(remote_url, required_format)
147 # The proper thing to do here would be to call
148 # "remote_bzr_dir.sprout()". But 2a fetch slowly checks which
149 # revisions are in the ancestry of the tip of the remote branch, which
150@@ -116,6 +107,13 @@
151 target_control.create_prefix()
152 remote_bzr_dir.transport.copy_tree_to_transport(target_control)
153 local_bzr_dir = BzrDir.open_from_transport(target)
154+ if local_bzr_dir.needs_format_conversion(
155+ format=required_format):
156+ try:
157+ local_bzr_dir.root_transport.delete_tree('backup.bzr')
158+ except NoSuchFile:
159+ pass
160+ upgrade(target_path, required_format)
161 if needs_tree:
162 local_bzr_dir.create_workingtree()
163 return local_bzr_dir.open_branch()
164@@ -133,11 +131,36 @@
165 except NotBranchError:
166 remote_branch = BzrDir.create_branch_and_repo(
167 target_url, format=required_format)
168+ old_branch = None
169+ else:
170+ if remote_branch.bzrdir.needs_format_conversion(
171+ required_format):
172+ # For upgrades, push to a new branch in
173+ # the new format. When done pushing,
174+ # retire the old .bzr directory and rename
175+ # the new one in place.
176+ old_branch = remote_branch
177+ upgrade_url = urljoin(target_url, "upgrade.bzr")
178+ try:
179+ remote_branch.bzrdir.root_transport.delete_tree(
180+ 'upgrade.bzr')
181+ except NoSuchFile:
182+ pass
183+ remote_branch = BzrDir.create_branch_and_repo(
184+ upgrade_url, format=required_format)
185+ else:
186+ old_branch = None
187 pull_result = remote_branch.pull(bzr_branch, overwrite=True)
188 # Because of the way we do incremental imports, there may be revisions
189 # in the branch's repo that are not in the ancestry of the branch tip.
190 # We need to transfer them too.
191 remote_branch.repository.fetch(bzr_branch.repository)
192+ if old_branch is not None:
193+ # The format has changed; move the new format
194+ # branch in place.
195+ base_transport = old_branch.bzrdir.root_transport
196+ old_branch.bzrdir.retire_bzrdir()
197+ base_transport.rename("upgrade.bzr/.bzr", ".bzr")
198 return pull_result.old_revid != pull_result.new_revid
199
200