changeset 6794:68f7ba35ea83 stable

topic: bring back oldbranchmap context manager for hg 4.9 This is only needed in Mercurial 4.9 because branchcache class there tries to use super() in its __init__() and it results in an infinite recursion because we also implement __init__() with super() in _topiccache and then replace the original branchmap.branchcache class with our own. At least there are now compatibility comments to help remove this hack ASAP.
author Anton Shestakov <av6@dwimlabs.net>
date Thu, 27 Jun 2024 16:59:29 +0400
parents 30471072eb81
children 1b59ddda3242
files hgext3rd/topic/topicmap.py
diffstat 1 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/topicmap.py	Wed Jun 26 13:38:46 2024 +0400
+++ b/hgext3rd/topic/topicmap.py	Thu Jun 27 16:59:29 2024 +0400
@@ -1,3 +1,4 @@
+import contextlib
 import hashlib
 
 from mercurial.i18n import _
@@ -163,10 +164,27 @@
     finally:
         repo._autobranchmaptopic = previous
 
+if util.safehasattr(branchmap, 'branchcache') and dict in branchmap.branchcache.__mro__:
+    # hg <= 4.9 (624d6683c705)
+    # let's break infinite recursion in __init__() that uses super()
+    orig = branchmap.branchcache
+
+    @contextlib.contextmanager
+    def oldbranchmap():
+        current = branchmap.branchcache
+        try:
+            branchmap.branchcache = orig
+            yield
+        finally:
+            branchmap.branchcache = current
+else:
+    oldbranchmap = util.nullcontextmanager
+
 class _topiccache(object): # combine me with branchmap.branchcache
 
     def __init__(self, *args, **kwargs):
-        super(_topiccache, self).__init__(*args, **kwargs)
+        with oldbranchmap():
+            super(_topiccache, self).__init__(*args, **kwargs)
         self.phaseshash = None
 
     def copy(self):