changeset 6564:2d3771d61068

topic: use a config option to signal explicit target arguments (for tns)
author Anton Shestakov <av6@dwimlabs.net>
date Mon, 09 Oct 2023 15:07:38 -0300
parents bdc8978232de
children 835f0adf8e39
files hgext3rd/topic/__init__.py hgext3rd/topic/discovery.py hgext3rd/topic/server.py
diffstat 3 files changed, 22 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Mon Oct 09 15:06:26 2023 -0300
+++ b/hgext3rd/topic/__init__.py	Mon Oct 09 15:07:38 2023 -0300
@@ -272,6 +272,11 @@
 configitem(b'_internal', b'tns-publish',
            default=False,
 )
+# used for signaling that the current command has explicit target arguments
+# (e.g. --rev or --branch) and we should ignore tns-default-* config
+configitem(b'_internal', b'tns-explicit-target',
+           default=False,
+)
 configitem(b'devel', b'tns-report-transactions',
            default=lambda: [],
 )
--- a/hgext3rd/topic/discovery.py	Mon Oct 09 15:06:26 2023 -0300
+++ b/hgext3rd/topic/discovery.py	Mon Oct 09 15:07:38 2023 -0300
@@ -12,6 +12,7 @@
     encoding,
     exchange,
     extensions,
+    hg,
     scmutil,
     util,
     wireprototypes,
@@ -354,6 +355,13 @@
         # to do the conversion
         return orig(self, rev, **kwargs)
 
+def wraphgpeer(orig, uiorrepo, opts, *args, **kwargs):
+    """hg.peer() that checks if there are explicit arguments for e.g. pull"""
+    peer = orig(uiorrepo, opts, *args, **kwargs)
+    if any(opts.get(k) for k in (b'rev', b'bookmark', b'branch')):
+        peer.ui.setconfig(b'_internal', b'tns-explicit-target', True, b'topic-namespaces')
+    return peer
+
 def wraphgremoteui(orig, src, opts):
     """hg.remoteui() that copies tns-related config options to peer ui"""
     dst = orig(src, opts)
@@ -389,4 +397,5 @@
         bundle2.parthandlermapping[b'check:updated-heads'] = bundle2.handlecheckupdatedheads
     extensions.wrapfunction(exchange, '_pushb2phases', _pushb2phases)
     exchange.b2partsgenmapping[b'phase'] = exchange._pushb2phases
+    extensions.wrapfunction(hg, 'peer', wraphgpeer)
     extensions.wrapfunction(hg, 'remoteui', wraphgremoteui)
--- a/hgext3rd/topic/server.py	Mon Oct 09 15:06:26 2023 -0300
+++ b/hgext3rd/topic/server.py	Mon Oct 09 15:07:38 2023 -0300
@@ -122,7 +122,10 @@
             if command == b'heads':
                 if self._peer.capable(b'ext-topics-tns-heads'):
                     command = b'tns_heads'
-                    args[b'namespaces'] = self._peer.ui.configlist(b'experimental', b'tns-default-pull-namespaces', [b'*'])
+                    if self._peer.ui.configbool(b'_internal', b'tns-explicit-target', False):
+                        args[b'namespaces'] = [b'*']
+                    else:
+                        args[b'namespaces'] = self._peer.ui.configlist(b'experimental', b'tns-default-pull-namespaces', [b'*'])
                 elif self._peer.capable(b'_exttopics_heads'):
                     command = b'_exttopics_heads'
                     if getattr(self._peer, '_exttopics_heads', None) is None:
@@ -137,7 +140,10 @@
             if command == b'heads':
                 if self._peer.capable(b'ext-topics-tns-heads'):
                     command = b'tns_heads'
-                    args[b'namespaces'] = self._peer.ui.configlist(b'experimental', b'tns-default-pull-namespaces', [b'*'])
+                    if self._peer.ui.configbool(b'_internal', b'tns-explicit-target', False):
+                        args[b'namespaces'] = [b'*']
+                    else:
+                        args[b'namespaces'] = self._peer.ui.configlist(b'experimental', b'tns-default-pull-namespaces', [b'*'])
             s = super(topiccommandexecutor, self)
             return s.callcommand(command, args)