D3716: ui: add an unsafeoperation context manager that can block SIGINT

yuja (Yuya Nishihara) phabricator at mercurial-scm.org
Thu Jun 14 11:35:45 EDT 2018


yuja added a comment.


  LGTM by a non-googler.
  
  > +    @contextlib.contextmanager
  >  +    def unsafeoperation(self):
  >  +        """Mark an operation as unsafe.
  
  Nit: the word "unsafe" seems too obscure. Maybe it could be "uninterruptible"
  or "noninterruptible"?
  
  > +        try:
  >  +            self._oldsiginthandler = signal.getsignal(signal.SIGINT)
  >  +            signal.signal(signal.SIGINT, disabledsiginthandler)
  
  `signal.signal()` may raise ValueError if it's called from sub thread.
  
  > - a/mercurial/configitems.py +++ b/mercurial/configitems.py @@ -560,6 +560,17 @@ coreconfigitem('experimental', 'mergedriver', default=None, ) +coreconfigitem('experimental', 'nointerrupt', default=False) +_nointmsg = """ +========================== +Interrupting Mercurial may leave your repo in a bad state. +If you really want to interrupt your current command, press +CTRL-C again. +========================== +""".strip() +coreconfigitem('experimental', 'nointerrupt-message', default=_nointmsg)
  
  Nit: perhaps we'll need to move the default message to ui.py to make it
  translatable.
  
  FWIW, I've added a similar function to lock.py at https://phab.mercurial-scm.org/rHGd77c3b02339308f8f3abda27947cf9387aa1cbc8. My version
  would be too strict to block user interrupt casually, but maybe we can
  factor out a utility function for both of these use cases?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3716

To: durin42, #hg-reviewers
Cc: yuja, martinvonz, mercurial-devel


More information about the Mercurial-devel mailing list