Patchwork [2,of,5] templatefilters: stringify None to '' just like templater._flatten() does

login
register
mail settings
Submitter Yuya Nishihara
Date April 7, 2015, 2:07 p.m.
Message ID <8c44ed02f5ff82584e55.1428415660@mimosa>
Download mbox | patch
Permalink /patch/8531/
State Changes Requested
Headers show

Comments

Yuya Nishihara - April 7, 2015, 2:07 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1426332422 -32400
#      Sat Mar 14 20:27:02 2015 +0900
# Node ID 8c44ed02f5ff82584e55c6978396ad004ec0dbe2
# Parent  6e0da90c09aab6f350afe167f176d37c4bb83a0e
templatefilters: stringify None to '' just like templater._flatten() does

This allows us to handle workingctx by if function:

    {if(node, '{rev}:{node|short}', '{p1rev}:{p1node|short}+')}

Patch

diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -324,6 +324,8 @@  def stringify(thing):
     """:stringify: Any type. Turns the value into text by converting values into
     text and concatenating them.
     """
+    if thing is None:
+        return ''
     if util.safehasattr(thing, '__iter__') and not isinstance(thing, str):
         return "".join([stringify(t) for t in thing if t is not None])
     return str(thing)
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
@@ -56,6 +56,10 @@  because there are several ways to:
 
   $ hg log -r 'wdir()' -T '{node}\n'
   
+  $ hg log -r 'wdir()' -T '{rev}\n'
+  
+  $ hg log -r 'wdir()' -T '{rev|stringify}\n'
+  
 
 Quoting for ui.logtemplate