##// END OF EJS Templates
pure/bdiff: fix circular import
Matt Mackall -
r7944:e9b48afd default
parent child Browse files
Show More
@@ -6,7 +6,16 b''
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 import struct, difflib
9 # mdiff import moved to bottom due to import cycle
9
10 def splitnewlines(text):
11 '''like str.splitlines, but only split on newlines.'''
12 lines = [l + '\n' for l in text.split('\n')]
13 if lines:
14 if lines[-1] == '\n':
15 lines.pop()
16 else:
17 lines[-1] = lines[-1][:-1]
18 return lines
10 19
11 20 def _normalizeblocks(a, b, blocks):
12 21 prev = None
@@ -59,11 +68,9 b' def bdiff(a, b):'
59 68 return "".join(bin)
60 69
61 70 def blocks(a, b):
62 an = mdiff.splitnewlines(a)
63 bn = mdiff.splitnewlines(b)
71 an = splitnewlines(a)
72 bn = splitnewlines(b)
64 73 d = difflib.SequenceMatcher(None, an, bn).get_matching_blocks()
65 74 d = _normalizeblocks(an, bn, d)
66 75 return [(i, i + n, j, j + n) for (i, j, n) in d]
67 76
68 # this breaks an import cycle
69 import mdiff
General Comments 0
You need to be logged in to leave comments. Login now