Patchwork [1,of,2] templatefilters: add slashpath() to convert path separator to slash

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 12, 2017, 3:03 p.m.
Message ID <c2ff7689990d5c163cff.1513091017@mimosa>
Download mbox | patch
Permalink /patch/26233/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 12, 2017, 3:03 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1508573942 -32400
#      Sat Oct 21 17:19:02 2017 +0900
# Node ID c2ff7689990d5c163cff48c38880928ee98e4248
# Parent  6ef72e8546b2c86b7ca4ba190fe1affcaa3a440c
templatefilters: add slashpath() to convert path separator to slash

Prepares for deprecating the ui.slash option, which isn't always respected.

Patch

diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -349,6 +349,11 @@  def shortdate(text):
     """Date. Returns a date like "2006-09-18"."""
     return util.shortdate(text)
 
+@templatefilter('slashpath')
+def slashpath(path):
+    """Any text. Replaces the native path separator with slash."""
+    return util.pconvert(path)
+
 @templatefilter('splitlines')
 def splitlines(text):
     """Any text. Split text into a list of lines."""
diff --git a/tests/test-locate.t b/tests/test-locate.t
--- a/tests/test-locate.t
+++ b/tests/test-locate.t
@@ -151,4 +151,13 @@  Issue294: hg remove --after dir fails wh
   $ hg files .
   [1]
 
+Convert native path separator to slash (issue5572)
+
+  $ hg files -T '{path|slashpath}\n'
+  ../b
+  ../dir.h/foo
+  ../t.h
+  ../t/e.h
+  ../t/x
+
   $ cd ../..