##// END OF EJS Templates
formatter: load templates section like a map file...
Yuya Nishihara -
r32875:c8f2cf18 default
parent child Browse files
Show More
@@ -1649,7 +1649,10 b' class changeset_templater(changeset_prin'
1649 self.t(self._parts['footer'], **props))
1649 self.t(self._parts['footer'], **props))
1650
1650
1651 def logtemplatespec(tmpl, mapfile):
1651 def logtemplatespec(tmpl, mapfile):
1652 return formatter.templatespec('changeset', tmpl, mapfile)
1652 if mapfile:
1653 return formatter.templatespec('changeset', tmpl, mapfile)
1654 else:
1655 return formatter.templatespec('', tmpl, None)
1653
1656
1654 def _lookuplogtemplate(ui, tmpl, style):
1657 def _lookuplogtemplate(ui, tmpl, style):
1655 """Find the template matching the given template spec or style
1658 """Find the template matching the given template spec or style
@@ -1706,7 +1709,7 b' def show_changeset(ui, repo, opts, buffe'
1706
1709
1707 spec = _lookuplogtemplate(ui, opts.get('template'), opts.get('style'))
1710 spec = _lookuplogtemplate(ui, opts.get('template'), opts.get('style'))
1708
1711
1709 if not spec.tmpl and not spec.mapfile:
1712 if not spec.ref and not spec.tmpl and not spec.mapfile:
1710 return changeset_printer(ui, repo, matchfn, opts, buffered)
1713 return changeset_printer(ui, repo, matchfn, opts, buffered)
1711
1714
1712 return changeset_templater(ui, repo, spec, matchfn, opts, buffered)
1715 return changeset_templater(ui, repo, spec, matchfn, opts, buffered)
@@ -391,11 +391,14 b' def lookuptemplate(ui, topic, tmpl):'
391 selected, all templates defined in the file will be loaded, and the
391 selected, all templates defined in the file will be loaded, and the
392 template matching the given topic will be rendered. No aliases will be
392 template matching the given topic will be rendered. No aliases will be
393 loaded from user config.
393 loaded from user config.
394
395 If no map file selected, all templates in [templates] section will be
396 available as well as aliases in [templatealias].
394 """
397 """
395
398
396 # looks like a literal template?
399 # looks like a literal template?
397 if '{' in tmpl:
400 if '{' in tmpl:
398 return templatespec(topic, tmpl, None)
401 return templatespec('', tmpl, None)
399
402
400 # perhaps a stock style?
403 # perhaps a stock style?
401 if not os.path.split(tmpl)[0]:
404 if not os.path.split(tmpl)[0]:
@@ -405,9 +408,8 b' def lookuptemplate(ui, topic, tmpl):'
405 return templatespec(topic, None, mapname)
408 return templatespec(topic, None, mapname)
406
409
407 # perhaps it's a reference to [templates]
410 # perhaps it's a reference to [templates]
408 t = ui.config('templates', tmpl)
411 if ui.config('templates', tmpl):
409 if t:
412 return templatespec(tmpl, None, None)
410 return templatespec(topic, templater.unquotestring(t), None)
411
413
412 if tmpl == 'list':
414 if tmpl == 'list':
413 ui.write(_("available styles: %s\n") % templater.stylelist())
415 ui.write(_("available styles: %s\n") % templater.stylelist())
@@ -420,10 +422,10 b' def lookuptemplate(ui, topic, tmpl):'
420 return templatespec(topic, None, os.path.realpath(tmpl))
422 return templatespec(topic, None, os.path.realpath(tmpl))
421 with util.posixfile(tmpl, 'rb') as f:
423 with util.posixfile(tmpl, 'rb') as f:
422 tmpl = f.read()
424 tmpl = f.read()
423 return templatespec(topic, tmpl, None)
425 return templatespec('', tmpl, None)
424
426
425 # constant string?
427 # constant string?
426 return templatespec(topic, tmpl, None)
428 return templatespec('', tmpl, None)
427
429
428 def loadtemplater(ui, spec, cache=None):
430 def loadtemplater(ui, spec, cache=None):
429 """Create a templater from either a literal template or loading from
431 """Create a templater from either a literal template or loading from
@@ -440,6 +442,8 b' def maketemplater(ui, tmpl, cache=None):'
440 def _maketemplater(ui, topic, tmpl, cache=None):
442 def _maketemplater(ui, topic, tmpl, cache=None):
441 aliases = ui.configitems('templatealias')
443 aliases = ui.configitems('templatealias')
442 t = templater.templater(cache=cache, aliases=aliases)
444 t = templater.templater(cache=cache, aliases=aliases)
445 t.cache.update((k, templater.unquotestring(v))
446 for k, v in ui.configitems('templates'))
443 if tmpl:
447 if tmpl:
444 t.cache[topic] = tmpl
448 t.cache[topic] = tmpl
445 return t
449 return t
@@ -109,6 +109,14 b' defines a template, ``nodedate``, which '
109
109
110 $ hg log -r . -Tnodedate
110 $ hg log -r . -Tnodedate
111
111
112 A template defined in ``templates`` section can also be referenced from
113 another template::
114
115 $ hg log -r . -T "{rev} {nodedate}"
116
117 but be aware that the keywords cannot be overridden by templates. For example,
118 a template defined as ``templates.rev`` cannot be referenced as ``{rev}``.
119
112 Examples
120 Examples
113 ========
121 ========
114
122
@@ -209,14 +209,29 b' Make sure user/global hgrc does not affe'
209
209
210 Add some simple styles to settings
210 Add some simple styles to settings
211
211
212 $ echo '[templates]' >> .hg/hgrc
212 $ cat <<'EOF' >> .hg/hgrc
213 $ printf 'simple = "{rev}\\n"\n' >> .hg/hgrc
213 > [templates]
214 $ printf 'simple2 = {rev}\\n\n' >> .hg/hgrc
214 > simple = "{rev}\n"
215 > simple2 = {rev}\n
216 > rev = "should not precede {rev} keyword\n"
217 > EOF
215
218
216 $ hg log -l1 -Tsimple
219 $ hg log -l1 -Tsimple
217 8
220 8
218 $ hg log -l1 -Tsimple2
221 $ hg log -l1 -Tsimple2
219 8
222 8
223 $ hg log -l1 -Trev
224 should not precede 8 keyword
225 $ hg log -l1 -T '{simple}'
226 8
227
228 Map file shouldn't see user templates:
229
230 $ cat <<EOF > tmpl
231 > changeset = 'nothing expanded:{simple}\n'
232 > EOF
233 $ hg log -l1 --style ./tmpl
234 nothing expanded:
220
235
221 Test templates and style maps in files:
236 Test templates and style maps in files:
222
237
General Comments 0
You need to be logged in to leave comments. Login now