Show More
@@ -47,6 +47,10 b' Also, for any expression that returns a ' | |||||
47 |
|
47 | |||
48 | - expr % "{template}" |
|
48 | - expr % "{template}" | |
49 |
|
49 | |||
|
50 | As seen in the above example, "{template}" is interpreted as a template. | |||
|
51 | To prevent it from being interpreted, you can use an escape character "\{" | |||
|
52 | or a raw string prefix, "r'...'". | |||
|
53 | ||||
50 | Some sample command line templates: |
|
54 | Some sample command line templates: | |
51 |
|
55 | |||
52 | - Format lists, e.g. files:: |
|
56 | - Format lists, e.g. files:: |
@@ -22,7 +22,7 b' elements = {' | |||||
22 | ")": (0, None, None), |
|
22 | ")": (0, None, None), | |
23 | "integer": (0, ("integer",), None), |
|
23 | "integer": (0, ("integer",), None), | |
24 | "symbol": (0, ("symbol",), None), |
|
24 | "symbol": (0, ("symbol",), None), | |
25 |
"string": (0, (" |
|
25 | "string": (0, ("template",), None), | |
26 | "rawstring": (0, ("rawstring",), None), |
|
26 | "rawstring": (0, ("rawstring",), None), | |
27 | "end": (0, None, None), |
|
27 | "end": (0, None, None), | |
28 | } |
|
28 | } | |
@@ -144,7 +144,9 b' def getfilter(exp, context):' | |||||
144 | return context._filters[f] |
|
144 | return context._filters[f] | |
145 |
|
145 | |||
146 | def gettemplate(exp, context): |
|
146 | def gettemplate(exp, context): | |
147 |
if exp[0] == ' |
|
147 | if exp[0] == 'template': | |
|
148 | return compiletemplate(exp[1], context) | |||
|
149 | if exp[0] == 'rawstring': | |||
148 | return compiletemplate(exp[1], context, strtoken=exp[0]) |
|
150 | return compiletemplate(exp[1], context, strtoken=exp[0]) | |
149 | if exp[0] == 'symbol': |
|
151 | if exp[0] == 'symbol': | |
150 | return context._load(exp[1]) |
|
152 | return context._load(exp[1]) | |
@@ -174,6 +176,12 b' def runsymbol(context, mapping, key):' | |||||
174 | v = list(v) |
|
176 | v = list(v) | |
175 | return v |
|
177 | return v | |
176 |
|
178 | |||
|
179 | def buildtemplate(exp, context): | |||
|
180 | ctmpl = compiletemplate(exp[1], context) | |||
|
181 | if len(ctmpl) == 1: | |||
|
182 | return ctmpl[0] # fast path for string with no template fragment | |||
|
183 | return (runtemplate, ctmpl) | |||
|
184 | ||||
177 | def runtemplate(context, mapping, template): |
|
185 | def runtemplate(context, mapping, template): | |
178 | for func, data in template: |
|
186 | for func, data in template: | |
179 | yield func(context, mapping, data) |
|
187 | yield func(context, mapping, data) | |
@@ -362,7 +370,7 b' def get(context, mapping, args):' | |||||
362 |
|
370 | |||
363 | def _evalifliteral(arg, context, mapping): |
|
371 | def _evalifliteral(arg, context, mapping): | |
364 | # get back to token tag to reinterpret string as template |
|
372 | # get back to token tag to reinterpret string as template | |
365 |
strtoken = { |
|
373 | strtoken = {runrawstring: 'rawstring'}.get(arg[0]) | |
366 | if strtoken: |
|
374 | if strtoken: | |
367 | yield runtemplate(context, mapping, |
|
375 | yield runtemplate(context, mapping, | |
368 | compiletemplate(arg[1], context, strtoken)) |
|
376 | compiletemplate(arg[1], context, strtoken)) | |
@@ -606,6 +614,7 b' exprmethods = {' | |||||
606 | "string": lambda e, c: (runstring, e[1]), |
|
614 | "string": lambda e, c: (runstring, e[1]), | |
607 | "rawstring": lambda e, c: (runrawstring, e[1]), |
|
615 | "rawstring": lambda e, c: (runrawstring, e[1]), | |
608 | "symbol": lambda e, c: (runsymbol, e[1]), |
|
616 | "symbol": lambda e, c: (runsymbol, e[1]), | |
|
617 | "template": buildtemplate, | |||
609 | "group": lambda e, c: compileexp(e[1], c, exprmethods), |
|
618 | "group": lambda e, c: compileexp(e[1], c, exprmethods), | |
610 | # ".": buildmember, |
|
619 | # ".": buildmember, | |
611 | "|": buildfilter, |
|
620 | "|": buildfilter, |
@@ -2803,6 +2803,15 b' unless explicit symbol is expected:' | |||||
2803 | hg: parse error: expected a symbol, got 'integer' |
|
2803 | hg: parse error: expected a symbol, got 'integer' | |
2804 | [255] |
|
2804 | [255] | |
2805 |
|
2805 | |||
|
2806 | Test string literal: | |||
|
2807 | ||||
|
2808 | $ hg log -Ra -r0 -T '{"string with no template fragment"}\n' | |||
|
2809 | string with no template fragment | |||
|
2810 | $ hg log -Ra -r0 -T '{"template: {rev}"}\n' | |||
|
2811 | template: 0 | |||
|
2812 | $ hg log -Ra -r0 -T '{r"rawstring: {rev}"}\n' | |||
|
2813 | rawstring: {rev} | |||
|
2814 | ||||
2806 | Test string escaping: |
|
2815 | Test string escaping: | |
2807 |
|
2816 | |||
2808 | $ hg log -R latesttag -r 0 --template '>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n' |
|
2817 | $ hg log -R latesttag -r 0 --template '>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n' |
General Comments 0
You need to be logged in to leave comments.
Login now