author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Tue, 10 Mar 2020 11:07:06 +0100 | |
changeset 5180 | 515d425c0a05 |
parent 5150 | e0c091b199bc |
child 5193 | a4d081923c81 |
permissions | -rw-r--r-- |
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 ( |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 |
extensions, |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 |
repoview, |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 |
wireprototypes, |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 |
wireprotov1peer, |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 |
wireprotov1server, |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 |
) |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 |
|
5148
366f6e4108d6
compat: fix subsettable import for mercurial <= 4.8
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5140
diff
changeset
|
13 |
try: |
366f6e4108d6
compat: fix subsettable import for mercurial <= 4.8
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5140
diff
changeset
|
14 |
from mercurial.utils import ( |
366f6e4108d6
compat: fix subsettable import for mercurial <= 4.8
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5140
diff
changeset
|
15 |
repoviewutil, |
366f6e4108d6
compat: fix subsettable import for mercurial <= 4.8
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5140
diff
changeset
|
16 |
) |
366f6e4108d6
compat: fix subsettable import for mercurial <= 4.8
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5140
diff
changeset
|
17 |
repoviewutil.subsettable |
366f6e4108d6
compat: fix subsettable import for mercurial <= 4.8
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5140
diff
changeset
|
18 |
except (AttributeError, ImportError): |
366f6e4108d6
compat: fix subsettable import for mercurial <= 4.8
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5140
diff
changeset
|
19 |
# hg <= 4.8 |
366f6e4108d6
compat: fix subsettable import for mercurial <= 4.8
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5140
diff
changeset
|
20 |
from mercurial import branchmap as repoviewutil |
5140
c705c4069fb1
fix: reinstall import from the right location
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5139
diff
changeset
|
21 |
|
5139
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 |
from . import ( |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 |
common, |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
24 |
constants, |
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 |
|
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
27 |
### Visibility restriction |
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 |
# 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
|
30 |
# 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
|
31 |
# 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
|
32 |
# 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
|
33 |
# |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
34 |
# 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
|
35 |
# 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
|
36 |
|
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
37 |
# 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
|
38 |
|
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
39 |
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
|
40 |
|
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
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
|
45 |
consider = mutable - filteredrevs |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
46 |
cl = repo.changelog |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
47 |
extrafiltered = set() |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
48 |
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
|
49 |
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
|
50 |
extrafiltered.add(r) |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
51 |
if extrafiltered: |
5150
e0c091b199bc
topic: extend topic gating to descendant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5148
diff
changeset
|
52 |
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
|
53 |
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
|
54 |
return filteredrevs |
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 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
|
57 |
"""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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
|
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
64 |
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
|
65 |
"""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
|
66 |
h = repo.heads() |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
67 |
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
|
68 |
|
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
69 |
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
|
70 |
"""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
|
71 |
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
|
72 |
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
|
73 |
caps.append(b'_exttopics_heads') |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
74 |
return caps |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
75 |
|
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
76 |
def setupserver(ui): |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
|
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
83 |
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
|
84 |
|
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
85 |
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
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
|
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
94 |
wireprotov1peer.peerexecutor = topicpeerexecutor |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
95 |
|
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
96 |
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
|
97 |
repoview.filtertable[FILTERNAME] = computeunservedtopic |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
98 |
repoviewutil.subsettable[FILTERNAME] = b'immutable' |
19b8ffd23795
topic: option to hide topic changesets to plain client
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
99 |
repoviewutil.subsettable[b'served'] = FILTERNAME |