[PATCH 2 of 2 STABLE] templatefilters: fix doc of basename()
Yuya Nishihara
yuya at tcha.org
Sun Jan 7 02:18:59 EST 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1515294449 -32400
# Sun Jan 07 12:07:29 2018 +0900
# Branch stable
# Node ID cb1d423650e18fdd4346f951d3fe9f2f47e2a24a
# Parent 614e385a5245a43232a10ee383d9894673b03b00
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 --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -90,9 +90,8 @@ def age(date, abbrev=False):
@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 --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -2218,6 +2218,11 @@ Age filter:
$ 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
More information about the Mercurial-devel
mailing list