Merge lp:~mwhudson/launchpad/incremental-save-all-revs into lp:launchpad

Proposed by Michael Hudson-Doyle
Status: Merged
Approved by: Tim Penhey
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~mwhudson/launchpad/incremental-save-all-revs
Merge into: lp:launchpad
Diff against target: 80 lines (+40/-5)
2 files modified
lib/lp/codehosting/codeimport/tests/test_worker.py (+25/-0)
lib/lp/codehosting/codeimport/worker.py (+15/-5)
To merge this branch: bzr merge lp:~mwhudson/launchpad/incremental-save-all-revs
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+20020@code.launchpad.net

Commit message

Preserve all revisions in an import branch's repository between runs, needed to make incremental imports work reliably.

To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

The attempt at importing the kernel incrementally failed because some revisions imported in the first step weren't preserved for the second. This branch changes the BazaarBranchStore to push/pull _all_ revisions in the branch's repository, not just those in the ancestry of the branch tip.

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

Seems reasonable.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/codehosting/codeimport/tests/test_worker.py'
2--- lib/lp/codehosting/codeimport/tests/test_worker.py 2010-02-22 05:37:36 +0000
3+++ lib/lp/codehosting/codeimport/tests/test_worker.py 2010-02-23 23:27:16 +0000
4@@ -254,6 +254,31 @@
5 store._getMirrorURL(self.arbitrary_branch_id),
6 sftp_prefix_noslash + '/' + '%08x' % self.arbitrary_branch_id)
7
8+ def test_all_revisions_saved(self):
9+ # All revisions in the branch's repo are transferred, not just those
10+ # in the ancestry of the tip.
11+ # Consider a branch with two heads in its repo:
12+ # revid
13+ # / \
14+ # revid1 revid2 <- branch tip
15+ # A naive push/pull would just store 'revid' and 'revid2' in the
16+ # branch store -- we need to make sure all three revisions are stored
17+ # and retrieved.
18+ builder = self.make_branch_builder('tree')
19+ revid = builder.build_snapshot(
20+ None, None, [('add', ('', 'root-id', 'directory', ''))])
21+ revid1 = builder.build_snapshot(None, [revid], [])
22+ revid2 = builder.build_snapshot(None, [revid], [])
23+ branch = builder.get_branch()
24+ source_tree = branch.bzrdir.create_workingtree()
25+ store = self.makeBranchStore()
26+ store.push(self.arbitrary_branch_id, source_tree, default_format)
27+ retrieved_tree = store.pull(
28+ self.arbitrary_branch_id, 'pulled', default_format)
29+ self.assertEqual(
30+ set([revid, revid1, revid2]),
31+ set(retrieved_tree.branch.repository.all_revision_ids()))
32+
33
34 class TestImportDataStore(WorkerTest):
35 """Tests for `ImportDataStore`."""
36
37=== modified file 'lib/lp/codehosting/codeimport/worker.py'
38--- lib/lp/codehosting/codeimport/worker.py 2010-02-19 03:32:39 +0000
39+++ lib/lp/codehosting/codeimport/worker.py 2010-02-23 23:27:16 +0000
40@@ -71,20 +71,26 @@
41 """
42 remote_url = self._getMirrorURL(db_branch_id)
43 try:
44- bzr_dir = BzrDir.open(remote_url)
45+ remote_bzr_dir = BzrDir.open(remote_url)
46 except NotBranchError:
47 return BzrDir.create_standalone_workingtree(
48 target_path, required_format)
49 # XXX Tim Penhey 2009-09-18 bug 432217 Automatic upgrade of import
50 # branches disabled. Need an orderly upgrade process.
51- if False and bzr_dir.needs_format_conversion(format=required_format):
52+ if False and remote_bzr_dir.needs_format_conversion(
53+ format=required_format):
54 try:
55- bzr_dir.root_transport.delete_tree('backup.bzr')
56+ remote_bzr_dir.root_transport.delete_tree('backup.bzr')
57 except NoSuchFile:
58 pass
59 upgrade(remote_url, required_format)
60- bzr_dir.sprout(target_path)
61- return BzrDir.open(target_path).open_workingtree()
62+ local_bzr_dir = remote_bzr_dir.sprout(target_path)
63+ # Because of the way we do incremental imports, there may be revisions
64+ # in the branch's repo that are not in the ancestry of the branch tip.
65+ # We need to transfer them too.
66+ local_bzr_dir.open_repository().fetch(
67+ remote_bzr_dir.open_repository())
68+ return local_bzr_dir.open_workingtree()
69
70 def push(self, db_branch_id, bzr_tree, required_format):
71 """Push up `bzr_tree` as the Bazaar branch for `code_import`.
72@@ -101,6 +107,10 @@
73 branch_to = BzrDir.create_branch_and_repo(
74 target_url, format=required_format)
75 pull_result = branch_to.pull(branch_from, overwrite=True)
76+ # Because of the way we do incremental imports, there may be revisions
77+ # in the branch's repo that are not in the ancestry of the branch tip.
78+ # We need to transfer them too.
79+ branch_to.repository.fetch(branch_from.repository)
80 return pull_result.old_revid != pull_result.new_revid
81
82