# HG changeset patch # User Jun Wu # Date 1502923728 25200 # Node ID 800bb35d891e420701415205bef2aa176b556446 # Parent e5d104c35e5195049f6a169673beef696fe22bae pushvars: do not mangle repo state Setting `repo._shellvars` works but is not a clean way to pass the pushvars information from the push command to the exchange operation. Therefore change it to actually pass `pushvars` as a push operation argument instead. This makes third party extension like remotenames easier to support pushvars cleanly. The key value parsing and verification code has been moved to a lower level so it's harder to be bypassed and easier to be used in remotenames which could replace `push` command entirely. Differential Revision: https://phab.mercurial-scm.org/D423 diff -r e5d104c35e51 -r 800bb35d891e mercurial/commands.py --- a/mercurial/commands.py Mon Aug 21 16:43:37 2017 +0530 +++ b/mercurial/commands.py Wed Aug 16 15:48:48 2017 -0700 @@ -4082,26 +4082,13 @@ finally: del repo._subtoppath - pushvars = opts.get('pushvars') - if pushvars: - shellvars = {} - for raw in pushvars: - if '=' not in raw: - msg = ("unable to parse variable '%s', should follow " - "'KEY=VALUE' or 'KEY=' format") - raise error.Abort(msg % raw) - k, v = raw.split('=', 1) - shellvars[k] = v - - repo._shellvars = shellvars + opargs = dict(opts.get('opargs', {})) # copy opargs since we may mutate it + opargs.setdefault('pushvars', []).extend(opts.get('pushvars', [])) pushop = exchange.push(repo, other, opts.get('force'), revs=revs, newbranch=opts.get('new_branch'), bookmarks=opts.get('bookmark', ()), - opargs=opts.get('opargs')) - - if pushvars: - del repo._shellvars + opargs=opargs) result = not pushop.cgresult diff -r e5d104c35e51 -r 800bb35d891e mercurial/exchange.py --- a/mercurial/exchange.py Mon Aug 21 16:43:37 2017 +0530 +++ b/mercurial/exchange.py Wed Aug 16 15:48:48 2017 -0700 @@ -294,7 +294,7 @@ """ def __init__(self, repo, remote, force=False, revs=None, newbranch=False, - bookmarks=()): + bookmarks=(), pushvars=None): # repo we push from self.repo = repo self.ui = repo.ui @@ -352,6 +352,8 @@ # map { pushkey partid -> callback handling failure} # used to handle exception from mandatory pushkey part failure self.pkfailcb = {} + # an iterable of pushvars or None + self.pushvars = pushvars @util.propertycache def futureheads(self): @@ -876,10 +878,20 @@ @b2partsgenerator('pushvars', idx=0) def _getbundlesendvars(pushop, bundler): '''send shellvars via bundle2''' - if getattr(pushop.repo, '_shellvars', ()): + pushvars = pushop.pushvars + if pushvars: + shellvars = {} + for raw in pushvars: + if '=' not in raw: + msg = ("unable to parse variable '%s', should follow " + "'KEY=VALUE' or 'KEY=' format") + raise error.Abort(msg % raw) + k, v = raw.split('=', 1) + shellvars[k] = v + part = bundler.newpart('pushvars') - for key, value in pushop.repo._shellvars.iteritems(): + for key, value in shellvars.iteritems(): part.addparam(key, value, mandatory=False) def _pushbundle2(pushop): diff -r e5d104c35e51 -r 800bb35d891e tests/test-pushvars.t --- a/tests/test-pushvars.t Mon Aug 21 16:43:37 2017 +0530 +++ b/tests/test-pushvars.t Wed Aug 16 15:48:48 2017 -0700 @@ -66,5 +66,6 @@ $ hg commit -Aqm b $ hg push --pushvars "DEBUG" pushing to $TESTTMP/repo (glob) + searching for changes abort: unable to parse variable 'DEBUG', should follow 'KEY=VALUE' or 'KEY=' format [255]