diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2017-12-16 00:15:57 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2018-01-12 13:18:02 +0100 |
commit | 4868442b8d724a24aaed681eda76559b0da0e0e3 (patch) | |
tree | 0d23f326bcbcc135019a67872d2003c5d22d9229 /gbp/git | |
parent | f1694df5c8948fbe3866fdfb92c947a2d380e640 (diff) |
gbp.git: Python compatibility fixes
Make gbp compatible with older versions of Python 3. As 'bytes' objects
do not support the '%' operator until Python v3.5 we introduce a
format_b() wrapper that handles this.
NOTE: This change should be reverted when Python v3.5 (or newer) has
been widely adopted.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'gbp/git')
-rw-r--r-- | gbp/git/fastimport.py | 11 | ||||
-rw-r--r-- | gbp/git/repository.py | 3 |
2 files changed, 8 insertions, 6 deletions
diff --git a/gbp/git/fastimport.py b/gbp/git/fastimport.py index 40433700..a9941036 100644 --- a/gbp/git/fastimport.py +++ b/gbp/git/fastimport.py @@ -20,6 +20,7 @@ import subprocess import time from gbp.errors import GbpError +from gbp.format import format_b from gbp.paths import to_bin @@ -48,7 +49,7 @@ class FastImport(object): "Invalid argument when spawning git fast-import: %s" % err) def _do_data(self, fd, size): - self._out.write(b"data %d\n" % size) + self._out.write(format_b(b"data %d\n", size)) while True: data = fd.read(self._bufsize) self._out.write(data) @@ -58,7 +59,7 @@ class FastImport(object): def _do_file(self, filename, mode, fd, size): name = b"/".join(to_bin(filename).split(b'/')[1:]) - self._out.write(b"M %d inline %s\n" % (mode, name)) + self._out.write(format_b(b"M %d inline %s\n", mode, name)) self._do_data(fd, size) def add_file(self, filename, fd, size, mode=m_regular): @@ -87,9 +88,9 @@ class FastImport(object): """ linktarget = to_bin(linktarget) linkname = to_bin(linkname) - self._out.write(b"M %d inline %s\n" % (self.m_symlink, linkname)) - self._out.write(b"data %d\n" % len(linktarget)) - self._out.write(b"%s\n" % linktarget) + self._out.write(format_b(b"M %d inline %s\n", self.m_symlink, linkname)) + self._out.write(format_b(b"data %d\n", len(linktarget))) + self._out.write(format_b(b"%s\n", linktarget)) def start_commit(self, branch, committer, msg): """ diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 3c858fa9..397ee9c9 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -24,6 +24,7 @@ from collections import defaultdict import gbp.log as log from gbp.errors import GbpError +from gbp.format import format_b from gbp.git.modifier import GitModifier from gbp.git.commit import GitCommit from gbp.git.errors import GitError @@ -1044,7 +1045,7 @@ class GitRepository(object): for mode, type_, sha1, name in contents: name = to_bin(name) - objs += b'%s %s %s\t%s\0' % (mode.encode(), type_.encode(), sha1.encode(), name) + objs += format_b(b'%s %s %s\t%s\0', mode.encode(), type_.encode(), sha1.encode(), name) sha1, err, ret = self._git_inout('mktree', args.args, |