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- authored and praiskup committed May 6, 2024
1 parent da1b4c8 commit a2209bb
Show file tree
Hide file tree
Showing 2 changed files with 10 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
2 changes: 2 additions & 0 deletions releng/release-notes-next/scm-git_timestamps.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The SCM plugin's option `git_timestamps` has been updated to work with Python 3
and to handle Git repositories with non-Unicode data. ([PR#1355][])

0 comments on commit a2209bb

Please sign in to comment.