[meld] filediff: Keep short equal parts at start/end of chunk (bgo#708811)



commit 7fe173a29c1ecf48898109cdfce61c406b00ac98
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Sep 28 07:34:08 2013 +1000

    filediff: Keep short equal parts at start/end of chunk (bgo#708811)
    
    We remove anything shorter than three characters for good reasons, but
    this is poor when the match occurs at the start or the end of a chunk.

 meld/filediff.py |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 3b26b08..8909906 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1313,11 +1313,24 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                     if texts != (text1, textn):
                         return
 
-                    # Remove equal matches of size less than 3; highlight
-                    # the remainder.
-                    matches = [m for m in matches if m.tag != "equal" or
-                               (m.end_a - m.start_a < 3) or
-                               (m.end_b - m.start_b < 3)]
+                    offsets = [ends[0].get_offset() - starts[0].get_offset(),
+                               ends[1].get_offset() - starts[1].get_offset()]
+
+                    def process_matches(match):
+                        if match.tag != "equal":
+                            return True
+                        # Always keep matches occurring at the start or end
+                        start_or_end = (
+                            (match.start_a == 0 and match.start_b == 0) or
+                            (match.end_a == offsets[0] and match.end_b == offsets[1]))
+                        if start_or_end:
+                            return False
+                       # Remove equal matches of size less than 3
+                        too_short = ((match.end_a - match.start_a < 3) or
+                                     (match.end_b - match.start_b < 3))
+                        return too_short
+
+                    matches = [m for m in matches if process_matches(m)]
 
                     for i in range(2):
                         start, end = starts[i].copy(), starts[i].copy()


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