comparison 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
comparison
equal deleted inserted replaced
28953:7f6b8ec691e3 28954:f97a0bcfd7a1
1476 '''format changeset information.''' 1476 '''format changeset information.'''
1477 1477
1478 def __init__(self, ui, repo, matchfn, diffopts, tmpl, mapfile, buffered): 1478 def __init__(self, ui, repo, matchfn, diffopts, tmpl, mapfile, buffered):
1479 changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) 1479 changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered)
1480 formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12]) 1480 formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12])
1481 filters = {'formatnode': formatnode}
1481 defaulttempl = { 1482 defaulttempl = {
1482 'parent': '{rev}:{node|formatnode} ', 1483 'parent': '{rev}:{node|formatnode} ',
1483 'manifest': '{rev}:{node|formatnode}', 1484 'manifest': '{rev}:{node|formatnode}',
1484 'file_copy': '{name} ({source})', 1485 'file_copy': '{name} ({source})',
1485 'extra': '{key}={value|stringescape}' 1486 'extra': '{key}={value|stringescape}'
1486 } 1487 }
1487 # filecopy is preserved for compatibility reasons 1488 # filecopy is preserved for compatibility reasons
1488 defaulttempl['filecopy'] = defaulttempl['file_copy'] 1489 defaulttempl['filecopy'] = defaulttempl['file_copy']
1489 self.t = templater.templater(mapfile, {'formatnode': formatnode}, 1490 assert not (tmpl and mapfile)
1490 cache=defaulttempl) 1491 if mapfile:
1491 if tmpl: 1492 self.t = templater.templater.frommapfile(mapfile, filters=filters,
1492 self.t.cache['changeset'] = tmpl 1493 cache=defaulttempl)
1494 else:
1495 self.t = templater.templater(filters=filters, cache=defaulttempl)
1496 if tmpl:
1497 self.t.cache['changeset'] = tmpl
1493 1498
1494 self.cache = {} 1499 self.cache = {}
1495 1500
1496 # find correct templates for current mode 1501 # find correct templates for current mode
1497 tmplmodes = [ 1502 tmplmodes = [