Mercurial > evolve
diff hgext3rd/topic/server.py @ 6652:92fd4581f569
topic: return our special executor classes for each instance
It looks like globally patching classes once when the extension is being
initialized is not a great idea (23cad1a872b6), because people might use other
extensions that get initialized earlier than topic or only for certain repos.
Replacing global executor classes is less safe than wrapping certain functions
that should return newly instantiated objects of said classes, so let's do that
instead.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Tue, 09 Jan 2024 15:39:28 -0300 |
parents | e9650b5616ac |
children | 71c4b6c2bcdc |
line wrap: on
line diff
--- a/hgext3rd/topic/server.py Wed Jan 17 14:27:57 2024 -0300 +++ b/hgext3rd/topic/server.py Tue Jan 09 15:39:28 2024 -0300 @@ -99,6 +99,34 @@ caps.append(b'ext-topics-tns-heads') return caps +class topiccommandexecutor(localrepo.localcommandexecutor): + def callcommand(self, command, args): + if command == b'heads': + if self._peer.capable(b'ext-topics-tns-heads'): + command = b'tns_heads' + 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) + +class topicpeerexecutor(wireprotov1peer.peerexecutor): + def callcommand(self, command, args): + if command == b'heads': + if self._peer.capable(b'ext-topics-tns-heads'): + command = b'tns_heads' + 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: + self._peer._exttopics_heads = self._peer.heads + s = super(topicpeerexecutor, self) + return s.callcommand(command, args) + def setupserver(ui): extensions.wrapfunction(wireprotov1server, 'heads', wrapheads) wireprotov1server.commands.pop(b'heads') @@ -131,38 +159,10 @@ wireprotov1peer.wirepeer.tns_heads = wp_tns_heads - class topicpeerexecutor(wireprotov1peer.peerexecutor): + def wp_commandexecutor(self): + return topicpeerexecutor(self) - def callcommand(self, command, args): - if command == b'heads': - if self._peer.capable(b'ext-topics-tns-heads'): - command = b'tns_heads' - 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: - self._peer._exttopics_heads = self._peer.heads - s = super(topicpeerexecutor, self) - return s.callcommand(command, args) - - wireprotov1peer.peerexecutor = topicpeerexecutor - - class topiccommandexecutor(localrepo.localcommandexecutor): - def callcommand(self, command, args): - if command == b'heads': - if self._peer.capable(b'ext-topics-tns-heads'): - command = b'tns_heads' - 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) - - localrepo.localcommandexecutor = topiccommandexecutor + wireprotov1peer.wirepeer.commandexecutor = wp_commandexecutor if FILTERNAME not in repoview.filtertable: repoview.filtertable[FILTERNAME] = computeunservedtopic