Show More
@@ -66,6 +66,8 b' In addition to filters, there are some b' | |||
|
66 | 66 | |
|
67 | 67 | - shortest(node) |
|
68 | 68 | |
|
69 | - startswith(string, text) | |
|
70 | ||
|
69 | 71 | - strip(text[, chars]) |
|
70 | 72 | |
|
71 | 73 | - sub(pat, repl, expr) |
@@ -124,3 +126,7 b' Some sample command line templates:' | |||
|
124 | 126 | - Mark the working copy parent with '@':: |
|
125 | 127 | |
|
126 | 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 | 466 | src = stringify(_evalifliteral(args[2], context, mapping)) |
|
467 | 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 | 480 | methods = { |
|
470 | 481 | "string": lambda e, c: (runstring, e[1]), |
|
471 | 482 | "rawstring": lambda e, c: (runrawstring, e[1]), |
@@ -490,6 +501,7 b' funcs = {' | |||
|
490 | 501 | "revset": revset, |
|
491 | 502 | "rstdoc": rstdoc, |
|
492 | 503 | "shortest": shortest, |
|
504 | "startswith": startswith, | |
|
493 | 505 | "strip": strip, |
|
494 | 506 | "sub": sub, |
|
495 | 507 | } |
@@ -1884,3 +1884,30 b' Test splitlines' | |||
|
1884 | 1884 | | foo other 3 |
|
1885 | 1885 | o foo line 1 |
|
1886 | 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