[meld] Extract Differ's auto-merging logic for the benefit of subclasses



commit 247c9445b03f57badb60a96c0d84a0a51b22d2c3
Author: Piotr Piastucki <the_leech users berlios de>
Date:   Mon Jul 6 18:17:40 2009 +0200

    Extract Differ's auto-merging logic for the benefit of subclasses
    
    Auto-merge-with-ancestor mode (bgo#578613) wants to be able to override
    the merging logic, so this commit pulls it out of _merge_diffs().
    _auto_merge() is a generator so that alternate implementations can return
    multiple merged change blocks.

 diffutil.py |   31 ++++++++++++++++++-------------
 1 files changed, 18 insertions(+), 13 deletions(-)
---
diff --git a/diffutil.py b/diffutil.py
index 1747bcb..a941927 100644
--- a/diffutil.py
+++ b/diffutil.py
@@ -177,6 +177,22 @@ class Differ(object):
             high.append(highc - d[HI] + d[2+HI])
         return low[0], high[0], lowc, highc, low[1], high[1]
 
+    def _auto_merge(self, using, texts):
+        """Automatically merge two sequences of change blocks"""
+        l0, h0, l1, h1, l2, h2 = self._merge_blocks(using)
+        if h0-l0 == h2-l2 and texts[0][l0:h0] == texts[2][l2:h2]:
+            if l1 != h1 and l0 == h0:
+                tag = "delete"
+            elif l1 != h1:
+                tag = "replace"
+            else:
+                tag = "insert"
+        else:
+            tag = "conflict"
+        out0 = (tag, l1, h1, l0, h0)
+        out1 = (tag, l1, h1, l2, h2)
+        yield out0, out1
+
     def _merge_diffs(self, seq0, seq1, texts):
         seq0, seq1 = seq0[:], seq1[:]
         seq = seq0, seq1
@@ -222,19 +238,8 @@ class Differ(object):
                 assert len(using[0])==1
                 yield using[0][0], None
             else:
-                l0, h0, l1, h1, l2, h2 = self._merge_blocks(using)
-                if h0-l0 == h2-l2 and texts[0][l0:h0] == texts[2][l2:h2]:
-                    if l1 != h1 and l0 == h0:
-                        tag = "delete"
-                    elif l1 != h1:
-                        tag = "replace"
-                    else:
-                        tag = "insert"
-                else:
-                    tag = "conflict"
-                out0 = (tag, l1, h1, l0, h0)
-                out1 = (tag, l1, h1, l2, h2)
-                yield out0, out1
+                for c in self._auto_merge(using, texts):
+                    yield c
 
     def set_sequences_iter(self, *sequences):
         assert 0 <= len(sequences) <= 3



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]