pure/bdiff: fix circular import
authorMatt Mackall <mpm@selenic.com>
Fri, 03 Apr 2009 12:37:30 -0500
changeset 7944 e9b48afd0e78
parent 7943 c289c3fc5985
child 7945 94d7e14cfa42
pure/bdiff: fix circular import
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