comparison mercurial/help/templates.txt @ 25596:c1975809a6b5

templater: take any string literals as template, but not for rawstring (BC) This patch series is intended to unify the interpretation of string literals. It is breaking change that boldly assumes a. string literal "..." never contains template-like fragment or it is intended to be a template b. we tend to use raw string literal r"..." for regexp pattern in which "{" should have different meaning Currently, we don't have a comprehensible rule how string literals are evaluated in template functions. For example, fill() takes "initialindent" and "hangindent" as templates, but not for "text", whereas "text" is a template in pad() function. date(date, fmt) diff(includepattern, excludepattern) fill(text, width, initialident: T, hangindent: T) get(dict, key) if(expr, then: T, else: T) ifcontains(search, thing, then: T, else: T) ifeq(expr1, expr2, then: T, else: T) indent(text, indentchars, firstline) join(list, sep) label(label: T, expr: T) pad(text: T, width, fillchar, right) revset(query, formatargs...]) rstdoc(text, style) shortest(node, minlength) startswith(pattern, text) strip(text, chars) sub(pattern, replacement, expression: T) word(number, text, separator) expr % template: T T: interpret "string" or r"rawstring" as template This patch series adjusts the rule as follows: a. string literal, '' or "", starts template processing (BC) b. raw string literal, r'' or r"", disables both \-escape and template processing (BC, done by subsequent patches) c. fragment not surrounded by {} is non-templated string "ccc{'aaa'}{r'bbb'}" ------------------ *: template --- c: string --- a: template --- b: rawstring Because this can eliminate the compilation of template arguments from the evaluation phase, "hg log -Tdefault" gets faster. % cd mozilla-central % LANG=C HGRCPATH=/dev/null hg log -Tdefault -r0:10000 --time > /dev/null before: real 4.870 secs (user 4.860+0.000 sys 0.010+0.000) after: real 3.480 secs (user 3.440+0.000 sys 0.030+0.000) Also, this will allow us to parse nested templates at once for better error indication.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 13 Jun 2015 19:49:54 +0900
parents f26efa4f0eff
children 35fa7c77c754
comparison
equal deleted inserted replaced
25595:a7dd6692e5cb 25596:c1975809a6b5
44 .. functionsmarker 44 .. functionsmarker
45 45
46 Also, for any expression that returns a list, there is a list operator: 46 Also, for any expression that returns a list, there is a list operator:
47 47
48 - expr % "{template}" 48 - expr % "{template}"
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'...'".
49 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::
53 57