Show More
@@ -1580,7 +1580,8 b' class changeset_templater(changeset_prin' | |||||
1580 |
|
1580 | |||
1581 | def __init__(self, ui, repo, matchfn, diffopts, tmpl, mapfile, buffered): |
|
1581 | def __init__(self, ui, repo, matchfn, diffopts, tmpl, mapfile, buffered): | |
1582 | changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) |
|
1582 | changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) | |
1583 |
|
|
1583 | tmplspec = logtemplatespec(tmpl, mapfile) | |
|
1584 | self.t = formatter.loadtemplater(ui, 'changeset', tmplspec, | |||
1584 | cache=templatekw.defaulttempl) |
|
1585 | cache=templatekw.defaulttempl) | |
1585 | self._counter = itertools.count() |
|
1586 | self._counter = itertools.count() | |
1586 | self.cache = {} |
|
1587 | self.cache = {} | |
@@ -1646,6 +1647,8 b' class changeset_templater(changeset_prin' | |||||
1646 | self.footer = templater.stringify( |
|
1647 | self.footer = templater.stringify( | |
1647 | self.t(self._parts['footer'], **props)) |
|
1648 | self.t(self._parts['footer'], **props)) | |
1648 |
|
1649 | |||
|
1650 | logtemplatespec = formatter.templatespec | |||
|
1651 | ||||
1649 | def _lookuplogtemplate(ui, tmpl, style): |
|
1652 | def _lookuplogtemplate(ui, tmpl, style): | |
1650 | """Find the template matching the given template spec or style |
|
1653 | """Find the template matching the given template spec or style | |
1651 |
|
1654 | |||
@@ -1656,7 +1659,7 b' def _lookuplogtemplate(ui, tmpl, style):' | |||||
1656 | if not tmpl and not style: # template are stronger than style |
|
1659 | if not tmpl and not style: # template are stronger than style | |
1657 | tmpl = ui.config('ui', 'logtemplate') |
|
1660 | tmpl = ui.config('ui', 'logtemplate') | |
1658 | if tmpl: |
|
1661 | if tmpl: | |
1659 | return templater.unquotestring(tmpl), None |
|
1662 | return logtemplatespec(templater.unquotestring(tmpl), None) | |
1660 | else: |
|
1663 | else: | |
1661 | style = util.expandpath(ui.config('ui', 'style', '')) |
|
1664 | style = util.expandpath(ui.config('ui', 'style', '')) | |
1662 |
|
1665 | |||
@@ -1667,10 +1670,10 b' def _lookuplogtemplate(ui, tmpl, style):' | |||||
1667 | or templater.templatepath(mapfile)) |
|
1670 | or templater.templatepath(mapfile)) | |
1668 | if mapname: |
|
1671 | if mapname: | |
1669 | mapfile = mapname |
|
1672 | mapfile = mapname | |
1670 | return None, mapfile |
|
1673 | return logtemplatespec(None, mapfile) | |
1671 |
|
1674 | |||
1672 | if not tmpl: |
|
1675 | if not tmpl: | |
1673 | return None, None |
|
1676 | return logtemplatespec(None, None) | |
1674 |
|
1677 | |||
1675 | return formatter.lookuptemplate(ui, 'changeset', tmpl) |
|
1678 | return formatter.lookuptemplate(ui, 'changeset', tmpl) | |
1676 |
|
1679 |
@@ -103,6 +103,7 b' baz: foo, bar' | |||||
103 |
|
103 | |||
104 | from __future__ import absolute_import |
|
104 | from __future__ import absolute_import | |
105 |
|
105 | |||
|
106 | import collections | |||
106 | import contextlib |
|
107 | import contextlib | |
107 | import itertools |
|
108 | import itertools | |
108 | import os |
|
109 | import os | |
@@ -373,6 +374,9 b' class templateformatter(baseformatter):' | |||||
373 | g = self._t(self._topic, ui=self._ui, cache=self._cache, **props) |
|
374 | g = self._t(self._topic, ui=self._ui, cache=self._cache, **props) | |
374 | self._out.write(templater.stringify(g)) |
|
375 | self._out.write(templater.stringify(g)) | |
375 |
|
376 | |||
|
377 | templatespec = collections.namedtuple(r'templatespec', | |||
|
378 | r'tmpl mapfile') | |||
|
379 | ||||
376 | def lookuptemplate(ui, topic, tmpl): |
|
380 | def lookuptemplate(ui, topic, tmpl): | |
377 | """Find the template matching the given -T/--template spec 'tmpl' |
|
381 | """Find the template matching the given -T/--template spec 'tmpl' | |
378 |
|
382 | |||
@@ -391,19 +395,19 b' def lookuptemplate(ui, topic, tmpl):' | |||||
391 |
|
395 | |||
392 | # looks like a literal template? |
|
396 | # looks like a literal template? | |
393 | if '{' in tmpl: |
|
397 | if '{' in tmpl: | |
394 | return tmpl, None |
|
398 | return templatespec(tmpl, None) | |
395 |
|
399 | |||
396 | # perhaps a stock style? |
|
400 | # perhaps a stock style? | |
397 | if not os.path.split(tmpl)[0]: |
|
401 | if not os.path.split(tmpl)[0]: | |
398 | mapname = (templater.templatepath('map-cmdline.' + tmpl) |
|
402 | mapname = (templater.templatepath('map-cmdline.' + tmpl) | |
399 | or templater.templatepath(tmpl)) |
|
403 | or templater.templatepath(tmpl)) | |
400 | if mapname and os.path.isfile(mapname): |
|
404 | if mapname and os.path.isfile(mapname): | |
401 | return None, mapname |
|
405 | return templatespec(None, mapname) | |
402 |
|
406 | |||
403 | # perhaps it's a reference to [templates] |
|
407 | # perhaps it's a reference to [templates] | |
404 | t = ui.config('templates', tmpl) |
|
408 | t = ui.config('templates', tmpl) | |
405 | if t: |
|
409 | if t: | |
406 | return templater.unquotestring(t), None |
|
410 | return templatespec(templater.unquotestring(t), None) | |
407 |
|
411 | |||
408 | if tmpl == 'list': |
|
412 | if tmpl == 'list': | |
409 | ui.write(_("available styles: %s\n") % templater.stylelist()) |
|
413 | ui.write(_("available styles: %s\n") % templater.stylelist()) | |
@@ -413,22 +417,21 b' def lookuptemplate(ui, topic, tmpl):' | |||||
413 | if ('/' in tmpl or '\\' in tmpl) and os.path.isfile(tmpl): |
|
417 | if ('/' in tmpl or '\\' in tmpl) and os.path.isfile(tmpl): | |
414 | # is it a mapfile for a style? |
|
418 | # is it a mapfile for a style? | |
415 | if os.path.basename(tmpl).startswith("map-"): |
|
419 | if os.path.basename(tmpl).startswith("map-"): | |
416 | return None, os.path.realpath(tmpl) |
|
420 | return templatespec(None, os.path.realpath(tmpl)) | |
417 | with util.posixfile(tmpl, 'rb') as f: |
|
421 | with util.posixfile(tmpl, 'rb') as f: | |
418 | tmpl = f.read() |
|
422 | tmpl = f.read() | |
419 | return tmpl, None |
|
423 | return templatespec(tmpl, None) | |
420 |
|
424 | |||
421 | # constant string? |
|
425 | # constant string? | |
422 | return tmpl, None |
|
426 | return templatespec(tmpl, None) | |
423 |
|
427 | |||
424 | def loadtemplater(ui, topic, spec, cache=None): |
|
428 | def loadtemplater(ui, topic, spec, cache=None): | |
425 | """Create a templater from either a literal template or loading from |
|
429 | """Create a templater from either a literal template or loading from | |
426 | a map file""" |
|
430 | a map file""" | |
427 | tmpl, mapfile = spec |
|
431 | assert not (spec.tmpl and spec.mapfile) | |
428 | assert not (tmpl and mapfile) |
|
432 | if spec.mapfile: | |
429 | if mapfile: |
|
433 | return templater.templater.frommapfile(spec.mapfile, cache=cache) | |
430 |
|
|
434 | return maketemplater(ui, topic, spec.tmpl, cache=cache) | |
431 | return maketemplater(ui, topic, tmpl, cache=cache) |
|
|||
432 |
|
435 | |||
433 | def maketemplater(ui, topic, tmpl, cache=None): |
|
436 | def maketemplater(ui, topic, tmpl, cache=None): | |
434 | """Create a templater from a string template 'tmpl'""" |
|
437 | """Create a templater from a string template 'tmpl'""" |
General Comments 0
You need to be logged in to leave comments.
Login now