[PATCH 2 of 5] templatefilters: stringify None to '' just like templater._flatten() does
Yuya Nishihara
yuya at tcha.org
Tue Apr 7 09:07:40 CDT 2015
# HG changeset patch
# User Yuya Nishihara <yuya at 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}+')}
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
More information about the Mercurial-devel
mailing list