diff --git a/pygit2.c b/pygit2.c index 2b24ef8..e781744 100644 --- a/pygit2.c +++ b/pygit2.c @@ -310,7 +310,10 @@ py_str_to_git_oid(PyObject *py_str, git_oid *oid) return 0; } -static PyObject* +#define git_oid_to_python(oid) \ + PyString_FromStringAndSize(oid.id, GIT_OID_RAWSZ) + +static PyObject * git_oid_to_py_str(const git_oid *oid) { char hex[GIT_OID_HEXSZ]; @@ -462,7 +465,7 @@ Repository_write(Repository *self, PyObject *args) if (err < 0) return Error_set_str(err, "failed to write data"); - return git_oid_to_py_str(&oid); + return git_oid_to_python(oid); } static PyObject * @@ -663,7 +666,7 @@ Repository_create_commit(Repository *self, PyObject *args) if (err < 0) return Error_set(err); - return git_oid_to_py_str(&oid); + return git_oid_to_python(oid); } static PyObject * @@ -697,7 +700,7 @@ Repository_create_tag(Repository *self, PyObject *args) if (err < 0) return NULL; - return git_oid_to_py_str(&oid); + return git_oid_to_python(oid); } static PyObject * @@ -1933,7 +1936,7 @@ Index_create_tree(Index *self) if (err < 0) return Error_set(err); - return git_oid_to_py_str(&oid); + return git_oid_to_python(oid); } static PyMethodDef Index_methods[] = { diff --git a/test/test_index.py b/test/test_index.py index 3c51792..6e73078 100644 --- a/test/test_index.py +++ b/test/test_index.py @@ -29,6 +29,7 @@ from __future__ import absolute_import from __future__ import unicode_literals +from binascii import b2a_hex import os import unittest @@ -91,7 +92,8 @@ class IndexTest(utils.RepoTestCase): self.assertTrue('bye.txt' in index) def test_create_tree(self): - sha = self.repo.index.create_tree() + oid = self.repo.index.create_tree() + sha = b2a_hex(oid).decode('ascii') self.assertEqual(sha, 'fd937514cb799514d4b81bb24c5fcfeb6472b245') def test_iter(self): diff --git a/test/test_repository.py b/test/test_repository.py index 28f2011..56a401f 100644 --- a/test/test_repository.py +++ b/test/test_repository.py @@ -64,8 +64,9 @@ class RepositoryTest(utils.BareRepoTestCase): # invalid object type self.assertRaises(GitError, self.repo.write, GIT_OBJ_ANY, data) - hex_sha = self.repo.write(GIT_OBJ_BLOB, data) - self.assertEqual(len(hex_sha), 40) + oid = self.repo.write(GIT_OBJ_BLOB, data) + self.assertEqual(type(oid), bytes) + self.assertEqual(len(oid), 20) def test_contains(self): self.assertRaises(TypeError, lambda: 123 in self.repo) @@ -117,8 +118,9 @@ class NewRepositoryTest(utils.NoRepoTestCase): def test_new_repo(self): repo = init_repository(self.temp_dir, False) - hex_sha = repo.write(GIT_OBJ_BLOB, "Test") - self.assertEqual(len(hex_sha), 40) + oid = repo.write(GIT_OBJ_BLOB, "Test") + self.assertEqual(type(oid), bytes) + self.assertEqual(len(oid), 20) assert os.path.exists(os.path.join(self._temp_dir, '.git'))