summaryrefslogtreecommitdiffstats
path: root/git_command.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2019-12-04 19:30:48 -0500
committerMike Frysinger <vapier@google.com>2020-02-19 18:03:46 +0000
commit56ce3468b4f2faa1cccfea01dc91e7db73fb3843 (patch)
treeae5ef606503262f21ac53e336196bfb9975c98e2 /git_command.py
parent02aa889ecd54d69fd6c3708d2e7f8654d57ac1e8 (diff)
downloadgit-repo-56ce3468b4f2faa1cccfea01dc91e7db73fb3843.tar.gz
assume environment always accepts strings
Different Python & OS versions have different environ behavior wrt accepted types & encoding. Since we're migrating to be Python 3 only, lets change our code to assume strings always work as that's what the newer Python 3 does. This will fail under Python 2 for some env vars, mostly on Windows, but the effort of maintaining shim layers that can handle these edge cases isn't worth it when we're dropping that code. We leave the logic in the `repo` launcher for now as it is simple, and we want it to be able to switch versions a bit longer than the rest of the tree. Here's the support table: | *NIX | Windows | Python 2 | ASCII string | str or bytes, not unicode | Python 3 | str or bytes | str only | Windows uses strings natively in its environment all the time. But it doesn't allow unicode strings under Python 2, so we have to encode. Python 2 on *NIX is funky in that it always lowers to ASCII, so we had to manually encode to avoid errors regardless of unicode or str. Python 3 on Windows & *NIX will accept strings. *NIX will also accept bytes but Windows will not. Bug: https://crbug.com/gerrit/12145 Change-Id: I3cf8f95a06902754ea1f08ad4b28503f7063531b Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/248972 Tested-by: Mike Frysinger <vapier@google.com> Reviewed-by: Michael Mortensen <mmortensen@google.com> Reviewed-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'git_command.py')
-rw-r--r--git_command.py22
1 files changed, 9 insertions, 13 deletions
diff --git a/git_command.py b/git_command.py
index 26668a39..a2782151 100644
--- a/git_command.py
+++ b/git_command.py
@@ -214,10 +214,6 @@ def git_require(min_version, fail=False, msg=''):
214 return False 214 return False
215 215
216 216
217def _setenv(env, name, value):
218 env[name] = value.encode()
219
220
221class GitCommand(object): 217class GitCommand(object):
222 def __init__(self, 218 def __init__(self,
223 project, 219 project,
@@ -237,21 +233,21 @@ class GitCommand(object):
237 self.tee = {'stdout': not capture_stdout, 'stderr': not capture_stderr} 233 self.tee = {'stdout': not capture_stdout, 'stderr': not capture_stderr}
238 234
239 if disable_editor: 235 if disable_editor:
240 _setenv(env, 'GIT_EDITOR', ':') 236 env['GIT_EDITOR'] = ':'
241 if ssh_proxy: 237 if ssh_proxy:
242 _setenv(env, 'REPO_SSH_SOCK', ssh_sock()) 238 env['REPO_SSH_SOCK'] = ssh_sock()
243 _setenv(env, 'GIT_SSH', _ssh_proxy()) 239 env['GIT_SSH'] = _ssh_proxy()
244 _setenv(env, 'GIT_SSH_VARIANT', 'ssh') 240 env['GIT_SSH_VARIANT'] = 'ssh'
245 if 'http_proxy' in env and 'darwin' == sys.platform: 241 if 'http_proxy' in env and 'darwin' == sys.platform:
246 s = "'http.proxy=%s'" % (env['http_proxy'],) 242 s = "'http.proxy=%s'" % (env['http_proxy'],)
247 p = env.get('GIT_CONFIG_PARAMETERS') 243 p = env.get('GIT_CONFIG_PARAMETERS')
248 if p is not None: 244 if p is not None:
249 s = p + ' ' + s 245 s = p + ' ' + s
250 _setenv(env, 'GIT_CONFIG_PARAMETERS', s) 246 env['GIT_CONFIG_PARAMETERS'] = s
251 if 'GIT_ALLOW_PROTOCOL' not in env: 247 if 'GIT_ALLOW_PROTOCOL' not in env:
252 _setenv(env, 'GIT_ALLOW_PROTOCOL', 248 env['GIT_ALLOW_PROTOCOL'] = (
253 'file:git:http:https:ssh:persistent-http:persistent-https:sso:rpc') 249 'file:git:http:https:ssh:persistent-http:persistent-https:sso:rpc')
254 _setenv(env, 'GIT_HTTP_USER_AGENT', user_agent.git) 250 env['GIT_HTTP_USER_AGENT'] = user_agent.git
255 251
256 if project: 252 if project:
257 if not cwd: 253 if not cwd:
@@ -262,7 +258,7 @@ class GitCommand(object):
262 command = [GIT] 258 command = [GIT]
263 if bare: 259 if bare:
264 if gitdir: 260 if gitdir:
265 _setenv(env, GIT_DIR, gitdir) 261 env[GIT_DIR] = gitdir
266 cwd = None 262 cwd = None
267 command.append(cmdv[0]) 263 command.append(cmdv[0])
268 # Need to use the --progress flag for fetch/clone so output will be 264 # Need to use the --progress flag for fetch/clone so output will be