# HG changeset patch # User Yuya Nishihara # Date 1515294449 -32400 # Node ID d1aae6d4efc5f5b2175220d9b397003feb2efa32 # Parent f39cf992216fc4aa6b6df0401e86485ef07d07b0 templatefilters: fix doc of basename() os.path.basename() does NOT strip trailing slashes. > Note that the result of this function is different from the Unix basename > program; where basename for '/foo/bar/' returns 'bar', the basename() > function returns an empty string (''). https://docs.python.org/2.7/library/os.path.html#os.path.basename diff -r f39cf992216f -r d1aae6d4efc5 mercurial/templatefilters.py --- a/mercurial/templatefilters.py Sun Jan 07 15:56:58 2018 +0900 +++ b/mercurial/templatefilters.py Sun Jan 07 12:07:29 2018 +0900 @@ -90,9 +90,8 @@ @templatefilter('basename') def basename(path): """Any text. Treats the text as a path, and returns the last - component of the path after splitting by the path separator - (ignoring trailing separators). For example, "foo/bar/baz" becomes - "baz" and "foo/bar//" becomes "bar". + component of the path after splitting by the path separator. + For example, "foo/bar/baz" becomes "baz" and "foo/bar//" becomes "". """ return os.path.basename(path) diff -r f39cf992216f -r d1aae6d4efc5 tests/test-command-template.t --- a/tests/test-command-template.t Sun Jan 07 15:56:58 2018 +0900 +++ b/tests/test-command-template.t Sun Jan 07 12:07:29 2018 +0900 @@ -2218,6 +2218,11 @@ $ cd .. $ rm -rf unstable-hash +Filename filters: + + $ hg debugtemplate '{"foo/bar"|basename}|{"foo/"|basename}|{"foo"|basename}|\n' + bar||foo| + Add a dummy commit to make up for the instability of the above: $ echo a > a