Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/sshpeer.py @ 35440:31d21309635b
sshpeer: allow for additional environment passing to ssh exe
We already have the ability to customize the ssh command line arguments, let's
add the ability to customize its environment as well.
Example use-case is ssh.exe from Git on Windows. If `HOME` enviroment variable
is present and has some non-empty value, ssh.exe will try to access that
location for some stuff (for example, it seems for resolving `~` in
`.ssh/config`). Git for Windows seems to sometimess set this variable to the
value of `/home/username` which probably works under Git Bash, but does not
work in a native `cmd.exe` or `powershell`. Whatever the root cause, setting
`HOME` to be an empty string heals things. Therefore, some distributors
might want to set `sshenv.HOME=` in the configuration (seems less intrusive
that forcing everyone to tweak their env).
Test Plan:
- rt
Differential Revision: https://phab.mercurial-scm.org/D1683
author | Kostia Balytskyi <ikostia@fb.com> |
---|---|
date | Thu, 14 Dec 2017 14:31:57 +0000 |
parents | 8b1c887d52e7 |
children | b520c8f98e1e |
comparison
equal
deleted
inserted
replaced
35439:f01101100043 | 35440:31d21309635b |
---|---|
134 self._port = u.port | 134 self._port = u.port |
135 self._path = u.path or '.' | 135 self._path = u.path or '.' |
136 | 136 |
137 sshcmd = self.ui.config("ui", "ssh") | 137 sshcmd = self.ui.config("ui", "ssh") |
138 remotecmd = self.ui.config("ui", "remotecmd") | 138 remotecmd = self.ui.config("ui", "remotecmd") |
139 sshaddenv = dict(self.ui.configitems("sshenv")) | |
140 sshenv = util.shellenviron(sshaddenv) | |
139 | 141 |
140 args = util.sshargs(sshcmd, self._host, self._user, self._port) | 142 args = util.sshargs(sshcmd, self._host, self._user, self._port) |
141 | 143 |
142 if create: | 144 if create: |
143 cmd = '%s %s %s' % (sshcmd, args, | 145 cmd = '%s %s %s' % (sshcmd, args, |
144 util.shellquote("%s init %s" % | 146 util.shellquote("%s init %s" % |
145 (_serverquote(remotecmd), _serverquote(self._path)))) | 147 (_serverquote(remotecmd), _serverquote(self._path)))) |
146 ui.debug('running %s\n' % cmd) | 148 ui.debug('running %s\n' % cmd) |
147 res = ui.system(cmd, blockedtag='sshpeer') | 149 res = ui.system(cmd, blockedtag='sshpeer', environ=sshenv) |
148 if res != 0: | 150 if res != 0: |
149 self._abort(error.RepoError(_("could not create remote repo"))) | 151 self._abort(error.RepoError(_("could not create remote repo"))) |
150 | 152 |
151 self._validaterepo(sshcmd, args, remotecmd) | 153 self._validaterepo(sshcmd, args, remotecmd, sshenv) |
152 | 154 |
153 # Begin of _basepeer interface. | 155 # Begin of _basepeer interface. |
154 | 156 |
155 @util.propertycache | 157 @util.propertycache |
156 def ui(self): | 158 def ui(self): |
178 def capabilities(self): | 180 def capabilities(self): |
179 return self._caps | 181 return self._caps |
180 | 182 |
181 # End of _basewirecommands interface. | 183 # End of _basewirecommands interface. |
182 | 184 |
183 def _validaterepo(self, sshcmd, args, remotecmd): | 185 def _validaterepo(self, sshcmd, args, remotecmd, sshenv=None): |
184 # cleanup up previous run | 186 # cleanup up previous run |
185 self._cleanup() | 187 self._cleanup() |
186 | 188 |
187 cmd = '%s %s %s' % (sshcmd, args, | 189 cmd = '%s %s %s' % (sshcmd, args, |
188 util.shellquote("%s -R %s serve --stdio" % | 190 util.shellquote("%s -R %s serve --stdio" % |
194 # to clean up correctly later | 196 # to clean up correctly later |
195 # | 197 # |
196 # no buffer allow the use of 'select' | 198 # no buffer allow the use of 'select' |
197 # feel free to remove buffering and select usage when we ultimately | 199 # feel free to remove buffering and select usage when we ultimately |
198 # move to threading. | 200 # move to threading. |
199 sub = util.popen4(cmd, bufsize=0) | 201 sub = util.popen4(cmd, bufsize=0, env=sshenv) |
200 self._pipeo, self._pipei, self._pipee, self._subprocess = sub | 202 self._pipeo, self._pipei, self._pipee, self._subprocess = sub |
201 | 203 |
202 self._pipei = util.bufferedinputpipe(self._pipei) | 204 self._pipei = util.bufferedinputpipe(self._pipei) |
203 self._pipei = doublepipe(self.ui, self._pipei, self._pipee) | 205 self._pipei = doublepipe(self.ui, self._pipei, self._pipee) |
204 self._pipeo = doublepipe(self.ui, self._pipeo, self._pipee) | 206 self._pipeo = doublepipe(self.ui, self._pipeo, self._pipee) |