Merge lp:~spiv/bzr/new-repo-stacking-bug-597942 into lp:bzr

Proposed by Andrew Bennetts
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 5319
Proposed branch: lp:~spiv/bzr/new-repo-stacking-bug-597942
Merge into: lp:bzr
Diff against target: 62 lines (+29/-1)
3 files modified
NEWS (+4/-0)
bzrlib/bzrdir.py (+2/-1)
bzrlib/tests/per_bzrdir/test_bzrdir.py (+23/-0)
To merge this branch: bzr merge lp:~spiv/bzr/new-repo-stacking-bug-597942
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+28368@code.launchpad.net

Commit message

Fix BzrDir.sprout to respect default stacking policies (#597942)

Description of the change

This fixes BzrDir.sprout to be aware that new repositories can have fallbacks even if the caller didn't ask for stacked=True. This happens when there is a default stacking policy at the target location.

An example that benefits is "bzr branch lp:bzr lp:~user/bzr/blah" will no longer transfer the full revision history.

To post a comment you must log in.
Revision history for this message
Andrew Bennetts (spiv) wrote :

Btw, this fix is probably a good backport candidate for 2.0 and 2.1. I'll make separate proposals for those when this is landed.

Revision history for this message
Robert Collins (lifeless) wrote :

I'm amazed and shocked. Shocked I tell you.

Please be landing.

Revision history for this message
Robert Collins (lifeless) :
review: Approve
Revision history for this message
Andrew Bennetts (spiv) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-06-23 08:14:21 +0000
3+++ NEWS 2010-06-24 06:42:28 +0000
4@@ -43,6 +43,10 @@
5 Bug Fixes
6 *********
7
8+* ``bzr branch`` to a new repository with a default stacking policy no
9+ longer transfers the full history unnecessarily.
10+ (Andrew Bennetts, #597942)
11+
12 * ``bzr init`` does not recursively scan directory contents anymore
13 leading to faster init for directories with existing content.
14 (Martin [gz], Parth Malwankar, #501307)
15
16=== modified file 'bzrlib/bzrdir.py'
17--- bzrlib/bzrdir.py 2010-05-25 17:27:52 +0000
18+++ bzrlib/bzrdir.py 2010-06-24 06:42:28 +0000
19@@ -1244,7 +1244,8 @@
20 repository_policy = result.determine_repository_policy(
21 force_new_repo, stacked_branch_url, require_stacking=stacked)
22 result_repo, is_new_repo = repository_policy.acquire_repository()
23- if is_new_repo and revision_id is not None and not stacked:
24+ is_stacked = stacked or (len(result_repo._fallback_repositories) != 0)
25+ if is_new_repo and revision_id is not None and not is_stacked:
26 fetch_spec = graph.PendingAncestryResult(
27 [revision_id], source_repository)
28 else:
29
30=== modified file 'bzrlib/tests/per_bzrdir/test_bzrdir.py'
31--- bzrlib/tests/per_bzrdir/test_bzrdir.py 2010-05-20 18:23:17 +0000
32+++ bzrlib/tests/per_bzrdir/test_bzrdir.py 2010-06-24 06:42:28 +0000
33@@ -1168,6 +1168,29 @@
34 self.assertEqual(tree.branch.last_revision(),
35 target.open_branch().last_revision())
36
37+ def test_sprout_with_revision_id_uses_default_stack_on(self):
38+ # Make a branch with three commits to stack on.
39+ builder = self.make_branch_builder('stack-on')
40+ builder.start_series()
41+ builder.build_commit(message='Rev 1.', rev_id='rev-1')
42+ builder.build_commit(message='Rev 2.', rev_id='rev-2')
43+ builder.build_commit(message='Rev 3.', rev_id='rev-3')
44+ builder.finish_series()
45+ stack_on = builder.get_branch()
46+ # Make a bzrdir with a default stacking policy to stack on that branch.
47+ config = self.make_bzrdir('policy-dir').get_config()
48+ try:
49+ config.set_default_stack_on(self.get_url('stack-on'))
50+ except errors.BzrError:
51+ raise TestNotApplicable('Only relevant for stackable formats.')
52+ # Sprout the stacked-on branch into the bzrdir.
53+ sprouted = stack_on.bzrdir.sprout(
54+ self.get_url('policy-dir/sprouted'), revision_id='rev-3')
55+ # Not all revisions are copied into the sprouted repository.
56+ repo = sprouted.open_repository()
57+ self.addCleanup(repo.lock_read().unlock)
58+ self.assertEqual(None, repo.get_parent_map(['rev-1']).get('rev-1'))
59+
60 def test_format_initialize_find_open(self):
61 # loopback test to check the current format initializes to itself.
62 if not self.bzrdir_format.is_supported():