From e15d03ddad206dcfda599621410e638322cacc1b Mon Sep 17 00:00:00 2001 From: David Michael Date: Thu, 4 Apr 2024 14:27:48 -0400 Subject: [PATCH] scm: Open stdout in text mode for Git timestamp subprocesses Mock would fail when using SCM with Git timestamps from attempting to mix encoded text strings with raw bytes since these subprocesses weren't using an encoding for their output. Omit showing the patch along with the timestamp. It will break the encoding if the diff contains invalid UTF-8 sequences. --- mock/py/mockbuild/scm.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mock/py/mockbuild/scm.py b/mock/py/mockbuild/scm.py index 54301912b..77bdc4cd6 100644 --- a/mock/py/mockbuild/scm.py +++ b/mock/py/mockbuild/scm.py @@ -114,14 +114,18 @@ def adjust_git_timestamps(self): cwd_dir = util.pretty_getcwd() self.log.debug("Adjusting timestamps in %s", self.src_dir) os.chdir(self.src_dir) - proc = subprocess.Popen(['git', 'ls-files', '-z'], shell=False, stdout=subprocess.PIPE) + proc = subprocess.Popen( + ['git', 'ls-files', '-z'], + shell=False, stdout=subprocess.PIPE, universal_newlines=True, + ) for f in proc.communicate()[0].split('\0')[:-1]: rev = subprocess.Popen( - ['git', 'rev-list', 'HEAD', f], shell=False, stdout=subprocess.PIPE + ['git', 'rev-list', 'HEAD', f], + shell=False, stdout=subprocess.PIPE, universal_newlines=True, ).stdout.readlines()[0].rstrip('\n') ts = subprocess.Popen( - ['git', 'show', '--pretty=format:%ai', '--abbrev-commit', rev, f], - shell=False, stdout=subprocess.PIPE + ['git', 'show', '--pretty=format:%ai', '--no-patch', rev, f], + shell=False, stdout=subprocess.PIPE, universal_newlines=True, ).stdout.readlines()[0].rstrip('\n') subprocess.Popen(['touch', '-d', ts, f], shell=False) os.chdir(cwd_dir)