Skip to content

Commit

Permalink
scm: Open stdout in text mode for Git timestamp subprocesses
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dm0- committed Apr 22, 2024
1 parent 4c92c9e commit e15d03d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions mock/py/mockbuild/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e15d03d

Please sign in to comment.