##// END OF EJS Templates
formatter: parse name of built-in formatter templates in standard way...
Yuya Nishihara -
r43370:90b9a7e0 default
parent child Browse files
Show More
@@ -531,6 +531,7 b' def lookuptemplate(ui, topic, tmpl):'
531 531 'tmpl' can be any of the following:
532 532
533 533 - a literal template (e.g. '{rev}')
534 - a reference to built-in template (i.e. formatter)
534 535 - a map-file name or path (e.g. 'changelog')
535 536 - a reference to [templates] in config file
536 537 - a path to raw template file
@@ -544,10 +545,17 b' def lookuptemplate(ui, topic, tmpl):'
544 545 available as well as aliases in [templatealias].
545 546 """
546 547
548 if not tmpl:
549 return templatespec(None, None, None)
550
547 551 # looks like a literal template?
548 552 if b'{' in tmpl:
549 553 return templatespec(b'', tmpl, None)
550 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)
558
551 559 # perhaps a stock style?
552 560 if not os.path.split(tmpl)[0]:
553 561 mapname = templater.templatepath(
@@ -712,17 +720,16 b' class templateresources(templater.resour'
712 720
713 721
714 722 def formatter(ui, out, topic, opts):
715 template = opts.get(b"template", b"")
716 if template == b"cbor":
723 spec = lookuptemplate(ui, topic, opts.get(b'template', b''))
724 if spec.ref == b"cbor":
717 725 return cborformatter(ui, out, topic, opts)
718 elif template == b"json":
726 elif spec.ref == b"json":
719 727 return jsonformatter(ui, out, topic, opts)
720 elif template == b"pickle":
728 elif spec.ref == b"pickle":
721 729 return pickleformatter(ui, out, topic, opts)
722 elif template == b"debug":
730 elif spec.ref == b"debug":
723 731 return debugformatter(ui, out, topic, opts)
724 elif template != b"":
725 spec = lookuptemplate(ui, topic, opts.get(b'template', b''))
732 elif spec.ref or spec.tmpl or spec.mapfile:
726 733 return templateformatter(ui, out, topic, opts, spec)
727 734 # developer config: ui.formatdebug
728 735 elif ui.configbool(b'ui', b'formatdebug'):
@@ -617,9 +617,6 b' def _lookuptemplate(ui, tmpl, style):'
617 617 mapfile = mapname
618 618 return templatespec(None, mapfile)
619 619
620 if not tmpl:
621 return templatespec(None, None)
622
623 620 return formatter.lookuptemplate(ui, b'changeset', tmpl)
624 621
625 622
@@ -642,12 +639,15 b' def changesetdisplayer(ui, repo, opts, d'
642 639 regular display via changesetprinter() is done.
643 640 """
644 641 postargs = (differ, opts, buffered)
645 if opts.get(b'template') in {b'cbor', b'json'}:
642 spec = _lookuptemplate(ui, opts.get(b'template'), opts.get(b'style'))
643
644 # machine-readable formats have slightly different keyword set than
645 # plain templates, which are handled by changesetformatter.
646 # note that {b'pickle', b'debug'} can also be added to the list if needed.
647 if spec.ref in {b'cbor', b'json'}:
646 648 fm = ui.formatter(b'log', opts)
647 649 return changesetformatter(ui, repo, fm, *postargs)
648 650
649 spec = _lookuptemplate(ui, opts.get(b'template'), opts.get(b'style'))
650
651 651 if not spec.ref and not spec.tmpl and not spec.mapfile:
652 652 return changesetprinter(ui, repo, *postargs)
653 653
@@ -1101,6 +1101,15 b' honor --git but not format-breaking diff'
1101 1101 }
1102 1102 ]
1103 1103
1104 Other unsupported formatter styles:
1105
1106 $ hg log -qr . -Tpickle
1107 abort: "pickle" not in template map
1108 [255]
1109 $ hg log -qr . -Tdebug
1110 abort: "debug" not in template map
1111 [255]
1112
1104 1113 Error if style not readable:
1105 1114
1106 1115 #if unix-permissions no-root
General Comments 0
You need to be logged in to leave comments. Login now