# HG changeset patch # User Matt Mackall # Date 1238780250 18000 # Node ID e9b48afd0e788b09b640636ba1f9545c8f32fbe0 # Parent c289c3fc598541977be42d402bc0d6848c9633b7 pure/bdiff: fix circular import diff -r c289c3fc5985 -r e9b48afd0e78 mercurial/pure/bdiff.py --- a/mercurial/pure/bdiff.py Fri Apr 03 12:37:07 2009 -0500 +++ b/mercurial/pure/bdiff.py Fri Apr 03 12:37:30 2009 -0500 @@ -6,7 +6,16 @@ # of the GNU General Public License, incorporated herein by reference. import struct, difflib -# mdiff import moved to bottom due to import cycle + +def splitnewlines(text): + '''like str.splitlines, but only split on newlines.''' + lines = [l + '\n' for l in text.split('\n')] + if lines: + if lines[-1] == '\n': + lines.pop() + else: + lines[-1] = lines[-1][:-1] + return lines def _normalizeblocks(a, b, blocks): prev = None @@ -59,11 +68,9 @@ return "".join(bin) def blocks(a, b): - an = mdiff.splitnewlines(a) - bn = mdiff.splitnewlines(b) + an = splitnewlines(a) + bn = splitnewlines(b) d = difflib.SequenceMatcher(None, an, bn).get_matching_blocks() d = _normalizeblocks(an, bn, d) return [(i, i + n, j, j + n) for (i, j, n) in d] -# this breaks an import cycle -import mdiff