Mercurial > hg-stable
changeset 29806:142ae01820a3
debugobsolete: add formatter support (issue5134)
It appears that computing index isn't cheap if --rev is specified. That's
why "index" field is available only if --index is specified.
I've named marker.flags() as "flag" because "flags" implies a list or dict
in template world.
Thanks to Piotr Listkiewicz for the initial implementation of this patch.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 15 Aug 2016 16:07:55 +0900 |
parents | 4891f3b93182 |
children | 6ab838b20359 |
files | mercurial/cmdutil.py mercurial/commands.py tests/test-completion.t tests/test-obsolete.t |
diffstat | 4 files changed, 113 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Mon Aug 15 12:58:33 2016 +0900 +++ b/mercurial/cmdutil.py Mon Aug 15 16:07:55 2016 +0900 @@ -1611,25 +1611,26 @@ 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.""" if index is not None: - ui.write("%i " % index) - ui.write(hex(marker.precnode())) - for repl in marker.succnodes(): - ui.write(' ') - ui.write(hex(repl)) - ui.write(' %X ' % marker.flags()) + fm.write('index', '%i ', index) + fm.write('precnode', '%s ', hex(marker.precnode())) + succs = marker.succnodes() + fm.condwrite(succs, 'succnodes', '%s ', + fm.formatlist(map(hex, succs), name='node')) + fm.write('flag', '%X ', marker.flags()) parents = marker.parentnodes() if parents is not None: - ui.write('{%s} ' % ', '.join(hex(p) for p in parents)) - ui.write('(%s) ' % util.datestr(marker.date())) - ui.write('{%s}' % (', '.join('%r: %r' % t for t in - sorted(marker.metadata().items()) - if t[0] != 'date'))) - ui.write('\n') + fm.write('parentnodes', '{%s} ', + fm.formatlist(map(hex, parents), name='node', sep=', ')) + fm.write('date', '(%s) ', fm.formatdate(marker.date())) + meta = marker.metadata().copy() + meta.pop('date', None) + fm.write('metadata', '{%s}', fm.formatdict(meta, fmt='%r: %r', sep=', ')) + fm.plain('\n') def finddate(ui, repo, date): """Find the tipmost changeset that matches the given date spec"""
--- a/mercurial/commands.py Mon Aug 15 12:58:33 2016 +0900 +++ b/mercurial/commands.py Mon Aug 15 16:07:55 2016 +0900 @@ -3044,7 +3044,7 @@ ('r', 'rev', [], _('display markers relevant to REV')), ('', 'index', False, _('display index of the marker')), ('', 'delete', [], _('delete markers specified by indices')), - ] + commitopts2, + ] + commitopts2 + formatteropts, _('[OBSOLETED [REPLACEMENT ...]]')) def debugobsolete(ui, repo, precursor=None, *successors, **opts): """create arbitrary obsolete marker @@ -3132,6 +3132,7 @@ markerset = set(markers) isrelevant = lambda m: m in markerset + fm = ui.formatter('debugobsolete', opts) for i, m in enumerate(markerstoiter): if not isrelevant(m): # marker can be irrelevant when we're iterating over a set @@ -3142,8 +3143,10 @@ # to get the correct indices, but only display the ones that # are relevant to --rev value continue + fm.startitem() ind = i if opts.get('index') else None - cmdutil.showmarker(ui, m, index=ind) + cmdutil.showmarker(fm, m, index=ind) + fm.end() @command('debugpathcomplete', [('f', 'full', None, _('complete an entire path')),
--- a/tests/test-completion.t Mon Aug 15 12:58:33 2016 +0900 +++ b/tests/test-completion.t Mon Aug 15 16:07:55 2016 +0900 @@ -261,7 +261,7 @@ debuglocks: force-lock, force-wlock debugmergestate: debugnamecomplete: - debugobsolete: flags, record-parents, rev, index, delete, date, user + debugobsolete: flags, record-parents, rev, index, delete, date, user, template debugpathcomplete: full, normal, added, removed debugpushkey: debugpvec:
--- a/tests/test-obsolete.t Mon Aug 15 12:58:33 2016 +0900 +++ b/tests/test-obsolete.t Mon Aug 15 16:07:55 2016 +0900 @@ -645,6 +645,80 @@ cda648ca50f50482b7055c0b0c4c117bba6733d9 3de5eca88c00aa039da7399a220f4a5221faa585 0 (*) {'user': 'test'} (glob) cdbce2fbb16313928851e97e0d85413f3f7eb77f ca819180edb99ed25ceafb3e9584ac287e240b00 0 (Thu Jan 01 00:22:17 1970 +0000) {'user': 'test'} +List of all markers in JSON + + $ hg debugobsolete -Tjson + [ + { + "date": [1339.0, 0], + "flag": 0, + "metadata": {"user": "test"}, + "precnode": "1339133913391339133913391339133913391339", + "succnodes": ["ca819180edb99ed25ceafb3e9584ac287e240b00"] + }, + { + "date": [1339.0, 0], + "flag": 0, + "metadata": {"user": "test"}, + "precnode": "1337133713371337133713371337133713371337", + "succnodes": ["5601fb93a350734d935195fee37f4054c529ff39"] + }, + { + "date": [121.0, 120], + "flag": 12, + "metadata": {"user": "test"}, + "precnode": "245bde4270cd1072a27757984f9cda8ba26f08ca", + "succnodes": ["cdbce2fbb16313928851e97e0d85413f3f7eb77f"] + }, + { + "date": [1338.0, 0], + "flag": 1, + "metadata": {"user": "test"}, + "precnode": "5601fb93a350734d935195fee37f4054c529ff39", + "succnodes": ["6f96419950729f3671185b847352890f074f7557"] + }, + { + "date": [1338.0, 0], + "flag": 0, + "metadata": {"user": "test"}, + "precnode": "ca819180edb99ed25ceafb3e9584ac287e240b00", + "succnodes": ["1337133713371337133713371337133713371337"] + }, + { + "date": [1337.0, 0], + "flag": 0, + "metadata": {"user": "test"}, + "precnode": "cdbce2fbb16313928851e97e0d85413f3f7eb77f", + "succnodes": ["ca819180edb99ed25ceafb3e9584ac287e240b00"] + }, + { + "date": [0.0, 0], + "flag": 0, + "metadata": {"user": "test"}, + "parentnodes": ["6f96419950729f3671185b847352890f074f7557"], + "precnode": "94b33453f93bdb8d457ef9b770851a618bf413e1", + "succnodes": [] + }, + { + "date": *, (glob) + "flag": 0, + "metadata": {"user": "test"}, + "precnode": "cda648ca50f50482b7055c0b0c4c117bba6733d9", + "succnodes": ["3de5eca88c00aa039da7399a220f4a5221faa585"] + } + ] + +Template keywords + + $ hg debugobsolete -r6 -T '{succnodes % "{node|short}"} {date|shortdate}\n' + 3de5eca88c00 ????-??-?? (glob) + $ hg debugobsolete -r6 -T '{join(metadata % "{key}={value}", " ")}\n' + user=test + $ hg debugobsolete -r6 -T '{metadata}\n' + 'user': 'test' + $ hg debugobsolete -r6 -T '{flag} {get(metadata, "user")}\n' + 0 test + #if serve Test the debug output for exchange @@ -1110,6 +1184,25 @@ $ hg debugobsolete --index --rev "3+7" 1 6fdef60fcbabbd3d50e9b9cbc2a240724b91a5e1 d27fb9b066076fd921277a4b9e8b9cb48c95bc6a 0 \(.*\) {'user': 'test'} (re) 3 4715cf767440ed891755448016c2b8cf70760c30 7ae79c5d60f049c7b0dd02f5f25b9d60aaf7b36d 0 \(.*\) {'user': 'test'} (re) + $ hg debugobsolete --index --rev "3+7" -Tjson + [ + { + "date": *, (glob) + "flag": 0, + "index": 1, + "metadata": {"user": "test"}, + "precnode": "6fdef60fcbabbd3d50e9b9cbc2a240724b91a5e1", + "succnodes": ["d27fb9b066076fd921277a4b9e8b9cb48c95bc6a"] + }, + { + "date": *, (glob) + "flag": 0, + "index": 3, + "metadata": {"user": "test"}, + "precnode": "4715cf767440ed891755448016c2b8cf70760c30", + "succnodes": ["7ae79c5d60f049c7b0dd02f5f25b9d60aaf7b36d"] + } + ] Test the --delete option of debugobsolete command $ hg debugobsolete --index