changeset 7944:e9b48afd0e78

pure/bdiff: fix circular import
author Matt Mackall <mpm@selenic.com>
date Fri, 03 Apr 2009 12:37:30 -0500
parents c289c3fc5985
children 94d7e14cfa42
files mercurial/pure/bdiff.py
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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