Mercurial > evolve
annotate hgext3rd/topic/flow.py @ 6803:5793b25f6525 mercurial-6.2
test-compat: merge mercurial-6.3 into mercurial-6.2
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Wed, 26 Jun 2024 15:02:24 +0400 |
parents | 9638df99836f |
children | b88cd2f549a8 |
rev | line source |
---|---|
3157
f286eefbd20d
topic: add an option to enforce a single head per name in a repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 from __future__ import absolute_import |
f286eefbd20d
topic: add an option to enforce a single head per name in a repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 |
f286eefbd20d
topic: add an option to enforce a single head per name in a repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
3 from mercurial import ( |
3159
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
4 commands, |
3157
f286eefbd20d
topic: add an option to enforce a single head per name in a repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 error, |
3159
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
6 exchange, |
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
7 extensions, |
3157
f286eefbd20d
topic: add an option to enforce a single head per name in a repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 node, |
3158
678a9802c56b
topic: add an option to automatically publish topic-less changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3157
diff
changeset
|
9 phases, |
5204
d7f87c7cb1f0
topic: compat with tr.changes[b'phases'], it's now a list
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
10 util, |
3157
f286eefbd20d
topic: add an option to enforce a single head per name in a repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 ) |
f286eefbd20d
topic: add an option to enforce a single head per name in a repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 |
f286eefbd20d
topic: add an option to enforce a single head per name in a repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 from mercurial.i18n import _ |
f286eefbd20d
topic: add an option to enforce a single head per name in a repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 |
4743
92e3db149d7d
py3: call branchmap.items() on py3 and continue to call iteritems() on py2
Martin von Zweigbergk <martinvonz@google.com>
parents:
4647
diff
changeset
|
15 from . import ( |
92e3db149d7d
py3: call branchmap.items() on py3 and continue to call iteritems() on py2
Martin von Zweigbergk <martinvonz@google.com>
parents:
4647
diff
changeset
|
16 compat, |
92e3db149d7d
py3: call branchmap.items() on py3 and continue to call iteritems() on py2
Martin von Zweigbergk <martinvonz@google.com>
parents:
4647
diff
changeset
|
17 ) |
92e3db149d7d
py3: call branchmap.items() on py3 and continue to call iteritems() on py2
Martin von Zweigbergk <martinvonz@google.com>
parents:
4647
diff
changeset
|
18 |
3157
f286eefbd20d
topic: add an option to enforce a single head per name in a repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 def enforcesinglehead(repo, tr): |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
20 branchmap = repo.filtered(b'visible').branchmap() |
4743
92e3db149d7d
py3: call branchmap.items() on py3 and continue to call iteritems() on py2
Martin von Zweigbergk <martinvonz@google.com>
parents:
4647
diff
changeset
|
21 for name, heads in compat.branchmapitems(branchmap): |
3157
f286eefbd20d
topic: add an option to enforce a single head per name in a repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 if len(heads) > 1: |
f286eefbd20d
topic: add an option to enforce a single head per name in a repository
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 hexs = [node.short(n) for n in heads] |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
24 raise error.Abort(_(b'%d heads on "%s"') % (len(heads), name), |
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
25 hint=(b', '.join(hexs))) |
3158
678a9802c56b
topic: add an option to automatically publish topic-less changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3157
diff
changeset
|
26 |
678a9802c56b
topic: add an option to automatically publish topic-less changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3157
diff
changeset
|
27 def publishbarebranch(repo, tr): |
678a9802c56b
topic: add an option to automatically publish topic-less changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3157
diff
changeset
|
28 """Publish changeset without topic""" |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
29 if b'node' not in tr.hookargs: # no new node |
3158
678a9802c56b
topic: add an option to automatically publish topic-less changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3157
diff
changeset
|
30 return |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
31 startnode = node.bin(tr.hookargs[b'node']) |
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
32 topublish = repo.revs(b'not public() and (%n:) - hidden() - topic()', startnode) |
3158
678a9802c56b
topic: add an option to automatically publish topic-less changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3157
diff
changeset
|
33 if topublish: |
678a9802c56b
topic: add an option to automatically publish topic-less changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3157
diff
changeset
|
34 cl = repo.changelog |
678a9802c56b
topic: add an option to automatically publish topic-less changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3157
diff
changeset
|
35 nodes = [cl.node(r) for r in topublish] |
678a9802c56b
topic: add an option to automatically publish topic-less changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3157
diff
changeset
|
36 repo._phasecache.advanceboundary(repo, tr, phases.public, nodes) |
3159
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
37 |
3235
8a772f0c54d9
topics: add a config to reject draft changeset without topic on a server
Pulkit Goyal <7895pulkit@gmail.com>
parents:
3226
diff
changeset
|
38 def rejectuntopicedchangeset(repo, tr): |
8a772f0c54d9
topics: add a config to reject draft changeset without topic on a server
Pulkit Goyal <7895pulkit@gmail.com>
parents:
3226
diff
changeset
|
39 """Reject the push if there are changeset without topic""" |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
40 if b'node' not in tr.hookargs: # no new revs |
3235
8a772f0c54d9
topics: add a config to reject draft changeset without topic on a server
Pulkit Goyal <7895pulkit@gmail.com>
parents:
3226
diff
changeset
|
41 return |
8a772f0c54d9
topics: add a config to reject draft changeset without topic on a server
Pulkit Goyal <7895pulkit@gmail.com>
parents:
3226
diff
changeset
|
42 |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
43 startnode = node.bin(tr.hookargs[b'node']) |
3282
3675fe74521d
topic: use 'hookargs' over 'tr.changes' for flow control
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3235
diff
changeset
|
44 |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
45 mode = repo.ui.config(b'experimental', b'topic-mode.server', b'ignore') |
3235
8a772f0c54d9
topics: add a config to reject draft changeset without topic on a server
Pulkit Goyal <7895pulkit@gmail.com>
parents:
3226
diff
changeset
|
46 |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
47 untopiced = repo.revs(b'not public() and (%n:) - hidden() - topic()', startnode) |
3235
8a772f0c54d9
topics: add a config to reject draft changeset without topic on a server
Pulkit Goyal <7895pulkit@gmail.com>
parents:
3226
diff
changeset
|
48 if untopiced: |
8a772f0c54d9
topics: add a config to reject draft changeset without topic on a server
Pulkit Goyal <7895pulkit@gmail.com>
parents:
3226
diff
changeset
|
49 num = len(untopiced) |
6742
0592ae24c470
topic: get changeset node using the designated functions
Anton Shestakov <av6@dwimlabs.net>
parents:
6322
diff
changeset
|
50 cl = repo.changelog |
0592ae24c470
topic: get changeset node using the designated functions
Anton Shestakov <av6@dwimlabs.net>
parents:
6322
diff
changeset
|
51 fnode = node.short(cl.node(untopiced.first())) |
3235
8a772f0c54d9
topics: add a config to reject draft changeset without topic on a server
Pulkit Goyal <7895pulkit@gmail.com>
parents:
3226
diff
changeset
|
52 if num == 1: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
53 msg = _(b"%s") % fnode |
3235
8a772f0c54d9
topics: add a config to reject draft changeset without topic on a server
Pulkit Goyal <7895pulkit@gmail.com>
parents:
3226
diff
changeset
|
54 else: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
55 msg = _(b"%s and %d more") % (fnode, num - 1) |
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
56 if mode == b'warning': |
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
57 fullmsg = _(b"pushed draft changeset without topic: %s\n") |
3235
8a772f0c54d9
topics: add a config to reject draft changeset without topic on a server
Pulkit Goyal <7895pulkit@gmail.com>
parents:
3226
diff
changeset
|
58 repo.ui.warn(fullmsg % msg) |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
59 elif mode == b'enforce': |
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
60 fullmsg = _(b"rejecting draft changesets: %s") |
3235
8a772f0c54d9
topics: add a config to reject draft changeset without topic on a server
Pulkit Goyal <7895pulkit@gmail.com>
parents:
3226
diff
changeset
|
61 raise error.Abort(fullmsg % msg) |
8a772f0c54d9
topics: add a config to reject draft changeset without topic on a server
Pulkit Goyal <7895pulkit@gmail.com>
parents:
3226
diff
changeset
|
62 else: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
63 repo.ui.warn(_(b"unknown 'topic-mode.server': %s\n" % mode)) |
3235
8a772f0c54d9
topics: add a config to reject draft changeset without topic on a server
Pulkit Goyal <7895pulkit@gmail.com>
parents:
3226
diff
changeset
|
64 |
4647
228caeb8b7af
topic: add a simple option to reject publishing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
65 def reject_publish(repo, tr): |
228caeb8b7af
topic: add a simple option to reject publishing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
66 """prevent a transaction to be publish anything""" |
5204
d7f87c7cb1f0
topic: compat with tr.changes[b'phases'], it's now a list
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
67 if util.safehasattr(tr.changes[b'phases'], 'items'): |
d7f87c7cb1f0
topic: compat with tr.changes[b'phases'], it's now a list
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
68 # hg <= 5.3 (fdc802f29b2c) |
d7f87c7cb1f0
topic: compat with tr.changes[b'phases'], it's now a list
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
69 published = { |
d7f87c7cb1f0
topic: compat with tr.changes[b'phases'], it's now a list
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
70 r for r, (o, n) in tr.changes[b'phases'].items() |
d7f87c7cb1f0
topic: compat with tr.changes[b'phases'], it's now a list
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
71 if n == phases.public |
d7f87c7cb1f0
topic: compat with tr.changes[b'phases'], it's now a list
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
72 } |
d7f87c7cb1f0
topic: compat with tr.changes[b'phases'], it's now a list
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
73 else: |
d7f87c7cb1f0
topic: compat with tr.changes[b'phases'], it's now a list
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
74 revranges = [ |
d7f87c7cb1f0
topic: compat with tr.changes[b'phases'], it's now a list
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
75 r for r, (o, n) in tr.changes[b'phases'] |
d7f87c7cb1f0
topic: compat with tr.changes[b'phases'], it's now a list
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
76 if n == phases.public |
d7f87c7cb1f0
topic: compat with tr.changes[b'phases'], it's now a list
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
77 ] |
d7f87c7cb1f0
topic: compat with tr.changes[b'phases'], it's now a list
Anton Shestakov <av6@dwimlabs.net>
parents:
5193
diff
changeset
|
78 published = {r for revrange in revranges for r in revrange} |
4647
228caeb8b7af
topic: add a simple option to reject publishing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
79 if published: |
228caeb8b7af
topic: add a simple option to reject publishing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
80 r = min(published) |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
81 msg = b"rejecting publishing of changeset %s" % repo[r] |
4647
228caeb8b7af
topic: add a simple option to reject publishing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
82 if len(published) > 1: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
83 msg += b' and %d others' % (len(published) - 1) |
4647
228caeb8b7af
topic: add a simple option to reject publishing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
84 raise error.Abort(msg) |
228caeb8b7af
topic: add a simple option to reject publishing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4263
diff
changeset
|
85 |
6743
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
86 def reject_csets_with_tns(repo, tr): |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
87 """Reject the push if there are changesets with any topic namespace""" |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
88 if b'node' not in tr.hookargs: # no new revs |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
89 return |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
90 |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
91 reject = repo.ui.config(b'experimental', b'tns-reject-push') |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
92 if not reject: |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
93 return |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
94 |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
95 startnode = node.bin(tr.hookargs[b'node']) |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
96 repo = repo.unfiltered() |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
97 with_tns = repo.revs(b'not public() and extra("topic-namespace") and (%n:) - hidden()', startnode) |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
98 if with_tns: |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
99 num = len(with_tns) |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
100 cl = repo.changelog |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
101 fnode = node.short(cl.node(with_tns.first())) |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
102 if num == 1: |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
103 msg = _(b"%s") % fnode |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
104 else: |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
105 msg = _(b"%s and %d more") % (fnode, num - 1) |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
106 fullmsg = _(b"rejecting draft changesets with topic namespace: %s") |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
107 raise error.Abort(fullmsg % msg) |
ab60707314e9
topic: new experimental.tns-reject-push config to refuse changesets with tns
Anton Shestakov <av6@dwimlabs.net>
parents:
6742
diff
changeset
|
108 |
3159
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
109 def wrappush(orig, repo, remote, *args, **kwargs): |
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
110 """interpret the --publish flag and pass it to the push operation""" |
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
111 newargs = kwargs.copy() |
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
112 if kwargs.pop('publish', False): |
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
113 opargs = kwargs.get('opargs') |
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
114 if opargs is None: |
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
115 opargs = {} |
4808
14c12df16ab5
python3: add raw prefix to edge-cases kwargs-like objects
Raphaël Gomès <rgomes@octobus.net>
parents:
4743
diff
changeset
|
116 newargs[r'opargs'] = opargs.copy() |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
117 newargs[r'opargs'][b'publish'] = True |
3159
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
118 return orig(repo, remote, *args, **newargs) |
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
119 |
3204
a342c454ccf3
pusoperation: wrap pushoperation __init__ directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3159
diff
changeset
|
120 def extendpushoperation(orig, self, *args, **kwargs): |
3159
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
121 publish = kwargs.pop('publish', False) |
3204
a342c454ccf3
pusoperation: wrap pushoperation __init__ directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3159
diff
changeset
|
122 orig(self, *args, **kwargs) |
a342c454ccf3
pusoperation: wrap pushoperation __init__ directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3159
diff
changeset
|
123 self.publish = publish |
3159
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
124 |
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
125 def wrapphasediscovery(orig, pushop): |
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
126 orig(pushop) |
3226
5dfe4e5cf9e4
topic: use more protective code to access publishing code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3204
diff
changeset
|
127 if getattr(pushop, 'publish', False): |
3159
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
128 if not pushop.remotephases.publishing: |
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
129 unfi = pushop.repo.unfiltered() |
6787
9638df99836f
topic: compatibility for RemotePhasesSummary.draft_roots
Anton Shestakov <av6@dwimlabs.net>
parents:
6743
diff
changeset
|
130 if util.safehasattr(pushop.remotephases, 'draftroots'): |
9638df99836f
topic: compatibility for RemotePhasesSummary.draft_roots
Anton Shestakov <av6@dwimlabs.net>
parents:
6743
diff
changeset
|
131 # hg <= 6.7 (22cc679a7312) |
9638df99836f
topic: compatibility for RemotePhasesSummary.draft_roots
Anton Shestakov <av6@dwimlabs.net>
parents:
6743
diff
changeset
|
132 droots = pushop.remotephases.draftroots |
9638df99836f
topic: compatibility for RemotePhasesSummary.draft_roots
Anton Shestakov <av6@dwimlabs.net>
parents:
6743
diff
changeset
|
133 revset = b'%ln and (not public() or %ln::)' |
9638df99836f
topic: compatibility for RemotePhasesSummary.draft_roots
Anton Shestakov <av6@dwimlabs.net>
parents:
6743
diff
changeset
|
134 else: |
9638df99836f
topic: compatibility for RemotePhasesSummary.draft_roots
Anton Shestakov <av6@dwimlabs.net>
parents:
6743
diff
changeset
|
135 droots = pushop.remotephases.draft_roots |
9638df99836f
topic: compatibility for RemotePhasesSummary.draft_roots
Anton Shestakov <av6@dwimlabs.net>
parents:
6743
diff
changeset
|
136 revset = b'%ln and (not public() or %ld::)' |
3159
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
137 future = list(unfi.set(revset, pushop.futureheads, droots)) |
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
138 pushop.outdatedphases = future |
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
139 |
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
140 def installpushflag(ui): |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
141 entry = extensions.wrapcommand(commands.table, b'push', wrappush) |
5193
a4d081923c81
compat: update hg-X.Y compat comments and test them
Anton Shestakov <av6@dwimlabs.net>
parents:
4814
diff
changeset
|
142 if not any(opt for opt in entry[1] if opt[1] == b'publish'): |
a4d081923c81
compat: update hg-X.Y compat comments and test them
Anton Shestakov <av6@dwimlabs.net>
parents:
4814
diff
changeset
|
143 # hg <= 4.8 (9b8d1ad851f8) |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
144 entry[1].append((b'', b'publish', False, |
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
145 _(b'push the changeset as public'))) |
3204
a342c454ccf3
pusoperation: wrap pushoperation __init__ directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3159
diff
changeset
|
146 extensions.wrapfunction(exchange.pushoperation, '__init__', |
a342c454ccf3
pusoperation: wrap pushoperation __init__ directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3159
diff
changeset
|
147 extendpushoperation) |
3159
90515d0bfb08
push: add a --publish flag
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3158
diff
changeset
|
148 extensions.wrapfunction(exchange, '_pushdiscoveryphase', wrapphasediscovery) |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4808
diff
changeset
|
149 exchange.pushdiscoverymapping[b'phase'] = exchange._pushdiscoveryphase |
5221
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
150 |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
151 def replacecheckpublish(orig, pushop): |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
152 listkeys = exchange.listkeys |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
153 repo = pushop.repo |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
154 ui = repo.ui |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
155 behavior = ui.config(b'experimental', b'auto-publish') |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
156 if pushop.publish or behavior not in (b'warn', b'confirm', b'abort'): |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
157 return |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
158 |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
159 # possible modes are: |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
160 # |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
161 # none -> nothing is published on push |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
162 # all -> everything is published on push |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
163 # auto -> only changeset without topic are published on push |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
164 # |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
165 # Unknown mode is assumed "all" for safety. |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
166 # |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
167 # TODO: do a wider brain storming about mode names. |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
168 |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
169 mode = b'all' |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
170 remotephases = listkeys(pushop.remote, b'phases') |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
171 if not remotephases.get(b'publishing', False): |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
172 mode = b'none' |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
173 for c in pushop.remote.capabilities(): |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
174 if c.startswith(b'ext-topics-publish'): |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
175 mode = c.split(b'=', 1)[1] |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
176 break |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
177 if mode == b'none': |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
178 return |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
179 |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
180 if pushop.revs is None: |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
181 published = repo.filtered(b'served').revs(b'not public()') |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
182 else: |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
183 published = repo.revs(b'::%ln - public()', pushop.revs) |
5932
fe25ec8f0124
topic: use "served" repo filter to guess what the server will publish
Anton Shestakov <av6@dwimlabs.net>
parents:
5230
diff
changeset
|
184 # we want to use pushop.revs in the revset even if they themselves are |
fe25ec8f0124
topic: use "served" repo filter to guess what the server will publish
Anton Shestakov <av6@dwimlabs.net>
parents:
5230
diff
changeset
|
185 # secret, but we don't want to have anything that the server won't see |
fe25ec8f0124
topic: use "served" repo filter to guess what the server will publish
Anton Shestakov <av6@dwimlabs.net>
parents:
5230
diff
changeset
|
186 # in the result of this expression |
fe25ec8f0124
topic: use "served" repo filter to guess what the server will publish
Anton Shestakov <av6@dwimlabs.net>
parents:
5230
diff
changeset
|
187 published &= repo.filtered(b'served') |
fe25ec8f0124
topic: use "served" repo filter to guess what the server will publish
Anton Shestakov <av6@dwimlabs.net>
parents:
5230
diff
changeset
|
188 |
5221
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
189 if mode == b'auto': |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
190 published = repo.revs(b'%ld::(%ld - topic())', published, published) |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
191 if published: |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
192 if behavior == b'warn': |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
193 ui.warn( |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
194 _(b'%i changesets about to be published\n') % len(published) |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
195 ) |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
196 elif behavior == b'confirm': |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
197 if ui.promptchoice( |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
198 _(b'push and publish %i changesets (yn)?$$ &Yes $$ &No') |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
199 % len(published) |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
200 ): |
6322
57f9cdbf6a99
topic: use compat.CanceledError for user quit situations
Anton Shestakov <av6@dwimlabs.net>
parents:
5932
diff
changeset
|
201 raise compat.CanceledError(_(b'user quit')) |
5221
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
202 elif behavior == b'abort': |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
203 msg = _(b'push would publish %i changesets') % len(published) |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
204 hint = _( |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
205 b"use --publish or adjust 'experimental.auto-publish'" |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
206 b" config" |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
207 ) |
af9f40236037
topics: fix auto-publish=abort with servers publishing bare branches
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4814
diff
changeset
|
208 raise error.Abort(msg, hint=hint) |