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