From 3910044a9758a1eef79d708ffc9411737df807dc Mon Sep 17 00:00:00 2001 From: Frej Drejhammar Date: Fri, 10 Jul 2020 16:41:38 +0200 Subject: [PATCH] Avoid crash during rev-parse when the default encoding is ascii In some locales the default encoding is ascii in which case subprocess.check_output() will fail if it is given a non-ascii ref as one of the arguments. By forcing the ref to be utf8 we will avoid a crash while still behaving correctly when the default encoding is utf8. The credits for this fix go to Nikita Bazhinov for discovering the fix and Chris J Billington for explaining it. Co-Authored-By: Nikita Bazhinov Co-Authored-By: Chris J Billington --- hg2git.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hg2git.py b/hg2git.py index 3839f53..e94270b 100755 --- a/hg2git.py +++ b/hg2git.py @@ -132,7 +132,8 @@ def get_git_sha1(name,type='heads'): try: # use git-rev-parse to support packed refs ref="refs/%s/%s" % (type,name.decode('utf8')) - l=subprocess.check_output(["git", "rev-parse", "--verify", "--quiet", ref]) + l=subprocess.check_output(["git", "rev-parse", "--verify", + "--quiet", ref.encode('utf8')]) if l == None or len(l) == 0: return None return l[0:40]