[meld] Make it easier to override the matcher class used by Differ



commit 5ae752e6c36293caa337bcafa2cb8ee6c15f984a
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Tue Jul 7 16:38:23 2009 +1000

    Make it easier to override the matcher class used by Differ
    
    In order to make it easy for (upcoming) Differ subclasses to use a
    different matcher, we make the matcher a class member variable.

 diffutil.py |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/diffutil.py b/diffutil.py
index c78b07f..1747bcb 100644
--- a/diffutil.py
+++ b/diffutil.py
@@ -66,6 +66,9 @@ def reverse_chunk(chunk):
 ################################################################################
 class Differ(object):
     """Utility class to hold diff2 or diff3 chunks"""
+
+    _matcher = IncrementalSequenceMatcher
+
     def __init__(self):
         # Internally, diffs are stored from text1 -> text0 and text1 -> text2.
         self.num_sequences = 0
@@ -116,7 +119,7 @@ class Differ(object):
         linesx = texts[x][rangex[0]:rangex[1]]
         lines1 = texts[1][range1[0]:range1[1]]
         #print "<<<\n%s\n===\n%s\n>>>" % ("\n".join(linesx),"\n".join(lines1))
-        newdiffs = IncrementalSequenceMatcher( None, lines1, linesx).get_difference_opcodes()
+        newdiffs = self._matcher(None, lines1, linesx).get_difference_opcodes()
         newdiffs = [ (c[0], c[1]+range1[0],c[2]+range1[0], c[3]+rangex[0],c[4]+rangex[0]) for c in newdiffs]
         if hiidx < len(self.diffs[which]):
             self.diffs[which][hiidx:] = [ (c[0],
@@ -240,7 +243,7 @@ class Differ(object):
         self.seqlength = [len(s) for s in sequences]
 
         for i in range(self.num_sequences - 1):
-            matcher = IncrementalSequenceMatcher(None, sequences[1], sequences[i*2])
+            matcher = self._matcher(None, sequences[1], sequences[i*2])
             work = matcher.initialise()
             while work.next() == None:
                 yield None



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