Patchwork [4,of,7] templatekw: minimize resource dependency of {envvars} and {termwidth}

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 26, 2018, 2:29 p.m.
Message ID <0d70933cd0d82836b911.1519655377@mimosa>
Download mbox | patch
Permalink /patch/28410/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 26, 2018, 2:29 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1519535673 -32400
#      Sun Feb 25 14:14:33 2018 +0900
# Node ID 0d70933cd0d82836b9117597b118d72589711118
# Parent  92789aee2463ee830f9e85ddb377b54ebd8c48aa
templatekw: minimize resource dependency of {envvars} and {termwidth}

These keywords can be evaluated without a repo.

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -443,10 +443,10 @@  def showdiffstat(repo, ctx, templ, **arg
     return '%s: +%s/-%s' % (len(stats), adds, removes)
 
 @templatekeyword('envvars')
-def showenvvars(repo, **args):
+def showenvvars(ui, **args):
     """A dictionary of environment variables. (EXPERIMENTAL)"""
     args = pycompat.byteskwargs(args)
-    env = repo.ui.exportableenviron()
+    env = ui.exportableenviron()
     env = util.sortdict((k, env[k]) for k in sorted(env))
     return showdict('envvar', env, args, plural='envvars')
 
@@ -897,9 +897,9 @@  def showtags(**args):
     return shownames('tags', **args)
 
 @templatekeyword('termwidth')
-def showtermwidth(repo, ctx, templ, **args):
+def showtermwidth(ui, **args):
     """Integer. The width of the current terminal."""
-    return repo.ui.termwidth()
+    return ui.termwidth()
 
 @templatekeyword('instabilities')
 def showinstabilities(**args):