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:
parent
0b23ea3fea
commit
54dd6714f2
13
pygit2.c
13
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[] = {
|
||||
|
@ -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):
|
||||
|
@ -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'))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user