# HG changeset patch # User Anton Shestakov # Date 1719493169 -14400 # Node ID 68f7ba35ea83e3196aa87458b34b38dd803e5b9c # Parent 30471072eb818a21a7b692a2ad3ec100ff527fa8 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. diff -r 30471072eb81 -r 68f7ba35ea83 hgext3rd/topic/topicmap.py --- 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):