comparison mercurial/mdiff.py @ 31272:e41946f39724

mdiff: extract a checknonewline inner function in unidiff()
author Denis Laxalde <denis.laxalde@logilab.fr>
date Fri, 03 Mar 2017 17:46:28 +0100
parents b3861be6aa6c
children 92714858dd3e
comparison
equal deleted inserted replaced
31271:b3861be6aa6c 31272:e41946f39724
223 epoch = util.datestr((0, 0)) 223 epoch = util.datestr((0, 0))
224 224
225 fn1 = util.pconvert(fn1) 225 fn1 = util.pconvert(fn1)
226 fn2 = util.pconvert(fn2) 226 fn2 = util.pconvert(fn2)
227 227
228 def checknonewline(lines):
229 for text in lines:
230 if text[-1] != '\n':
231 text += "\n\ No newline at end of file\n"
232 yield text
233
228 if not opts.text and (util.binary(a) or util.binary(b)): 234 if not opts.text and (util.binary(a) or util.binary(b)):
229 if a and b and len(a) == len(b) and a == b: 235 if a and b and len(a) == len(b) and a == b:
230 return sentinel 236 return sentinel
231 headerlines = [] 237 headerlines = []
232 l = ['Binary file %s has changed\n' % fn1] 238 l = ['Binary file %s has changed\n' % fn1]
256 headerlines = [ 262 headerlines = [
257 "--- %s%s%s" % (aprefix, fn1, datetag(ad, fn1)), 263 "--- %s%s%s" % (aprefix, fn1, datetag(ad, fn1)),
258 "+++ %s%s%s" % (bprefix, fn2, datetag(bd, fn2)), 264 "+++ %s%s%s" % (bprefix, fn2, datetag(bd, fn2)),
259 ] 265 ]
260 266
261 for ln in xrange(len(l)): 267 return headerlines, "".join(checknonewline(l))
262 if l[ln][-1] != '\n':
263 l[ln] += "\n\ No newline at end of file\n"
264
265 return headerlines, "".join(l)
266 268
267 def _unidiff(t1, t2, opts=defaultopts): 269 def _unidiff(t1, t2, opts=defaultopts):
268 """Yield hunks of a headerless unified diff from t1 and t2 texts. 270 """Yield hunks of a headerless unified diff from t1 and t2 texts.
269 271
270 Each hunk consists of a (hunkrange, hunklines) tuple where `hunkrange` is a 272 Each hunk consists of a (hunkrange, hunklines) tuple where `hunkrange` is a