comparison mercurial/templatekw.py @ 36442:e46b24582fa0

templatekw: minimize resource dependency of {envvars} and {termwidth} These keywords can be evaluated without a repo.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 25 Feb 2018 14:14:33 +0900
parents 27cd83152d31
children e8d37838f5df
comparison
equal deleted inserted replaced
36441:27cd83152d31 36442:e46b24582fa0
441 stats = patch.diffstatdata(util.iterlines(ctx.diff(noprefix=False))) 441 stats = patch.diffstatdata(util.iterlines(ctx.diff(noprefix=False)))
442 maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats) 442 maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
443 return '%s: +%s/-%s' % (len(stats), adds, removes) 443 return '%s: +%s/-%s' % (len(stats), adds, removes)
444 444
445 @templatekeyword('envvars') 445 @templatekeyword('envvars')
446 def showenvvars(repo, **args): 446 def showenvvars(ui, **args):
447 """A dictionary of environment variables. (EXPERIMENTAL)""" 447 """A dictionary of environment variables. (EXPERIMENTAL)"""
448 args = pycompat.byteskwargs(args) 448 args = pycompat.byteskwargs(args)
449 env = repo.ui.exportableenviron() 449 env = ui.exportableenviron()
450 env = util.sortdict((k, env[k]) for k in sorted(env)) 450 env = util.sortdict((k, env[k]) for k in sorted(env))
451 return showdict('envvar', env, args, plural='envvars') 451 return showdict('envvar', env, args, plural='envvars')
452 452
453 @templatekeyword('extras') 453 @templatekeyword('extras')
454 def showextras(**args): 454 def showextras(**args):
895 def showtags(**args): 895 def showtags(**args):
896 """List of strings. Any tags associated with the changeset.""" 896 """List of strings. Any tags associated with the changeset."""
897 return shownames('tags', **args) 897 return shownames('tags', **args)
898 898
899 @templatekeyword('termwidth') 899 @templatekeyword('termwidth')
900 def showtermwidth(repo, ctx, templ, **args): 900 def showtermwidth(ui, **args):
901 """Integer. The width of the current terminal.""" 901 """Integer. The width of the current terminal."""
902 return repo.ui.termwidth() 902 return ui.termwidth()
903 903
904 @templatekeyword('instabilities') 904 @templatekeyword('instabilities')
905 def showinstabilities(**args): 905 def showinstabilities(**args):
906 """List of strings. Evolution instabilities affecting the changeset. 906 """List of strings. Evolution instabilities affecting the changeset.
907 (EXPERIMENTAL) 907 (EXPERIMENTAL)