Patchwork D1166: ui: move request exit handlers to global state

login
register
mail settings
Submitter phabricator
Date Oct. 17, 2017, 8:23 p.m.
Message ID <differential-rev-PHID-DREV-wgjwvhcrruzuzg7b2fht-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/25140/
State Superseded
Headers show

Comments

phabricator - Oct. 17, 2017, 8:23 p.m.
singhsrb created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Since the ui objects can be created with the 'load' class method, it
  is possible to lose the exit handlers information from the old ui instance. For
  example, running 'test-bad-extension.t' leads to this situation where chg
  creates a new ui instance which does not copy the exit handlers from the
  earlier ui instance. For exit handlers, which are special cases anyways, it
  probably makes sense to have a global state of the handlers. This would ensure
  that the exit handlers registered once are definitely executed at the end of
  the request.

TEST PLAN
  Ran all the tests without '--chg' option. This also fixes the
  'test-bad-extension.t' with the '--chg' option.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/ui.py

CHANGE DETAILS




To: singhsrb, #hg-reviewers
Cc: mercurial-devel
phabricator - Oct. 17, 2017, 9:18 p.m.
quark accepted this revision.
quark added a comment.


  This was discussed internally. Exit handlers should be per process (ex. "global"), non-copyable to avoid run them multiple times. So this change is a pure improvement.

REPOSITORY
  rHG Mercurial

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

To: singhsrb, #hg-reviewers, quark
Cc: quark, mercurial-devel

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -183,6 +183,9 @@ 
 # retrieving configuration value.
 _unset = object()
 
+# _reqexithandlers: callbacks run at the end of a request
+_reqexithandlers = []
+
 class ui(object):
     def __init__(self, src=None):
         """Create a fresh new ui object if no src given
@@ -193,8 +196,6 @@ 
         """
         # _buffers: used for temporary capture of output
         self._buffers = []
-        # _exithandlers: callbacks run at the end of a request
-        self._exithandlers = []
         # 3-tuple describing how each buffer in the stack behaves.
         # Values are (capture stderr, capture subprocesses, apply labels).
         self._bufferstates = []
@@ -220,7 +221,6 @@ 
         self._styles = {}
 
         if src:
-            self._exithandlers = src._exithandlers
             self.fout = src.fout
             self.ferr = src.ferr
             self.fin = src.fin
@@ -1090,6 +1090,10 @@ 
 
         return True
 
+    @property
+    def _exithandlers(self):
+        return _reqexithandlers
+
     def atexit(self, func, *args, **kwargs):
         '''register a function to run after dispatching a request