Patchwork [STABLE,v2] extensions: clear aftercallbacks after execution (issue4646)

login
register
mail settings
Submitter Gregory Szorc
Date May 6, 2015, 4:53 p.m.
Message ID <44b054c3a46eac63d5fe.1430931223@gps-mbp.local>
Download mbox | patch
Permalink /patch/8933/
State Accepted
Headers show

Comments

Gregory Szorc - May 6, 2015, 4:53 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1430931130 25200
#      Wed May 06 09:52:10 2015 -0700
# Branch stable
# Node ID 44b054c3a46eac63d5fed06ffb8fffc38d5668f6
# Parent  41cd8171e58f991373dcd0b4897dc1e5978d42dd
extensions: clear aftercallbacks after execution (issue4646)

It was reported that enabling pager without color could cause a hang.
Inserting print statements revealed that the callbacks in
extensions._aftercallbacks were being invoked twice.

extensions.loadall can be called multiple times. If entries in
extensions._aftercallbacks linger between calls, this could result
in double execution of the callbacks. This can lead to unwanted
behavior.

The reproduce steps in the bug seem to only occur when the output of
a command is less than the size of the current screen. This is not
something that can easily be tested. I verified the test case works
with this patch and that pager and color interaction continues to
work. Since we have no existing automated tests for pager, this sadly
appears to be the best testing I can do.
Matt Mackall - May 6, 2015, 10:03 p.m.
On Wed, 2015-05-06 at 09:53 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1430931130 25200
> #      Wed May 06 09:52:10 2015 -0700
> # Branch stable
> # Node ID 44b054c3a46eac63d5fed06ffb8fffc38d5668f6
> # Parent  41cd8171e58f991373dcd0b4897dc1e5978d42dd
> extensions: clear aftercallbacks after execution (issue4646)

Queued for stable, thanks.

Patch

diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -133,8 +133,12 @@  def loadall(ui):
 
         for fn in _aftercallbacks[shortname]:
             fn(loaded=False)
 
+    # loadall() is called multiple times and lingering _aftercallbacks
+    # entries could result in double execution. See issue4646.
+    _aftercallbacks.clear()
+
 def afterloaded(extension, callback):
     '''Run the specified function after a named extension is loaded.
 
     If the named extension is already loaded, the callback will be called