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

Yuya Nishihara yuya at tcha.org
Sat Jul 9 07:12:38 EDT 2016


On Tue, 05 Jul 2016 11:43:00 +0200, liscju wrote:
> # HG changeset patch
> # User liscju <piotr.listkiewicz at gmail.com>
> # Date 1467710115 -7200
> #      Tue Jul 05 11:15:15 2016 +0200
> # Node ID 75dcd3200e5eb25cea41e39a26bcde12f50de376
> # Parent  6a98f9408a504be455d4382801610daceac429e6
> debugobsolete: add formatter support (issue5134)
> 
> This solution keeps the same output debugobsolete had
> before formatter support, but there are few issues
> I didnt manage to resolve:
> 
> 1) succnodes, parents were space separated strings, in
> formatter they should be passed as list to be printed
> by jsonformatter output as for example:
> succnodes: [succnode1, succnode2, etc]
> 
> 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.

> 2) metadata should be printed as dictionary, but when
> it is passed as one it changes plain old formatting.

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.

> 3) flags formatting, fm.write('flags', '%X', marker.flags())
> behaves differently for plain formatting(it prints some flags
> as C) but for json formatting it always prints number.

"C" is hex value. It should be decimal integer in JSON.

> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -1611,25 +1611,42 @@ def show_changeset(ui, repo, opts, buffe
>  
>      return changeset_templater(ui, repo, matchfn, opts, tmpl, mapfile, buffered)
>  
> -def showmarker(ui, marker, index=None):
> +def showmarker(fm, marker, index=None):
>      """utility function to display obsolescence marker in a readable way
>  
>      To be used by debug function."""
> +    fm.startitem()

Better to move fm.startitem() to the caller because this function doesn't
control the loop.

> +    fm.condwrite(index is not None, 'index', '%i', index)
>      if index is not None:
> -        ui.write("%i " % index)
> +        fm.plain(' ')

JSON and template outputs should always have index, i.e.

  fm.condwrite(showindex, 'index', '%i ', index)

> +    fm.write('date', '%s', util.datestr(marker.date()))

It should be a date tuple in template/machine format.


More information about the Mercurial-devel mailing list