# HG changeset patch # User Boris Feld # Date 1494409931 -7200 # Node ID e28026b4d3c18ccb113257f900a0b4bfdca7adcf # Parent e6d3b83b306b2b3c99794232a0e4ce005bc3d0af obshistory: use formatter instead of ui.write in the debugobshistory command Replace ui.write with a formater to have template support and json output. Update tests to assert json outputs. diff -r e6d3b83b306b -r e28026b4d3c1 hgext3rd/evolve/__init__.py --- a/hgext3rd/evolve/__init__.py Wed May 10 13:04:31 2017 +0200 +++ b/hgext3rd/evolve/__init__.py Wed May 10 11:52:11 2017 +0200 @@ -3261,15 +3261,18 @@ @eh.command( '^debugobshistory', - [('r', 'rev', [], _("revision to debug"))], - _('hg debugobshistory [OPTION]... [-r] [REV]')) + [] + commands.formatteropts, + _('hg debugobshistory [OPTION]... [REV]')) def debugobshistory(ui, repo, *revs, **opts): revs = scmutil.revrange(repo, revs) + fm = ui.formatter('debugobshistory', opts) for rev in revs: - _debugobshistorysingle(ui, repo, rev) - -def _debugobshistorysingle(ui, repo, rev): + _debugobshistorysingle(ui, fm, repo, rev) + + fm.end() + +def _debugobshistorysingle(ui, fm, repo, rev): """ Display the obsolescence history for a single revision """ precursors = repo.obsstore.precursors @@ -3279,41 +3282,66 @@ while nodes: ctxnode = nodes.pop() - _debugobshistorydisplaynode(ui, repo, ctxnode) + _debugobshistorydisplaynode(ui, fm, repo, ctxnode) succs = successors.get(ctxnode, ()) + markerfm = fm.nested("debugobshistory.markers") for successor in sorted(succs): - _debugobshistorydisplaymarker(ui, repo, successor) + _debugobshistorydisplaymarker(ui, markerfm, repo, successor) + markerfm.end() precs = precursors.get(ctxnode, ()) nodes.extend(precursor[0] for precursor in sorted(precs)) -def _debugobshistorydisplaynode(ui, repo, node): +def _debugobshistorydisplaynode(ui, fm, repo, node): ctx = repo.unfiltered()[node] shortdescription = ctx.description().splitlines()[0] - args = (ui.label(str(ctx), "evolve.short_node"), - ui.label(str(int(ctx)), "evolve.rev"), - ui.label(shortdescription, "evolve.short_description")) - - ui.write("%s (%s) %s\n" % args) - -def _debugobshistorydisplaymarker(ui, repo, marker): + fm.startitem() + fm.write('debugobshistory.node', '%s', str(ctx), + label="evolve.short_node") + fm.plain(' ') + + fm.write('debugobshistory.rev', '(%d)', int(ctx), + label="evolve.rev") + fm.plain(' ') + + fm.write('debugobshistory.shortdescription', '%s', shortdescription, + label="evolve.short_description") + fm.plain('\n') + +def _debugobshistorydisplaymarker(ui, fm, repo, marker): succnodes = marker[1] date = marker[4] metadata = dict(marker[3]) - msgargs = (ui.label(metadata['user'], "evolve.user"), - ui.label(util.datestr(date), "evolve.date")) - # If no successors with a marker, the commit has been pruned + fm.startitem() + fm.plain(' ') + + # Detect pruned revisions if len(succnodes) == 0: - msgargs = (ui.label("pruned", "evolve.verb"),) + msgargs - msg = " %s by %s (%s)\n" + verb = 'pruned' else: + verb = 'rewritten' + + fm.write('debugobshistory.verb', '%s', verb, + label="evolve.verb") + fm.plain(' by ') + + fm.write('debugobshistory.marker_user', '%s', metadata['user'], + label="evolve.user") + fm.plain(' ') + + fm.write('debugobshistory.marker_date', '(%s)', fm.formatdate(date), + label="evolve.date") + + if len(succnodes) > 0: + fm.plain(' as ') + shortsnodes = (node.short(succnode) for succnode in sorted(succnodes)) - labelednodes = (ui.label(node, "evolve.short_node") for node in shortsnodes) - msgargs = (ui.label("rewritten", "evolve.verb"),) + msgargs + (", ".join(labelednodes),) - msg = " %s by %s (%s) as %s\n" - - ui.write(msg % msgargs) + nodes = fm.formatlist(shortsnodes, 'debugobshistory.succnodes', sep=', ') + fm.write('debugobshistory.succnodes', '%s', nodes, + label="evolve.short_node") + + fm.plain("\n") diff -r e6d3b83b306b -r e28026b4d3c1 tests/test-evolve-obshistory.t --- a/tests/test-evolve-obshistory.t Wed May 10 13:04:31 2017 +0200 +++ b/tests/test-evolve-obshistory.t Wed May 10 11:52:11 2017 +0200 @@ -57,9 +57,57 @@ 4ae3a4151de9 (3) A1 471f378eab4c (1) A0 rewritten by test (*20*) as 4ae3a4151de9 (glob) + $ hg debugobshistory 4ae3a4151de9 -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [], + "debugobshistory.node": "4ae3a4151de9", + "debugobshistory.rev": 3, + "debugobshistory.shortdescription": "A1" + }, + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "4ae3a4151de9" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "471f378eab4c", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + } + ] $ hg debugobshistory --hidden 471f378eab4c 471f378eab4c (1) A0 rewritten by test (*20*) as 4ae3a4151de9 (glob) + $ hg debugobshistory --hidden 471f378eab4c -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "4ae3a4151de9" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "471f378eab4c", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + } + ] $ hg update 471f378eab4c abort: hidden revision '471f378eab4c'! (use --hidden to access hidden revisions; successor: 4ae3a4151de9) @@ -125,8 +173,35 @@ $ hg debugobshistory 'desc(B0)' --hidden 0dec01379d3b (2) B0 pruned by test (*20*) (glob) + $ hg debugobshistory 'desc(B0)' --hidden -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.verb": "pruned" + } + ], + "debugobshistory.node": "0dec01379d3b", + "debugobshistory.rev": 2, + "debugobshistory.shortdescription": "B0" + } + ] $ hg debugobshistory 'desc(A0)' 471f378eab4c (1) A0 + $ hg debugobshistory 'desc(A0)' -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [], + "debugobshistory.node": "471f378eab4c", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + } + ] $ hg up 1 0 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg up 0dec01379d3b @@ -228,14 +303,92 @@ $ hg debugobshistory 471597cad322 --hidden 471597cad322 (1) A0 rewritten by test (*20*) as 337fec4d2edc, f257fde29c7a (glob) + $ hg debugobshistory 471597cad322 --hidden -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "337fec4d2edc", + "f257fde29c7a" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "471597cad322", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + } + ] $ hg debugobshistory 337fec4d2edc 337fec4d2edc (2) A0 471597cad322 (1) A0 rewritten by test (*20*) as 337fec4d2edc, f257fde29c7a (glob) + $ hg debugobshistory 337fec4d2edc -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [], + "debugobshistory.node": "337fec4d2edc", + "debugobshistory.rev": 2, + "debugobshistory.shortdescription": "A0" + }, + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "337fec4d2edc", + "f257fde29c7a" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "471597cad322", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + } + ] $ hg debugobshistory f257fde29c7a f257fde29c7a (3) A0 471597cad322 (1) A0 rewritten by test (*20*) as 337fec4d2edc, f257fde29c7a (glob) + $ hg debugobshistory f257fde29c7a -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [], + "debugobshistory.node": "f257fde29c7a", + "debugobshistory.rev": 3, + "debugobshistory.shortdescription": "A0" + }, + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "337fec4d2edc", + "f257fde29c7a" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "471597cad322", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + } + ] $ hg update 471597cad322 abort: hidden revision '471597cad322'! (use --hidden to access hidden revisions; successors: 337fec4d2edc, f257fde29c7a) @@ -401,10 +554,64 @@ $ hg debugobshistory de7290d8b885 --hidden de7290d8b885 (1) A0 rewritten by test (*20*) as 1ae8bc733a14, 337fec4d2edc, c7f044602e9b, f257fde29c7a (glob) + $ hg debugobshistory de7290d8b885 --hidden -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "1ae8bc733a14", + "337fec4d2edc", + "c7f044602e9b", + "f257fde29c7a" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "de7290d8b885", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + } + ] $ hg debugobshistory c7f044602e9b c7f044602e9b (5) A0 de7290d8b885 (1) A0 rewritten by test (*20*) as 1ae8bc733a14, 337fec4d2edc, c7f044602e9b, f257fde29c7a (glob) + $ hg debugobshistory c7f044602e9b -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [], + "debugobshistory.node": "c7f044602e9b", + "debugobshistory.rev": 5, + "debugobshistory.shortdescription": "A0" + }, + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "1ae8bc733a14", + "337fec4d2edc", + "c7f044602e9b", + "f257fde29c7a" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "de7290d8b885", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + } + ] $ hg update de7290d8b885 abort: hidden revision 'de7290d8b885'! (use --hidden to access hidden revisions; successors: 337fec4d2edc, f257fde29c7a and 2 more) @@ -474,15 +681,102 @@ $ hg debugobshistory --hidden 471f378eab4c 471f378eab4c (1) A0 rewritten by test (*20*) as eb5a0daa2192 (glob) + $ hg debugobshistory --hidden 471f378eab4c -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "eb5a0daa2192" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "471f378eab4c", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + } + ] $ hg debugobshistory --hidden 0dec01379d3b 0dec01379d3b (2) B0 rewritten by test (*20*) as eb5a0daa2192 (glob) + $ hg debugobshistory --hidden 0dec01379d3b -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "eb5a0daa2192" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "0dec01379d3b", + "debugobshistory.rev": 2, + "debugobshistory.shortdescription": "B0" + } + ] $ hg debugobshistory eb5a0daa2192 eb5a0daa2192 (3) C0 471f378eab4c (1) A0 rewritten by test (*20*) as eb5a0daa2192 (glob) 0dec01379d3b (2) B0 rewritten by test (*20*) as eb5a0daa2192 (glob) + $ hg debugobshistory eb5a0daa2192 -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [], + "debugobshistory.node": "eb5a0daa2192", + "debugobshistory.rev": 3, + "debugobshistory.shortdescription": "C0" + }, + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "eb5a0daa2192" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "471f378eab4c", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + }, + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "eb5a0daa2192" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "0dec01379d3b", + "debugobshistory.rev": 2, + "debugobshistory.shortdescription": "B0" + } + ] $ hg update 471f378eab4c abort: hidden revision '471f378eab4c'! (use --hidden to access hidden revisions; successor: eb5a0daa2192) @@ -570,16 +864,124 @@ 471f378eab4c (1) A0 rewritten by test (*20*) as 65b757b745b9 (glob) rewritten by test (*20*) as fdf9bde5129a (glob) + $ hg debugobshistory --hidden 471f378eab4c -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "65b757b745b9" + ], + "debugobshistory.verb": "rewritten" + }, + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "fdf9bde5129a" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "471f378eab4c", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + } + ] $ hg debugobshistory fdf9bde5129a fdf9bde5129a (2) A1 471f378eab4c (1) A0 rewritten by test (*20*) as 65b757b745b9 (glob) rewritten by test (*20*) as fdf9bde5129a (glob) + $ hg debugobshistory fdf9bde5129a -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [], + "debugobshistory.node": "fdf9bde5129a", + "debugobshistory.rev": 2, + "debugobshistory.shortdescription": "A1" + }, + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "65b757b745b9" + ], + "debugobshistory.verb": "rewritten" + }, + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "fdf9bde5129a" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "471f378eab4c", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + } + ] $ hg debugobshistory 65b757b745b9 65b757b745b9 (3) A2 471f378eab4c (1) A0 rewritten by test (*20*) as 65b757b745b9 (glob) rewritten by test (*20*) as fdf9bde5129a (glob) + $ hg debugobshistory 65b757b745b9 -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [], + "debugobshistory.node": "65b757b745b9", + "debugobshistory.rev": 3, + "debugobshistory.shortdescription": "A2" + }, + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "65b757b745b9" + ], + "debugobshistory.verb": "rewritten" + }, + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "fdf9bde5129a" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "471f378eab4c", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + } + ] $ hg update 471f378eab4c abort: hidden revision '471f378eab4c'! (use --hidden to access hidden revisions; diverged) @@ -662,9 +1064,51 @@ $ hg debugobshistory --hidden 471f378eab4c 471f378eab4c (1) A0 rewritten by test (*20*) as eb5a0daa2192 (glob) + $ hg debugobshistory --hidden 471f378eab4c -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "eb5a0daa2192" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "471f378eab4c", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + } + ] $ hg debugobshistory --hidden 0dec01379d3b 0dec01379d3b (2) B0 rewritten by test (*20*) as b7ea6d14e664 (glob) + $ hg debugobshistory --hidden 0dec01379d3b -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "b7ea6d14e664" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "0dec01379d3b", + "debugobshistory.rev": 2, + "debugobshistory.shortdescription": "B0" + } + ] $ hg debugobshistory eb5a0daa2192 eb5a0daa2192 (4) C0 b7ea6d14e664 (3) B1 @@ -673,6 +1117,69 @@ rewritten by test (*20*) as b7ea6d14e664 (glob) 471f378eab4c (1) A0 rewritten by test (*20*) as eb5a0daa2192 (glob) + $ hg debugobshistory eb5a0daa2192 -Tjson | python -m json.tool + [ + { + "debugobshistory.markers": [], + "debugobshistory.node": "eb5a0daa2192", + "debugobshistory.rev": 4, + "debugobshistory.shortdescription": "C0" + }, + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "eb5a0daa2192" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "b7ea6d14e664", + "debugobshistory.rev": 3, + "debugobshistory.shortdescription": "B1" + }, + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "b7ea6d14e664" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "0dec01379d3b", + "debugobshistory.rev": 2, + "debugobshistory.shortdescription": "B0" + }, + { + "debugobshistory.markers": [ + { + "debugobshistory.marker_date": [ + *, (glob) + 0 (glob) + ], + "debugobshistory.marker_user": "test", + "debugobshistory.succnodes": [ + "eb5a0daa2192" + ], + "debugobshistory.verb": "rewritten" + } + ], + "debugobshistory.node": "471f378eab4c", + "debugobshistory.rev": 1, + "debugobshistory.shortdescription": "A0" + } + ] $ hg update 471f378eab4c abort: hidden revision '471f378eab4c'! (use --hidden to access hidden revisions; successor: eb5a0daa2192)