##// END OF EJS Templates
templater: introduce startswith function...
Ryan McElroy -
r21821:4a445dc5 default
parent child Browse files
Show More
@@ -66,6 +66,8 b' In addition to filters, there are some b'
66
66
67 - shortest(node)
67 - shortest(node)
68
68
69 - startswith(string, text)
70
69 - strip(text[, chars])
71 - strip(text[, chars])
70
72
71 - sub(pat, repl, expr)
73 - sub(pat, repl, expr)
@@ -124,3 +126,7 b' Some sample command line templates:'
124 - Mark the working copy parent with '@'::
126 - Mark the working copy parent with '@'::
125
127
126 $ hg log --template "{ifcontains(rev, revset('.'), '@')}\n"
128 $ hg log --template "{ifcontains(rev, revset('.'), '@')}\n"
129
130 - Show only commit descriptions that start with "template"::
131
132 $ hg log --template "{startswith(\"template\", firstline(desc))}\n"
@@ -466,6 +466,17 b' def sub(context, mapping, args):'
466 src = stringify(_evalifliteral(args[2], context, mapping))
466 src = stringify(_evalifliteral(args[2], context, mapping))
467 yield re.sub(pat, rpl, src)
467 yield re.sub(pat, rpl, src)
468
468
469 def startswith(context, mapping, args):
470 if len(args) != 2:
471 raise error.ParseError(_("startswith expects two arguments"))
472
473 patn = stringify(args[0][0](context, mapping, args[0][1]))
474 text = stringify(args[1][0](context, mapping, args[1][1]))
475 if text.startswith(patn):
476 return text
477 return ''
478
479
469 methods = {
480 methods = {
470 "string": lambda e, c: (runstring, e[1]),
481 "string": lambda e, c: (runstring, e[1]),
471 "rawstring": lambda e, c: (runrawstring, e[1]),
482 "rawstring": lambda e, c: (runrawstring, e[1]),
@@ -490,6 +501,7 b' funcs = {'
490 "revset": revset,
501 "revset": revset,
491 "rstdoc": rstdoc,
502 "rstdoc": rstdoc,
492 "shortest": shortest,
503 "shortest": shortest,
504 "startswith": startswith,
493 "strip": strip,
505 "strip": strip,
494 "sub": sub,
506 "sub": sub,
495 }
507 }
@@ -1884,3 +1884,30 b' Test splitlines'
1884 | foo other 3
1884 | foo other 3
1885 o foo line 1
1885 o foo line 1
1886 foo line 2
1886 foo line 2
1887
1888 Test startswith
1889 $ hg log -Gv -R a --template "{startswith(desc)}"
1890 hg: parse error: startswith expects two arguments
1891 [255]
1892
1893 $ hg log -Gv -R a --template "{startswith('line', desc)}"
1894 @
1895 |
1896 o
1897 |
1898 o
1899
1900 o
1901 |\
1902 | o
1903 | |
1904 o |
1905 |/
1906 o
1907 |
1908 o
1909 |
1910 o
1911 |
1912 o line 1
1913 line 2
General Comments 0
You need to be logged in to leave comments. Login now