Show More
@@ -1580,7 +1580,7 b' class changeset_templater(changeset_prin' | |||||
1580 |
|
1580 | |||
1581 | def __init__(self, ui, repo, tmplspec, matchfn, diffopts, buffered): |
|
1581 | def __init__(self, ui, repo, tmplspec, matchfn, diffopts, buffered): | |
1582 | changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) |
|
1582 | changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) | |
1583 |
self.t = formatter.loadtemplater(ui, |
|
1583 | self.t = formatter.loadtemplater(ui, tmplspec, | |
1584 | cache=templatekw.defaulttempl) |
|
1584 | cache=templatekw.defaulttempl) | |
1585 | self._counter = itertools.count() |
|
1585 | self._counter = itertools.count() | |
1586 | self.cache = {} |
|
1586 | self.cache = {} | |
@@ -1646,7 +1646,8 b' class changeset_templater(changeset_prin' | |||||
1646 | self.footer = templater.stringify( |
|
1646 | self.footer = templater.stringify( | |
1647 | self.t(self._parts['footer'], **props)) |
|
1647 | self.t(self._parts['footer'], **props)) | |
1648 |
|
1648 | |||
1649 | logtemplatespec = formatter.templatespec |
|
1649 | def logtemplatespec(tmpl, mapfile): | |
|
1650 | return formatter.templatespec('changeset', tmpl, mapfile) | |||
1650 |
|
1651 | |||
1651 | def _lookuplogtemplate(ui, tmpl, style): |
|
1652 | def _lookuplogtemplate(ui, tmpl, style): | |
1652 | """Find the template matching the given template spec or style |
|
1653 | """Find the template matching the given template spec or style |
@@ -349,7 +349,7 b' class templateformatter(baseformatter):' | |||||
349 | self._out = out |
|
349 | self._out = out | |
350 | self._topic = topic |
|
350 | self._topic = topic | |
351 | spec = lookuptemplate(ui, topic, opts.get('template', '')) |
|
351 | spec = lookuptemplate(ui, topic, opts.get('template', '')) | |
352 |
self._t = loadtemplater(ui, |
|
352 | self._t = loadtemplater(ui, spec, cache=templatekw.defaulttempl) | |
353 | self._counter = itertools.count() |
|
353 | self._counter = itertools.count() | |
354 | self._cache = {} # for templatekw/funcs to store reusable data |
|
354 | self._cache = {} # for templatekw/funcs to store reusable data | |
355 | def context(self, **ctxs): |
|
355 | def context(self, **ctxs): | |
@@ -375,7 +375,7 b' class templateformatter(baseformatter):' | |||||
375 | self._out.write(templater.stringify(g)) |
|
375 | self._out.write(templater.stringify(g)) | |
376 |
|
376 | |||
377 | templatespec = collections.namedtuple(r'templatespec', |
|
377 | templatespec = collections.namedtuple(r'templatespec', | |
378 | r'tmpl mapfile') |
|
378 | r'ref tmpl mapfile') | |
379 |
|
379 | |||
380 | def lookuptemplate(ui, topic, tmpl): |
|
380 | def lookuptemplate(ui, topic, tmpl): | |
381 | """Find the template matching the given -T/--template spec 'tmpl' |
|
381 | """Find the template matching the given -T/--template spec 'tmpl' | |
@@ -395,19 +395,19 b' def lookuptemplate(ui, topic, tmpl):' | |||||
395 |
|
395 | |||
396 | # looks like a literal template? |
|
396 | # looks like a literal template? | |
397 | if '{' in tmpl: |
|
397 | if '{' in tmpl: | |
398 | return templatespec(tmpl, None) |
|
398 | return templatespec(topic, tmpl, None) | |
399 |
|
399 | |||
400 | # perhaps a stock style? |
|
400 | # perhaps a stock style? | |
401 | if not os.path.split(tmpl)[0]: |
|
401 | if not os.path.split(tmpl)[0]: | |
402 | mapname = (templater.templatepath('map-cmdline.' + tmpl) |
|
402 | mapname = (templater.templatepath('map-cmdline.' + tmpl) | |
403 | or templater.templatepath(tmpl)) |
|
403 | or templater.templatepath(tmpl)) | |
404 | if mapname and os.path.isfile(mapname): |
|
404 | if mapname and os.path.isfile(mapname): | |
405 | return templatespec(None, mapname) |
|
405 | return templatespec(topic, None, mapname) | |
406 |
|
406 | |||
407 | # perhaps it's a reference to [templates] |
|
407 | # perhaps it's a reference to [templates] | |
408 | t = ui.config('templates', tmpl) |
|
408 | t = ui.config('templates', tmpl) | |
409 | if t: |
|
409 | if t: | |
410 | return templatespec(templater.unquotestring(t), None) |
|
410 | return templatespec(topic, templater.unquotestring(t), None) | |
411 |
|
411 | |||
412 | if tmpl == 'list': |
|
412 | if tmpl == 'list': | |
413 | ui.write(_("available styles: %s\n") % templater.stylelist()) |
|
413 | ui.write(_("available styles: %s\n") % templater.stylelist()) | |
@@ -417,21 +417,21 b' def lookuptemplate(ui, topic, tmpl):' | |||||
417 | if ('/' in tmpl or '\\' in tmpl) and os.path.isfile(tmpl): |
|
417 | if ('/' in tmpl or '\\' in tmpl) and os.path.isfile(tmpl): | |
418 | # is it a mapfile for a style? |
|
418 | # is it a mapfile for a style? | |
419 | if os.path.basename(tmpl).startswith("map-"): |
|
419 | if os.path.basename(tmpl).startswith("map-"): | |
420 | return templatespec(None, os.path.realpath(tmpl)) |
|
420 | return templatespec(topic, None, os.path.realpath(tmpl)) | |
421 | with util.posixfile(tmpl, 'rb') as f: |
|
421 | with util.posixfile(tmpl, 'rb') as f: | |
422 | tmpl = f.read() |
|
422 | tmpl = f.read() | |
423 | return templatespec(tmpl, None) |
|
423 | return templatespec(topic, tmpl, None) | |
424 |
|
424 | |||
425 | # constant string? |
|
425 | # constant string? | |
426 | return templatespec(tmpl, None) |
|
426 | return templatespec(topic, tmpl, None) | |
427 |
|
427 | |||
428 |
def loadtemplater(ui |
|
428 | def loadtemplater(ui, spec, cache=None): | |
429 | """Create a templater from either a literal template or loading from |
|
429 | """Create a templater from either a literal template or loading from | |
430 | a map file""" |
|
430 | a map file""" | |
431 | assert not (spec.tmpl and spec.mapfile) |
|
431 | assert not (spec.tmpl and spec.mapfile) | |
432 | if spec.mapfile: |
|
432 | if spec.mapfile: | |
433 | return templater.templater.frommapfile(spec.mapfile, cache=cache) |
|
433 | return templater.templater.frommapfile(spec.mapfile, cache=cache) | |
434 |
return maketemplater(ui, |
|
434 | return maketemplater(ui, spec.ref, spec.tmpl, cache=cache) | |
435 |
|
435 | |||
436 | def maketemplater(ui, topic, tmpl, cache=None): |
|
436 | def maketemplater(ui, topic, tmpl, cache=None): | |
437 | """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