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

Yuya Nishihara yuya at tcha.org
Sun Jul 10 08:31:08 EDT 2016


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)


More information about the Mercurial-devel mailing list