Use basic types for objects and grouped types into groups
This commit is contained in:
@@ -32,39 +32,47 @@
|
|||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
|
||||||
/* Python objects */
|
/*
|
||||||
|
* Python objects
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
/* git_repository */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
PyObject *index; /* It will be None for a bare repository */
|
PyObject *index; /* It will be None for a bare repository */
|
||||||
PyObject *config;
|
PyObject *config; /* It will be None for a bare repository */
|
||||||
} Repository;
|
} Repository;
|
||||||
|
|
||||||
/* The structs for some of the object subtypes are identical except for
|
|
||||||
* the type of their object pointers. */
|
#define SIMPLE_TYPE(_name, _ptr_type, _ptr_name) \
|
||||||
#define OBJECT_STRUCT(_name, _ptr_type, _ptr_name) \
|
|
||||||
typedef struct {\
|
typedef struct {\
|
||||||
PyObject_HEAD\
|
PyObject_HEAD\
|
||||||
Repository *repo;\
|
Repository *repo;\
|
||||||
_ptr_type *_ptr_name;\
|
_ptr_type *_ptr_name;\
|
||||||
} _name;
|
} _name;
|
||||||
|
|
||||||
OBJECT_STRUCT(Object, git_object, obj)
|
|
||||||
OBJECT_STRUCT(Commit, git_commit, commit)
|
|
||||||
OBJECT_STRUCT(Tree, git_tree, tree)
|
|
||||||
OBJECT_STRUCT(TreeBuilder, git_treebuilder, bld)
|
|
||||||
OBJECT_STRUCT(Blob, git_blob, blob)
|
|
||||||
OBJECT_STRUCT(Tag, git_tag, tag)
|
|
||||||
OBJECT_STRUCT(Index, git_index, index)
|
|
||||||
OBJECT_STRUCT(Walker, git_revwalk, walk)
|
|
||||||
OBJECT_STRUCT(Remote, git_remote, remote)
|
|
||||||
OBJECT_STRUCT(Diff, git_diff_list, list)
|
|
||||||
|
|
||||||
|
/* git object types
|
||||||
|
*
|
||||||
|
* The structs for some of the object subtypes are identical except for
|
||||||
|
* the type of their object pointers. */
|
||||||
|
SIMPLE_TYPE(Object, git_object, obj)
|
||||||
|
SIMPLE_TYPE(Commit, git_commit, commit)
|
||||||
|
SIMPLE_TYPE(Tree, git_tree, tree)
|
||||||
|
SIMPLE_TYPE(Blob, git_blob, blob)
|
||||||
|
SIMPLE_TYPE(Tag, git_tag, tag)
|
||||||
|
|
||||||
|
|
||||||
|
/* git_config */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
git_config* config;
|
git_config* config;
|
||||||
} Config;
|
} Config;
|
||||||
|
|
||||||
|
|
||||||
|
/* git_note */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
Repository *repo;
|
Repository *repo;
|
||||||
@@ -79,9 +87,12 @@ typedef struct {
|
|||||||
char* ref;
|
char* ref;
|
||||||
} NoteIter;
|
} NoteIter;
|
||||||
|
|
||||||
|
|
||||||
|
/* git _diff */
|
||||||
|
SIMPLE_TYPE(Diff, git_diff_list, list)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
|
|
||||||
Diff* diff;
|
Diff* diff;
|
||||||
size_t i;
|
size_t i;
|
||||||
size_t n;
|
size_t n;
|
||||||
@@ -98,12 +109,6 @@ typedef struct {
|
|||||||
unsigned similarity;
|
unsigned similarity;
|
||||||
} Patch;
|
} Patch;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
PyObject_HEAD
|
|
||||||
PyObject *owner; /* Tree or TreeBuilder */
|
|
||||||
const git_tree_entry *entry;
|
|
||||||
} TreeEntry;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
PyObject* lines;
|
PyObject* lines;
|
||||||
@@ -113,12 +118,26 @@ typedef struct {
|
|||||||
int new_lines;
|
int new_lines;
|
||||||
} Hunk;
|
} Hunk;
|
||||||
|
|
||||||
|
|
||||||
|
/* git_tree_walk , git_treebuilder*/
|
||||||
|
SIMPLE_TYPE(TreeBuilder, git_treebuilder, bld)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PyObject_HEAD
|
||||||
|
PyObject *owner; /* Tree or TreeBuilder */
|
||||||
|
const git_tree_entry *entry;
|
||||||
|
} TreeEntry;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
Tree *owner;
|
Tree *owner;
|
||||||
int i;
|
int i;
|
||||||
} TreeIter;
|
} TreeIter;
|
||||||
|
|
||||||
|
|
||||||
|
/* git_index */
|
||||||
|
SIMPLE_TYPE(Index, git_index, index)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
const git_index_entry *entry;
|
const git_index_entry *entry;
|
||||||
@@ -130,6 +149,10 @@ typedef struct {
|
|||||||
int i;
|
int i;
|
||||||
} IndexIter;
|
} IndexIter;
|
||||||
|
|
||||||
|
|
||||||
|
/* git_reference, git_reflog */
|
||||||
|
SIMPLE_TYPE(Walker, git_revwalk, walk)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
git_reference *reference;
|
git_reference *reference;
|
||||||
@@ -137,9 +160,9 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
PyObject *oid_old;
|
git_signature *signature;
|
||||||
PyObject *oid_new;
|
char *oid_old;
|
||||||
PyObject *committer;
|
char *oid_new;
|
||||||
char *message;
|
char *message;
|
||||||
} RefLogEntry;
|
} RefLogEntry;
|
||||||
|
|
||||||
@@ -151,6 +174,7 @@ typedef struct {
|
|||||||
} RefLogIter;
|
} RefLogIter;
|
||||||
|
|
||||||
|
|
||||||
|
/* git_signature */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
Object *obj;
|
Object *obj;
|
||||||
@@ -159,6 +183,10 @@ typedef struct {
|
|||||||
} Signature;
|
} Signature;
|
||||||
|
|
||||||
|
|
||||||
|
/* git_remote */
|
||||||
|
SIMPLE_TYPE(Remote, git_remote, remote)
|
||||||
|
|
||||||
|
|
||||||
PyObject*
|
PyObject*
|
||||||
lookup_object_prefix(Repository *repo, const git_oid *oid, size_t len,
|
lookup_object_prefix(Repository *repo, const git_oid *oid, size_t len,
|
||||||
git_otype type);
|
git_otype type);
|
||||||
|
@@ -47,40 +47,24 @@ void RefLogIter_dealloc(RefLogIter *self)
|
|||||||
PyObject_Del(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* RefLogIter_iternext(PyObject *self)
|
PyObject* RefLogIter_iternext(RefLogIter *self)
|
||||||
{
|
{
|
||||||
RefLogIter *p = (RefLogIter *) self;
|
|
||||||
const git_reflog_entry *entry;
|
const git_reflog_entry *entry;
|
||||||
char oid_old[40], oid_new[40];
|
RefLogEntry *py_entry;
|
||||||
|
|
||||||
if (p->i < p->size) {
|
if (self->i < self->size) {
|
||||||
RefLogEntry *py_entry;
|
entry = git_reflog_entry_byindex(self->reflog, self->i);
|
||||||
git_signature *signature;
|
py_entry = PyObject_New(RefLogEntry, &RefLogEntryType);
|
||||||
|
|
||||||
entry = git_reflog_entry_byindex(p->reflog, p->i);
|
|
||||||
py_entry = (RefLogEntry*) PyType_GenericNew(&RefLogEntryType, NULL,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
git_oid_fmt(oid_old, git_reflog_entry_id_old(entry));
|
|
||||||
git_oid_fmt(oid_new, git_reflog_entry_id_new(entry));
|
|
||||||
|
|
||||||
py_entry->oid_new = PyUnicode_FromStringAndSize(oid_new, 40);
|
|
||||||
py_entry->oid_old = PyUnicode_FromStringAndSize(oid_old, 40);
|
|
||||||
|
|
||||||
|
py_entry->oid_old = git_oid_allocfmt(git_reflog_entry_id_old(entry));
|
||||||
|
py_entry->oid_new = git_oid_allocfmt(git_reflog_entry_id_new(entry));
|
||||||
py_entry->message = strdup(git_reflog_entry_message(entry));
|
py_entry->message = strdup(git_reflog_entry_message(entry));
|
||||||
|
py_entry->signature = git_signature_dup(
|
||||||
|
git_reflog_entry_committer(entry));
|
||||||
|
|
||||||
signature = git_signature_dup(
|
++(self->i);
|
||||||
git_reflog_entry_committer(entry)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (signature != NULL)
|
|
||||||
py_entry->committer = build_signature(
|
|
||||||
(Object*)py_entry, signature, "utf-8");
|
|
||||||
|
|
||||||
++(p->i);
|
|
||||||
|
|
||||||
return (PyObject*) py_entry;
|
return (PyObject*) py_entry;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PyErr_SetNone(PyExc_StopIteration);
|
PyErr_SetNone(PyExc_StopIteration);
|
||||||
@@ -383,13 +367,23 @@ Reference_log(Reference *self)
|
|||||||
return (PyObject*)iter;
|
return (PyObject*)iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PyDoc_STRVAR(RefLogEntry_committer__doc__, "Committer.");
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
RefLogEntry_committer__get__(RefLogEntry *self)
|
||||||
|
{
|
||||||
|
return build_signature((Object*) self, self->signature, "utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
RefLogEntry_init(RefLogEntry *self, PyObject *args, PyObject *kwds)
|
RefLogEntry_init(RefLogEntry *self, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
self->oid_old = Py_None;
|
self->oid_old = NULL;
|
||||||
self->oid_new = Py_None;
|
self->oid_new = NULL;
|
||||||
self->message = "";
|
self->message = NULL;
|
||||||
self->committer = Py_None;
|
self->signature = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -398,18 +392,22 @@ RefLogEntry_init(RefLogEntry *self, PyObject *args, PyObject *kwds)
|
|||||||
static void
|
static void
|
||||||
RefLogEntry_dealloc(RefLogEntry *self)
|
RefLogEntry_dealloc(RefLogEntry *self)
|
||||||
{
|
{
|
||||||
Py_CLEAR(self->oid_old);
|
free(self->oid_old);
|
||||||
Py_CLEAR(self->oid_new);
|
free(self->oid_new);
|
||||||
Py_CLEAR(self->committer);
|
|
||||||
free(self->message);
|
free(self->message);
|
||||||
|
git_signature_free(self->signature);
|
||||||
PyObject_Del(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyMemberDef RefLogEntry_members[] = {
|
PyMemberDef RefLogEntry_members[] = {
|
||||||
MEMBER(RefLogEntry, oid_new, T_OBJECT, "New oid."),
|
MEMBER(RefLogEntry, oid_new, T_STRING, "New oid."),
|
||||||
MEMBER(RefLogEntry, oid_old, T_OBJECT, "Old oid."),
|
MEMBER(RefLogEntry, oid_old, T_STRING, "Old oid."),
|
||||||
MEMBER(RefLogEntry, message, T_STRING, "Message."),
|
MEMBER(RefLogEntry, message, T_STRING, "Message."),
|
||||||
MEMBER(RefLogEntry, committer, T_OBJECT, "Committer."),
|
{NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
PyGetSetDef RefLogEntry_getseters[] = {
|
||||||
|
GETTER(RefLogEntry, committer),
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user