Mercurial > hg
comparison mercurial/mdiff.py @ 15529:b35cf47286a6
mdiff: split lines in allblocks() only when necessary
These are only required to handle the --ignore-blank-lines case
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Fri, 18 Nov 2011 14:16:47 +0100 |
parents | a84698badf0b |
children | eeac5e179243 |
comparison
equal
deleted
inserted
replaced
15528:a84698badf0b | 15529:b35cf47286a6 |
---|---|
110 line1 and line2 are text1 and text2 split with splitnewlines() if | 110 line1 and line2 are text1 and text2 split with splitnewlines() if |
111 they are already available. | 111 they are already available. |
112 """ | 112 """ |
113 if opts is None: | 113 if opts is None: |
114 opts = defaultopts | 114 opts = defaultopts |
115 if lines1 is None: | |
116 lines1 = splitnewlines(text1) | |
117 if lines2 is None: | |
118 lines2 = splitnewlines(text2) | |
119 if opts.ignorews or opts.ignorewsamount: | 115 if opts.ignorews or opts.ignorewsamount: |
120 text1 = wsclean(opts, text1, False) | 116 text1 = wsclean(opts, text1, False) |
121 text2 = wsclean(opts, text2, False) | 117 text2 = wsclean(opts, text2, False) |
122 diff = bdiff.blocks(text1, text2) | 118 diff = bdiff.blocks(text1, text2) |
123 for i, s1 in enumerate(diff): | 119 for i, s1 in enumerate(diff): |
128 if i > 0: | 124 if i > 0: |
129 s = diff[i - 1] | 125 s = diff[i - 1] |
130 else: | 126 else: |
131 s = [0, 0, 0, 0] | 127 s = [0, 0, 0, 0] |
132 s = [s[1], s1[0], s[3], s1[2]] | 128 s = [s[1], s1[0], s[3], s1[2]] |
133 old = lines1[s[0]:s[1]] | |
134 new = lines2[s[2]:s[3]] | |
135 | 129 |
136 # bdiff sometimes gives huge matches past eof, this check eats them, | 130 # bdiff sometimes gives huge matches past eof, this check eats them, |
137 # and deals with the special first match case described above | 131 # and deals with the special first match case described above |
138 if old or new: | 132 if s[0] != s[1] or s[2] != s[3]: |
139 type = '!' | 133 type = '!' |
140 if opts.ignoreblanklines: | 134 if opts.ignoreblanklines: |
141 cold = wsclean(opts, "".join(old)) | 135 if lines1 is None: |
142 cnew = wsclean(opts, "".join(new)) | 136 lines1 = splitnewlines(text1) |
143 if cold == cnew: | 137 if lines2 is None: |
138 lines2 = splitnewlines(text2) | |
139 old = wsclean(opts, "".join(lines1[s[0]:s[1]])) | |
140 new = wsclean(opts, "".join(lines2[s[2]:s[3]])) | |
141 if old == new: | |
144 type = '~' | 142 type = '~' |
145 yield s, type | 143 yield s, type |
146 yield s1, '=' | 144 yield s1, '=' |
147 | 145 |
148 def diffline(revs, a, b, opts): | 146 def diffline(revs, a, b, opts): |