Methods to create objects return raw oid

Now methods that create new objects return the raw oid instead of the
hexadecimal form.
This commit is contained in:
J. David Ibáñez 2011-09-02 15:43:44 +02:00
parent 0b23ea3fea
commit 54dd6714f2
3 changed files with 17 additions and 10 deletions

@ -310,7 +310,10 @@ py_str_to_git_oid(PyObject *py_str, git_oid *oid)
return 0; 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) git_oid_to_py_str(const git_oid *oid)
{ {
char hex[GIT_OID_HEXSZ]; char hex[GIT_OID_HEXSZ];
@ -462,7 +465,7 @@ Repository_write(Repository *self, PyObject *args)
if (err < 0) if (err < 0)
return Error_set_str(err, "failed to write data"); return Error_set_str(err, "failed to write data");
return git_oid_to_py_str(&oid); return git_oid_to_python(oid);
} }
static PyObject * static PyObject *
@ -663,7 +666,7 @@ Repository_create_commit(Repository *self, PyObject *args)
if (err < 0) if (err < 0)
return Error_set(err); return Error_set(err);
return git_oid_to_py_str(&oid); return git_oid_to_python(oid);
} }
static PyObject * static PyObject *
@ -697,7 +700,7 @@ Repository_create_tag(Repository *self, PyObject *args)
if (err < 0) if (err < 0)
return NULL; return NULL;
return git_oid_to_py_str(&oid); return git_oid_to_python(oid);
} }
static PyObject * static PyObject *
@ -1933,7 +1936,7 @@ Index_create_tree(Index *self)
if (err < 0) if (err < 0)
return Error_set(err); return Error_set(err);
return git_oid_to_py_str(&oid); return git_oid_to_python(oid);
} }
static PyMethodDef Index_methods[] = { static PyMethodDef Index_methods[] = {

@ -29,6 +29,7 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import unicode_literals from __future__ import unicode_literals
from binascii import b2a_hex
import os import os
import unittest import unittest
@ -91,7 +92,8 @@ class IndexTest(utils.RepoTestCase):
self.assertTrue('bye.txt' in index) self.assertTrue('bye.txt' in index)
def test_create_tree(self): 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') self.assertEqual(sha, 'fd937514cb799514d4b81bb24c5fcfeb6472b245')
def test_iter(self): def test_iter(self):

@ -64,8 +64,9 @@ class RepositoryTest(utils.BareRepoTestCase):
# invalid object type # invalid object type
self.assertRaises(GitError, self.repo.write, GIT_OBJ_ANY, data) self.assertRaises(GitError, self.repo.write, GIT_OBJ_ANY, data)
hex_sha = self.repo.write(GIT_OBJ_BLOB, data) oid = self.repo.write(GIT_OBJ_BLOB, data)
self.assertEqual(len(hex_sha), 40) self.assertEqual(type(oid), bytes)
self.assertEqual(len(oid), 20)
def test_contains(self): def test_contains(self):
self.assertRaises(TypeError, lambda: 123 in self.repo) self.assertRaises(TypeError, lambda: 123 in self.repo)
@ -117,8 +118,9 @@ class NewRepositoryTest(utils.NoRepoTestCase):
def test_new_repo(self): def test_new_repo(self):
repo = init_repository(self.temp_dir, False) repo = init_repository(self.temp_dir, False)
hex_sha = repo.write(GIT_OBJ_BLOB, "Test") oid = repo.write(GIT_OBJ_BLOB, "Test")
self.assertEqual(len(hex_sha), 40) self.assertEqual(type(oid), bytes)
self.assertEqual(len(oid), 20)
assert os.path.exists(os.path.join(self._temp_dir, '.git')) assert os.path.exists(os.path.join(self._temp_dir, '.git'))