Patchwork [2,of,2,STABLE] templatefilters: fix doc of basename()

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 7, 2018, 7:18 a.m.
Message ID <cb1d423650e18fdd4346.1515309539@mimosa>
Download mbox | patch
Permalink /patch/26600/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 7, 2018, 7:18 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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

Patch

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