Rev 4652: Implements --take-this and --take-other when resolving text conflicts in file:///home/vila/src/bzr/experimental/conflict-manager/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Nov 10 16:24:31 GMT 2010
At file:///home/vila/src/bzr/experimental/conflict-manager/
------------------------------------------------------------
revno: 4652
revision-id: v.ladeuil+lp at free.fr-20101110162431-zm06mtpvz75wzubh
parent: v.ladeuil+lp at free.fr-20101110111551-gq8asl7aellww11q
fixes bug(s): https://launchpad.net/bugs/638451
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 638451-malformed
timestamp: Wed 2010-11-10 17:24:31 +0100
message:
Implements --take-this and --take-other when resolving text conflicts
-------------- next part --------------
=== modified file 'bzrlib/conflicts.py'
--- a/bzrlib/conflicts.py 2010-11-07 16:09:43 +0000
+++ b/bzrlib/conflicts.py 2010-11-10 16:24:31 +0000
@@ -626,6 +626,37 @@
def associated_filenames(self):
return [self.path + suffix for suffix in CONFLICT_SUFFIXES]
+ def _resolve(self, tt, winner_suffix):
+ """Resolve the conflict by copying one of .THIS or .OTHER into file.
+
+ :param tt: The TreeTransform where the conflict is resolved.
+ :param winner_suffix: Either 'THIS' or 'OTHER'
+
+ The resolution is symmetric, when taking THIS, item.THIS is renamed
+ into item and vice-versa. This takes one of the files as a whole
+ ignoring every difference that could have been merged cleanly.
+ """
+ # To avoid useless copies, we switch item and item.winner_suffix, only
+ # item will exist after the conflict has been resolved anyway.
+ item_tid = tt.trans_id_file_id(self.file_id)
+ item_parent_tid = tt.get_tree_parent(item_tid)
+ winner_path = self.path + '.' + winner_suffix
+ winner_tid = tt.trans_id_tree_path(winner_path)
+ winner_parent_tid = tt.get_tree_parent(winner_tid)
+ # Switch the paths to preserve the content
+ tt.adjust_path(self.path, winner_parent_tid, winner_tid)
+ tt.adjust_path(winner_path, item_parent_tid, item_tid)
+ # Associate the file_id to the right content
+ tt.unversion_file(item_tid)
+ tt.version_file(self.file_id, winner_tid)
+ tt.apply()
+
+ def action_take_this(self, tree):
+ self._resolve_with_cleanups(tree, 'THIS')
+
+ def action_take_other(self, tree):
+ self._resolve_with_cleanups(tree, 'OTHER')
+
class HandledConflict(Conflict):
"""A path problem that has been provisionally resolved.
=== modified file 'bzrlib/tests/test_conflicts.py'
--- a/bzrlib/tests/test_conflicts.py 2010-11-10 11:15:50 +0000
+++ b/bzrlib/tests/test_conflicts.py 2010-11-10 16:24:31 +0000
@@ -197,11 +197,6 @@
self.run_script(self.preamble)
-class TestResolveTextConflicts(TestResolveConflicts):
- # TBC
- pass
-
-
def mirror_scenarios(base_scenarios):
"""Return a list of mirrored scenarios.
@@ -372,6 +367,50 @@
check_other()
+class TestResolveTextConflicts(TestParametrizedResolveConflicts):
+
+ _conflict_type = conflicts.TextConflict
+
+ # Set by the scenarios
+ # path and file-id for the file involved in the conflict
+ _path = None
+ _file_id = None
+
+ scenarios = mirror_scenarios(
+ [
+ # File modified/deleted
+ (dict(_base_actions='create_file',
+ _path='file', _file_id='file-id'),
+ ('filed_modified_A',
+ dict(actions='modify_file_A', check='file_has_content_A')),
+ ('file_modified_B',
+ dict(actions='modify_file_B', check='file_has_content_B')),),
+ ])
+
+ def do_create_file(self):
+ return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
+
+ def do_modify_file_A(self):
+ return [('modify', ('file-id', 'trunk content\nfeature A\n'))]
+
+ def do_modify_file_B(self):
+ return [('modify', ('file-id', 'trunk content\nfeature B\n'))]
+
+ def check_file_has_content_A(self):
+ self.assertFileEqual('trunk content\nfeature A\n', 'branch/file')
+
+ def check_file_has_content_B(self):
+ self.assertFileEqual('trunk content\nfeature B\n', 'branch/file')
+
+ def _get_resolve_path_arg(self, wt, action):
+ return self._path
+
+ def assertTextConflict(self, wt, c):
+ self.assertEqual(self._file_id, c.file_id)
+ self.assertEqual(self._path, c.path)
+ _assert_conflict = assertTextConflict
+
+
class TestResolveContentsConflict(TestParametrizedResolveConflicts):
_conflict_type = conflicts.ContentsConflict
=== modified file 'bzrlib/transform.py'
--- a/bzrlib/transform.py 2010-11-07 15:56:46 +0000
+++ b/bzrlib/transform.py 2010-11-10 16:24:31 +0000
@@ -130,7 +130,7 @@
self._new_root = self.trans_id_tree_file_id(root_id)
else:
self._new_root = None
- # Indictor of whether the transform has been applied
+ # Indicator of whether the transform has been applied
self._done = False
# A progress bar
self._pb = pb
=== modified file 'doc/en/release-notes/bzr-2.3.txt'
--- a/doc/en/release-notes/bzr-2.3.txt 2010-11-10 11:15:50 +0000
+++ b/doc/en/release-notes/bzr-2.3.txt 2010-11-10 16:24:31 +0000
@@ -31,6 +31,11 @@
options matching a given regular expression is now controlled via the
``--all`` option. (Vincent Ladeuil, bug #670251)
+* ``bzr resolve`` now accepts ``--take-this`` and ``--take-other`` actions
+ for text conflicts. This *replace* the whole file with the content
+ designated by the action. This will *ignore* all differences that would
+ have been merge cleanly otherwise. (Vincent Ladeuil, #638451)
+
* ``bzr resolve`` now reports the number of conflicts resolved and the
number of remaining conflicts. This provides a better feedback about the
whole resolution process. (Vincent Ladeuil)
=== modified file 'doc/en/whats-new/whats-new-in-2.3.txt'
--- a/doc/en/whats-new/whats-new-in-2.3.txt 2010-11-07 16:09:43 +0000
+++ b/doc/en/whats-new/whats-new-in-2.3.txt 2010-11-10 16:24:31 +0000
@@ -111,6 +111,12 @@
default behaviour is specified (if needed) by setting the variable to
``conflict``. (Vincent Ladeuil, #323111)
+* ``bzr resolve --take-this`` and ``bzr resolve --take-other`` can now be
+ used for text conflicts. This will ignore the differences that was merged
+ cleanly and replace the file with its content in the current branch
+ (``--take-this``) or with its content in the merged branch
+ (``--take-other``). (Vincent Ladeuil, #638451)
+
* ``bzr resolve`` now provides more feedback about the conflicts just
resolved and the remaining ones. (Vincent Ladeuil)
More information about the bazaar-commits
mailing list