summaryrefslogtreecommitdiffstats
path: root/subcmds/sync.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 /subcmds/sync.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 'subcmds/sync.py')
-rw-r--r--subcmds/sync.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 1988cc72..0ac308e6 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -794,13 +794,13 @@ later is required to fix a server side protocol bug.
794 if branch.startswith(R_HEADS): 794 if branch.startswith(R_HEADS):
795 branch = branch[len(R_HEADS):] 795 branch = branch[len(R_HEADS):]
796 796
797 env = os.environ.copy() 797 if 'SYNC_TARGET' in os.environ:
798 if 'SYNC_TARGET' in env: 798 target = os.environ('SYNC_TARGET')
799 target = env['SYNC_TARGET']
800 [success, manifest_str] = server.GetApprovedManifest(branch, target) 799 [success, manifest_str] = server.GetApprovedManifest(branch, target)
801 elif 'TARGET_PRODUCT' in env and 'TARGET_BUILD_VARIANT' in env: 800 elif ('TARGET_PRODUCT' in os.environ and
802 target = '%s-%s' % (env['TARGET_PRODUCT'], 801 'TARGET_BUILD_VARIANT' in os.environ):
803 env['TARGET_BUILD_VARIANT']) 802 target = '%s-%s' % (os.environ('TARGET_PRODUCT'),
803 os.environ('TARGET_BUILD_VARIANT'))
804 [success, manifest_str] = server.GetApprovedManifest(branch, target) 804 [success, manifest_str] = server.GetApprovedManifest(branch, target)
805 else: 805 else:
806 [success, manifest_str] = server.GetApprovedManifest(branch) 806 [success, manifest_str] = server.GetApprovedManifest(branch)
@@ -1111,8 +1111,8 @@ def _VerifyTag(project):
1111 return False 1111 return False
1112 1112
1113 env = os.environ.copy() 1113 env = os.environ.copy()
1114 env['GIT_DIR'] = project.gitdir.encode() 1114 env['GIT_DIR'] = project.gitdir
1115 env['GNUPGHOME'] = gpg_dir.encode() 1115 env['GNUPGHOME'] = gpg_dir
1116 1116
1117 cmd = [GIT, 'tag', '-v', cur] 1117 cmd = [GIT, 'tag', '-v', cur]
1118 proc = subprocess.Popen(cmd, 1118 proc = subprocess.Popen(cmd,