diff mercurial/exchange.py @ 33885:800bb35d891e

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
author Jun Wu <quark@fb.com>
date Wed, 16 Aug 2017 15:48:48 -0700
parents 389f7b17ffb3
children 13dc7f29531e
line wrap: on
line diff
--- 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):