# HG changeset patch # User Yuya Nishihara # Date 1515294573 -32400 # Node ID 9ee10b3284da1ec3f0de7ce24e45af91dcd628a5 # Parent c6ce479f7a28644487c430d9629c720ff9079fc3 templatefilters: add dirname() filter This is different from stripdir() in that the last component is always removed. diff -r c6ce479f7a28 -r 9ee10b3284da mercurial/templatefilters.py --- a/mercurial/templatefilters.py Sun Jan 07 11:21:25 2018 +0900 +++ b/mercurial/templatefilters.py Sun Jan 07 12:09:33 2018 +0900 @@ -100,6 +100,13 @@ """List or text. Returns the length as an integer.""" return len(i) +@templatefilter('dirname') +def dirname(path): + """Any text. Treats the text as a path, and strips the last + component of the path after splitting by the path separator. + """ + return os.path.dirname(path) + @templatefilter('domain') def domain(author): """Any text. Finds the first string that looks like an email diff -r c6ce479f7a28 -r 9ee10b3284da tests/test-command-template.t --- a/tests/test-command-template.t Sun Jan 07 11:21:25 2018 +0900 +++ b/tests/test-command-template.t Sun Jan 07 12:09:33 2018 +0900 @@ -2232,6 +2232,10 @@ $ hg debugtemplate '{"foo/bar"|basename}|{"foo/"|basename}|{"foo"|basename}|\n' bar||foo| + $ hg debugtemplate '{"foo/bar"|dirname}|{"foo/"|dirname}|{"foo"|dirname}|\n' + foo|foo|| + $ hg debugtemplate '{"foo/bar"|stripdir}|{"foo/"|stripdir}|{"foo"|stripdir}|\n' + foo|foo|foo| Add a dummy commit to make up for the instability of the above: