mercurial/util.py
changeset 20244 47d0843647d1
parent 20202 a6014018ec28
child 20353 0889585b44f1
equal deleted inserted replaced
20243:cc09cfea3dd4 20244:47d0843647d1
  1981 
  1981 
  1982     def __call__(self, *args):
  1982     def __call__(self, *args):
  1983         self._hooks.sort(key=lambda x: x[0])
  1983         self._hooks.sort(key=lambda x: x[0])
  1984         for source, hook in self._hooks:
  1984         for source, hook in self._hooks:
  1985             hook(*args)
  1985             hook(*args)
       
  1986 
       
  1987 def debugstacktrace(msg='stacktrace', skip=0, f=sys.stderr):
       
  1988     '''Writes a message to f (stderr) with a nicely formatted stacktrace.
       
  1989     Skips the 'skip' last entries.
       
  1990     It can be used everywhere and do intentionally not require an ui object.
       
  1991     Not be used in production code but very convenient while developing.
       
  1992     '''
       
  1993     f.write('%s at:\n' % msg)
       
  1994     entries = [('%s:%s' % (fn, ln), func)
       
  1995         for fn, ln, func, _text in traceback.extract_stack()[:-skip - 1]]
       
  1996     if entries:
       
  1997         fnmax = max(len(entry[0]) for entry in entries)
       
  1998         for fnln, func in entries:
       
  1999             f.write(' %-*s in %s\n' % (fnmax, fnln, func))
       
  2000 
       
  2001 # convenient shortcut
       
  2002 dst = debugstacktrace