martinvonz created this revision. Herald added a reviewer: hg-reviewers. Herald added a subscriber: mercurial-patches.
REVISION SUMMARY It's surprisingly hard to get the first line from a string, so let's have our own function in `stringutil` for it. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D12404 AFFECTED FILES mercurial/templatefilters.py mercurial/utils/stringutil.py CHANGE DETAILS 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'...') 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) To: martinvonz, #hg-reviewers Cc: mercurial-patches, mercurial-devel _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel