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:
J. David Ibáñez 2013-05-06 23:16:50 +02:00
parent 1a93cb0a89
commit d6c1d49ef6
5 changed files with 24 additions and 27 deletions

View File

@ -31,6 +31,7 @@
#include "utils.h"
#include "signature.h"
#include "commit.h"
#include "object.h"
extern PyTypeObject TreeType;
@ -149,32 +150,43 @@ Commit_tree__get__(Commit *commit)
PyDoc_STRVAR(Commit_parents__doc__, "The list of parent commits.");
PyObject *
Commit_parents__get__(Commit *commit)
Commit_parents__get__(Commit *self)
{
git_repository *repo;
unsigned int i, parent_count;
const git_oid *parent_oid;
PyObject *obj;
git_commit *parent;
int err;
PyObject *py_parent;
PyObject *list;
parent_count = git_commit_parentcount(commit->commit);
parent_count = git_commit_parentcount(self->commit);
list = PyList_New(parent_count);
if (!list)
return NULL;
repo = git_object_owner((git_object*)self->commit);
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) {
Py_DECREF(list);
Error_set(GIT_ENOTFOUND);
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);
return NULL;
}
PyList_SET_ITEM(list, i, obj);
PyList_SET_ITEM(list, i, py_parent);
}
return list;

View File

@ -96,14 +96,15 @@ PyDoc_STRVAR(Object_read_raw__doc__,
PyObject *
Object_read_raw(Object *self)
{
git_repository *repo;
const git_oid *oid;
git_odb_object *obj;
PyObject *aux;
repo = git_object_owner(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)
return NULL;

View File

@ -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
Repository_init(Repository *self, PyObject *args, PyObject *kwds)
{

View File

@ -292,7 +292,7 @@ Tree_diff(Tree *self, PyObject *args, PyObject *kwds)
git_diff_list *diff;
git_tree* tree = NULL;
git_index* index;
git_repository* repo;
git_repository *repo;
int err, empty_tree = 0;
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))
return NULL;
repo = self->repo->repo;
repo = git_tree_owner(self->tree);
if (py_obj == NULL) {
if (empty_tree > 0)
err = git_diff_tree_to_tree(&diff, repo, self->tree, NULL, &opts);

View File

@ -193,6 +193,4 @@ typedef struct {
SIMPLE_TYPE(Remote, git_remote, remote)
PyObject* lookup_object(Repository *repo, const git_oid *oid, git_otype type);
#endif