Mercurial > evolve
annotate hgext3rd/topic/discovery.py @ 5189:26b47a967a1d
compat: update a couple of obviously outdated version comments
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Mon, 09 Mar 2020 18:36:10 +0700 |
parents | 515d425c0a05 |
children | a4d081923c81 |
rev | line source |
---|---|
1934
9d6d30e36cdd
discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1921
diff
changeset
|
1 from __future__ import absolute_import |
9d6d30e36cdd
discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1921
diff
changeset
|
2 |
3182
bc09dd507c41
topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2696
diff
changeset
|
3 import collections |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
4 import weakref |
1934
9d6d30e36cdd
discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1921
diff
changeset
|
5 |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
6 from mercurial.i18n import _ |
1934
9d6d30e36cdd
discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1921
diff
changeset
|
7 from mercurial import ( |
1944
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
8 bundle2, |
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
9 discovery, |
1934
9d6d30e36cdd
discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1921
diff
changeset
|
10 error, |
9d6d30e36cdd
discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1921
diff
changeset
|
11 exchange, |
1944
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
12 extensions, |
2676
10dedac0d82e
topic: also insert the extra head check with using the new head checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2675
diff
changeset
|
13 util, |
1934
9d6d30e36cdd
discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1921
diff
changeset
|
14 ) |
4540
22cde12d9467
topic: only wrap _headssummary for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
15 from . import ( |
22cde12d9467
topic: only wrap _headssummary for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
16 common, |
4743
92e3db149d7d
py3: call branchmap.items() on py3 and continue to call iteritems() on py2
Martin von Zweigbergk <martinvonz@google.com>
parents:
4742
diff
changeset
|
17 compat, |
4540
22cde12d9467
topic: only wrap _headssummary for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
18 ) |
1934
9d6d30e36cdd
discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1921
diff
changeset
|
19 |
5180
515d425c0a05
compat: drop 4.5 related compatibility around wireprotocol module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
20 from mercurial import wireprotov1server |
3678
d725fe3e3989
topic: handle wireproto module change from b4d85bc122bd
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3186
diff
changeset
|
21 |
3689
415c872d3308
topic: remove compatibility for older version in discovery wrapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3678
diff
changeset
|
22 def _headssummary(orig, pushop, *args, **kwargs): |
415c872d3308
topic: remove compatibility for older version in discovery wrapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3678
diff
changeset
|
23 repo = pushop.repo.unfiltered() |
415c872d3308
topic: remove compatibility for older version in discovery wrapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3678
diff
changeset
|
24 remote = pushop.remote |
2558
65cf338258d2
fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents:
1965
diff
changeset
|
25 |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
26 publishing = (b'phases' not in remote.listkeys(b'namespaces') |
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
27 or bool(remote.listkeys(b'phases').get(b'publishing', False))) |
4540
22cde12d9467
topic: only wrap _headssummary for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
28 |
22cde12d9467
topic: only wrap _headssummary for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
29 if not common.hastopicext(pushop.repo): |
22cde12d9467
topic: only wrap _headssummary for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
30 return orig(pushop, *args, **kwargs) |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
31 elif ((publishing or not remote.capable(b'topics')) |
3186
9d9ff55d1bb1
compat: fix comp ability of the new phase logic for Mercurial < 4.4
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3182
diff
changeset
|
32 and not getattr(pushop, 'publish', False)): |
3689
415c872d3308
topic: remove compatibility for older version in discovery wrapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3678
diff
changeset
|
33 return orig(pushop, *args, **kwargs) |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
34 |
3182
bc09dd507c41
topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2696
diff
changeset
|
35 publishedset = () |
bc09dd507c41
topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2696
diff
changeset
|
36 remotebranchmap = None |
bc09dd507c41
topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2696
diff
changeset
|
37 origremotebranchmap = remote.branchmap |
4263
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
38 publishednode = [c.node() for c in pushop.outdatedphases] |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
39 publishedset = repo.revs(b'ancestors(%ln + %ln)', |
4263
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
40 publishednode, |
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
41 pushop.remotephases.publicheads) |
3182
bc09dd507c41
topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2696
diff
changeset
|
42 |
4929
bb2b4f6c99dc
compat: compatibility for cl.nodemap.get vs cl.index.get_rev
Anton Shestakov <av6@dwimlabs.net>
parents:
4814
diff
changeset
|
43 getrev = compat.getgetrev(repo.unfiltered().changelog) |
3182
bc09dd507c41
topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2696
diff
changeset
|
44 |
4263
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
45 def remotebranchmap(): |
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
46 # drop topic information from changeset about to be published |
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
47 result = collections.defaultdict(list) |
4743
92e3db149d7d
py3: call branchmap.items() on py3 and continue to call iteritems() on py2
Martin von Zweigbergk <martinvonz@google.com>
parents:
4742
diff
changeset
|
48 for branch, heads in compat.branchmapitems(origremotebranchmap()): |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
49 if b':' not in branch: |
4263
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
50 result[branch].extend(heads) |
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
51 else: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
52 namedbranch = branch.split(b':', 1)[0] |
4263
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
53 for h in heads: |
4929
bb2b4f6c99dc
compat: compatibility for cl.nodemap.get vs cl.index.get_rev
Anton Shestakov <av6@dwimlabs.net>
parents:
4814
diff
changeset
|
54 r = getrev(h) |
4263
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
55 if r is not None and r in publishedset: |
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
56 result[namedbranch].append(h) |
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
57 else: |
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
58 result[branch].append(h) |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
59 for heads in result.values(): |
4263
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
60 heads.sort() |
35130e428ebd
compat: drop code dealing with incompatibility for --publish with 4.3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4194
diff
changeset
|
61 return result |
3182
bc09dd507c41
topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2696
diff
changeset
|
62 |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
63 class repocls(repo.__class__): |
2696
a32afe67e8a6
topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2695
diff
changeset
|
64 # awful hack to see branch as "branch:topic" |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
65 def __getitem__(self, key): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
66 ctx = super(repocls, self).__getitem__(key) |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
67 oldbranch = ctx.branch |
3182
bc09dd507c41
topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2696
diff
changeset
|
68 rev = ctx.rev() |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
69 |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
70 def branch(): |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
71 branch = oldbranch() |
3182
bc09dd507c41
topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2696
diff
changeset
|
72 if rev in publishedset: |
bc09dd507c41
topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2696
diff
changeset
|
73 return branch |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
74 topic = ctx.topic() |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
75 if topic: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
76 branch = b"%s:%s" % (branch, topic) |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
77 return branch |
1965 | 78 |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
79 ctx.branch = branch |
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
80 return ctx |
1965 | 81 |
2696
a32afe67e8a6
topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2695
diff
changeset
|
82 def revbranchcache(self): |
a32afe67e8a6
topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2695
diff
changeset
|
83 rbc = super(repocls, self).revbranchcache() |
4192
e527df0f2a68
topic: add the changelog argument to branchinfo()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
4123
diff
changeset
|
84 localchangelog = self.changelog |
2696
a32afe67e8a6
topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2695
diff
changeset
|
85 |
4192
e527df0f2a68
topic: add the changelog argument to branchinfo()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
4123
diff
changeset
|
86 def branchinfo(rev, changelog=None): |
e527df0f2a68
topic: add the changelog argument to branchinfo()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
4123
diff
changeset
|
87 if changelog is None: |
e527df0f2a68
topic: add the changelog argument to branchinfo()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
4123
diff
changeset
|
88 changelog = localchangelog |
2696
a32afe67e8a6
topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2695
diff
changeset
|
89 branch, close = changelog.branchinfo(rev) |
3182
bc09dd507c41
topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2696
diff
changeset
|
90 if rev in publishedset: |
bc09dd507c41
topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2696
diff
changeset
|
91 return branch, close |
2696
a32afe67e8a6
topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2695
diff
changeset
|
92 topic = repo[rev].topic() |
a32afe67e8a6
topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2695
diff
changeset
|
93 if topic: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
94 branch = b"%s:%s" % (branch, topic) |
2696
a32afe67e8a6
topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2695
diff
changeset
|
95 return branch, close |
a32afe67e8a6
topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2695
diff
changeset
|
96 |
a32afe67e8a6
topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2695
diff
changeset
|
97 rbc.branchinfo = branchinfo |
a32afe67e8a6
topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2695
diff
changeset
|
98 return rbc |
a32afe67e8a6
topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2695
diff
changeset
|
99 |
2695
b4824e169f18
topic: cleanup the repository wrapping logic in topic discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2676
diff
changeset
|
100 oldrepocls = repo.__class__ |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
101 try: |
1886
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
102 repo.__class__ = repocls |
3186
9d9ff55d1bb1
compat: fix comp ability of the new phase logic for Mercurial < 4.4
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3182
diff
changeset
|
103 if remotebranchmap is not None: |
9d9ff55d1bb1
compat: fix comp ability of the new phase logic for Mercurial < 4.4
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3182
diff
changeset
|
104 remote.branchmap = remotebranchmap |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
105 unxx = repo.filtered(b'unfiltered-topic') |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
106 repo.unfiltered = lambda: unxx |
3689
415c872d3308
topic: remove compatibility for older version in discovery wrapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3678
diff
changeset
|
107 pushop.repo = repo |
415c872d3308
topic: remove compatibility for older version in discovery wrapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3678
diff
changeset
|
108 summary = orig(pushop) |
4742
db3e7f6b5ceb
py3: switch from iteritems() to items() in the topics extension
Martin von Zweigbergk <martinvonz@google.com>
parents:
4544
diff
changeset
|
109 for key, value in summary.items(): |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
110 if b':' in key: # This is a topic |
1886
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
111 if value[0] is None and value[1]: |
2674
9585fac76d2d
topic: adjust head checking wrapping to not interfere with concurrent push
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2673
diff
changeset
|
112 summary[key] = ([value[1][0]], ) + value[1:] |
1886
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
113 return summary |
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
114 finally: |
4804
079dbf36e884
python3: add raw prefix in cases harder to analyze at the token level
Raphaël Gomès <rgomes@octobus.net>
parents:
4743
diff
changeset
|
115 if r'unfiltered' in vars(repo): |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
116 del repo.unfiltered |
2695
b4824e169f18
topic: cleanup the repository wrapping logic in topic discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2676
diff
changeset
|
117 repo.__class__ = oldrepocls |
3186
9d9ff55d1bb1
compat: fix comp ability of the new phase logic for Mercurial < 4.4
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3182
diff
changeset
|
118 if remotebranchmap is not None: |
9d9ff55d1bb1
compat: fix comp ability of the new phase logic for Mercurial < 4.4
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3182
diff
changeset
|
119 remote.branchmap = origremotebranchmap |
1886
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
120 |
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
121 def wireprotobranchmap(orig, repo, proto): |
4541
7e98faf278d6
topic: only wrap wireprotobranchmap for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4540
diff
changeset
|
122 if not common.hastopicext(repo): |
7e98faf278d6
topic: only wrap wireprotobranchmap for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4540
diff
changeset
|
123 return orig(repo, proto) |
1886
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
124 oldrepo = repo.__class__ |
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
125 try: |
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
126 class repocls(repo.__class__): |
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
127 def branchmap(self): |
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
128 usetopic = not self.publishing() |
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
129 return super(repocls, self).branchmap(topic=usetopic) |
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
130 repo.__class__ = repocls |
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
131 return orig(repo, proto) |
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
132 finally: |
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
133 repo.__class__ = oldrepo |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
134 |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
135 |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
136 # Discovery have deficiency around phases, branch can get new heads with pure |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
137 # phases change. This happened with a changeset was allowed to be pushed |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
138 # because it had a topic, but it later become public and create a new branch |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
139 # head. |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
140 # |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
141 # Handle this by doing an extra check for new head creation server side |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
142 def _nbheads(repo): |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
143 data = {} |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
144 for b in repo.branchmap().iterbranches(): |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
145 if b':' in b[0]: |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
146 continue |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
147 data[b[0]] = len(b[1]) |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
148 return data |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
149 |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
150 def handlecheckheads(orig, op, inpart): |
2675
304232cc14b6
topic: some document for an obscure function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2674
diff
changeset
|
151 """This is used to check for new heads when publishing changeset""" |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
152 orig(op, inpart) |
4542
f5127bfc1588
topic: only wrap handlecheckheads for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4541
diff
changeset
|
153 if not common.hastopicext(op.repo) or op.repo.publishing(): |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
154 return |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
155 tr = op.gettransaction() |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
156 if tr.hookargs[b'source'] not in (b'push', b'serve'): # not a push |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
157 return |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
158 tr._prepushheads = _nbheads(op.repo) |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
159 reporef = weakref.ref(op.repo) |
4123
119fced5a891
topic: add a compatibility to access transaction's validator
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3917
diff
changeset
|
160 if util.safehasattr(tr, 'validator'): # hg <= 4.7 |
119fced5a891
topic: add a compatibility to access transaction's validator
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3917
diff
changeset
|
161 oldvalidator = tr.validator |
119fced5a891
topic: add a compatibility to access transaction's validator
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3917
diff
changeset
|
162 else: |
119fced5a891
topic: add a compatibility to access transaction's validator
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3917
diff
changeset
|
163 oldvalidator = tr._validator |
1921 | 164 |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
165 def validator(tr): |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
166 repo = reporef() |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
167 if repo is not None: |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
168 repo.invalidatecaches() |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
169 finalheads = _nbheads(repo) |
4742
db3e7f6b5ceb
py3: switch from iteritems() to items() in the topics extension
Martin von Zweigbergk <martinvonz@google.com>
parents:
4544
diff
changeset
|
170 for branch, oldnb in tr._prepushheads.items(): |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
171 newnb = finalheads.pop(branch, 0) |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
172 if oldnb < newnb: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
173 msg = _(b'push create a new head on branch "%s"' % branch) |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
174 raise error.Abort(msg) |
4742
db3e7f6b5ceb
py3: switch from iteritems() to items() in the topics extension
Martin von Zweigbergk <martinvonz@google.com>
parents:
4544
diff
changeset
|
175 for branch, newnb in finalheads.items(): |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
176 if 1 < newnb: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
177 msg = _(b'push create more than 1 head on new branch "%s"' |
1921 | 178 % branch) |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
179 raise error.Abort(msg) |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
180 return oldvalidator(tr) |
4123
119fced5a891
topic: add a compatibility to access transaction's validator
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3917
diff
changeset
|
181 if util.safehasattr(tr, 'validator'): # hg <= 4.7 |
119fced5a891
topic: add a compatibility to access transaction's validator
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3917
diff
changeset
|
182 tr.validator = validator |
119fced5a891
topic: add a compatibility to access transaction's validator
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3917
diff
changeset
|
183 else: |
119fced5a891
topic: add a compatibility to access transaction's validator
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3917
diff
changeset
|
184 tr._validator = validator |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
185 handlecheckheads.params = frozenset() |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
186 |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
187 def _pushb2phases(orig, pushop, bundler): |
4543
7f1e1ba3d16b
topic: only wrap _pushb2phases for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4542
diff
changeset
|
188 if common.hastopicext(pushop.repo): |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
189 checktypes = (b'check:heads', b'check:updated-heads') |
4543
7f1e1ba3d16b
topic: only wrap _pushb2phases for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4542
diff
changeset
|
190 hascheck = any(p.type in checktypes for p in bundler._parts) |
7f1e1ba3d16b
topic: only wrap _pushb2phases for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4542
diff
changeset
|
191 if not hascheck and pushop.outdatedphases: |
7f1e1ba3d16b
topic: only wrap _pushb2phases for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4542
diff
changeset
|
192 exchange._pushb2ctxcheckheads(pushop, bundler) |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
193 return orig(pushop, bundler) |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
194 |
1903
58cdf061d49a
topic: don't take topic into account when pushing to non-topic repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
195 def wireprotocaps(orig, repo, proto): |
58cdf061d49a
topic: don't take topic into account when pushing to non-topic repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
196 caps = orig(repo, proto) |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
197 if common.hastopicext(repo) and repo.peer().capable(b'topics'): |
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
198 caps.append(b'topics') |
1903
58cdf061d49a
topic: don't take topic into account when pushing to non-topic repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
199 return caps |
1944
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
200 |
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
201 def modsetup(ui): |
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
202 """run at uisetup time to install all destinations wrapping""" |
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
203 extensions.wrapfunction(discovery, '_headssummary', _headssummary) |
5180
515d425c0a05
compat: drop 4.5 related compatibility around wireprotocol module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
204 extensions.wrapfunction(wireprotov1server, 'branchmap', wireprotobranchmap) |
515d425c0a05
compat: drop 4.5 related compatibility around wireprotocol module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
205 extensions.wrapfunction(wireprotov1server, '_capabilities', wireprotocaps) |
2676
10dedac0d82e
topic: also insert the extra head check with using the new head checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2675
diff
changeset
|
206 # we need a proper wrap b2 part stuff |
1944
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
207 extensions.wrapfunction(bundle2, 'handlecheckheads', handlecheckheads) |
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
208 bundle2.handlecheckheads.params = frozenset() |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
209 bundle2.parthandlermapping[b'check:heads'] = bundle2.handlecheckheads |
2676
10dedac0d82e
topic: also insert the extra head check with using the new head checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2675
diff
changeset
|
210 if util.safehasattr(bundle2, 'handlecheckupdatedheads'): |
10dedac0d82e
topic: also insert the extra head check with using the new head checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2675
diff
changeset
|
211 # we still need a proper wrap b2 part stuff |
10dedac0d82e
topic: also insert the extra head check with using the new head checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2675
diff
changeset
|
212 extensions.wrapfunction(bundle2, 'handlecheckupdatedheads', handlecheckheads) |
10dedac0d82e
topic: also insert the extra head check with using the new head checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2675
diff
changeset
|
213 bundle2.handlecheckupdatedheads.params = frozenset() |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
214 bundle2.parthandlermapping[b'check:updated-heads'] = bundle2.handlecheckupdatedheads |
1944
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
215 extensions.wrapfunction(exchange, '_pushb2phases', _pushb2phases) |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
216 exchange.b2partsgenmapping[b'phase'] = exchange._pushb2phases |