# HG changeset patch # User Anton Shestakov # Date 1675609292 -14400 # Node ID 0bc90758f61340fd446c6ffa7dfe33f0718ecb94 # Parent afd252e8f6e6941b1b4cb75f511010e905f5c31f topic: wrap branchmap.read() as well (compatibility for hg <= 4.9) In hg 5.0+ this logic lives in branchcache.load method, but in older versions there's a module-level function that loads on-disk cache and returns a branchcache object. Since we need the cache to have branch names in the FQBN format, we need to wrap branchmap.load() and do the conversion there as well. diff -r afd252e8f6e6 -r 0bc90758f613 hgext3rd/topic/topicmap.py --- a/hgext3rd/topic/topicmap.py Fri Feb 03 16:25:59 2023 +0400 +++ b/hgext3rd/topic/topicmap.py Sun Feb 05 19:01:32 2023 +0400 @@ -140,7 +140,9 @@ except AttributeError: # hg <= 4.9 (3461814417f3) extensions.wrapfunction(branchmap, 'updatecache', _wrapupdatebmcache) - + # branchcache in hg <= 4.9 doesn't have load method, instead there's a + # module-level function to read on-disk cache and return a branchcache + extensions.wrapfunction(branchmap, 'read', _wrapbmread) def _wrapupdatebmcache(orig, repo): previous = getattr(repo, '_autobranchmaptopic', False) @@ -249,3 +251,21 @@ super(_topiccache, self).update(repo, revgen) self.phaseshash = _phaseshash(repo, self.tiprev) + +def _wrapbmread(orig, repo): + """call branchmap.read(), and then transform branch names to be in the + new "//" format + """ + partial = orig(repo) + if partial is None: + # because of IOError or OSError + return partial + + entries = compat.bcentries(partial) + + for branch in tuple(entries): + formatted = common.formatfqbn(branch=branch) + if branch != formatted: + entries[formatted] = entries.pop(branch) + + return partial