comparison mercurial/debugcommands.py @ 39405:0f549da54379

stringutil: teach pprint() to indent This will make data structure dumping in various places a bit easier to read and diff. Since I wanted this for `hg debugwireproto` output, I added indentation to it. A more advanced pretty printer implementation would conditionally add newlines if output is too long. But it is vastly simpler to be consistent and always add newlines when indenting. Again, I'm not crazy about the verbosity of the code and there is room to consolidate logic for "print a collection." But this isn't the most complicated code in the world and I'm not convinced it is worth doing. Differential Revision: https://phab.mercurial-scm.org/D4399
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 27 Aug 2018 09:13:58 -0700
parents 655b5b465953
children e5eb67dea6e8
comparison
equal deleted inserted replaced
39404:b4e7e1f09c09 39405:0f549da54379
3242 res = e.callcommand(command, args).result() 3242 res = e.callcommand(command, args).result()
3243 3243
3244 if isinstance(res, wireprotov2peer.commandresponse): 3244 if isinstance(res, wireprotov2peer.commandresponse):
3245 val = list(res.cborobjects()) 3245 val = list(res.cborobjects())
3246 ui.status(_('response: %s\n') % 3246 ui.status(_('response: %s\n') %
3247 stringutil.pprint(val, bprefix=True)) 3247 stringutil.pprint(val, bprefix=True, indent=2))
3248
3249 else: 3248 else:
3250 ui.status(_('response: %s\n') % 3249 ui.status(_('response: %s\n') %
3251 stringutil.pprint(res, bprefix=True)) 3250 stringutil.pprint(res, bprefix=True, indent=2))
3252 3251
3253 elif action == 'batchbegin': 3252 elif action == 'batchbegin':
3254 if batchedcommands is not None: 3253 if batchedcommands is not None:
3255 raise error.Abort(_('nested batchbegin not allowed')) 3254 raise error.Abort(_('nested batchbegin not allowed'))
3256 3255
3320 getattr(e, 'read', lambda: None)() 3319 getattr(e, 'read', lambda: None)()
3321 continue 3320 continue
3322 3321
3323 if res.headers.get('Content-Type') == 'application/mercurial-cbor': 3322 if res.headers.get('Content-Type') == 'application/mercurial-cbor':
3324 ui.write(_('cbor> %s\n') % 3323 ui.write(_('cbor> %s\n') %
3325 stringutil.pprint(cbor.loads(body), bprefix=True)) 3324 stringutil.pprint(cbor.loads(body), bprefix=True,
3325 indent=2))
3326 3326
3327 elif action == 'close': 3327 elif action == 'close':
3328 peer.close() 3328 peer.close()
3329 elif action == 'readavailable': 3329 elif action == 'readavailable':
3330 if not stdout or not stderr: 3330 if not stdout or not stderr: