fix build error during gbs funtion test 56/293356/11
authorbiao716.wang <biao716.wang@samsung.com>
Thu, 25 May 2023 02:36:00 +0000 (11:36 +0900)
committerbiao716.wang <biao716.wang@samsung.com>
Tue, 13 Jun 2023 08:40:51 +0000 (17:40 +0900)
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>
gbp/deb/changelog.py
gbp/git/repository.py
gbp/pkg/__init__.py
gbp/rpm/__init__.py
gbp/scripts/common/buildpackage.py
gbp/scripts/common/pq.py

index a670332..912c13c 100644 (file)
@@ -93,12 +93,13 @@ class ChangeLog(object):
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
-        (output, errors) = cmd.communicate(self._contents.encode('utf-8'))
+        (output, errors) = cmd.communicate(self._contents.encode())
         if cmd.returncode:
             raise ParseChangeLogError("Failed to parse changelog. "
                                       "dpkg-parsechangelog said:\n%s" % errors.decode().strip())
         # Parse the result of dpkg-parsechangelog (which looks like
         # email headers)
+        output = output.decode()
         cp = email.message_from_string(output)
         try:
             if ':' in cp['Version']:
index d52d5c9..cb1b041 100644 (file)
@@ -144,7 +144,7 @@ class GitRepository(object):
         @param cwd: directory to swith to when running the command, defaults to I{self.path}
         @type cwd: C{str}
         @return: stdout, return code
-        @rtype: C{tuple} of C{list} of C{str} and C{int}
+        @rtype: C{tuple} of C{list} of C{bytestr} and C{int}
 
         @deprecated: use L{gbp.git.repository.GitRepository._git_inout} instead.
         """
@@ -178,7 +178,7 @@ class GitRepository(object):
         @param capture_stderr: whether to capture stderr
         @type capture_stderr: C{bool}
         @return: stdout, stderr, return code
-        @rtype: C{tuple} of C{str}, C{str}, C{int}
+        @rtype: C{tuple} of C{bytestr}, C{bytestr}, C{int}
         """
         if not cwd:
             cwd = self.path
@@ -960,7 +960,7 @@ class GitRepository(object):
             # Expect to have two filenames for renames and copies
             if status[0] in ['R', 'C']:
                 filepath = elements.pop(0) + b'\x00' + filepath
-            result[status].append(filepath)
+            result[status].append(filepath.decode())
 
         return result
 
@@ -1750,7 +1750,7 @@ class GitRepository(object):
         while len(file_fields) and file_fields[0] != b'':
             status = file_fields.pop(0).decode().strip()
             path = file_fields.pop(0)
-            files[status].append(path)
+            files[status].append(path.decode())
 
         return {'id': commitish,
                 'author': author,
@@ -1862,7 +1862,7 @@ class GitRepository(object):
             if status in ['R', 'C']:
                 result[status].append(filepath)
                 filepath = elements.pop(0)
-            result[status].append(filepath)
+            result[status].append(filepath.decode())
 
         return result
 #}
index 1103249..ee46ccb 100644 (file)
@@ -336,8 +336,6 @@ class UpstreamSource(object):
         """
         topdir_files = set()
         for typ, path in file_list:
-            #path is byte type, not str.
-            path = path.decode()
             split = re.sub('^(?:./|../)*', '', path).split('/')
             if len(split) == 1:
                 topdir_files.add((typ, path))
@@ -366,7 +364,7 @@ class UpstreamSource(object):
                     raise GbpError("Listing tar archive content failed")
                 for line in out.splitlines():
                     fields = line.split(None, 5)
-                    files.append((fields[0][0], fields[-1]))
+                    files.append((fields[0][0], fields[-1].decode()))
             else:
                 raise GbpError("Unsupported archive format %s, unable to "
                                "determine prefix for '%s'" %
index 0affa45..54e9e6a 100644 (file)
@@ -485,7 +485,7 @@ class SpecFile(object):
         indent_re = re.compile(r'^([a-z]+([0-9]+)?\s*:\s*)', flags=re.I)
         match = indent_re.match(str(insertafter))
         if not match:
-            match = indent_re.match(str(insertafter.__next__))
+            match = indent_re.match(str(insertafter.next))
         indent = 12 if not match else len(match.group(1))
         text = '%-*s%s\n' % (indent, '%s:' % tagname, value)
         if key in self._tags:
@@ -579,11 +579,11 @@ class SpecFile(object):
                                "which to update" % name)
             line = self._special_directives[name][0]['line']
             gbp.log.debug("Removing content of %s section" % name)
-            while line.__next__:
-                match = self.directive_re.match(str(line.__next__))
+            while line.next:
+                match = self.directive_re.match(str(line.next))
                 if match and match.group('name') in self.section_identifiers:
                     break
-                self._content.delete(line.__next__)
+                self._content.delete(line.next)
         else:
             gbp.log.debug("Adding %s section to the end of spec file" % name)
             line = self._content.append('%%%s\n' % name)
@@ -603,8 +603,8 @@ class SpecFile(object):
         text = ''
         if 'changelog' in self._special_directives:
             line = self._special_directives['changelog'][0]['line']
-            while line.__next__:
-                line = line.__next__
+            while line.next:
+                line = line.next
                 match = self.directive_re.match(str(line))
                 if match and match.group('name') in self.section_identifiers:
                     break
@@ -631,7 +631,7 @@ class SpecFile(object):
             if not macro['id'] in ignored:
                 macro_prev = self._delete_special_macro('patch', macro['id'])
                 # Remove surrounding if-else
-                macro_next = macro_prev.__next__
+                macro_next = macro_prev.next
                 if (str(macro_prev).startswith('%if') and
                         str(macro_next).startswith('%endif')):
                     self._content.delete(macro_next)
index 12eede9..df65826 100644 (file)
@@ -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:
index 05993d1..bd49e94 100644 (file)
@@ -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