Add Repository.expand_id()
As we allow users of the library to use short strings, we must expand them. This is however only available through a function in C. Expose that function from the repository to allow python code to get a full id from a short hex string.
This commit is contained in:
@@ -1433,6 +1433,24 @@ Repository_reset(Repository *self, PyObject* args)
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(Repository_expand_id__doc__,
|
||||||
|
"expand_id(hex) -> Oid\n"
|
||||||
|
"\n"
|
||||||
|
"Expand a string into a full Oid according to the objects in this repsitory.\n");
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
Repository_expand_id(Repository *self, PyObject *py_hex)
|
||||||
|
{
|
||||||
|
git_oid oid;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = py_oid_to_git_oid_expand(self->repo, py_hex, &oid);
|
||||||
|
if (err < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return git_oid_to_python(&oid);
|
||||||
|
}
|
||||||
|
|
||||||
PyMethodDef Repository_methods[] = {
|
PyMethodDef Repository_methods[] = {
|
||||||
METHOD(Repository, create_blob, METH_VARARGS),
|
METHOD(Repository, create_blob, METH_VARARGS),
|
||||||
METHOD(Repository, create_blob_fromworkdir, METH_VARARGS),
|
METHOD(Repository, create_blob_fromworkdir, METH_VARARGS),
|
||||||
@@ -1461,6 +1479,7 @@ PyMethodDef Repository_methods[] = {
|
|||||||
METHOD(Repository, listall_branches, METH_VARARGS),
|
METHOD(Repository, listall_branches, METH_VARARGS),
|
||||||
METHOD(Repository, create_branch, METH_VARARGS),
|
METHOD(Repository, create_branch, METH_VARARGS),
|
||||||
METHOD(Repository, reset, METH_VARARGS),
|
METHOD(Repository, reset, METH_VARARGS),
|
||||||
|
METHOD(Repository, expand_id, METH_O),
|
||||||
METHOD(Repository, _from_c, METH_VARARGS),
|
METHOD(Repository, _from_c, METH_VARARGS),
|
||||||
METHOD(Repository, _disown, METH_NOARGS),
|
METHOD(Repository, _disown, METH_NOARGS),
|
||||||
{NULL}
|
{NULL}
|
||||||
|
1
test/data/testrepo
Submodule
1
test/data/testrepo
Submodule
Submodule test/data/testrepo added at 2be5719152
@@ -156,6 +156,11 @@ class RepositoryTest(utils.BareRepoTestCase):
|
|||||||
commit.message)
|
commit.message)
|
||||||
self.assertRaises(ValueError, self.repo.__getitem__, too_short_prefix)
|
self.assertRaises(ValueError, self.repo.__getitem__, too_short_prefix)
|
||||||
|
|
||||||
|
def test_expand_id(self):
|
||||||
|
commit_sha = '5fe808e8953c12735680c257f56600cb0de44b10'
|
||||||
|
expanded = self.repo.expand_id(commit_sha[:7])
|
||||||
|
self.assertEqual(commit_sha, expanded.hex)
|
||||||
|
|
||||||
@unittest.skipIf(__pypy__ is not None, "skip refcounts checks in pypy")
|
@unittest.skipIf(__pypy__ is not None, "skip refcounts checks in pypy")
|
||||||
def test_lookup_commit_refcount(self):
|
def test_lookup_commit_refcount(self):
|
||||||
start = sys.getrefcount(self.repo)
|
start = sys.getrefcount(self.repo)
|
||||||
|
Reference in New Issue
Block a user