From f03e6162f99e4bfdd60c08168dabef3a1bdb1825 Mon Sep 17 00:00:00 2001 From: Craig Northway Date: Fri, 25 Jul 2014 11:53:57 +1000 Subject: [PATCH 1/4] Basic test for __unpack_args to verify unicode handling works (cherry picked from commit 8fa25b1cd5a82679c7b12d546b96c30cafed0559) Signed-off-by: David Black Conflicts: git/test/test_git.py --- git/test/test_git.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/git/test/test_git.py b/git/test/test_git.py index e67cb92b0..5d4756baf 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -5,8 +5,9 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php import os, sys -from git.test.lib import ( TestBase, - patch, +from git.test.lib import ( + TestBase, + patch, raises, assert_equal, assert_true, @@ -16,7 +17,7 @@ GitCommandError ) class TestGit(TestBase): - + @classmethod def setUp(cls): super(TestGit, cls).setUp() @@ -29,6 +30,14 @@ def test_call_process_calls_execute(self, git): assert_true(git.called) assert_equal(git.call_args, ((['git', 'version'],), {})) + def test_call_unpack_args_unicode(self): + args = Git._Git__unpack_args(u'Unicode' + unichr(40960)) + assert_equal(args, ['Unicode\xea\x80\x80']) + + def test_call_unpack_args(self): + args = Git._Git__unpack_args(['git', 'log', '--', u'Unicode' + unichr(40960)]) + assert_equal(args, ['git', 'log', '--', 'Unicode\xea\x80\x80']) + @raises(GitCommandError) def test_it_raises_errors(self): self.git.this_does_not_exist() @@ -58,7 +67,7 @@ def test_it_ignores_false_kwargs(self, git): # this_should_not_be_ignored=False implies it *should* be ignored output = self.git.version(pass_this_kwarg=False) assert_true("pass_this_kwarg" not in git.call_args[1]) - + def test_persistent_cat_file_command(self): # read header only import subprocess as sp @@ -67,37 +76,37 @@ def test_persistent_cat_file_command(self): g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n") g.stdin.flush() obj_info = g.stdout.readline() - + # read header + data g = self.git.cat_file(batch=True, istream=sp.PIPE,as_process=True) g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n") g.stdin.flush() obj_info_two = g.stdout.readline() assert obj_info == obj_info_two - + # read data - have to read it in one large chunk size = int(obj_info.split()[2]) data = g.stdout.read(size) terminating_newline = g.stdout.read(1) - + # now we should be able to read a new object g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n") g.stdin.flush() assert g.stdout.readline() == obj_info - - + + # same can be achived using the respective command functions hexsha, typename, size = self.git.get_object_header(hexsha) hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha) assert typename == typename_two and size == size_two - + def test_version(self): v = self.git.version_info assert isinstance(v, tuple) for n in v: assert isinstance(n, int) #END verify number types - + def test_cmd_override(self): prev_cmd = self.git.GIT_PYTHON_GIT_EXECUTABLE try: From eb52c96d7e849e68fda40e4fa7908434e7b0b022 Mon Sep 17 00:00:00 2001 From: Craig Northway Date: Fri, 18 Jul 2014 08:35:59 +1000 Subject: [PATCH 2/4] Fixing unicode types (cherry picked from commit ca2b901e7229fc5c793762fd4e4c1c38c5a78e80) --- git/cmd.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/git/cmd.py b/git/cmd.py index b3274dd8f..73126fba6 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -410,12 +410,16 @@ def transform_kwargs(self, split_single_char_options=False, **kwargs): @classmethod def __unpack_args(cls, arg_list): if not isinstance(arg_list, (list,tuple)): + if isinstance(arg_list, unicode): + return [arg_list.encode('utf-8')] return [ str(arg_list) ] outlist = list() for arg in arg_list: if isinstance(arg_list, (list, tuple)): outlist.extend(cls.__unpack_args( arg )) + elif isinstance(arg_list, unicode): + outlist.append(arg_list.encode('utf-8')) # END recursion else: outlist.append(str(arg)) From e8987f2746637cbe518e6fe5cf574a9f151472ed Mon Sep 17 00:00:00 2001 From: David Black Date: Wed, 12 Nov 2014 13:39:18 +1100 Subject: [PATCH 3/4] Switch http://github.com/gitpython-developers/gitdb.git to https://github.com/gitpython-developers/gitdb.git . Signed-off-by: David Black --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 533fc59f2..612c39d95 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "gitdb"] path = git/ext/gitdb - url = http://github.com/gitpython-developers/gitdb.git + url = https://github.com/gitpython-developers/gitdb.git From c390e223553964fc8577d6837caf19037c4cd6f6 Mon Sep 17 00:00:00 2001 From: David Black Date: Wed, 12 Nov 2014 15:50:15 +1100 Subject: [PATCH 4/4] Fix the Repo commit and tree methods to work with unicode revs. Signed-off-by: David Black --- git/repo/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git/repo/base.py b/git/repo/base.py index 8191b3057..a45d215ea 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -376,7 +376,7 @@ def commit(self, rev=None): if rev is None: return self.head.commit else: - return self.rev_parse(str(rev)+"^0") + return self.rev_parse(unicode(rev)+"^0") def iter_trees(self, *args, **kwargs): """:return: Iterator yielding Tree objects @@ -399,7 +399,7 @@ def tree(self, rev=None): if rev is None: return self.head.commit.tree else: - return self.rev_parse(str(rev)+"^{tree}") + return self.rev_parse(unicode(rev)+"^{tree}") def iter_commits(self, rev=None, paths='', **kwargs): """A list of Commit objects representing the history of a given ref/commit