comparison hgext3rd/topic/flow.py @ 6641:995c6163e97b

topic: drop compatibility for hg push with --publish flag in hg 4.8
author Anton Shestakov <av6@dwimlabs.net>
date Mon, 06 Nov 2023 00:58:11 -0300
parents 57f9cdbf6a99
children 691a9301b51e
comparison
equal deleted inserted replaced
6640:7169272b1b90 6641:995c6163e97b
1 from __future__ import absolute_import 1 from __future__ import absolute_import
2 2
3 from mercurial import ( 3 from mercurial import (
4 commands,
5 error, 4 error,
6 exchange, 5 exchange,
7 extensions,
8 node, 6 node,
9 phases, 7 phases,
10 util, 8 util,
11 ) 9 )
12 10
80 msg = b"rejecting publishing of changeset %s" % repo[r] 78 msg = b"rejecting publishing of changeset %s" % repo[r]
81 if len(published) > 1: 79 if len(published) > 1:
82 msg += b' and %d others' % (len(published) - 1) 80 msg += b' and %d others' % (len(published) - 1)
83 raise error.Abort(msg) 81 raise error.Abort(msg)
84 82
85 def wrappush(orig, repo, remote, *args, **kwargs):
86 """interpret the --publish flag and pass it to the push operation"""
87 newargs = kwargs.copy()
88 if kwargs.pop('publish', False):
89 opargs = kwargs.get('opargs')
90 if opargs is None:
91 opargs = {}
92 newargs[r'opargs'] = opargs.copy()
93 newargs[r'opargs'][b'publish'] = True
94 return orig(repo, remote, *args, **newargs)
95
96 def extendpushoperation(orig, self, *args, **kwargs):
97 publish = kwargs.pop('publish', False)
98 orig(self, *args, **kwargs)
99 self.publish = publish
100
101 def wrapphasediscovery(orig, pushop):
102 orig(pushop)
103 if getattr(pushop, 'publish', False):
104 if not pushop.remotephases.publishing:
105 unfi = pushop.repo.unfiltered()
106 droots = pushop.remotephases.draftroots
107 revset = b'%ln and (not public() or %ln::)'
108 future = list(unfi.set(revset, pushop.futureheads, droots))
109 pushop.outdatedphases = future
110
111 def installpushflag(ui):
112 entry = extensions.wrapcommand(commands.table, b'push', wrappush)
113 if not any(opt for opt in entry[1] if opt[1] == b'publish'):
114 # hg <= 4.8 (9b8d1ad851f8)
115 entry[1].append((b'', b'publish', False,
116 _(b'push the changeset as public')))
117 extensions.wrapfunction(exchange.pushoperation, '__init__',
118 extendpushoperation)
119 extensions.wrapfunction(exchange, '_pushdiscoveryphase', wrapphasediscovery)
120 exchange.pushdiscoverymapping[b'phase'] = exchange._pushdiscoveryphase
121
122 def replacecheckpublish(orig, pushop): 83 def replacecheckpublish(orig, pushop):
123 listkeys = exchange.listkeys 84 listkeys = exchange.listkeys
124 repo = pushop.repo 85 repo = pushop.repo
125 ui = repo.ui 86 ui = repo.ui
126 behavior = ui.config(b'experimental', b'auto-publish') 87 behavior = ui.config(b'experimental', b'auto-publish')