comparison mercurial/hgweb/webutil.py @ 24712:bbf1ae6b6a44

hgweb: expose raw line numbers to templates Surpringly, the templates didn't receive an unmodified version of the line numbers. Expose it to make implementing the JSON templates easier. In theory, we could post-process an existing template variable. But extra string manipulation seems quite wasteful, especially on items that could occur hundreds or even thousands of times in output.
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 10 Apr 2015 22:34:12 -0400
parents 5ec4bda3097a
children 858618d43524
comparison
equal deleted inserted replaced
24711:ab6e3729747e 24712:bbf1ae6b6a44
350 start += 1 350 start += 1
351 351
352 blockcount = countgen() 352 blockcount = countgen()
353 def prettyprintlines(diff, blockno): 353 def prettyprintlines(diff, blockno):
354 for lineno, l in enumerate(diff.splitlines(True)): 354 for lineno, l in enumerate(diff.splitlines(True)):
355 lineno = "%d.%d" % (blockno, lineno + 1) 355 difflineno = "%d.%d" % (blockno, lineno + 1)
356 if l.startswith('+'): 356 if l.startswith('+'):
357 ltype = "difflineplus" 357 ltype = "difflineplus"
358 elif l.startswith('-'): 358 elif l.startswith('-'):
359 ltype = "difflineminus" 359 ltype = "difflineminus"
360 elif l.startswith('@'): 360 elif l.startswith('@'):
361 ltype = "difflineat" 361 ltype = "difflineat"
362 else: 362 else:
363 ltype = "diffline" 363 ltype = "diffline"
364 yield tmpl(ltype, 364 yield tmpl(ltype,
365 line=l, 365 line=l,
366 lineid="l%s" % lineno, 366 lineno=lineno + 1,
367 linenumber="% 8s" % lineno) 367 lineid="l%s" % difflineno,
368 linenumber="% 8s" % difflineno)
368 369
369 if files: 370 if files:
370 m = match.exact(repo.root, repo.getcwd(), files) 371 m = match.exact(repo.root, repo.getcwd(), files)
371 else: 372 else:
372 m = match.always(repo.root, repo.getcwd()) 373 m = match.always(repo.root, repo.getcwd())
403 lineid = leftlineno and ("l%s" % leftlineno) or '' 404 lineid = leftlineno and ("l%s" % leftlineno) or ''
404 lineid += rightlineno and ("r%s" % rightlineno) or '' 405 lineid += rightlineno and ("r%s" % rightlineno) or ''
405 return tmpl('comparisonline', 406 return tmpl('comparisonline',
406 type=type, 407 type=type,
407 lineid=lineid, 408 lineid=lineid,
409 leftlineno=leftlineno,
408 leftlinenumber="% 6s" % (leftlineno or ''), 410 leftlinenumber="% 6s" % (leftlineno or ''),
409 leftline=leftline or '', 411 leftline=leftline or '',
412 rightlineno=rightlineno,
410 rightlinenumber="% 6s" % (rightlineno or ''), 413 rightlinenumber="% 6s" % (rightlineno or ''),
411 rightline=rightline or '') 414 rightline=rightline or '')
412 415
413 def getblock(opcodes): 416 def getblock(opcodes):
414 for type, llo, lhi, rlo, rhi in opcodes: 417 for type, llo, lhi, rlo, rhi in opcodes: