diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -268,10 +268,7 @@ @templatefilter(b'firstline', intype=bytes) def firstline(text): """Any text. Returns the first line of text.""" - try: - return text.splitlines()[0] - except IndexError: - return b'' + return stringutil.firstline(text) @templatefilter(b'hex', intype=bytes) diff --git a/mercurial/utils/stringutil.py b/mercurial/utils/stringutil.py --- a/mercurial/utils/stringutil.py +++ b/mercurial/utils/stringutil.py @@ -685,6 +685,14 @@ return _correctauthorformat.match(author) is not None +def firstline(text): + """Return the first line of the input""" + try: + return text.splitlines()[0] + except IndexError: + return b'' + + def ellipsis(text, maxlength=400): """Trim string to at most maxlength (default: 400) columns in display.""" return encoding.trim(text, maxlength, ellipsis=b'...')