# HG changeset patch # User Pierre-Yves David # Date 2019-11-17 05:26:41 # Node ID 6301ea7a26b6fb71b36065f63204cf5e61ca79c7 # Parent 0ddd97e45cc620ec43fa4bba1b7a9752896928f7 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 diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -3466,6 +3466,7 @@ def debugstacktrace( f=procutil.stderr, otherf=procutil.stdout, depth=0, + prefix=b'', ): '''Writes a message to f (stderr) with a nicely formatted stacktrace. Skips the 'skip' entries closest to the call, then show 'depth' entries. @@ -3475,9 +3476,9 @@ def debugstacktrace( ''' if otherf: otherf.flush() - f.write(b'%s at:\n' % msg.rstrip()) + f.write(b'%s%s at:\n' % (prefix, msg.rstrip())) for line in getstackframes(skip + 1, depth=depth): - f.write(line) + f.write(prefix + line) f.flush()