Mercurial > evolve
annotate hgext3rd/topic/server.py @ 6387:a87abe69a2f8 stable
topic: branchmap already imports subsettable from repoviewutil
Even on hg <= 4.9.
But let's add a comment so that we can import from repoviewutil module directly
when we drop compatibility with 4.9.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Sun, 05 Feb 2023 18:47:38 +0400 |
parents | 6357551cb66f |
children | 445240ccb701 |
rev | line source |
---|---|
5139
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 # topic/server.py - server specific behavior with topic |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 # |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
3 # This software may be used and distributed according to the terms of the |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 # GNU General Public License version 2 or any later version. |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 from mercurial import ( |
6387
a87abe69a2f8
topic: branchmap already imports subsettable from repoviewutil
Anton Shestakov <av6@dwimlabs.net>
parents:
5931
diff
changeset
|
6 branchmap, |
5139
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 extensions, |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 repoview, |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 wireprototypes, |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 wireprotov1peer, |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 wireprotov1server, |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 ) |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 from . import ( |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 common, |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 constants, |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 ) |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 ### Visibility restriction |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 # |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
21 # Serving draft changesets with topics to clients without topic extension can |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 # confuse them, because they won't see the topic label and will consider them |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 # normal anonymous heads. Instead we have the option to not serve changesets |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
24 # with topics to clients without topic support. |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
25 # |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
26 # To achieve this, we alter the behavior of the standard `heads` commands and |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
27 # introduce a new `heads` command that only clients with topic will know about. |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
28 |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
29 # compat version of the wireprotocommand decorator, taken from evolve compat |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
30 |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
31 FILTERNAME = b'served-no-topic' |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
32 |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
33 def computeunservedtopic(repo, visibilityexceptions=None): |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
34 assert not repo.changelog.filteredrevs |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
35 filteredrevs = repoview.filtertable[b'served'](repo, visibilityexceptions).copy() |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
36 mutable = repoview.filtertable[b'immutable'](repo, visibilityexceptions) |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
37 consider = mutable - filteredrevs |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
38 cl = repo.changelog |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
39 extrafiltered = set() |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
40 for r in consider: |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
41 if cl.changelogrevision(r).extra.get(constants.extrakey, b''): |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
42 extrafiltered.add(r) |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
43 if extrafiltered: |
5150
e0c091b199bc
topic: extend topic gating to descendant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5148
diff
changeset
|
44 extrafiltered = set(repo.revs('%ld::%ld', extrafiltered, consider)) |
5139
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
45 filteredrevs = frozenset(filteredrevs | extrafiltered) |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
46 return filteredrevs |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
47 |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
48 def wrapheads(orig, repo, proto): |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
49 """wrap head to hide topic^W draft changeset to old client""" |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
50 hidetopics = repo.ui.configbool(b'experimental', b'topic.server-gate-topic-changesets') |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
51 if common.hastopicext(repo) and hidetopics: |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
52 h = repo.filtered(FILTERNAME).heads() |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
53 return wireprototypes.bytesresponse(wireprototypes.encodelist(h) + b'\n') |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
54 return orig(repo, proto) |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
55 |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
56 def topicheads(repo, proto): |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
57 """Same as the normal wireprotocol command, but accessing with a different end point.""" |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
58 h = repo.heads() |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
59 return wireprototypes.bytesresponse(wireprototypes.encodelist(h) + b'\n') |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
60 |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
61 def wireprotocaps(orig, repo, proto): |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
62 """advertise the new topic specific `head` command for client with topic""" |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
63 caps = orig(repo, proto) |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
64 if common.hastopicext(repo) and repo.peer().capable(b'topics'): |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
65 caps.append(b'_exttopics_heads') |
5931
6357551cb66f
topic: announce ext-topics-publish capability in case of SSH and HTTP too
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
66 if repo.ui.configbool(b'phases', b'publish'): |
6357551cb66f
topic: announce ext-topics-publish capability in case of SSH and HTTP too
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
67 mode = b'all' |
6357551cb66f
topic: announce ext-topics-publish capability in case of SSH and HTTP too
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
68 elif repo.ui.configbool(b'experimental', b'topic.publish-bare-branch'): |
6357551cb66f
topic: announce ext-topics-publish capability in case of SSH and HTTP too
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
69 mode = b'auto' |
6357551cb66f
topic: announce ext-topics-publish capability in case of SSH and HTTP too
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
70 else: |
6357551cb66f
topic: announce ext-topics-publish capability in case of SSH and HTTP too
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
71 mode = b'none' |
6357551cb66f
topic: announce ext-topics-publish capability in case of SSH and HTTP too
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
72 caps.append(b'ext-topics-publish=%s' % mode) |
5139
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
73 return caps |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
74 |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
75 def setupserver(ui): |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
76 extensions.wrapfunction(wireprotov1server, 'heads', wrapheads) |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
77 wireprotov1server.commands.pop(b'heads') |
5180
515d425c0a05
compat: drop 4.5 related compatibility around wireprotocol module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5150
diff
changeset
|
78 wireprotov1server.wireprotocommand(b'heads', permission=b'pull')(wireprotov1server.heads) |
515d425c0a05
compat: drop 4.5 related compatibility around wireprotocol module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5150
diff
changeset
|
79 wireprotov1server.wireprotocommand(b'_exttopics_heads', permission=b'pull')(topicheads) |
5139
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
80 extensions.wrapfunction(wireprotov1server, '_capabilities', wireprotocaps) |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
81 |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
82 class topicpeerexecutor(wireprotov1peer.peerexecutor): |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
83 |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
84 def callcommand(self, command, args): |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
85 if command == b'heads': |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
86 if self._peer.capable(b'_exttopics_heads'): |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
87 command = b'_exttopics_heads' |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
88 if getattr(self._peer, '_exttopics_heads', None) is None: |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
89 self._peer._exttopics_heads = self._peer.heads |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
90 s = super(topicpeerexecutor, self) |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
91 return s.callcommand(command, args) |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
92 |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
93 wireprotov1peer.peerexecutor = topicpeerexecutor |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
94 |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
95 if FILTERNAME not in repoview.filtertable: |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
96 repoview.filtertable[FILTERNAME] = computeunservedtopic |
6387
a87abe69a2f8
topic: branchmap already imports subsettable from repoviewutil
Anton Shestakov <av6@dwimlabs.net>
parents:
5931
diff
changeset
|
97 # hg <= 4.9 (caebe5e7f4bd) |
a87abe69a2f8
topic: branchmap already imports subsettable from repoviewutil
Anton Shestakov <av6@dwimlabs.net>
parents:
5931
diff
changeset
|
98 branchmap.subsettable[FILTERNAME] = b'immutable' |
a87abe69a2f8
topic: branchmap already imports subsettable from repoviewutil
Anton Shestakov <av6@dwimlabs.net>
parents:
5931
diff
changeset
|
99 branchmap.subsettable[b'served'] = FILTERNAME |