Show More
@@ -207,7 +207,7 b' def _formatflags(ui, repo, rev, flags):' | |||||
207 | if not tmpl: |
|
207 | if not tmpl: | |
208 | return b' '.join(flags) |
|
208 | return b' '.join(flags) | |
209 | out = util.stringio() |
|
209 | out = util.stringio() | |
210 |
spec = formatter.templatespec( |
|
210 | spec = formatter.literal_templatespec(templater.unquotestring(tmpl)) | |
211 | with formatter.templateformatter(ui, out, b'patchbombflag', {}, spec) as fm: |
|
211 | with formatter.templateformatter(ui, out, b'patchbombflag', {}, spec) as fm: | |
212 | fm.startitem() |
|
212 | fm.startitem() | |
213 | fm.context(ctx=repo[rev]) |
|
213 | fm.context(ctx=repo[rev]) |
@@ -3375,7 +3375,7 b' def commitforceeditor(' | |||||
3375 |
|
3375 | |||
3376 | def buildcommittemplate(repo, ctx, subs, extramsg, ref): |
|
3376 | def buildcommittemplate(repo, ctx, subs, extramsg, ref): | |
3377 | ui = repo.ui |
|
3377 | ui = repo.ui | |
3378 |
spec = formatter.templatespec(ref |
|
3378 | spec = formatter.reference_templatespec(ref) | |
3379 | t = logcmdutil.changesettemplater(ui, repo, spec) |
|
3379 | t = logcmdutil.changesettemplater(ui, repo, spec) | |
3380 | t.t.cache.update( |
|
3380 | t.t.cache.update( | |
3381 | (k, templater.unquotestring(v)) |
|
3381 | (k, templater.unquotestring(v)) |
@@ -542,6 +542,22 b' class templatespec(object):' | |||||
542 | refargs = attr.ib(default=None) |
|
542 | refargs = attr.ib(default=None) | |
543 |
|
543 | |||
544 |
|
544 | |||
|
545 | def empty_templatespec(): | |||
|
546 | return templatespec(None, None, None) | |||
|
547 | ||||
|
548 | ||||
|
549 | def reference_templatespec(ref, refargs=None): | |||
|
550 | return templatespec(ref, None, None, refargs) | |||
|
551 | ||||
|
552 | ||||
|
553 | def literal_templatespec(tmpl): | |||
|
554 | return templatespec(b'', tmpl, None) | |||
|
555 | ||||
|
556 | ||||
|
557 | def mapfile_templatespec(topic, mapfile): | |||
|
558 | return templatespec(topic, None, mapfile) | |||
|
559 | ||||
|
560 | ||||
545 | def lookuptemplate(ui, topic, tmpl): |
|
561 | def lookuptemplate(ui, topic, tmpl): | |
546 | """Find the template matching the given -T/--template spec 'tmpl' |
|
562 | """Find the template matching the given -T/--template spec 'tmpl' | |
547 |
|
563 | |||
@@ -563,21 +579,21 b' def lookuptemplate(ui, topic, tmpl):' | |||||
563 | """ |
|
579 | """ | |
564 |
|
580 | |||
565 | if not tmpl: |
|
581 | if not tmpl: | |
566 |
return templatespec( |
|
582 | return empty_templatespec() | |
567 |
|
583 | |||
568 | # looks like a literal template? |
|
584 | # looks like a literal template? | |
569 | if b'{' in tmpl: |
|
585 | if b'{' in tmpl: | |
570 |
return templatespec( |
|
586 | return literal_templatespec(tmpl) | |
571 |
|
587 | |||
572 | # a reference to built-in (formatter) template |
|
588 | # a reference to built-in (formatter) template | |
573 | if tmpl in {b'cbor', b'json', b'pickle', b'debug'}: |
|
589 | if tmpl in {b'cbor', b'json', b'pickle', b'debug'}: | |
574 |
return templatespec(tmpl |
|
590 | return reference_templatespec(tmpl) | |
575 |
|
591 | |||
576 | # a function-style reference to built-in template |
|
592 | # a function-style reference to built-in template | |
577 | func, fsep, ftail = tmpl.partition(b'(') |
|
593 | func, fsep, ftail = tmpl.partition(b'(') | |
578 | if func in {b'cbor', b'json'} and fsep and ftail.endswith(b')'): |
|
594 | if func in {b'cbor', b'json'} and fsep and ftail.endswith(b')'): | |
579 | templater.parseexpr(tmpl) # make sure syntax errors are confined |
|
595 | templater.parseexpr(tmpl) # make sure syntax errors are confined | |
580 |
return templatespec(func |
|
596 | return reference_templatespec(func, refargs=ftail[:-1]) | |
581 |
|
597 | |||
582 | # perhaps a stock style? |
|
598 | # perhaps a stock style? | |
583 | if not os.path.split(tmpl)[0]: |
|
599 | if not os.path.split(tmpl)[0]: | |
@@ -585,11 +601,11 b' def lookuptemplate(ui, topic, tmpl):' | |||||
585 | b'map-cmdline.' + tmpl |
|
601 | b'map-cmdline.' + tmpl | |
586 | ) or templater.templatepath(tmpl) |
|
602 | ) or templater.templatepath(tmpl) | |
587 | if mapname: |
|
603 | if mapname: | |
588 |
return templatespec(topic |
|
604 | return mapfile_templatespec(topic, mapname) | |
589 |
|
605 | |||
590 | # perhaps it's a reference to [templates] |
|
606 | # perhaps it's a reference to [templates] | |
591 | if ui.config(b'templates', tmpl): |
|
607 | if ui.config(b'templates', tmpl): | |
592 |
return templatespec(tmpl |
|
608 | return reference_templatespec(tmpl) | |
593 |
|
609 | |||
594 | if tmpl == b'list': |
|
610 | if tmpl == b'list': | |
595 | ui.write(_(b"available styles: %s\n") % templater.stylelist()) |
|
611 | ui.write(_(b"available styles: %s\n") % templater.stylelist()) | |
@@ -599,13 +615,13 b' def lookuptemplate(ui, topic, tmpl):' | |||||
599 | if (b'/' in tmpl or b'\\' in tmpl) and os.path.isfile(tmpl): |
|
615 | if (b'/' in tmpl or b'\\' in tmpl) and os.path.isfile(tmpl): | |
600 | # is it a mapfile for a style? |
|
616 | # is it a mapfile for a style? | |
601 | if os.path.basename(tmpl).startswith(b"map-"): |
|
617 | if os.path.basename(tmpl).startswith(b"map-"): | |
602 |
return templatespec(topic |
|
618 | return mapfile_templatespec(topic, os.path.realpath(tmpl)) | |
603 | with util.posixfile(tmpl, b'rb') as f: |
|
619 | with util.posixfile(tmpl, b'rb') as f: | |
604 | tmpl = f.read() |
|
620 | tmpl = f.read() | |
605 |
return templatespec( |
|
621 | return literal_templatespec(tmpl) | |
606 |
|
622 | |||
607 | # constant string? |
|
623 | # constant string? | |
608 |
return templatespec( |
|
624 | return literal_templatespec(tmpl) | |
609 |
|
625 | |||
610 |
|
626 | |||
611 | def templatepartsmap(spec, t, partnames): |
|
627 | def templatepartsmap(spec, t, partnames): |
General Comments 0
You need to be logged in to leave comments.
Login now