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

Yuya Nishihara yuya at tcha.org
Tue Jul 12 09:23:13 EDT 2016


On Tue, 12 Jul 2016 11:57:17 +0200, Piotr Listkiewicz wrote:
> > 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

Yes. If we want to avoid two separate calls, we could add fm.formatdict().

> > 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.

Printing index=None is wrong. It needs a real index value plus a condition
whether or not index is printed in plain output.

> 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

plainformatter.formatlist() returns a formatted string,
templateformatter.formatlist() returns a list object designed for templater,
otherwise returns a list.

I wrote a draft patch:
https://bitbucket.org/yuja/hg-work/commits/05abf1351e40

> 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?

[timestamp, tzoffset]

See "hg log -Tjson" for how date should be rendered.


More information about the Mercurial-devel mailing list