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