529 """Find the template matching the given -T/--template spec 'tmpl' |
529 """Find the template matching the given -T/--template spec 'tmpl' |
530 |
530 |
531 'tmpl' can be any of the following: |
531 'tmpl' can be any of the following: |
532 |
532 |
533 - a literal template (e.g. '{rev}') |
533 - a literal template (e.g. '{rev}') |
|
534 - a reference to built-in template (i.e. formatter) |
534 - a map-file name or path (e.g. 'changelog') |
535 - a map-file name or path (e.g. 'changelog') |
535 - a reference to [templates] in config file |
536 - a reference to [templates] in config file |
536 - a path to raw template file |
537 - a path to raw template file |
537 |
538 |
538 A map file defines a stand-alone template environment. If a map file |
539 A map file defines a stand-alone template environment. If a map file |
542 |
543 |
543 If no map file selected, all templates in [templates] section will be |
544 If no map file selected, all templates in [templates] section will be |
544 available as well as aliases in [templatealias]. |
545 available as well as aliases in [templatealias]. |
545 """ |
546 """ |
546 |
547 |
|
548 if not tmpl: |
|
549 return templatespec(None, None, None) |
|
550 |
547 # looks like a literal template? |
551 # looks like a literal template? |
548 if b'{' in tmpl: |
552 if b'{' in tmpl: |
549 return templatespec(b'', tmpl, None) |
553 return templatespec(b'', tmpl, None) |
|
554 |
|
555 # a reference to built-in (formatter) template |
|
556 if tmpl in {b'cbor', b'json', b'pickle', b'debug'}: |
|
557 return templatespec(tmpl, None, None) |
550 |
558 |
551 # perhaps a stock style? |
559 # perhaps a stock style? |
552 if not os.path.split(tmpl)[0]: |
560 if not os.path.split(tmpl)[0]: |
553 mapname = templater.templatepath( |
561 mapname = templater.templatepath( |
554 b'map-cmdline.' + tmpl |
562 b'map-cmdline.' + tmpl |
710 b'fctx': _loadfctx, |
718 b'fctx': _loadfctx, |
711 } |
719 } |
712 |
720 |
713 |
721 |
714 def formatter(ui, out, topic, opts): |
722 def formatter(ui, out, topic, opts): |
715 template = opts.get(b"template", b"") |
723 spec = lookuptemplate(ui, topic, opts.get(b'template', b'')) |
716 if template == b"cbor": |
724 if spec.ref == b"cbor": |
717 return cborformatter(ui, out, topic, opts) |
725 return cborformatter(ui, out, topic, opts) |
718 elif template == b"json": |
726 elif spec.ref == b"json": |
719 return jsonformatter(ui, out, topic, opts) |
727 return jsonformatter(ui, out, topic, opts) |
720 elif template == b"pickle": |
728 elif spec.ref == b"pickle": |
721 return pickleformatter(ui, out, topic, opts) |
729 return pickleformatter(ui, out, topic, opts) |
722 elif template == b"debug": |
730 elif spec.ref == b"debug": |
723 return debugformatter(ui, out, topic, opts) |
731 return debugformatter(ui, out, topic, opts) |
724 elif template != b"": |
732 elif spec.ref or spec.tmpl or spec.mapfile: |
725 spec = lookuptemplate(ui, topic, opts.get(b'template', b'')) |
|
726 return templateformatter(ui, out, topic, opts, spec) |
733 return templateformatter(ui, out, topic, opts, spec) |
727 # developer config: ui.formatdebug |
734 # developer config: ui.formatdebug |
728 elif ui.configbool(b'ui', b'formatdebug'): |
735 elif ui.configbool(b'ui', b'formatdebug'): |
729 return debugformatter(ui, out, topic, opts) |
736 return debugformatter(ui, out, topic, opts) |
730 # deprecated config: ui.formatjson |
737 # deprecated config: ui.formatjson |