diff --git a/script/git-export-patches b/script/git-export-patches index f40082806a1b0..bb76b29513b53 100755 --- a/script/git-export-patches +++ b/script/git-export-patches @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python import argparse import sys diff --git a/script/git-import-patches b/script/git-import-patches index 1d18a9ae2cc69..053682f982d33 100755 --- a/script/git-import-patches +++ b/script/git-import-patches @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python import argparse import sys diff --git a/script/lib/git.py b/script/lib/git.py index cb8f7434dd630..429b2e4f866ce 100644 --- a/script/lib/git.py +++ b/script/lib/git.py @@ -229,6 +229,14 @@ def remove_patch_filename(patch): force_keep_next_line = l.startswith('Subject: ') +def to_utf8(patch): + """Python 2/3 compatibility: unicode has been renamed to str in Python3""" + if sys.version_info[0] >= 3: + return str(patch, "utf-8") + else: + return unicode(patch, "utf-8") + + def export_patches(repo, out_dir, patch_range=None, dry_run=False): if patch_range is None: patch_range, num_patches = guess_base_commit(repo) @@ -250,7 +258,7 @@ def export_patches(repo, out_dir, patch_range=None, dry_run=False): for patch in patches: filename = get_file_name(patch) filepath = posixpath.join(out_dir, filename) - existing_patch = unicode(io.open(filepath, 'rb').read(), "utf-8") + existing_patch = to_utf8(io.open(filepath, 'rb').read()) formatted_patch = join_patch(patch) if formatted_patch != existing_patch: bad_patches.append(filename)