##// END OF EJS Templates
hgweb: use patch.diffhunks in webutil.diffs to simplify the algorithm...
Denis Laxalde -
r31276:cd29673c default
parent child Browse files
Show More
@@ -412,15 +412,8 b' def listfilediffs(tmpl, files, node, max'
412
412
413 def diffs(repo, tmpl, ctx, basectx, files, parity, style):
413 def diffs(repo, tmpl, ctx, basectx, files, parity, style):
414
414
415 def countgen():
415 def prettyprintlines(lines, blockno):
416 start = 1
416 for lineno, l in enumerate(lines, 1):
417 while True:
418 yield start
419 start += 1
420
421 blockcount = countgen()
422 def prettyprintlines(diff, blockno):
423 for lineno, l in enumerate(diff.splitlines(True), 1):
424 difflineno = "%d.%d" % (blockno, lineno)
417 difflineno = "%d.%d" % (blockno, lineno)
425 if l.startswith('+'):
418 if l.startswith('+'):
426 ltype = "difflineplus"
419 ltype = "difflineplus"
@@ -445,19 +438,16 b' def diffs(repo, tmpl, ctx, basectx, file'
445 node1 = basectx.node()
438 node1 = basectx.node()
446 node2 = ctx.node()
439 node2 = ctx.node()
447
440
448 block = []
441 diffhunks = patch.diffhunks(repo, node1, node2, m, opts=diffopts)
449 for chunk in patch.diff(repo, node1, node2, m, opts=diffopts):
442 for blockno, (header, hunks) in enumerate(diffhunks, 1):
450 if chunk.startswith('diff') and block:
443 if style != 'raw':
451 blockno = next(blockcount)
444 header = header[1:]
445 lines = [h + '\n' for h in header]
446 for hunkrange, hunklines in hunks:
447 lines.extend(hunklines)
448 if lines:
452 yield tmpl('diffblock', parity=next(parity), blockno=blockno,
449 yield tmpl('diffblock', parity=next(parity), blockno=blockno,
453 lines=prettyprintlines(''.join(block), blockno))
450 lines=prettyprintlines(lines, blockno))
454 block = []
455 if chunk.startswith('diff') and style != 'raw':
456 chunk = ''.join(chunk.splitlines(True)[1:])
457 block.append(chunk)
458 blockno = next(blockcount)
459 yield tmpl('diffblock', parity=next(parity), blockno=blockno,
460 lines=prettyprintlines(''.join(block), blockno))
461
451
462 def compare(tmpl, context, leftlines, rightlines):
452 def compare(tmpl, context, leftlines, rightlines):
463 '''Generator function that provides side-by-side comparison data.'''
453 '''Generator function that provides side-by-side comparison data.'''
General Comments 0
You need to be logged in to leave comments. Login now