refs: resolving a direct ref returns the same object
When resolving a direct reference the same Python object is returned, with the refcount incremented by one. The reference is reloaded.
This commit is contained in:
parent
584a8b1473
commit
73a4a3a649
2
TODO.txt
2
TODO.txt
@ -7,6 +7,8 @@ References
|
|||||||
==========
|
==========
|
||||||
- Wrap missing functions: git_reference_foreach, git_reference_is_packed,
|
- Wrap missing functions: git_reference_foreach, git_reference_is_packed,
|
||||||
git_reference_reload
|
git_reference_reload
|
||||||
|
- Write more twisted tests. Like accessing a reference deleted by someone
|
||||||
|
else.
|
||||||
|
|
||||||
Other
|
Other
|
||||||
=========
|
=========
|
||||||
|
14
pygit2.c
14
pygit2.c
@ -2416,12 +2416,22 @@ Reference_resolve(Reference *self, PyObject *args)
|
|||||||
|
|
||||||
CHECK_REFERENCE(self);
|
CHECK_REFERENCE(self);
|
||||||
|
|
||||||
/* Resolve */
|
/* Direct: reload */
|
||||||
|
if (git_reference_type(self->reference) == GIT_REF_OID) {
|
||||||
|
err = git_reference_reload(self->reference);
|
||||||
|
if (err < 0) {
|
||||||
|
self->reference = NULL;
|
||||||
|
return Error_set(err);
|
||||||
|
}
|
||||||
|
Py_INCREF(self);
|
||||||
|
return (PyObject *)self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Symbolic: resolve */
|
||||||
err = git_reference_resolve(&c_reference, self->reference);
|
err = git_reference_resolve(&c_reference, self->reference);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return Error_set(err);
|
return Error_set(err);
|
||||||
|
|
||||||
/* Make an instance of Reference and return it */
|
|
||||||
return wrap_reference(c_reference);
|
return wrap_reference(c_reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,6 +143,12 @@ class ReferencesTest(utils.RepoTestCase):
|
|||||||
self.assertEqual(reference.hex, LAST_COMMIT)
|
self.assertEqual(reference.hex, LAST_COMMIT)
|
||||||
|
|
||||||
|
|
||||||
|
def test_reference_resolve_identity(self):
|
||||||
|
head = self.repo.lookup_reference('HEAD')
|
||||||
|
ref = head.resolve()
|
||||||
|
self.assertTrue(ref.resolve() is ref)
|
||||||
|
|
||||||
|
|
||||||
def test_create_reference(self):
|
def test_create_reference(self):
|
||||||
# We add a tag as a new reference that points to "origin/master"
|
# We add a tag as a new reference that points to "origin/master"
|
||||||
reference = self.repo.create_reference('refs/tags/version1',
|
reference = self.repo.create_reference('refs/tags/version1',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user