[PATCH RFC] debugobsolete: add formatter support (issue5134)

Piotr Listkiewicz piotr.listkiewicz at gmail.com
Tue Jul 12 05:57:17 EDT 2016


>
> For this particular case, you can use fm.data() and fix _jsonifyobj() to
> support dicts. There are more complicated examples in evolve.py and
> journal.py,
> but "{metadata}" can be a plain dict since it isn't a nested template
> structure.


It wouldn't be a problem that fm.data(..) for plainformatter prints
nothing? It means we would need two invocation of writing metadata:

fm.plain( expression_to_stringify_metadata) # only for plain
fm.data(metadata) # only for templates != plain


> JSON and template outputs should always have index, i.e.
>   fm.condwrite(showindex, 'index', '%i ', index)


As far as i checked only a plainformatter care about the condition in the
condwrite, other templates prints value no matter what condition is. Or i
just don't get the point.

I came up with a better idea.
>   # formatlist(name: str, data: iterable, fmt='%s': str, sep='': str)
>   #            -> str|list|templatekw._hybrid
>   hexnodes = [hex(repl) for repl in marker.succnodes()]
>   fm.write('succnodes', '%s', fm.formatlist('node', hexnodes, fmt='%s '))
> It can avoid copying the functionality of (cond)?write(), and has fewer
> arguments.


I have a problem what formatlist should return for jsonformatter:
1) list - it crash because json doesnt support jsonifying list
2) string - it won't work because json fm.write escapes characters like '['
3) templatekw._hybrid - i have no idea how to do this, i see this returns
generator, i have no idea how to use it

Maybe we could handle datestr() in the same way?
>   fm.formatdate(date: (int, int), format=...) -> str|(int, int)


Plainformatter in this case should probably  return util.datestr(date) but
what about jsonformatter?. JSON spec does not specify how date should look
like, should it return tuple of int and as a result print date as tuple?

2016-07-10 14:31 GMT+02:00 Yuya Nishihara <yuya at tcha.org>:

> On Sat, 9 Jul 2016 20:12:38 +0900, Yuya Nishihara wrote:
> > On Tue, 05 Jul 2016 11:43:00 +0200, liscju wrote:
> > > Problem is how to pass it as list, but at the same time
> > > keep the same output it had before.
> >
> > Yeah, it's known issue.
> >
> > https://bz.mercurial-scm.org/show_bug.cgi?id=5217#c2
> >
> > The idea I have in mind is to add new API for lists.
> >
> >   # writelist(field: str, elemname: str, elemfmt: str, data: iterable,
> >   #           sep='': str)
> >   fm.writelist('succnodes', 'node', '%s ',
> >                (hex(repl) for repl in marker.succnodes()))
> >
> > The point of the formatter API is to avoid divergence between plain and
> > template/machine outputs.  I think writelist() can handle common cases
> well.
>
> I came up with a better idea.
>
>   # formatlist(name: str, data: iterable, fmt='%s': str, sep='': str)
>   #            -> str|list|templatekw._hybrid
>   hexnodes = [hex(repl) for repl in marker.succnodes()]
>   fm.write('succnodes', '%s', fm.formatlist('node', hexnodes, fmt='%s '))
>
> It can avoid copying the functionality of (cond)?write(), and has fewer
> arguments.
>
> > > +    fm.write('date', '%s', util.datestr(marker.date()))
> >
> > It should be a date tuple in template/machine format.
>
> Maybe we could handle datestr() in the same way?
>
>   fm.formatdate(date: (int, int), format=...) -> str|(int, int)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20160712/8ee7de83/attachment.html>


More information about the Mercurial-devel mailing list