D1683: sshpeer: allow for additional environment passing to ssh exe

ikostia (Kostia Balytskyi) phabricator at mercurial-scm.org
Fri Dec 15 16:15:44 EST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG47921dafb44b: sshpeer: allow for additional environment passing to ssh exe (authored by ikostia, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1683?vs=4429&id=4519

REVISION DETAIL
  https://phab.mercurial-scm.org/D1683

AFFECTED FILES
  mercurial/sshpeer.py
  tests/test-ssh.t

CHANGE DETAILS

diff --git a/tests/test-ssh.t b/tests/test-ssh.t
--- a/tests/test-ssh.t
+++ b/tests/test-ssh.t
@@ -596,3 +596,21 @@
   abort: no suitable response from remote hg!
   (Please see http://company/internalwiki/ssh.html)
   [255]
+
+test that custom environment is passed down to ssh executable
+  $ cat >>dumpenv <<EOF
+  > #! /bin/sh
+  > echo \$VAR >&2
+  > EOF
+  $ chmod +x dumpenv
+  $ hg pull ssh://something --config ui.ssh="./dumpenv"
+  pulling from ssh://something/
+  remote: 
+  abort: no suitable response from remote hg!
+  [255]
+  $ hg pull ssh://something --config ui.ssh="./dumpenv" --config sshenv.VAR=17
+  pulling from ssh://something/
+  remote: 17
+  abort: no suitable response from remote hg!
+  [255]
+
diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -136,19 +136,21 @@
 
         sshcmd = self.ui.config("ui", "ssh")
         remotecmd = self.ui.config("ui", "remotecmd")
+        sshaddenv = dict(self.ui.configitems("sshenv"))
+        sshenv = util.shellenviron(sshaddenv)
 
         args = util.sshargs(sshcmd, self._host, self._user, self._port)
 
         if create:
             cmd = '%s %s %s' % (sshcmd, args,
                 util.shellquote("%s init %s" %
                     (_serverquote(remotecmd), _serverquote(self._path))))
             ui.debug('running %s\n' % cmd)
-            res = ui.system(cmd, blockedtag='sshpeer')
+            res = ui.system(cmd, blockedtag='sshpeer', environ=sshenv)
             if res != 0:
                 self._abort(error.RepoError(_("could not create remote repo")))
 
-        self._validaterepo(sshcmd, args, remotecmd)
+        self._validaterepo(sshcmd, args, remotecmd, sshenv)
 
     # Begin of _basepeer interface.
 
@@ -180,7 +182,7 @@
 
     # End of _basewirecommands interface.
 
-    def _validaterepo(self, sshcmd, args, remotecmd):
+    def _validaterepo(self, sshcmd, args, remotecmd, sshenv=None):
         # cleanup up previous run
         self._cleanup()
 
@@ -196,7 +198,7 @@
         # no buffer allow the use of 'select'
         # feel free to remove buffering and select usage when we ultimately
         # move to threading.
-        sub = util.popen4(cmd, bufsize=0)
+        sub = util.popen4(cmd, bufsize=0, env=sshenv)
         self._pipeo, self._pipei, self._pipee, self._subprocess = sub
 
         self._pipei = util.bufferedinputpipe(self._pipei)



To: ikostia, #hg-reviewers, mbthomas, durin42
Cc: durin42, mbthomas, mercurial-devel


More information about the Mercurial-devel mailing list