comparison mercurial/cmdutil.py @ 31179:48a8b2e5fe31

templater: port formatnode filter from changeset_templater This slightly reduces the difference between changeset_templater and formatter, and helps extending formatter to support changeset templating. New formatnode() is not a template filter, but a function since a filter cannot access to ui. And it's marked as DEPRECATED since I think it exists only for compatibility reasons.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 25 Feb 2017 16:26:58 +0900
parents accdd5e62066
children 1ec89cf0ea49
comparison
equal deleted inserted replaced
31178:41a9edc5d00f 31179:48a8b2e5fe31
1440 class changeset_templater(changeset_printer): 1440 class changeset_templater(changeset_printer):
1441 '''format changeset information.''' 1441 '''format changeset information.'''
1442 1442
1443 def __init__(self, ui, repo, matchfn, diffopts, tmpl, mapfile, buffered): 1443 def __init__(self, ui, repo, matchfn, diffopts, tmpl, mapfile, buffered):
1444 changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) 1444 changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered)
1445 formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12])
1446 filters = {'formatnode': formatnode}
1447 defaulttempl = { 1445 defaulttempl = {
1448 'parent': '{rev}:{node|formatnode} ', 1446 'parent': '{rev}:{node|formatnode} ',
1449 'manifest': '{rev}:{node|formatnode}', 1447 'manifest': '{rev}:{node|formatnode}',
1450 'file_copy': '{name} ({source})', 1448 'file_copy': '{name} ({source})',
1451 'envvar': '{key}={value}', 1449 'envvar': '{key}={value}',
1453 } 1451 }
1454 # filecopy is preserved for compatibility reasons 1452 # filecopy is preserved for compatibility reasons
1455 defaulttempl['filecopy'] = defaulttempl['file_copy'] 1453 defaulttempl['filecopy'] = defaulttempl['file_copy']
1456 assert not (tmpl and mapfile) 1454 assert not (tmpl and mapfile)
1457 if mapfile: 1455 if mapfile:
1458 self.t = templater.templater.frommapfile(mapfile, filters=filters, 1456 self.t = templater.templater.frommapfile(mapfile,
1459 cache=defaulttempl) 1457 cache=defaulttempl)
1460 else: 1458 else:
1461 self.t = formatter.maketemplater(ui, 'changeset', tmpl, 1459 self.t = formatter.maketemplater(ui, 'changeset', tmpl,
1462 filters=filters,
1463 cache=defaulttempl) 1460 cache=defaulttempl)
1464 1461
1465 self.cache = {} 1462 self.cache = {}
1466 1463
1467 # find correct templates for current mode 1464 # find correct templates for current mode