comparison mercurial/formatter.py @ 32894:8da65da039c3

formatter: always store a literal template unnamed Now spec.ref should be '' if spec.tmpl is specified. Since spec.ref is the option to select the initial template to be rendered, it doesn't make sense to store the given literal template as spec.ref.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 06 May 2017 17:03:59 +0900
parents c8f2cf18b82e
children e14484e7f562
comparison
equal deleted inserted replaced
32893:c8f2cf18b82e 32894:8da65da039c3
431 """Create a templater from either a literal template or loading from 431 """Create a templater from either a literal template or loading from
432 a map file""" 432 a map file"""
433 assert not (spec.tmpl and spec.mapfile) 433 assert not (spec.tmpl and spec.mapfile)
434 if spec.mapfile: 434 if spec.mapfile:
435 return templater.templater.frommapfile(spec.mapfile, cache=cache) 435 return templater.templater.frommapfile(spec.mapfile, cache=cache)
436 return _maketemplater(ui, spec.ref, spec.tmpl, cache=cache) 436 return maketemplater(ui, spec.tmpl, cache=cache)
437 437
438 def maketemplater(ui, tmpl, cache=None): 438 def maketemplater(ui, tmpl, cache=None):
439 """Create a templater from a string template 'tmpl'""" 439 """Create a templater from a string template 'tmpl'"""
440 return _maketemplater(ui, '', tmpl, cache=cache)
441
442 def _maketemplater(ui, topic, tmpl, cache=None):
443 aliases = ui.configitems('templatealias') 440 aliases = ui.configitems('templatealias')
444 t = templater.templater(cache=cache, aliases=aliases) 441 t = templater.templater(cache=cache, aliases=aliases)
445 t.cache.update((k, templater.unquotestring(v)) 442 t.cache.update((k, templater.unquotestring(v))
446 for k, v in ui.configitems('templates')) 443 for k, v in ui.configitems('templates'))
447 if tmpl: 444 if tmpl:
448 t.cache[topic] = tmpl 445 t.cache[''] = tmpl
449 return t 446 return t
450 447
451 def formatter(ui, out, topic, opts): 448 def formatter(ui, out, topic, opts):
452 template = opts.get("template", "") 449 template = opts.get("template", "")
453 if template == "json": 450 if template == "json":