[PATCH] templater.firstline should handle empty strings
Brendan Cully
brendan at kublai.com
Tue Jul 4 22:10:53 UTC 2006
# HG changeset patch
# User Brendan Cully <brendan at kublai.com>
# Node ID 77955f4f89b7d5e715a443767d4d43c1e614a3dc
# Parent b73552a00b209c8fcd71fd23fb990c5d05910010
templater.firstline should handle empty strings
diff -r b73552a00b20 -r 77955f4f89b7 mercurial/templater.py
--- a/mercurial/templater.py Mon Jun 26 16:47:24 2006 +0200
+++ b/mercurial/templater.py Tue Jul 04 15:10:23 2006 -0700
@@ -221,6 +221,13 @@ def fill(text, width):
fp.write(rest)
return fp.getvalue()
+def firstline(text):
+ '''return the first line of text'''
+ try:
+ return text.splitlines(1)[0].rstrip('\r\n')
+ except IndexError:
+ return ''
+
def isodate(date):
'''turn a (timestamp, tzoff) tuple into an iso 8631 date and time.'''
return util.datestr(date, format='%Y-%m-%d %H:%M')
@@ -280,7 +287,7 @@ common_filters = {
"escape": lambda x: cgi.escape(x, True),
"fill68": lambda x: fill(x, width=68),
"fill76": lambda x: fill(x, width=76),
- "firstline": lambda x: x.splitlines(1)[0].rstrip('\r\n'),
+ "firstline": firstline,
"tabindent": lambda x: indent(x, '\t'),
"isodate": isodate,
"obfuscate": obfuscate,
More information about the Mercurial
mailing list