##// 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 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 import struct, difflib
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 def _normalizeblocks(a, b, blocks):
20 def _normalizeblocks(a, b, blocks):
12 prev = None
21 prev = None
@@ -59,11 +68,9 b' def bdiff(a, b):'
59 return "".join(bin)
68 return "".join(bin)
60
69
61 def blocks(a, b):
70 def blocks(a, b):
62 an = mdiff.splitnewlines(a)
71 an = splitnewlines(a)
63 bn = mdiff.splitnewlines(b)
72 bn = splitnewlines(b)
64 d = difflib.SequenceMatcher(None, an, bn).get_matching_blocks()
73 d = difflib.SequenceMatcher(None, an, bn).get_matching_blocks()
65 d = _normalizeblocks(an, bn, d)
74 d = _normalizeblocks(an, bn, d)
66 return [(i, i + n, j, j + n) for (i, j, n) in d]
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