Mercurial > evolve
annotate hgext3rd/topic/discovery.py @ 6364:e8d85d51c7b2 stable
topic: monkey-patch ctx.branch() correctly in override_context_branch
There's a `for p in ctx.parents()` loop in this block of code, and it's used to
monkey-patch .branch() method for both parents of ctx. It assigns each parent
of ctx to variable `p` (implicitly) and p.branch method to variable `pbranch`
(explicitly).
This worked fine when there's only one p1, but when there were 2 parents, this
code was broken, and our tests didn't catch this because the use of
override_context_branch context manager is quite limited.
The problem is that the newly created function uses `p` and `pbranch`, and the
closures for the new p1.branch() and p2.branch() didn't get created until the
for-loop finished, and the values `p` and `pbranch` could change before that.
In other words, the new .branch method of p1 was effectively identical to p2's
because the values that were available to it were from the second cycle of the
for-loop, when it the loop was at p2.
Now we pass the values to a function that creates the new .branch methods, and
since these values are provided to overridebranch() as arguments, they get
enclosed when the function returns.
This was seen (and tested) during topic namespaces-related work, when
override_context_branch usage was expanded to include some local operations.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Thu, 15 Dec 2022 17:07:25 +0400 |
parents | 885a972d5069 |
children | 3271ec128328 |
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 |
5683
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
4 import contextlib |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
5 import weakref |
1934
9d6d30e36cdd
discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1921
diff
changeset
|
6 |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
7 from mercurial.i18n import _ |
1934
9d6d30e36cdd
discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1921
diff
changeset
|
8 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
|
9 bundle2, |
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
10 discovery, |
1934
9d6d30e36cdd
discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1921
diff
changeset
|
11 error, |
9d6d30e36cdd
discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1921
diff
changeset
|
12 exchange, |
1944
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
13 extensions, |
5581
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
14 scmutil, |
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
|
15 util, |
1934
9d6d30e36cdd
discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1921
diff
changeset
|
16 ) |
4540
22cde12d9467
topic: only wrap _headssummary for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
17 from . import ( |
22cde12d9467
topic: only wrap _headssummary for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
18 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
|
19 compat, |
4540
22cde12d9467
topic: only wrap _headssummary for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
20 ) |
1934
9d6d30e36cdd
discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1921
diff
changeset
|
21 |
5180
515d425c0a05
compat: drop 4.5 related compatibility around wireprotocol module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
22 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
|
23 |
5683
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
24 @contextlib.contextmanager |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
25 def override_context_branch(repo, publishedset=()): |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
26 unfi = repo.unfiltered() |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
27 |
6364
e8d85d51c7b2
topic: monkey-patch ctx.branch() correctly in override_context_branch
Anton Shestakov <av6@dwimlabs.net>
parents:
6125
diff
changeset
|
28 def overridebranch(p, origbranch): |
e8d85d51c7b2
topic: monkey-patch ctx.branch() correctly in override_context_branch
Anton Shestakov <av6@dwimlabs.net>
parents:
6125
diff
changeset
|
29 def branch(): |
e8d85d51c7b2
topic: monkey-patch ctx.branch() correctly in override_context_branch
Anton Shestakov <av6@dwimlabs.net>
parents:
6125
diff
changeset
|
30 b = origbranch() |
e8d85d51c7b2
topic: monkey-patch ctx.branch() correctly in override_context_branch
Anton Shestakov <av6@dwimlabs.net>
parents:
6125
diff
changeset
|
31 if p.rev() in publishedset: |
e8d85d51c7b2
topic: monkey-patch ctx.branch() correctly in override_context_branch
Anton Shestakov <av6@dwimlabs.net>
parents:
6125
diff
changeset
|
32 return b |
e8d85d51c7b2
topic: monkey-patch ctx.branch() correctly in override_context_branch
Anton Shestakov <av6@dwimlabs.net>
parents:
6125
diff
changeset
|
33 t = p.topic() |
e8d85d51c7b2
topic: monkey-patch ctx.branch() correctly in override_context_branch
Anton Shestakov <av6@dwimlabs.net>
parents:
6125
diff
changeset
|
34 if t: |
e8d85d51c7b2
topic: monkey-patch ctx.branch() correctly in override_context_branch
Anton Shestakov <av6@dwimlabs.net>
parents:
6125
diff
changeset
|
35 b = b"%s:%s" % (b, t) |
e8d85d51c7b2
topic: monkey-patch ctx.branch() correctly in override_context_branch
Anton Shestakov <av6@dwimlabs.net>
parents:
6125
diff
changeset
|
36 return b |
e8d85d51c7b2
topic: monkey-patch ctx.branch() correctly in override_context_branch
Anton Shestakov <av6@dwimlabs.net>
parents:
6125
diff
changeset
|
37 return branch |
e8d85d51c7b2
topic: monkey-patch ctx.branch() correctly in override_context_branch
Anton Shestakov <av6@dwimlabs.net>
parents:
6125
diff
changeset
|
38 |
5683
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
39 class repocls(unfi.__class__): |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
40 # awful hack to see branch as "branch:topic" |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
41 def __getitem__(self, key): |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
42 ctx = super(repocls, self).__getitem__(key) |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
43 oldbranch = ctx.branch |
5684
4de216446c53
topic: also wrap the `ctx.branch` of parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5683
diff
changeset
|
44 oldparents = ctx.parents |
5683
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
45 rev = ctx.rev() |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
46 |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
47 def branch(): |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
48 branch = oldbranch() |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
49 if rev in publishedset: |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
50 return branch |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
51 topic = ctx.topic() |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
52 if topic: |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
53 branch = b"%s:%s" % (branch, topic) |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
54 return branch |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
55 |
5684
4de216446c53
topic: also wrap the `ctx.branch` of parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5683
diff
changeset
|
56 def parents(): |
4de216446c53
topic: also wrap the `ctx.branch` of parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5683
diff
changeset
|
57 parents = oldparents() |
4de216446c53
topic: also wrap the `ctx.branch` of parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5683
diff
changeset
|
58 for p in parents: |
4de216446c53
topic: also wrap the `ctx.branch` of parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5683
diff
changeset
|
59 if getattr(p, '_topic_ext_branch_hack', False): |
4de216446c53
topic: also wrap the `ctx.branch` of parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5683
diff
changeset
|
60 continue |
4de216446c53
topic: also wrap the `ctx.branch` of parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5683
diff
changeset
|
61 |
6364
e8d85d51c7b2
topic: monkey-patch ctx.branch() correctly in override_context_branch
Anton Shestakov <av6@dwimlabs.net>
parents:
6125
diff
changeset
|
62 p.branch = overridebranch(p, p.branch) |
5684
4de216446c53
topic: also wrap the `ctx.branch` of parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5683
diff
changeset
|
63 p._topic_ext_branch_hack = True |
4de216446c53
topic: also wrap the `ctx.branch` of parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5683
diff
changeset
|
64 return parents |
4de216446c53
topic: also wrap the `ctx.branch` of parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5683
diff
changeset
|
65 |
5683
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
66 ctx.branch = branch |
5684
4de216446c53
topic: also wrap the `ctx.branch` of parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5683
diff
changeset
|
67 ctx.parents = parents |
5683
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
68 return ctx |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
69 |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
70 def revbranchcache(self): |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
71 rbc = super(repocls, self).revbranchcache() |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
72 localchangelog = self.changelog |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
73 |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
74 def branchinfo(rev, changelog=None): |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
75 if changelog is None: |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
76 changelog = localchangelog |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
77 branch, close = changelog.branchinfo(rev) |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
78 if rev in publishedset: |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
79 return branch, close |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
80 topic = unfi[rev].topic() |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
81 if topic: |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
82 branch = b"%s:%s" % (branch, topic) |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
83 return branch, close |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
84 |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
85 rbc.branchinfo = branchinfo |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
86 return rbc |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
87 |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
88 oldrepocls = unfi.__class__ |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
89 try: |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
90 unfi.__class__ = repocls |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
91 if repo.filtername is not None: |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
92 repo = unfi.filtered(repo.filtername) |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
93 else: |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
94 repo = unfi |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
95 yield repo |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
96 finally: |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
97 unfi.__class__ = oldrepocls |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
98 |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
99 |
3689
415c872d3308
topic: remove compatibility for older version in discovery wrapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3678
diff
changeset
|
100 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
|
101 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
|
102 remote = pushop.remote |
2558
65cf338258d2
fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents:
1965
diff
changeset
|
103 |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4804
diff
changeset
|
104 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
|
105 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
|
106 |
22cde12d9467
topic: only wrap _headssummary for repo with topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 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
|
111 return orig(pushop, *args, **kwargs) |
2653
13313d0cab71
topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2567
diff
changeset
|
112 |
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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 |
4929
bb2b4f6c99dc
compat: compatibility for cl.nodemap.get vs cl.index.get_rev
Anton Shestakov <av6@dwimlabs.net>
parents:
4814
diff
changeset
|
121 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
|
122 |
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
|
123 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
|
124 # 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 |
5683
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
141 with override_context_branch(repo, publishedset=publishedset): |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
142 try: |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
143 if remotebranchmap is not None: |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
144 remote.branchmap = remotebranchmap |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
145 unxx = repo.filtered(b'unfiltered-topic') |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
146 repo.unfiltered = lambda: unxx |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
147 pushop.repo = repo |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
148 summary = orig(pushop) |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
149 for key, value in summary.items(): |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
150 if b':' in key: # This is a topic |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
151 if value[0] is None and value[1]: |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
152 summary[key] = ([value[1][0]], ) + value[1:] |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
153 return summary |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
154 finally: |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
155 if r'unfiltered' in vars(repo): |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
156 del repo.unfiltered |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
157 if remotebranchmap is not None: |
1dece375d2ab
topic: extract awful `ctx.branch` hijacking used in discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5581
diff
changeset
|
158 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
|
159 |
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
160 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
|
161 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
|
162 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
|
163 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
|
164 try: |
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 finally: |
0504e76bfbd9
push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
172 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
|
173 |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
174 |
5222
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
175 def _get_branch_name(ctx): |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
176 # make it easy for extension with the branch logic there |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
177 return ctx.branch() |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
178 |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
179 |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
180 def _filter_obsolete_heads(repo, heads): |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
181 """filter heads to return non-obsolete ones |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
182 |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
183 Given a list of heads (on the same named branch) return a new list of heads |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
184 where the obsolete part have been skimmed out. |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
185 """ |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
186 new_heads = [] |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
187 old_heads = heads[:] |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
188 while old_heads: |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
189 rh = old_heads.pop() |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
190 ctx = repo[rh] |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
191 current_name = _get_branch_name(ctx) |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
192 # run this check early to skip the evaluation of the whole branch |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
193 if not ctx.obsolete(): |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
194 new_heads.append(rh) |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
195 continue |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
196 |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
197 # Get all revs/nodes on the branch exclusive to this head |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
198 # (already filtered heads are "ignored")) |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
199 sections_revs = repo.revs( |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
200 b'only(%d, (%ld+%ld))', rh, old_heads, new_heads, |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
201 ) |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
202 keep_revs = [] |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
203 for r in sections_revs: |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
204 ctx = repo[r] |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
205 if ctx.obsolete(): |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
206 continue |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
207 if _get_branch_name(ctx) != current_name: |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
208 continue |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
209 keep_revs.append(r) |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
210 for h in repo.revs(b'heads(%ld and (::%ld))', sections_revs, keep_revs): |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
211 new_heads.append(h) |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
212 new_heads.sort() |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
213 return new_heads |
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
214 |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
215 # 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
|
216 # 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
|
217 # 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
|
218 # head. |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
219 # |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
220 # 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
|
221 def _nbheads(repo): |
6125
885a972d5069
topic: no need to filter obsolete heads in Mercurial 6.1
Anton Shestakov <av6@dwimlabs.net>
parents:
5684
diff
changeset
|
222 code = scmutil.filteredhash.__code__ |
885a972d5069
topic: no need to filter obsolete heads in Mercurial 6.1
Anton Shestakov <av6@dwimlabs.net>
parents:
5684
diff
changeset
|
223 if r'needobsolete' not in code.co_varnames[:code.co_argcount]: |
885a972d5069
topic: no need to filter obsolete heads in Mercurial 6.1
Anton Shestakov <av6@dwimlabs.net>
parents:
5684
diff
changeset
|
224 # hg <= 6.0 (053a5bf508da) |
885a972d5069
topic: no need to filter obsolete heads in Mercurial 6.1
Anton Shestakov <av6@dwimlabs.net>
parents:
5684
diff
changeset
|
225 filterfn = _filter_obsolete_heads |
885a972d5069
topic: no need to filter obsolete heads in Mercurial 6.1
Anton Shestakov <av6@dwimlabs.net>
parents:
5684
diff
changeset
|
226 else: |
885a972d5069
topic: no need to filter obsolete heads in Mercurial 6.1
Anton Shestakov <av6@dwimlabs.net>
parents:
5684
diff
changeset
|
227 filterfn = lambda repo, heads: heads |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
228 data = {} |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
229 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
|
230 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
|
231 continue |
5222
ba53591d4aab
head-checking: filter out obsolete heads when checking for new heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
5041
diff
changeset
|
232 oldheads = [repo[n].rev() for n in b[1]] |
6125
885a972d5069
topic: no need to filter obsolete heads in Mercurial 6.1
Anton Shestakov <av6@dwimlabs.net>
parents:
5684
diff
changeset
|
233 newheads = filterfn(repo, oldheads) |
5581
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
234 data[b[0]] = newheads |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
235 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
|
236 |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
237 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
|
238 """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
|
239 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
|
240 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
|
241 return |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
242 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
|
243 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
|
244 return |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
245 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
|
246 reporef = weakref.ref(op.repo) |
5193
a4d081923c81
compat: update hg-X.Y compat comments and test them
Anton Shestakov <av6@dwimlabs.net>
parents:
5189
diff
changeset
|
247 if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66) |
4123
119fced5a891
topic: add a compatibility to access transaction's validator
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3917
diff
changeset
|
248 oldvalidator = tr.validator |
5203
034d6d0efa7d
topic: fix compatibility issues caused because of change in transaction API
Pulkit Goyal <7895pulkit@gmail.com>
parents:
5193
diff
changeset
|
249 elif util.safehasattr(tr, '_validator'): |
034d6d0efa7d
topic: fix compatibility issues caused because of change in transaction API
Pulkit Goyal <7895pulkit@gmail.com>
parents:
5193
diff
changeset
|
250 # hg <= 5.3 (36f08ae87ef6) |
4123
119fced5a891
topic: add a compatibility to access transaction's validator
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3917
diff
changeset
|
251 oldvalidator = tr._validator |
1921 | 252 |
5203
034d6d0efa7d
topic: fix compatibility issues caused because of change in transaction API
Pulkit Goyal <7895pulkit@gmail.com>
parents:
5193
diff
changeset
|
253 def _validate(tr): |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 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
|
258 for branch, oldnb in tr._prepushheads.items(): |
5581
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
259 newheads = finalheads.pop(branch, []) |
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
260 if len(oldnb) < len(newheads): |
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
261 cl = repo.changelog |
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
262 newheads = sorted(set(newheads).difference(oldnb)) |
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
263 heads = scmutil.nodesummaries(repo, [cl.node(r) for r in newheads]) |
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
264 msg = _( |
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
265 b"push creates new heads on branch '%s': %s" |
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
266 % (branch, heads) |
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
267 ) |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
268 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
|
269 for branch, newnb in finalheads.items(): |
5581
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
270 if 1 < len(newnb): |
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
271 cl = repo.changelog |
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
272 heads = scmutil.nodesummaries(repo, [cl.node(r) for r in newnb]) |
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
273 msg = _( |
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
274 b"push creates new branch '%s' with multiple heads: %s" |
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
275 % (branch, heads) |
36ccafa69095
discovery: list the new heads like core does when failing a multi-head push
Matt Harbison <matt_harbison@yahoo.com>
parents:
5377
diff
changeset
|
276 ) |
5377
a267a7d3e1c5
topic: copy an abort message (new branch) from upstream exactly
Anton Shestakov <av6@dwimlabs.net>
parents:
5376
diff
changeset
|
277 hint = _(b"merge or see 'hg help push' for details about " |
a267a7d3e1c5
topic: copy an abort message (new branch) from upstream exactly
Anton Shestakov <av6@dwimlabs.net>
parents:
5376
diff
changeset
|
278 b"pushing new heads") |
a267a7d3e1c5
topic: copy an abort message (new branch) from upstream exactly
Anton Shestakov <av6@dwimlabs.net>
parents:
5376
diff
changeset
|
279 raise error.Abort(msg, hint=hint) |
5203
034d6d0efa7d
topic: fix compatibility issues caused because of change in transaction API
Pulkit Goyal <7895pulkit@gmail.com>
parents:
5193
diff
changeset
|
280 |
034d6d0efa7d
topic: fix compatibility issues caused because of change in transaction API
Pulkit Goyal <7895pulkit@gmail.com>
parents:
5193
diff
changeset
|
281 def validator(tr): |
034d6d0efa7d
topic: fix compatibility issues caused because of change in transaction API
Pulkit Goyal <7895pulkit@gmail.com>
parents:
5193
diff
changeset
|
282 _validate(tr) |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
283 return oldvalidator(tr) |
5203
034d6d0efa7d
topic: fix compatibility issues caused because of change in transaction API
Pulkit Goyal <7895pulkit@gmail.com>
parents:
5193
diff
changeset
|
284 |
5193
a4d081923c81
compat: update hg-X.Y compat comments and test them
Anton Shestakov <av6@dwimlabs.net>
parents:
5189
diff
changeset
|
285 if util.safehasattr(tr, 'validator'): # hg <= 4.7 (ebbba3ba3f66) |
4123
119fced5a891
topic: add a compatibility to access transaction's validator
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3917
diff
changeset
|
286 tr.validator = validator |
5203
034d6d0efa7d
topic: fix compatibility issues caused because of change in transaction API
Pulkit Goyal <7895pulkit@gmail.com>
parents:
5193
diff
changeset
|
287 elif util.safehasattr(tr, '_validator'): |
034d6d0efa7d
topic: fix compatibility issues caused because of change in transaction API
Pulkit Goyal <7895pulkit@gmail.com>
parents:
5193
diff
changeset
|
288 # hg <= 5.3 (36f08ae87ef6) |
034d6d0efa7d
topic: fix compatibility issues caused because of change in transaction API
Pulkit Goyal <7895pulkit@gmail.com>
parents:
5193
diff
changeset
|
289 tr._validator = validator |
4123
119fced5a891
topic: add a compatibility to access transaction's validator
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3917
diff
changeset
|
290 else: |
5203
034d6d0efa7d
topic: fix compatibility issues caused because of change in transaction API
Pulkit Goyal <7895pulkit@gmail.com>
parents:
5193
diff
changeset
|
291 tr.addvalidator(b'000-new-head-check', _validate) |
034d6d0efa7d
topic: fix compatibility issues caused because of change in transaction API
Pulkit Goyal <7895pulkit@gmail.com>
parents:
5193
diff
changeset
|
292 |
1887
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
293 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
|
294 |
68125d026b07
push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1886
diff
changeset
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 |
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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 return caps |
1944
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
308 |
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
309 def modsetup(ui): |
daad8249d5cf
discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1934
diff
changeset
|
310 """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
|
311 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
|
312 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
|
313 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
|
314 # 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 # 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 exchange.b2partsgenmapping[b'phase'] = exchange._pushb2phases |