comparison mercurial/pure/bdiff.py @ 7944:e9b48afd0e78

pure/bdiff: fix circular import
author Matt Mackall <mpm@selenic.com>
date Fri, 03 Apr 2009 12:37:30 -0500
parents 9044d3567f6d
children 46293a0c7e9f
comparison
equal deleted inserted replaced
7943:c289c3fc5985 7944:e9b48afd0e78
4 # 4 #
5 # This software may be used and distributed according to the terms 5 # This software may be used and distributed according to the terms
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
13 for curr in blocks: 22 for curr in blocks:
14 if prev is None: 23 if prev is None:
57 lb = bm + size 66 lb = bm + size
58 67
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