Use git_{object,tree}_owner (#228)
Note that libgit2's git_commit_owner is missing from the public interface, so we cannot use it.
This commit is contained in:
parent
1a93cb0a89
commit
d6c1d49ef6
26
src/commit.c
26
src/commit.c
@ -31,6 +31,7 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "signature.h"
|
#include "signature.h"
|
||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
|
#include "object.h"
|
||||||
|
|
||||||
extern PyTypeObject TreeType;
|
extern PyTypeObject TreeType;
|
||||||
|
|
||||||
@ -149,32 +150,43 @@ Commit_tree__get__(Commit *commit)
|
|||||||
PyDoc_STRVAR(Commit_parents__doc__, "The list of parent commits.");
|
PyDoc_STRVAR(Commit_parents__doc__, "The list of parent commits.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Commit_parents__get__(Commit *commit)
|
Commit_parents__get__(Commit *self)
|
||||||
{
|
{
|
||||||
|
git_repository *repo;
|
||||||
unsigned int i, parent_count;
|
unsigned int i, parent_count;
|
||||||
const git_oid *parent_oid;
|
const git_oid *parent_oid;
|
||||||
PyObject *obj;
|
git_commit *parent;
|
||||||
|
int err;
|
||||||
|
PyObject *py_parent;
|
||||||
PyObject *list;
|
PyObject *list;
|
||||||
|
|
||||||
parent_count = git_commit_parentcount(commit->commit);
|
parent_count = git_commit_parentcount(self->commit);
|
||||||
list = PyList_New(parent_count);
|
list = PyList_New(parent_count);
|
||||||
if (!list)
|
if (!list)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
repo = git_object_owner((git_object*)self->commit);
|
||||||
for (i=0; i < parent_count; i++) {
|
for (i=0; i < parent_count; i++) {
|
||||||
parent_oid = git_commit_parent_id(commit->commit, i);
|
parent_oid = git_commit_parent_id(self->commit, i);
|
||||||
if (parent_oid == NULL) {
|
if (parent_oid == NULL) {
|
||||||
Py_DECREF(list);
|
Py_DECREF(list);
|
||||||
Error_set(GIT_ENOTFOUND);
|
Error_set(GIT_ENOTFOUND);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
obj = lookup_object(commit->repo, parent_oid, GIT_OBJ_COMMIT);
|
|
||||||
if (obj == NULL) {
|
err = git_commit_lookup(&parent, repo, parent_oid);
|
||||||
|
if (err < 0) {
|
||||||
|
Py_DECREF(list);
|
||||||
|
return Error_set_oid(err, parent_oid, GIT_OID_HEXSZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
py_parent = wrap_object((git_object*)parent, self->repo);
|
||||||
|
if (py_parent == NULL) {
|
||||||
Py_DECREF(list);
|
Py_DECREF(list);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyList_SET_ITEM(list, i, obj);
|
PyList_SET_ITEM(list, i, py_parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
@ -96,14 +96,15 @@ PyDoc_STRVAR(Object_read_raw__doc__,
|
|||||||
PyObject *
|
PyObject *
|
||||||
Object_read_raw(Object *self)
|
Object_read_raw(Object *self)
|
||||||
{
|
{
|
||||||
|
git_repository *repo;
|
||||||
const git_oid *oid;
|
const git_oid *oid;
|
||||||
git_odb_object *obj;
|
git_odb_object *obj;
|
||||||
PyObject *aux;
|
PyObject *aux;
|
||||||
|
|
||||||
|
repo = git_object_owner(self->obj);
|
||||||
oid = git_object_id(self->obj);
|
oid = git_object_id(self->obj);
|
||||||
assert(oid);
|
|
||||||
|
|
||||||
obj = Repository_read_raw(self->repo->repo, oid, GIT_OID_HEXSZ);
|
obj = Repository_read_raw(repo, oid, GIT_OID_HEXSZ);
|
||||||
if (obj == NULL)
|
if (obj == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -65,20 +65,6 @@ int_to_loose_object_type(int type_id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *
|
|
||||||
lookup_object(Repository *repo, const git_oid *oid, git_otype type)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
git_object *obj;
|
|
||||||
|
|
||||||
err = git_object_lookup_prefix(&obj, repo->repo, oid, GIT_OID_HEXSZ,
|
|
||||||
type);
|
|
||||||
if (err < 0)
|
|
||||||
return Error_set_oid(err, oid, GIT_OID_HEXSZ);
|
|
||||||
|
|
||||||
return wrap_object(obj, repo);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
Repository_init(Repository *self, PyObject *args, PyObject *kwds)
|
Repository_init(Repository *self, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
|
@ -292,7 +292,7 @@ Tree_diff(Tree *self, PyObject *args, PyObject *kwds)
|
|||||||
git_diff_list *diff;
|
git_diff_list *diff;
|
||||||
git_tree* tree = NULL;
|
git_tree* tree = NULL;
|
||||||
git_index* index;
|
git_index* index;
|
||||||
git_repository* repo;
|
git_repository *repo;
|
||||||
int err, empty_tree = 0;
|
int err, empty_tree = 0;
|
||||||
char *keywords[] = {"obj", "flags", "empty_tree", NULL};
|
char *keywords[] = {"obj", "flags", "empty_tree", NULL};
|
||||||
|
|
||||||
@ -303,7 +303,7 @@ Tree_diff(Tree *self, PyObject *args, PyObject *kwds)
|
|||||||
&py_obj, &opts.flags, &empty_tree))
|
&py_obj, &opts.flags, &empty_tree))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
repo = self->repo->repo;
|
repo = git_tree_owner(self->tree);
|
||||||
if (py_obj == NULL) {
|
if (py_obj == NULL) {
|
||||||
if (empty_tree > 0)
|
if (empty_tree > 0)
|
||||||
err = git_diff_tree_to_tree(&diff, repo, self->tree, NULL, &opts);
|
err = git_diff_tree_to_tree(&diff, repo, self->tree, NULL, &opts);
|
||||||
|
@ -193,6 +193,4 @@ typedef struct {
|
|||||||
SIMPLE_TYPE(Remote, git_remote, remote)
|
SIMPLE_TYPE(Remote, git_remote, remote)
|
||||||
|
|
||||||
|
|
||||||
PyObject* lookup_object(Repository *repo, const git_oid *oid, git_otype type);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user