<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">For this particular case, you can use fm.data() and fix _jsonifyobj() to<br></span><span style="font-size:12.8px">support dicts. There are more complicated examples in evolve.py and journal.py,<br></span><span style="font-size:12.8px">but "{metadata}" can be a plain dict since it isn't a nested template structure.</span></blockquote><div><br></div><div>It wouldn't be a problem that fm.data(..) for plainformatter prints nothing? It means we would need two invocation of writing metadata:</div><div><br></div><div>fm.plain( expression_to_stringify_metadata) # only for plain</div><div>fm.data(metadata) # only for templates != plain</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">JSON and template outputs should always have index, i.e.</span><br style="font-size:12.8px"><span style="font-size:12.8px">  fm.condwrite(showindex, 'index', '%i ', index)</span></blockquote><div><br></div><div>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.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">I came up with a better idea.</span><br style="font-size:12.8px"><span style="font-size:12.8px">  # formatlist(name: str, data: iterable, fmt='%s': str, sep='': str)<br></span><span style="font-size:12.8px">  #            -> str|list|templatekw._hybrid<br></span><span style="font-size:12.8px">  hexnodes = [hex(repl) for repl in marker.succnodes()]<br></span><span style="font-size:12.8px">  fm.write('succnodes', '%s', fm.formatlist('node', hexnodes, fmt='%s '))</span><br style="font-size:12.8px"><span style="font-size:12.8px">It can avoid copying the functionality of (cond)?write(), and has fewer<br></span><span style="font-size:12.8px">arguments.</span></blockquote><div><br></div><div>I have a problem what formatlist should return for jsonformatter:</div><div>1) list - it crash because json doesnt support jsonifying list</div><div>2) string - it won't work because json fm.write escapes characters like '['</div><div>3) templatekw._hybrid - i have no idea how to do this, i see this returns generator, i have no idea how to use it</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">Maybe we could handle datestr() in the same way?</span><br style="font-size:12.8px"><span style="font-size:12.8px">  fm.formatdate(date: (int, int), format=...) -> str|(int, int)</span></blockquote><div><br></div><div>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?</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-07-10 14:31 GMT+02:00 Yuya Nishihara <span dir="ltr"><<a href="mailto:yuya@tcha.org" target="_blank">yuya@tcha.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Sat, 9 Jul 2016 20:12:38 +0900, Yuya Nishihara wrote:<br>
> On Tue, 05 Jul 2016 11:43:00 +0200, liscju wrote:<br>
</span><span class="">> > Problem is how to pass it as list, but at the same time<br>
> > keep the same output it had before.<br>
><br>
> Yeah, it's known issue.<br>
><br>
> <a href="https://bz.mercurial-scm.org/show_bug.cgi?id=5217#c2" rel="noreferrer" target="_blank">https://bz.mercurial-scm.org/show_bug.cgi?id=5217#c2</a><br>
><br>
> The idea I have in mind is to add new API for lists.<br>
><br>
>   # writelist(field: str, elemname: str, elemfmt: str, data: iterable,<br>
>   #           sep='': str)<br>
>   fm.writelist('succnodes', 'node', '%s ',<br>
>                (hex(repl) for repl in marker.succnodes()))<br>
><br>
> The point of the formatter API is to avoid divergence between plain and<br>
> template/machine outputs.  I think writelist() can handle common cases well.<br>
<br>
</span>I came up with a better idea.<br>
<br>
  # formatlist(name: str, data: iterable, fmt='%s': str, sep='': str)<br>
  #            -> str|list|templatekw._hybrid<br>
  hexnodes = [hex(repl) for repl in marker.succnodes()]<br>
  fm.write('succnodes', '%s', fm.formatlist('node', hexnodes, fmt='%s '))<br>
<br>
It can avoid copying the functionality of (cond)?write(), and has fewer<br>
arguments.<br>
<span class=""><br>
> > +    fm.write('date', '%s', util.datestr(marker.date()))<br>
><br>
> It should be a date tuple in template/machine format.<br>
<br>
</span>Maybe we could handle datestr() in the same way?<br>
<br>
  fm.formatdate(date: (int, int), format=...) -> str|(int, int)<br>
</blockquote></div><br></div>