Mercurial > public > mercurial-scm > hg
diff mercurial/cmdutil.py @ 28954:f97a0bcfd7a1
templater: separate function to create templater from map file (API)
New frommapfile() function will make it clear when template aliases will be
loaded. They should be applied to command arguments and templates in hgrc,
but not to map files. Otherwise, our stock styles and web templates
(i.e map-file templates) could be modified unintentionally.
Future patches will add "aliases" argument to __init__(), but not to
frommapfile().
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 03 Apr 2016 23:26:48 +0900 |
parents | 80be5dbe6e74 |
children | 78759f78a44e |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Sun Apr 03 23:18:30 2016 +0900 +++ b/mercurial/cmdutil.py Sun Apr 03 23:26:48 2016 +0900 @@ -1478,6 +1478,7 @@ def __init__(self, ui, repo, matchfn, diffopts, tmpl, mapfile, buffered): changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12]) + filters = {'formatnode': formatnode} defaulttempl = { 'parent': '{rev}:{node|formatnode} ', 'manifest': '{rev}:{node|formatnode}', @@ -1486,10 +1487,14 @@ } # filecopy is preserved for compatibility reasons defaulttempl['filecopy'] = defaulttempl['file_copy'] - self.t = templater.templater(mapfile, {'formatnode': formatnode}, - cache=defaulttempl) - if tmpl: - self.t.cache['changeset'] = tmpl + assert not (tmpl and mapfile) + if mapfile: + self.t = templater.templater.frommapfile(mapfile, filters=filters, + cache=defaulttempl) + else: + self.t = templater.templater(filters=filters, cache=defaulttempl) + if tmpl: + self.t.cache['changeset'] = tmpl self.cache = {}