diff hgext3rd/topic/__init__.py @ 6271:caf302fb8f4d

topic: use branch//namespace/topic format everywhere except exchange We're converting branchmap from using the new "//" format into using the old ":" format as the first step for exchange process. It will make exchange compatible with older clients that had branchmap in the ":" format without topic namespaces. This obviously means that right now topic namespaces don't affect exchange at all.
author Anton Shestakov <av6@dwimlabs.net>
date Fri, 08 Jul 2022 17:54:40 +0400
parents 63d6cc96557c
children 47268350b3bc
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Fri Jul 08 09:50:12 2022 +0200
+++ b/hgext3rd/topic/__init__.py	Fri Jul 08 17:54:40 2022 +0400
@@ -570,19 +570,32 @@
         # overwritten at the instance level by topicmap.py
         _autobranchmaptopic = True
 
-        def branchmap(self, topic=None):
+        def branchmap(self, topic=None, convertbm=False):
             if topic is None:
                 topic = getattr(self, '_autobranchmaptopic', False)
             topicfilter = topicmap.topicfilter(self.filtername)
             if not topic or topicfilter == self.filtername:
                 return super(topicrepo, self).branchmap()
-            return self.filtered(topicfilter).branchmap()
+            bm = self.filtered(topicfilter).branchmap()
+            if convertbm:
+                if util.safehasattr(bm, '_entries'):
+                    entries = bm._entries
+                else:
+                    # hg <= 4.9 (624d6683c705+b137a6793c51)
+                    entries = bm
+                for key in list(entries):
+                    branch, tns, topic = common.parsefqbn(key)
+                    if topic:
+                        value = entries.pop(key)
+                        # we lose namespace when converting to ":" format
+                        key = b'%s:%s' % (branch, topic)
+                        entries[key] = value
+            return bm
 
         def branchheads(self, branch=None, start=None, closed=False):
             if branch is None:
                 branch = self[None].branch()
-                if self.currenttopic:
-                    branch = b"%s:%s" % (branch, self.currenttopic)
+                branch = common.formatfqbn(branch, self.currenttns, self.currenttopic)
             return super(topicrepo, self).branchheads(branch=branch,
                                                       start=start,
                                                       closed=closed)
@@ -599,7 +612,7 @@
                 class topicpeer(peer.__class__):
                     def branchmap(self):
                         usetopic = not self._repo.publishing()
-                        return self._repo.branchmap(topic=usetopic)
+                        return self._repo.branchmap(topic=usetopic, convertbm=usetopic)
                 peer.__class__ = topicpeer
             return peer