summaryrefslogtreecommitdiff
path: root/gbp/scripts/common/pq.py
diff options
context:
space:
mode:
authorbiao716.wang <biao716.wang@samsung.com>2023-05-25 11:36:00 +0900
committerbiao716.wang <biao716.wang@samsung.com>2023-06-13 17:40:51 +0900
commit78967eec718c92a49c5783beb31d844ac303c15f (patch)
tree98908329e5a25939c4d36252f942f5d37933adda /gbp/scripts/common/pq.py
parent95e33623ea4c69c1ce3360904f053d5a1a172ed3 (diff)
downloadgit-buildpackage-78967eec718c92a49c5783beb31d844ac303c15f.tar.gz
git-buildpackage-78967eec718c92a49c5783beb31d844ac303c15f.tar.bz2
git-buildpackage-78967eec718c92a49c5783beb31d844ac303c15f.zip
fix build error during gbs funtion test
https://github.com/agx/git-buildpackage/commit/1b5a47f4bda5d8809998750c3a35b4e02c8b2851 https://github.com/agx/git-buildpackage/commit/1b5a47f4bda5d8809998750c3a35b4e02c8b2851 modify patch file wrong encoding. https://github.com/agx/git-buildpackage/commit/c4bc6561c788f71b5131d0bd8e92478e83808200 pq: don't eagerly encode email headers https://github.com/agx/git-buildpackage/commit/9dc2129c4448416f43300ce859f1e1f4a1070048 pq: properly retry non-ascii charset on patch body encode https://github.com/agx/git-buildpackage/commit/04ae7d5654684d8077a4125c90e36f4195057fa9 git: Don't decode diff output https://github.com/agx/git-buildpackage/commit/c159d0ba16636bc3692b89555b258a3bc7907902 pq export: Write out patches as UTF-8 if necessary Change-Id: I6982c800361b8cc1ad4c16211fca450803e5eb02 Signed-off-by: biao716.wang <biao716.wang@samsung.com>
Diffstat (limited to 'gbp/scripts/common/pq.py')
-rw-r--r--gbp/scripts/common/pq.py30
1 files changed, 19 insertions, 11 deletions
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