Submitter | Alexander Plavin |
---|---|
Date | June 25, 2013, 5:57 p.m. |
Message ID | <b86e8cb9939493bdccce.1372183047@debian-alexander.dolgopa> |
Download | mbox | patch |
Permalink | /patch/1745/ |
State | Superseded, archived |
Headers | show |
Comments
This function will be used in my next patches, and it seems handy anyway. 2013/6/25 Alexander Plavin <me@aplavin.ru> > # HG changeset patch > # User Alexander Plavin <me@aplavin.ru> > # Date 1372179742 -14400 > # Tue Jun 25 21:02:22 2013 +0400 > # Node ID b86e8cb9939493bdccce4ec5301cd0b7ea5c9cd7 > # Parent 1bef6f99a12d9062e737bb623da627719a3987e6 > templater: add strip function with chars as an extra argument > > This allows specifying characters to strip, like the Python strip function. > > diff -r 1bef6f99a12d -r b86e8cb99394 mercurial/templater.py > --- a/mercurial/templater.py Thu May 23 17:53:38 2013 -0500 > +++ b/mercurial/templater.py Tue Jun 25 21:02:22 2013 +0400 > @@ -333,6 +333,16 @@ > return util.datestr(date, fmt) > return util.datestr(date) > > +def strip(context, mapping, args): > + if not (1 <= len(args) <= 2): > + raise error.ParseError(_("strip expects one or two arguments")) > + > + text = args[0][0](context, mapping, args[0][1]) > + if len(args) == 2: > + chars = args[1][0](context, mapping, args[1][1]) > + return text.strip(chars) > + return text.strip() > + > methods = { > "string": lambda e, c: (runstring, e[1]), > "symbol": lambda e, c: (runsymbol, e[1]), > @@ -353,6 +363,7 @@ > "sub": sub, > "fill": fill, > "date": date, > + "strip": strip, > } > > # template engine >
On Tue, 2013-06-25 at 21:57 +0400, Alexander Plavin wrote: > # HG changeset patch > # User Alexander Plavin <me@aplavin.ru> > # Date 1372179742 -14400 > # Tue Jun 25 21:02:22 2013 +0400 > # Node ID b86e8cb9939493bdccce4ec5301cd0b7ea5c9cd7 > # Parent 1bef6f99a12d9062e737bb623da627719a3987e6 > templater: add strip function with chars as an extra argument > > This allows specifying characters to strip, like the Python strip function. This'll want documentation/examples. That lives in mercurial/help/, I think. A one-line test case would be good too, see test-command-template.t.
2013/6/25 Matt Mackall <mpm@selenic.com> > On Tue, 2013-06-25 at 21:57 +0400, Alexander Plavin wrote: > > # HG changeset patch > > # User Alexander Plavin <me@aplavin.ru> > > # Date 1372179742 -14400 > > # Tue Jun 25 21:02:22 2013 +0400 > > # Node ID b86e8cb9939493bdccce4ec5301cd0b7ea5c9cd7 > > # Parent 1bef6f99a12d9062e737bb623da627719a3987e6 > > templater: add strip function with chars as an extra argument > > > > This allows specifying characters to strip, like the Python strip > function. > > This'll want documentation/examples. That lives in mercurial/help/, I > think. A one-line test case would be good too, see > test-command-template.t. > This function makes not much sense for commands, like hg log. Also this function is quite obvious, and I didn't find tests for multiple other function there too. So, it seemed to me that test isn't needed. As for documentation, will add it. I thought that the functions list is autogenerated, like filters one. > > -- > Mathematics is the supreme nostalgia of our time. > > >
On Tue, 2013-06-25 at 22:12 +0400, Alexander Plavin wrote: > > > > 2013/6/25 Matt Mackall <mpm@selenic.com> > On Tue, 2013-06-25 at 21:57 +0400, Alexander Plavin wrote: > > # HG changeset patch > > # User Alexander Plavin <me@aplavin.ru> > > # Date 1372179742 -14400 > > # Tue Jun 25 21:02:22 2013 +0400 > > # Node ID b86e8cb9939493bdccce4ec5301cd0b7ea5c9cd7 > > # Parent 1bef6f99a12d9062e737bb623da627719a3987e6 > > templater: add strip function with chars as an extra > argument > > > > This allows specifying characters to strip, like the Python > strip function. > > > This'll want documentation/examples. That lives in > mercurial/help/, I > think. A one-line test case would be good too, see > test-command-template.t. > > > This function makes not much sense for commands, like hg log. Finding weak excuses not to write a one-line test case may not be the most efficient route to getting your patch accepted. Looking forward to v3.
Patch
diff -r 1bef6f99a12d -r b86e8cb99394 mercurial/templater.py --- a/mercurial/templater.py Thu May 23 17:53:38 2013 -0500 +++ b/mercurial/templater.py Tue Jun 25 21:02:22 2013 +0400 @@ -333,6 +333,16 @@ return util.datestr(date, fmt) return util.datestr(date) +def strip(context, mapping, args): + if not (1 <= len(args) <= 2): + raise error.ParseError(_("strip expects one or two arguments")) + + text = args[0][0](context, mapping, args[0][1]) + if len(args) == 2: + chars = args[1][0](context, mapping, args[1][1]) + return text.strip(chars) + return text.strip() + methods = { "string": lambda e, c: (runstring, e[1]), "symbol": lambda e, c: (runsymbol, e[1]), @@ -353,6 +363,7 @@ "sub": sub, "fill": fill, "date": date, + "strip": strip, } # template engine