# HG changeset patch # User Brendan Cully # Date 1152052565 25200 # Node ID bf67d0f6531c5ed29ababbbfd62f5371f3fa9c85 # Parent 1120302009d79ea3b0bb0c73a5671783eac6b5cf templater.firstline should handle empty strings diff -r 1120302009d7 -r bf67d0f6531c mercurial/templater.py --- a/mercurial/templater.py Mon Jul 03 00:33:19 2006 -0300 +++ b/mercurial/templater.py Tue Jul 04 15:36:05 2006 -0700 @@ -221,6 +221,13 @@ 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') @@ -284,7 +291,7 @@ "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'), "hgdate": hgdate, "isodate": isodate,