Patchwork D11966: simplemerge: make merge_groups() yield only 2-tuples

login
register
mail settings
Submitter phabricator
Date Jan. 6, 2022, 8:34 p.m.
Message ID <differential-rev-PHID-DREV-h3oc3vgiphp7totloyna-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50292/
State New
Headers show

Comments

phabricator - Jan. 6, 2022, 8:34 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  `merge_groups()` currently yields 2-tuples or 4-tuples, making the
  callers check the first element to decide how to interpret the
  rest. Let's make it yield only 2-tuples, thereby simplifying life a
  little for the callers.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11966

AFFECTED FILES
  mercurial/simplemerge.py
  tests/test-simplemerge.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-simplemerge.py b/tests/test-simplemerge.py
--- a/tests/test-simplemerge.py
+++ b/tests/test-simplemerge.py
@@ -285,7 +285,7 @@ 
             list(m3.merge_groups()),
             [
                 (b'unchanged', [b'aaa\n']),
-                (b'conflict', [], [b'111\n'], [b'222\n']),
+                (b'conflict', ([], [b'111\n'], [b'222\n'])),
                 (b'unchanged', [b'bbb\n']),
             ],
         )
diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -160,7 +160,7 @@ 
         'b', lines
              Lines taken from b
 
-        'conflict', base_lines, a_lines, b_lines
+        'conflict', (base_lines, a_lines, b_lines)
              Lines from base were changed to either a or b and conflict.
         """
         for t in self.merge_regions():
@@ -174,9 +174,11 @@ 
             elif what == b'conflict':
                 yield (
                     what,
-                    self.base[t[1] : t[2]],
-                    self.a[t[3] : t[4]],
-                    self.b[t[5] : t[6]],
+                    (
+                        self.base[t[1] : t[2]],
+                        self.a[t[3] : t[4]],
+                        self.b[t[5] : t[6]],
+                    ),
                 )
             else:
                 raise ValueError(what)
@@ -417,9 +419,9 @@ 
 def _mergediff(m3, name_a, name_b, name_base):
     lines = []
     conflicts = False
-    for group in m3.merge_groups():
-        if group[0] == b'conflict':
-            base_lines, a_lines, b_lines = group[1:]
+    for what, group_lines in m3.merge_groups():
+        if what == b'conflict':
+            base_lines, a_lines, b_lines = group_lines
             base_text = b''.join(base_lines)
             b_blocks = list(
                 mdiff.allblocks(
@@ -472,18 +474,18 @@ 
             lines.append(b">>>>>>>\n")
             conflicts = True
         else:
-            lines.extend(group[1])
+            lines.extend(group_lines)
     return lines, conflicts
 
 
 def _resolve(m3, sides):
     lines = []
-    for group in m3.merge_groups():
-        if group[0] == b'conflict':
+    for what, group_lines in m3.merge_groups():
+        if what == b'conflict':
             for side in sides:
-                lines.extend(group[side + 1])
+                lines.extend(group_lines[side])
         else:
-            lines.extend(group[1])
+            lines.extend(group_lines)
     return lines