Submitter | Yuya Nishihara |
---|---|
Date | Sept. 30, 2018, 1:43 p.m. |
Message ID | <6b1a87ee875353454323.1538315029@mimosa> |
Download | mbox | patch |
Permalink | /patch/35222/ |
State | Superseded |
Headers | show |
Comments
On Sun, 30 Sep 2018 22:43:49 +0900 Yuya Nishihara <yuya@tcha.org> wrote: > # HG changeset patch > # User Yuya Nishihara <yuya@tcha.org> > # Date 1538289985 -32400 > # Sun Sep 30 15:46:25 2018 +0900 > # Node ID 6b1a87ee8753534543236e3a64e66e8f0382b5eb > # Parent 22f0acc9d2d80ae870d92636d9023b7849b616bb > templatefilters: alias element of {_|splitlines} to {text} > > We've renamed {line} of annotation result as such. > > diff --git a/tests/test-template-functions.t b/tests/test-template-functions.t > --- a/tests/test-template-functions.t > +++ b/tests/test-template-functions.t > @@ -1254,6 +1254,10 @@ Test splitlines > o foo line 1 > foo line 2 > > + $ hg log -R a -r0 -T '{desc|splitlines % "{text}\n"}' > + line 1 > + line 2 > + I see it this way: # feels very natural lines = foo.splitlines() -or- for line in foo.splitlines() # looks weird texts = foo.splitlines() -or- for text in foo.splitlines()
Patch
diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -387,7 +387,9 @@ def slashpath(path): @templatefilter('splitlines', intype=bytes) def splitlines(text): """Any text. Split text into a list of lines.""" - return templateutil.hybridlist(text.splitlines(), name='line') + return templateutil.hybrid(None, text.splitlines(), + lambda x: {'line': x, 'text': x}, + pycompat.identity) @templatefilter('stringescape', intype=bytes) def stringescape(text): diff --git a/tests/test-template-functions.t b/tests/test-template-functions.t --- a/tests/test-template-functions.t +++ b/tests/test-template-functions.t @@ -1254,6 +1254,10 @@ Test splitlines o foo line 1 foo line 2 + $ hg log -R a -r0 -T '{desc|splitlines % "{text}\n"}' + line 1 + line 2 + $ hg log -R a -r0 -T '{desc|splitlines}\n' line 1 line 2 $ hg log -R a -r0 -T '{join(desc|splitlines, "|")}\n'