Mercurial > public > mercurial-scm > hg-stable
diff mercurial/exchange.py @ 32729:16ada4cbb1a9
push: add a way to allow concurrent pushes on unrelated heads
Client has a mechanism for the server to check that nothing changed server side
since the client prepared a push. That check is wide and any head changed on
the server will lead to an aborted push. We introduce a way for the client to
send a less strict checking. That logic will check that no heads impacted by
the push have been affected. If other unrelated heads (including named branches
heads) have been affected, the push will proceed.
This is very helpful for repositories with high developers traffic on different
heads, a common setup.
That behavior is currently controlled by an experimental option. The config
should live in the "server" section but bike-shedding of the name will happen
in the next changesets. Servers advertise this capability through a new bundle2
capability 'checkeads', using the value 'related'.
The 'test-push-race.t' is updated to check that new capabilities on the
documented cases.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 29 May 2017 05:53:58 +0200 |
parents | 9929af2b09b4 |
children | a470bbb4e3af |
line wrap: on
line diff
--- a/mercurial/exchange.py Mon May 29 05:52:13 2017 +0200 +++ b/mercurial/exchange.py Mon May 29 05:53:58 2017 +0200 @@ -323,8 +323,21 @@ self.bkresult = None # discover.outgoing object (contains common and outgoing data) self.outgoing = None - # all remote heads before the push + # all remote topological heads before the push self.remoteheads = None + # Details of the remote branch pre and post push + # + # mapping: {'branch': ([remoteheads], + # [newheads], + # [unsyncedheads], + # [discardedheads])} + # - branch: the branch name + # - remoteheads: the list of remote heads known locally + # None if the branch is new + # - newheads: the new remote heads (known locally) with outgoing pushed + # - unsyncedheads: the list of remote heads unknown locally. + # - discardedheads: the list of remote heads made obsolete by the push + self.pushbranchmap = None # testable as a boolean indicating if any nodes are missing locally. self.incoming = None # phases changes that must be pushed along side the changesets @@ -712,8 +725,23 @@ Exists as an independent function to aid extensions """ - if not pushop.force: - bundler.newpart('check:heads', data=iter(pushop.remoteheads)) + # * 'force' do not check for push race, + # * if we don't push anything, there are nothing to check. + if not pushop.force and pushop.outgoing.missingheads: + allowunrelated = 'related' in bundler.capabilities.get('checkheads', ()) + if not allowunrelated: + bundler.newpart('check:heads', data=iter(pushop.remoteheads)) + else: + affected = set() + for branch, heads in pushop.pushbranchmap.iteritems(): + remoteheads, newheads, unsyncedheads, discardedheads = heads + if remoteheads is not None: + remote = set(remoteheads) + affected |= set(discardedheads) & remote + affected |= remote - set(newheads) + if affected: + data = iter(sorted(affected)) + bundler.newpart('check:updated-heads', data=data) @b2partsgenerator('changeset') def _pushb2ctx(pushop, bundler):