Hi,
I am attaching yet another patch that simplifies Differ class.
Cheers,
Piotr
Kai Willadsen wrote:
Hi,
Attached for review are the first few patches in a series aimed at
cleaning up diffutil.Differ. These include some cleanup of unused
arguments and return values, as well as some small refactoring.
Comments appreciated.
Kai
------------------------------------------------------------------------
_______________________________________________
meld-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/meld-list
>From 7ad31ac0f501023700d970339f29cc356aee9308 Mon Sep 17 00:00:00 2001
From: Piotr Piastucki <[email protected]>
Date: Sun, 7 Jun 2009 09:11:11 +0200
Subject: [PATCH] Simplify Differ
---
diffutil.py | 26 ++++++++------------------
1 files changed, 8 insertions(+), 18 deletions(-)
diff --git a/diffutil.py b/diffutil.py
index ab88818..66f3b9a 100644
--- a/diffutil.py
+++ b/diffutil.py
@@ -172,25 +172,17 @@ class Differ(object):
c = cs[1]
yield c[0], c[1], c[2], c[3], c[4], 2
- def _merge_blocks(self, using, low_seq, high_seq, last_diff):
+ def _merge_blocks(self, using):
LO, HI = 1,2
- lowc = using[low_seq][ 0][LO]
- highc = using[low_seq][-1][HI]
- if len(using[not low_seq]):
- lowc = min(lowc, using[not low_seq][ 0][LO])
- highc = max(highc, using[not low_seq][-1][HI])
+ lowc = min(using[0][ 0][LO], using[1][ 0][LO])
+ highc = max(using[0][-1][HI], using[1][-1][HI])
low = []
high = []
for i in (0,1):
- if len(using[i]):
- d = using[i][0]
- low.append( lowc - d[LO] + d[2+LO] )
- d = using[i][-1]
- high.append( highc - d[HI] + d[2+HI] )
- else:
- d = last_diff
- low.append( lowc - d[LO] + d[2+LO] )
- high.append( highc - d[HI] + d[2+HI] )
+ d = using[i][0]
+ low.append( lowc - d[LO] + d[2+LO] )
+ d = using[i][-1]
+ high.append( highc - d[HI] + d[2+HI] )
return low[0], high[0], lowc, highc, low[1], high[1]
def _merge_diffs(self, seq0, seq1, texts):
@@ -231,8 +223,6 @@ class Differ(object):
high_diff = other_diff
high_mark = other_diff[HI]
- block = self._merge_blocks( using, base_seq, high_seq, block)
-
if len(using[0])==0:
assert len(using[1])==1
yield None, using[1][0]
@@ -240,7 +230,7 @@ class Differ(object):
assert len(using[0])==1
yield using[0][0], None
else:
- l0, h0, l1, h1, l2, h2 = block
+ l0, h0, l1, h1, l2, h2 = block = self._merge_blocks( using )
if h0-l0 == h2-l2 and texts[0][l0:h0] == texts[2][l2:h2]:
if l1 != h1:
out0 = ('replace', block[2], block[3], block[0], block[1])
--
1.6.0.4
_______________________________________________
meld-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/meld-list