From d689d9af9c22952ac0fc3054944e8024eb757ff8 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Wed, 6 May 2015 06:37:30 +1200 Subject: Issue #1451976: handle commits with non-utf8 text History may have commits with non utf8 text in them. Rather than forcing users to rebase, handle it gracefully. Change-Id: I6f6302c815b02234e27ee31f7ce87eab101b40ea Closes-Bug: #1451976 --- pbr/git.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pbr/git.py b/pbr/git.py index a64661f..ac9ccb1 100644 --- a/pbr/git.py +++ b/pbr/git.py @@ -50,7 +50,9 @@ def _run_shell_command(cmd, throw_on_error=False, buffer=True, env=None): "%s returned %d" % (cmd, output.returncode)) if len(out) == 0 or not out[0] or not out[0].strip(): return '' - return out[0].strip().decode('utf-8') + # Since we don't control the history, and forcing users to rebase arbitrary + # history to fix utf8 issues is harsh, decode with replace. + return out[0].strip().decode('utf-8', 'replace') def _run_git_command(cmd, git_dir, **kwargs): @@ -96,6 +98,8 @@ def _find_git_files(dirname='', git_dir=None): if git_dir: log.info("[pbr] In git context, generating filelist from git") file_list = _run_git_command(['ls-files', '-z'], git_dir) + # Users can fix utf8 issues locally with a single commit, so we are + # strict here. file_list = file_list.split(b'\x00'.decode('utf-8')) return [f for f in file_list if f] -- cgit v1.2.1