Mercurial > public > mercurial-scm > hg
comparison mercurial/logcmdutil.py @ 43100:90b9a7e06c2c
formatter: parse name of built-in formatter templates in standard way
This slightly makes it easier to add "-Tjson(...)" handling, which should
be enabled only if the template specifier doesn't look like a literal
template. In other words, it should be handled after "if '{' in tmpl".
This makes "log -Tpickle" and "log -Tdebug" abort, which I think is better
than just printing "picklepicklepickle...".
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 05 Oct 2019 23:20:35 -0400 |
parents | 687b865b95ad |
children | 829088e87032 |
comparison
equal
deleted
inserted
replaced
43099:f1c5358f0d65 | 43100:90b9a7e06c2c |
---|---|
615 ) or templater.templatepath(mapfile) | 615 ) or templater.templatepath(mapfile) |
616 if mapname: | 616 if mapname: |
617 mapfile = mapname | 617 mapfile = mapname |
618 return templatespec(None, mapfile) | 618 return templatespec(None, mapfile) |
619 | 619 |
620 if not tmpl: | |
621 return templatespec(None, None) | |
622 | |
623 return formatter.lookuptemplate(ui, b'changeset', tmpl) | 620 return formatter.lookuptemplate(ui, b'changeset', tmpl) |
624 | 621 |
625 | 622 |
626 def maketemplater(ui, repo, tmpl, buffered=False): | 623 def maketemplater(ui, repo, tmpl, buffered=False): |
627 """Create a changesettemplater from a literal template 'tmpl' | 624 """Create a changesettemplater from a literal template 'tmpl' |
640 4. [ui] setting 'style' | 637 4. [ui] setting 'style' |
641 If all of these values are either the unset or the empty string, | 638 If all of these values are either the unset or the empty string, |
642 regular display via changesetprinter() is done. | 639 regular display via changesetprinter() is done. |
643 """ | 640 """ |
644 postargs = (differ, opts, buffered) | 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 fm = ui.formatter(b'log', opts) | 648 fm = ui.formatter(b'log', opts) |
647 return changesetformatter(ui, repo, fm, *postargs) | 649 return changesetformatter(ui, repo, fm, *postargs) |
648 | |
649 spec = _lookuptemplate(ui, opts.get(b'template'), opts.get(b'style')) | |
650 | 650 |
651 if not spec.ref and not spec.tmpl and not spec.mapfile: | 651 if not spec.ref and not spec.tmpl and not spec.mapfile: |
652 return changesetprinter(ui, repo, *postargs) | 652 return changesetprinter(ui, repo, *postargs) |
653 | 653 |
654 return changesettemplater(ui, repo, spec, *postargs) | 654 return changesettemplater(ui, repo, spec, *postargs) |