Patchwork [6,of,5] templatefilters: fix crash by string formatting of '{x|splitlines}'

login
register
mail settings
Submitter Yuya Nishihara
Date April 16, 2017, 1:27 p.m.
Message ID <9301c79b46ba6424585d.1492349223@mimosa>
Download mbox | patch
Permalink /patch/20239/
State Accepted
Delegated to: Kevin Bullock
Headers show

Comments

Yuya Nishihara - April 16, 2017, 1:27 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1492221077 -32400
#      Sat Apr 15 10:51:17 2017 +0900
# Node ID 9301c79b46ba6424585dd4ad0ec638b9be69de1b
# Parent  3776ae7011f71bdc5e51be7cfd4219bf438ca384
templatefilters: fix crash by string formatting of '{x|splitlines}'

Before, it crashed because mapping['templ'] was missing. As it didn't support
the legacy list template from the beginning, we can simply use hybridlist().

Patch

diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -339,7 +339,7 @@  def shortdate(text):
 @templatefilter('splitlines')
 def splitlines(text):
     """Any text. Split text into a list of lines."""
-    return templatekw.showlist('line', text.splitlines(), {}, plural='lines')
+    return templatekw.hybridlist(text.splitlines(), name='line')
 
 @templatefilter('stringescape')
 def stringescape(text):
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
@@ -3894,6 +3894,11 @@  Test splitlines
   o  foo line 1
      foo line 2
 
+  $ hg log -R a -r0 -T '{desc|splitlines}\n'
+  line 1 line 2
+  $ hg log -R a -r0 -T '{join(desc|splitlines, "|")}\n'
+  line 1|line 2
+
 Test startswith
   $ hg log -Gv -R a --template "{startswith(desc)}"
   hg: parse error: startswith expects two arguments