Show More
@@ -3671,8 +3671,12 def debugtemplate(ui, repo, tmpl, **opts | |||
|
3671 | 3671 | raise error.Abort(_('malformed keyword definition: %s') % d) |
|
3672 | 3672 | |
|
3673 | 3673 | if ui.verbose: |
|
3674 | aliases = ui.configitems('templatealias') | |
|
3674 | 3675 | tree = templater.parse(tmpl) |
|
3675 | 3676 | ui.note(templater.prettyformat(tree), '\n') |
|
3677 | newtree = templater.expandaliases(tree, aliases) | |
|
3678 | if newtree != tree: | |
|
3679 | ui.note("* expanded:\n", templater.prettyformat(newtree), '\n') | |
|
3676 | 3680 | |
|
3677 | 3681 | mapfile = None |
|
3678 | 3682 | if revs is None: |
@@ -872,6 +872,25 exprmethods = { | |||
|
872 | 872 | methods = exprmethods.copy() |
|
873 | 873 | methods["integer"] = exprmethods["symbol"] # '{1}' as variable |
|
874 | 874 | |
|
875 | class _aliasrules(parser.basealiasrules): | |
|
876 | """Parsing and expansion rule set of template aliases""" | |
|
877 | _section = _('template alias') | |
|
878 | _parse = staticmethod(_parseexpr) | |
|
879 | ||
|
880 | @staticmethod | |
|
881 | def _trygetfunc(tree): | |
|
882 | """Return (name, args) if tree is func(...) or ...|filter; otherwise | |
|
883 | None""" | |
|
884 | if tree[0] == 'func' and tree[1][0] == 'symbol': | |
|
885 | return tree[1][1], getlist(tree[2]) | |
|
886 | if tree[0] == '|' and tree[2][0] == 'symbol': | |
|
887 | return tree[2][1], [tree[1]] | |
|
888 | ||
|
889 | def expandaliases(tree, aliases): | |
|
890 | """Return new tree of aliases are expanded""" | |
|
891 | aliasmap = _aliasrules.buildmap(aliases) | |
|
892 | return _aliasrules.expand(aliasmap, tree) | |
|
893 | ||
|
875 | 894 | # template engine |
|
876 | 895 | |
|
877 | 896 | stringify = templatefilters.stringify |
@@ -3654,6 +3654,100 json filter should escape HTML tags so t | |||
|
3654 | 3654 | $ hg log -T "{'<foo@example.org>'|json}\n" -R a -l1 |
|
3655 | 3655 | "\u003cfoo@example.org\u003e" |
|
3656 | 3656 | |
|
3657 | Templater supports aliases of symbol and func() styles: | |
|
3658 | ||
|
3659 | $ hg clone -q a aliases | |
|
3660 | $ cd aliases | |
|
3661 | $ cat <<EOF >> .hg/hgrc | |
|
3662 | > [templatealias] | |
|
3663 | > r = rev | |
|
3664 | > rn = "{r}:{node|short}" | |
|
3665 | > status(c, files) = files % "{c} {file}\n" | |
|
3666 | > utcdate(d) = localdate(d, "UTC") | |
|
3667 | > EOF | |
|
3668 | ||
|
3669 | $ hg debugtemplate -vr0 '{rn} {utcdate(date)|isodate}\n' | |
|
3670 | (template | |
|
3671 | ('symbol', 'rn') | |
|
3672 | ('string', ' ') | |
|
3673 | (| | |
|
3674 | (func | |
|
3675 | ('symbol', 'utcdate') | |
|
3676 | ('symbol', 'date')) | |
|
3677 | ('symbol', 'isodate')) | |
|
3678 | ('string', '\n')) | |
|
3679 | * expanded: | |
|
3680 | (template | |
|
3681 | (template | |
|
3682 | ('symbol', 'rev') | |
|
3683 | ('string', ':') | |
|
3684 | (| | |
|
3685 | ('symbol', 'node') | |
|
3686 | ('symbol', 'short'))) | |
|
3687 | ('string', ' ') | |
|
3688 | (| | |
|
3689 | (func | |
|
3690 | ('symbol', 'localdate') | |
|
3691 | (list | |
|
3692 | ('symbol', 'date') | |
|
3693 | ('string', 'UTC'))) | |
|
3694 | ('symbol', 'isodate')) | |
|
3695 | ('string', '\n')) | |
|
3696 | hg: parse error: unknown function 'utcdate' | |
|
3697 | [255] | |
|
3698 | ||
|
3699 | $ hg debugtemplate -vr0 '{status("A", file_adds)}' | |
|
3700 | (template | |
|
3701 | (func | |
|
3702 | ('symbol', 'status') | |
|
3703 | (list | |
|
3704 | ('string', 'A') | |
|
3705 | ('symbol', 'file_adds')))) | |
|
3706 | * expanded: | |
|
3707 | (template | |
|
3708 | (% | |
|
3709 | ('symbol', 'file_adds') | |
|
3710 | (template | |
|
3711 | ('string', 'A') | |
|
3712 | ('string', ' ') | |
|
3713 | ('symbol', 'file') | |
|
3714 | ('string', '\n')))) | |
|
3715 | hg: parse error: unknown function 'status' | |
|
3716 | [255] | |
|
3717 | ||
|
3718 | A unary function alias can be called as a filter: | |
|
3719 | ||
|
3720 | $ hg debugtemplate -vr0 '{date|utcdate|isodate}\n' | |
|
3721 | (template | |
|
3722 | (| | |
|
3723 | (| | |
|
3724 | ('symbol', 'date') | |
|
3725 | ('symbol', 'utcdate')) | |
|
3726 | ('symbol', 'isodate')) | |
|
3727 | ('string', '\n')) | |
|
3728 | * expanded: | |
|
3729 | (template | |
|
3730 | (| | |
|
3731 | (func | |
|
3732 | ('symbol', 'localdate') | |
|
3733 | (list | |
|
3734 | ('symbol', 'date') | |
|
3735 | ('string', 'UTC'))) | |
|
3736 | ('symbol', 'isodate')) | |
|
3737 | ('string', '\n')) | |
|
3738 | hg: parse error: unknown function 'utcdate' | |
|
3739 | [255] | |
|
3740 | ||
|
3741 | Unparsable alias: | |
|
3742 | ||
|
3743 | $ hg debugtemplate --config templatealias.bad='x(' -v '{bad}' | |
|
3744 | (template | |
|
3745 | ('symbol', 'bad')) | |
|
3746 | abort: failed to parse the definition of template alias "bad": at 2: not a prefix: end | |
|
3747 | [255] | |
|
3748 | ||
|
3749 | $ cd .. | |
|
3750 | ||
|
3657 | 3751 | Set up repository for non-ascii encoding tests: |
|
3658 | 3752 | |
|
3659 | 3753 | $ hg init nonascii |
General Comments 0
You need to be logged in to leave comments.
Login now