diff options
Diffstat (limited to 'gbp/scripts/common')
-rw-r--r-- | gbp/scripts/common/buildpackage.py | 2 | ||||
-rw-r--r-- | gbp/scripts/common/pq.py | 30 |
2 files changed, 20 insertions, 12 deletions
diff --git a/gbp/scripts/common/buildpackage.py b/gbp/scripts/common/buildpackage.py index 12eede9e..df65826e 100644 --- a/gbp/scripts/common/buildpackage.py +++ b/gbp/scripts/common/buildpackage.py @@ -150,7 +150,7 @@ def dump_tree(repo, export_dir, treeish, with_submodules, recursive=True): if recursive: paths = '' else: - paths = ["'%s'" % nam.decode() for _mod, typ, _sha, nam in + paths = ['%s' % nam.decode() for _mod, typ, _sha, nam in repo.list_tree(treeish) if typ == 'blob'] try: diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py index 05993d1d..bd49e94d 100644 --- a/gbp/scripts/common/pq.py +++ b/gbp/scripts/common/pq.py @@ -28,6 +28,7 @@ import time from email.message import Message from email.header import Header from email.charset import Charset, QP +from email.policy import Compat32 from gbp.git import GitRepositoryError from gbp.git.modifier import GitModifier, GitTz @@ -182,7 +183,6 @@ def patch_path_filter(file_status, exclude_regex=None): include_paths = [] for file_list in list(file_status.values()): for fname in file_list: - fname = fname.decode() if not re.match(exclude_regex, fname): include_paths.append(fname) else: @@ -209,27 +209,35 @@ def write_patch_file(filename, commit_info, diff): # Git compat: put name in quotes if special characters found if re.search("[,.@()\[\]\\\:;]", name): name = '"%s"' % name - from_header = Header(name.encode('utf-8'), charset, 77, 'from') - from_header.append(email.encode('utf-8')) + from_header = Header(header_name='from') + try: + from_header.append(name, 'us-ascii') + except UnicodeDecodeError: + from_header.append(name, charset) + from_header.append('<%s>' % email) msg['From'] = from_header date = commit_info['author'].datetime datestr = date.strftime('%a, %-d %b %Y %H:%M:%S %z') - msg['Date'] = Header(datestr.encode('utf-8'), charset, 77, 'date') - msg['Subject'] = Header(commit_info['subject'].encode('utf-8'), - charset, 77, 'subject') + msg['Date'] = Header(datestr, 'us-ascii', 'date') + subject_header = Header(header_name='subject') + try: + subject_header.append(commit_info['subject'], 'us-ascii') + except UnicodeDecodeError: + subject_header.append(commit_info['subject'], charset) + msg['Subject'] = subject_header # Write message body if commit_info['body']: # Strip extra linefeeds body = commit_info['body'].rstrip() + '\n' try: - msg.set_payload(body.encode('ascii')) - except UnicodeDecodeError: + msg.set_payload(body.encode('us-ascii')) + except UnicodeEncodeError: msg.set_payload(body, charset) - patch.write(msg.as_string(unixfrom=False).encode('utf-8')) - + policy = Compat32(max_line_length=77) + patch.write(msg.as_bytes(unixfrom=False, policy=policy)) # Write diff patch.write(b'---\n') - patch.write(diff.encode()) + patch.write(diff) except IOError as err: raise GbpError('Unable to create patch file: %s' % err) return filename |