Now Reference.target returns an Oid, not hex

If the reference is direct, of course.
This commit is contained in:
J. David Ibáñez
2013-04-20 09:03:13 +02:00
parent 7261f4e1e7
commit a3a928a513
2 changed files with 18 additions and 23 deletions

View File

@@ -204,18 +204,17 @@ Reference_target__get__(Reference *self)
CHECK_REFERENCE(self); CHECK_REFERENCE(self);
/* Get the target */ /* Case 1: Direct */
if (GIT_REF_OID == git_reference_type(self->reference)) { if (GIT_REF_OID == git_reference_type(self->reference))
return git_oid_to_py_str(git_reference_target(self->reference)); return git_oid_to_python(git_reference_target(self->reference));
} else {
/* Case 2: Symbolic */
c_name = git_reference_symbolic_target(self->reference); c_name = git_reference_symbolic_target(self->reference);
if (c_name == NULL) { if (c_name == NULL) {
PyErr_SetString(PyExc_ValueError, "no target available"); PyErr_SetString(PyExc_ValueError, "no target available");
return NULL; return NULL;
} }
}
/* Make a PyString and return it */
return to_path(c_name); return to_path(c_name);
} }
@@ -262,21 +261,17 @@ PyDoc_STRVAR(Reference_oid__doc__, "Object id.");
PyObject * PyObject *
Reference_oid__get__(Reference *self) Reference_oid__get__(Reference *self)
{ {
const git_oid *oid;
CHECK_REFERENCE(self); CHECK_REFERENCE(self);
/* Case 1: Direct */
if (GIT_REF_OID == git_reference_type(self->reference))
return git_oid_to_python(git_reference_target(self->reference));
/* Get the oid (only for "direct" references) */ /* Get the oid (only for "direct" references) */
oid = git_reference_target(self->reference);
if (oid == NULL) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"oid is only available if the reference is direct " "oid is only available if the reference is direct "
"(i.e. not symbolic)"); "(i.e. not symbolic)");
return NULL; return NULL;
}
/* Convert and return it */
return git_oid_to_python(oid);
} }
int int

View File

@@ -176,7 +176,7 @@ class ReferencesTest(utils.RepoTestCase):
self.assertTrue('refs/tags/version1' in refs) self.assertTrue('refs/tags/version1' in refs)
reference = self.repo.lookup_reference('refs/tags/version1') reference = self.repo.lookup_reference('refs/tags/version1')
self.assertEqual(reference.hex, LAST_COMMIT) self.assertEqual(reference.hex, LAST_COMMIT)
self.assertEqual(reference.target, LAST_COMMIT) self.assertEqual(reference.target.hex, LAST_COMMIT)
# try to create existing reference # try to create existing reference
self.assertRaises(ValueError, self.repo.create_reference, self.assertRaises(ValueError, self.repo.create_reference,