Rev 5558: (vila) Implement resolve --take-this and --take-other for text conflicts. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Dec 3 08:31:46 GMT 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5558 [merge]
revision-id: pqm at pqm.ubuntu.com-20101203083144-b2qfwgifwp1wq6zv
parent: pqm at pqm.ubuntu.com-20101202172840-i4wtlbm8vt4wi1j0
parent: v.ladeuil+lp at free.fr-20101203075235-gkdxzf7no10sjcfe
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2010-12-03 08:31:44 +0000
message:
  (vila) Implement resolve --take-this and --take-other for text conflicts.
   (Vincent Ladeuil)
modified:
  bzrlib/conflicts.py            conflicts.py-20051001061850-78ef952ba63d2b42
  bzrlib/help_topics/en/conflict-types.txt conflicts.txt-20070723221841-ns3jvwxdb4okn6fk-1
  bzrlib/tests/blackbox/test_resolve.py test_resolve.py-20101103145514-ygpa369r69hhxsmi-1
  bzrlib/tests/test_conflicts.py test_conflicts.py-20051006031059-e2dad9bbeaa5891f
  bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
  doc/en/release-notes/bzr-2.3.txt NEWS-20050323055033-4e00b5db738777ff
  doc/en/whats-new/whats-new-in-2.3.txt whatsnewin2.3.txt-20100818072501-x2h25r7jbnknvy30-1
=== 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/help_topics/en/conflict-types.txt'
--- a/bzrlib/help_topics/en/conflict-types.txt	2010-10-15 14:57:42 +0000
+++ b/bzrlib/help_topics/en/conflict-types.txt	2010-11-24 16:28:11 +0000
@@ -87,11 +87,11 @@
 
 The correct resolution would be "Martin Pool released Bazaar."
 
-You can handle text conflicts either by editing the main copy of the file, or
-by invoking external tools on the THIS, OTHER and BASE versions.  It's worth
-mentioning that resolving text conflicts rarely involves picking one set of
-changes over the other.  More often, the two sets of changes must be
-intelligently combined.
+You can handle text conflicts either by editing the main copy of the file,
+or by invoking external tools on the THIS, OTHER and BASE versions.  It's
+worth mentioning that resolving text conflicts rarely involves picking one
+set of changes over the other (but see below when you encounter these
+cases).  More often, the two sets of changes must be intelligently combined.
 
 If you edit the main copy, be sure to remove the herringbone markers.  When
 you are done editing, the file should look like it never had a conflict, and be
@@ -104,6 +104,16 @@
 ``.BASE``, ``.THIS`` and ``.OTHER`` files if they are still present in the
 working tree.
 
+
+When you want to pick one set of changes over the other, you can use ``bzr
+resolve`` with one of the following actions:
+
+* ``--action=take-this`` will issue ``mv FILE.THIS FILE``,
+* ``--action=take-other`` will issue ``mv FILE.OTHER FILE``.
+
+Note that if you have modified ``FILE.THIS`` or ``FILE.OTHER``, these
+modifications will be taken into account.
+
 Content conflicts
 -----------------
 

=== modified file 'bzrlib/tests/blackbox/test_resolve.py'
--- a/bzrlib/tests/blackbox/test_resolve.py	2010-11-07 16:09:43 +0000
+++ b/bzrlib/tests/blackbox/test_resolve.py	2010-11-10 18:17:06 +0000
@@ -91,48 +91,3 @@
         self.build_tree_contents([('tree/file', 'a\n')])
         note = self.run_bzr('resolve', working_dir='tree')[1]
         self.assertContainsRe(note, 'All conflicts resolved.')
-
-
-class TestResolveSilentlyIgnore(script.TestCaseWithTransportAndScript):
-
-    def test_bug_646961(self):
-        self.run_script("""\
-            $ bzr init base
-            Created a standalone tree (format: 2a)
-            $ cd base
-            $ echo >file1
-            $ bzr add
-            adding file1
-            $ bzr ci -m "stuff"
-            2>Committing to: .../base/
-            2>added file1
-            2>Committed revision 1.
-            $ cd ..
-            $ bzr branch base branch
-            2>Branched 1 revision(s).
-            $ cd base
-            $ echo "1" >> file1
-            $ bzr ci -m "branch 1"
-            2>Committing to: .../base/
-            2>modified file1
-            2>Committed revision 2.
-            $ cd ../branch
-            $ echo "2" >> file1
-            $ bzr ci -m "branch 2"
-            2>Committing to: .../branch/
-            2>modified file1
-            2>Committed revision 2.
-            $ cd ../base
-            $ bzr merge ../branch
-            2> M  file1
-            2>Text conflict in file1
-            2>1 conflicts encountered.
-            # The following succeeds silently without resolving the conflict
-            $ bzr resolve file1 --take-other
-            2>0 conflict(s) resolved, 1 remaining
-            # The following wil fail when --take-other is implemented
-            # for text conflicts
-            $ bzr conflicts
-            Text conflict in file1
-            """)
-

=== 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-19 16:28:25 +0000
+++ b/bzrlib/transform.py	2010-11-24 16:01:57 +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-12-02 16:24:54 +0000
+++ b/doc/en/release-notes/bzr-2.3.txt	2010-12-03 07:52:35 +0000
@@ -26,6 +26,11 @@
 .. Improvements to existing commands, especially improved performance 
    or memory usage, or better results.
 
+* ``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)
+
 Bug Fixes
 *********
 

=== modified file 'doc/en/whats-new/whats-new-in-2.3.txt'
--- a/doc/en/whats-new/whats-new-in-2.3.txt	2010-12-02 15:48:12 +0000
+++ b/doc/en/whats-new/whats-new-in-2.3.txt	2010-12-03 07:51:28 +0000
@@ -131,6 +131,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 were 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