comparison mercurial/hgweb/webutil.py @ 42337:832c59d1196e

templater: drop support for old style keywords (API) These changes originated from several commits over a period of time, so I'm slightly unsure if this is correct. But the tests pass.
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 18 May 2019 19:56:06 -0400
parents 0531dff73d0b
children 6ccf539aec71
comparison
equal deleted inserted replaced
42336:fa4b13e81f60 42337:832c59d1196e
406 406
407 def whyunstable(context, mapping): 407 def whyunstable(context, mapping):
408 return templateutil.mappinggenerator(_whyunstablegen, args=(mapping,)) 408 return templateutil.mappinggenerator(_whyunstablegen, args=(mapping,))
409 409
410 whyunstable._requires = {'repo', 'ctx'} 410 whyunstable._requires = {'repo', 'ctx'}
411
412 # helper to mark a function as a new-style template keyword; can be removed
413 # once old-style function gets unsupported and new-style becomes the default
414 def _kwfunc(f):
415 f._requires = ()
416 return f
417 411
418 def commonentry(repo, ctx): 412 def commonentry(repo, ctx):
419 node = scmutil.binnode(ctx) 413 node = scmutil.binnode(ctx)
420 return { 414 return {
421 # TODO: perhaps ctx.changectx() should be assigned if ctx is a 415 # TODO: perhaps ctx.changectx() should be assigned if ctx is a
437 'branch': nodebranchnodefault(ctx), 431 'branch': nodebranchnodefault(ctx),
438 'inbranch': nodeinbranch(repo, ctx), 432 'inbranch': nodeinbranch(repo, ctx),
439 'branches': nodebranchdict(repo, ctx), 433 'branches': nodebranchdict(repo, ctx),
440 'tags': nodetagsdict(repo, node), 434 'tags': nodetagsdict(repo, node),
441 'bookmarks': nodebookmarksdict(repo, node), 435 'bookmarks': nodebookmarksdict(repo, node),
442 'parent': _kwfunc(lambda context, mapping: parents(ctx)), 436 'parent': lambda context, mapping: parents(ctx),
443 'child': _kwfunc(lambda context, mapping: children(ctx)), 437 'child': lambda context, mapping: children(ctx),
444 } 438 }
445 439
446 def changelistentry(web, ctx): 440 def changelistentry(web, ctx):
447 '''Obtain a dictionary to be used for entries in a changelist. 441 '''Obtain a dictionary to be used for entries in a changelist.
448 442
455 showtags = showtag(repo, 'changelogtag', n) 449 showtags = showtag(repo, 'changelogtag', n)
456 files = listfilediffs(ctx.files(), n, web.maxfiles) 450 files = listfilediffs(ctx.files(), n, web.maxfiles)
457 451
458 entry = commonentry(repo, ctx) 452 entry = commonentry(repo, ctx)
459 entry.update({ 453 entry.update({
460 'allparents': _kwfunc(lambda context, mapping: parents(ctx)), 454 'allparents': lambda context, mapping: parents(ctx),
461 'parent': _kwfunc(lambda context, mapping: parents(ctx, rev - 1)), 455 'parent': lambda context, mapping: parents(ctx, rev - 1),
462 'child': _kwfunc(lambda context, mapping: children(ctx, rev + 1)), 456 'child': lambda context, mapping: children(ctx, rev + 1),
463 'changelogtag': showtags, 457 'changelogtag': showtags,
464 'files': files, 458 'files': files,
465 }) 459 })
466 return entry 460 return entry
467 461
527 changesettag=showtags, 521 changesettag=showtags,
528 changesetbookmark=showbookmarks, 522 changesetbookmark=showbookmarks,
529 changesetbranch=showbranch, 523 changesetbranch=showbranch,
530 files=templateutil.mappedgenerator(_listfilesgen, 524 files=templateutil.mappedgenerator(_listfilesgen,
531 args=(ctx, web.stripecount)), 525 args=(ctx, web.stripecount)),
532 diffsummary=_kwfunc(lambda context, mapping: diffsummary(diffstatsgen)), 526 diffsummary=lambda context, mapping: diffsummary(diffstatsgen),
533 diffstat=diffstats, 527 diffstat=diffstats,
534 archives=web.archivelist(ctx.hex()), 528 archives=web.archivelist(ctx.hex()),
535 **pycompat.strkwargs(commonentry(web.repo, ctx))) 529 **pycompat.strkwargs(commonentry(web.repo, ctx)))
536 530
537 def _listfilediffsgen(context, files, node, max): 531 def _listfilediffsgen(context, files, node, max):