Merge lp:~abentley/bzr/fix-switch-branch into lp:bzr

Proposed by Aaron Bentley
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~abentley/bzr/fix-switch-branch
Merge into: lp:bzr
Diff against target: 93 lines (+33/-4)
4 files modified
NEWS (+3/-0)
bzrlib/merge.py (+4/-1)
bzrlib/switch.py (+1/-2)
bzrlib/tests/test_switch.py (+25/-1)
To merge this branch: bzr merge lp:~abentley/bzr/fix-switch-branch
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+24050@code.launchpad.net

Description of the change

Hi all,

This branch fixes a bug it took me a while to track down, because I initially
assume it was related to pipelines.

Basically, the issue is that Merge3Merger does not guarantee that
self.this_branch has a value, but ConfigurableFileMerger assumes it does.

Merger does provide this guarantee, but switch doesn't use Merger.

This manifested in switch as:
  File "/home/abentley/bzr/fix-switch-branch/bzrlib/merge.py", line 1313, in _do_merge_contents
    hook_status, lines = hook.merge_contents(params)
  File "/home/abentley/bzr/fix-switch-branch/bzrlib/merge.py", line 161, in merge_contents
    not self.filename_matches_config(params)):
  File "/home/abentley/bzr/fix-switch-branch/bzrlib/merge.py", line 133, in filename_matches_config
    config = self.merger.this_branch.get_config()
AttributeError: 'NoneType' object has no attribute 'get_config'

But of course, it is only triggered if a ConfigurableFileMerger is used, e.g.
when editing NEWS.

This branch fixes it at Merge3Merger, by ensuring that this_branch is set to
this_tree.branch if not supplied. It could also have been fixed at switch, but
I was concerned that this could lead to repeats of this problem.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

There is an open bug on this, in fact there are like 3. It should be mentioned in NEWS. Otherwise:

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

John A Meinel wrote:
> Review: Approve
> There is an open bug on this, in fact there are like 3. It should be mentioned in NEWS. Otherwise:

The bug is 559436, and it even has a fix I wrote that is still waiting for
review:

<https://code.edge.launchpad.net/~spiv/bzr/switch-crash-559436/+merge/23817>

Happily it's essentially the same as Aaron's fix, but I wonder why his got
reviewed already when mine from 3 days earlier is still waiting? Is it because
I targetted 2.1?

-Andrew.

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Andrew Bennetts wrote:
> John A Meinel wrote:
>> Review: Approve
>> There is an open bug on this, in fact there are like 3. It should be mentioned in NEWS. Otherwise:
>
> The bug is 559436, and it even has a fix I wrote that is still waiting for
> review:
>
> <https://code.edge.launchpad.net/~spiv/bzr/switch-crash-559436/+merge/23817>
>
> Happily it's essentially the same as Aaron's fix, but I wonder why his got
> reviewed already when mine from 3 days earlier is still waiting? Is it because
> I targetted 2.1?
>
> -Andrew.
>

For my part, it is because his e-mail showed up while I was willing to
review. Plus it has a test...

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkvWTdYACgkQJdeBCYSNAAMz+ACfQDdyJMctqtqSbbWmbqLsc47A
bRQAoLEbH1DrgPQWMd39+7XNfqMpcSw0
=exb9
-----END PGP SIGNATURE-----

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2010-04-24 09:08:27 +0000
+++ NEWS 2010-04-26 23:42:26 +0000
@@ -110,6 +110,9 @@
110 http://bugs.python.org/issue8396 .110 http://bugs.python.org/issue8396 .
111 (Parth Malwankar, #413406)111 (Parth Malwankar, #413406)
112112
113* ``bzr switch`` does not die if a ConfigurableFileMerger is used.
114 (Aaron Bentley, #559436)
115
113* ``bzr update`` when a pending merge in the working tree has been merged116* ``bzr update`` when a pending merge in the working tree has been merged
114 into the master branch will no longer claim that old commits have become117 into the master branch will no longer claim that old commits have become
115 pending merges. (Robert Collins, #562079)118 pending merges. (Robert Collins, #562079)
116119
=== modified file 'bzrlib/merge.py'
--- bzrlib/merge.py 2010-04-16 07:56:51 +0000
+++ bzrlib/merge.py 2010-04-26 23:42:26 +0000
@@ -704,7 +704,8 @@
704 :param this_tree: The local tree in the merge operation704 :param this_tree: The local tree in the merge operation
705 :param base_tree: The common tree in the merge operation705 :param base_tree: The common tree in the merge operation
706 :param other_tree: The other tree to merge changes from706 :param other_tree: The other tree to merge changes from
707 :param this_branch: The branch associated with this_tree707 :param this_branch: The branch associated with this_tree. Defaults to
708 this_tree.branch if not supplied.
708 :param interesting_ids: The file_ids of files that should be709 :param interesting_ids: The file_ids of files that should be
709 participate in the merge. May not be combined with710 participate in the merge. May not be combined with
710 interesting_files.711 interesting_files.
@@ -728,6 +729,8 @@
728 if interesting_files is not None and interesting_ids is not None:729 if interesting_files is not None and interesting_ids is not None:
729 raise ValueError(730 raise ValueError(
730 'specify either interesting_ids or interesting_files')731 'specify either interesting_ids or interesting_files')
732 if this_branch is None:
733 this_branch = this_tree.branch
731 self.interesting_ids = interesting_ids734 self.interesting_ids = interesting_ids
732 self.interesting_files = interesting_files735 self.interesting_files = interesting_files
733 self.this_tree = working_tree736 self.this_tree = working_tree
734737
=== modified file 'bzrlib/switch.py'
--- bzrlib/switch.py 2010-03-25 14:22:41 +0000
+++ bzrlib/switch.py 2010-04-26 23:42:26 +0000
@@ -17,8 +17,7 @@
17# Original author: David Allouche17# Original author: David Allouche
1818
19from bzrlib import errors, merge, revision19from bzrlib import errors, merge, revision
20from bzrlib.branch import Branch, BranchFormat, BranchReferenceFormat20from bzrlib.branch import Branch
21from bzrlib.bzrdir import BzrDir
22from bzrlib.trace import note21from bzrlib.trace import note
2322
2423
2524
=== modified file 'bzrlib/tests/test_switch.py'
--- bzrlib/tests/test_switch.py 2010-01-15 04:05:36 +0000
+++ bzrlib/tests/test_switch.py 2010-04-26 23:42:26 +0000
@@ -19,7 +19,13 @@
1919
20import os20import os
2121
22from bzrlib import branch, errors, switch, tests22from bzrlib import (
23 branch,
24 errors,
25 merge as _mod_merge,
26 switch,
27 tests,
28)
2329
2430
25class TestSwitch(tests.TestCaseWithTransport):31class TestSwitch(tests.TestCaseWithTransport):
@@ -129,6 +135,24 @@
129 switch.switch(checkout.bzrdir, tree2.branch)135 switch.switch(checkout.bzrdir, tree2.branch)
130 self.assertEqual('custom-root-id', tree2.get_root_id())136 self.assertEqual('custom-root-id', tree2.get_root_id())
131137
138 def test_switch_configurable_file_merger(self):
139 class DummyMerger(_mod_merge.ConfigurableFileMerger):
140 name_prefix = 'file'
141
142 _mod_merge.Merger.hooks.install_named_hook(
143 'merge_file_content', DummyMerger,
144 'test factory')
145 foo = self.make_branch('foo')
146 checkout = foo.create_checkout('checkout', lightweight=True)
147 self.build_tree_contents([('checkout/file', 'a')])
148 checkout.add('file')
149 checkout.commit('a')
150 bar = foo.bzrdir.sprout('bar').open_workingtree()
151 self.build_tree_contents([('bar/file', 'b')])
152 bar.commit('b')
153 self.build_tree_contents([('checkout/file', 'c')])
154 switch.switch(checkout.bzrdir, bar.branch)
155
132156
133class TestSwitchHeavyweight(TestSwitch):157class TestSwitchHeavyweight(TestSwitch):
134158