From d6c1d49ef68f108368c597ea811f708cca5c3f79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20David=20Ib=C3=A1=C3=B1ez?= Date: Mon, 6 May 2013 23:16:50 +0200 Subject: [PATCH] Use git_{object,tree}_owner (#228) Note that libgit2's git_commit_owner is missing from the public interface, so we cannot use it. --- src/commit.c | 26 +++++++++++++++++++------- src/object.c | 5 +++-- src/repository.c | 14 -------------- src/tree.c | 4 ++-- src/types.h | 2 -- 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/commit.c b/src/commit.c index d87ec57..b8e8fbf 100644 --- a/src/commit.c +++ b/src/commit.c @@ -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; diff --git a/src/object.c b/src/object.c index f5f9c4f..67bff88 100644 --- a/src/object.c +++ b/src/object.c @@ -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; diff --git a/src/repository.c b/src/repository.c index 5b81e5d..eb9e2f6 100644 --- a/src/repository.c +++ b/src/repository.c @@ -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) { diff --git a/src/tree.c b/src/tree.c index f6a01cf..a3ac026 100644 --- a/src/tree.c +++ b/src/tree.c @@ -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); diff --git a/src/types.h b/src/types.h index a1a0105..fdc451e 100644 --- a/src/types.h +++ b/src/types.h @@ -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