Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 43754:02ededbef627
util: add an optional `prefix` argument to debugstacktrace
This is useful when using it in a specific context.
Differential Revision: https://phab.mercurial-scm.org/D7477
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sun, 17 Nov 2019 06:26:41 +0100 |
parents | 7eb701e355bd |
children | 40bd667491a7 |
comparison
equal
deleted
inserted
replaced
43753:2276a9a1c037 | 43754:02ededbef627 |
---|---|
3464 msg=b'stacktrace', | 3464 msg=b'stacktrace', |
3465 skip=0, | 3465 skip=0, |
3466 f=procutil.stderr, | 3466 f=procutil.stderr, |
3467 otherf=procutil.stdout, | 3467 otherf=procutil.stdout, |
3468 depth=0, | 3468 depth=0, |
3469 prefix=b'', | |
3469 ): | 3470 ): |
3470 '''Writes a message to f (stderr) with a nicely formatted stacktrace. | 3471 '''Writes a message to f (stderr) with a nicely formatted stacktrace. |
3471 Skips the 'skip' entries closest to the call, then show 'depth' entries. | 3472 Skips the 'skip' entries closest to the call, then show 'depth' entries. |
3472 By default it will flush stdout first. | 3473 By default it will flush stdout first. |
3473 It can be used everywhere and intentionally does not require an ui object. | 3474 It can be used everywhere and intentionally does not require an ui object. |
3474 Not be used in production code but very convenient while developing. | 3475 Not be used in production code but very convenient while developing. |
3475 ''' | 3476 ''' |
3476 if otherf: | 3477 if otherf: |
3477 otherf.flush() | 3478 otherf.flush() |
3478 f.write(b'%s at:\n' % msg.rstrip()) | 3479 f.write(b'%s%s at:\n' % (prefix, msg.rstrip())) |
3479 for line in getstackframes(skip + 1, depth=depth): | 3480 for line in getstackframes(skip + 1, depth=depth): |
3480 f.write(line) | 3481 f.write(prefix + line) |
3481 f.flush() | 3482 f.flush() |
3482 | 3483 |
3483 | 3484 |
3484 # convenient shortcut | 3485 # convenient shortcut |
3485 dst = debugstacktrace | 3486 dst = debugstacktrace |