Define the METHOD macro and deploy it
This commit is contained in:
parent
bf81dfe193
commit
6a5e4879d9
@ -96,7 +96,10 @@ char * py_str_to_c_str(PyObject *value, const char *encoding);
|
|||||||
py_str_to_c_str(py_path, Py_FileSystemDefaultEncoding)
|
py_str_to_c_str(py_path, Py_FileSystemDefaultEncoding)
|
||||||
|
|
||||||
|
|
||||||
/* Helpers to make shorter PyGetSetDef blocks */
|
/* Helpers to make shorter PyMethodDef and PyGetSetDef blocks */
|
||||||
|
#define METHOD(type, name, args)\
|
||||||
|
{#name, (PyCFunction) type ## _ ## name, args, type ## _ ## name ## __doc__}
|
||||||
|
|
||||||
#define GETTER(type, attr)\
|
#define GETTER(type, attr)\
|
||||||
{#attr, (getter) type ## _ ## attr ## __get__, NULL,\
|
{#attr, (getter) type ## _ ## attr ## __get__, NULL,\
|
||||||
type ## _ ## attr ## __doc__, NULL}
|
type ## _ ## attr ## __doc__, NULL}
|
||||||
|
@ -46,8 +46,7 @@ Index_init(Index *self, PyObject *args, PyObject *kwds)
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (kwds) {
|
if (kwds) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError, "Index takes no keyword arguments");
|
||||||
"Index takes no keyword arguments");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +78,7 @@ Index_traverse(Index *self, visitproc visit, void *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyDoc_STRVAR(Index_add__doc__,
|
PyDoc_STRVAR(Index_add__doc__,
|
||||||
"add(path)\n\n"
|
"add(path)\n\n"
|
||||||
"Add or update an index entry from a file in disk.");
|
"Add or update an index entry from a file in disk.");
|
||||||
@ -99,6 +99,7 @@ Index_add(Index *self, PyObject *args)
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyDoc_STRVAR(Index_clear__doc__,
|
PyDoc_STRVAR(Index_clear__doc__,
|
||||||
"clear()\n\n"
|
"clear()\n\n"
|
||||||
"Clear the contents (all the entries) of an index object.");
|
"Clear the contents (all the entries) of an index object.");
|
||||||
@ -160,13 +161,14 @@ Index_diff(Index *self, PyObject *args)
|
|||||||
return (PyObject*)py_diff;
|
return (PyObject*)py_diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(Index_find__doc__,
|
|
||||||
|
PyDoc_STRVAR(Index__find__doc__,
|
||||||
"_find(path) -> integer\n\n"
|
"_find(path) -> integer\n\n"
|
||||||
"Find the first index of any entries which point to given path in the "
|
"Find the first index of any entries which point to given path in the "
|
||||||
"index file.");
|
"index file.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Index_find(Index *self, PyObject *py_path)
|
Index__find(Index *self, PyObject *py_path)
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
size_t idx;
|
size_t idx;
|
||||||
@ -416,17 +418,15 @@ Index_write_tree(Index *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyMethodDef Index_methods[] = {
|
PyMethodDef Index_methods[] = {
|
||||||
{"add", (PyCFunction)Index_add, METH_VARARGS, Index_add__doc__},
|
METHOD(Index, add, METH_VARARGS),
|
||||||
{"remove", (PyCFunction)Index_remove, METH_VARARGS, Index_remove__doc__},
|
METHOD(Index, remove, METH_VARARGS),
|
||||||
{"clear", (PyCFunction)Index_clear, METH_NOARGS, Index_clear__doc__},
|
METHOD(Index, clear, METH_NOARGS),
|
||||||
{"diff", (PyCFunction)Index_diff, METH_VARARGS, Index_diff__doc__},
|
METHOD(Index, diff, METH_VARARGS),
|
||||||
{"_find", (PyCFunction)Index_find, METH_O, Index_find__doc__},
|
METHOD(Index, _find, METH_O),
|
||||||
{"read", (PyCFunction)Index_read, METH_NOARGS, Index_read__doc__},
|
METHOD(Index, read, METH_NOARGS),
|
||||||
{"write", (PyCFunction)Index_write, METH_NOARGS, Index_write__doc__},
|
METHOD(Index, write, METH_NOARGS),
|
||||||
{"read_tree", (PyCFunction)Index_read_tree, METH_O,
|
METHOD(Index, read_tree, METH_O),
|
||||||
Index_read_tree__doc__},
|
METHOD(Index, write_tree, METH_NOARGS),
|
||||||
{"write_tree", (PyCFunction)Index_write_tree, METH_NOARGS,
|
|
||||||
Index_write_tree__doc__},
|
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -550,43 +550,47 @@ IndexEntry_dealloc(IndexEntry *self)
|
|||||||
PyObject_Del(self);
|
PyObject_Del(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyDoc_STRVAR(IndexEntry_mode__doc__, "Mode.");
|
PyDoc_STRVAR(IndexEntry_mode__doc__, "Mode.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
IndexEntry_get_mode(IndexEntry *self)
|
IndexEntry_mode__get__(IndexEntry *self)
|
||||||
{
|
{
|
||||||
return PyInt_FromLong(self->entry->mode);
|
return PyInt_FromLong(self->entry->mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyDoc_STRVAR(IndexEntry_path__doc__, "Path.");
|
PyDoc_STRVAR(IndexEntry_path__doc__, "Path.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
IndexEntry_get_path(IndexEntry *self)
|
IndexEntry_path__get__(IndexEntry *self)
|
||||||
{
|
{
|
||||||
return to_path(self->entry->path);
|
return to_path(self->entry->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyDoc_STRVAR(IndexEntry_oid__doc__, "Object id.");
|
PyDoc_STRVAR(IndexEntry_oid__doc__, "Object id.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
IndexEntry_get_oid(IndexEntry *self)
|
IndexEntry_oid__get__(IndexEntry *self)
|
||||||
{
|
{
|
||||||
return git_oid_to_python(self->entry->oid.id);
|
return git_oid_to_python(self->entry->oid.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyDoc_STRVAR(IndexEntry_hex__doc__, "Hex id.");
|
PyDoc_STRVAR(IndexEntry_hex__doc__, "Hex id.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
IndexEntry_get_hex(IndexEntry *self)
|
IndexEntry_hex__get__(IndexEntry *self)
|
||||||
{
|
{
|
||||||
return git_oid_to_py_str(&self->entry->oid);
|
return git_oid_to_py_str(&self->entry->oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyGetSetDef IndexEntry_getseters[] = {
|
PyGetSetDef IndexEntry_getseters[] = {
|
||||||
{"mode", (getter)IndexEntry_get_mode, NULL, IndexEntry_mode__doc__, NULL},
|
GETTER(IndexEntry, mode),
|
||||||
{"path", (getter)IndexEntry_get_path, NULL, IndexEntry_path__doc__, NULL},
|
GETTER(IndexEntry, path),
|
||||||
{"oid", (getter)IndexEntry_get_oid, NULL, IndexEntry_oid__doc__, NULL},
|
GETTER(IndexEntry, oid),
|
||||||
{"hex", (getter)IndexEntry_get_hex, NULL, IndexEntry_hex__doc__, NULL},
|
GETTER(IndexEntry, hex),
|
||||||
{NULL},
|
{NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -49,11 +49,11 @@ Object_dealloc(Object* self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyDoc_STRVAR(Object_get_oid__doc__,
|
PyDoc_STRVAR(Object_oid__doc__,
|
||||||
"The object id, a byte string 20 bytes long.");
|
"The object id, a byte string 20 bytes long.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Object_get_oid(Object *self)
|
Object_oid__get__(Object *self)
|
||||||
{
|
{
|
||||||
const git_oid *oid;
|
const git_oid *oid;
|
||||||
|
|
||||||
@ -64,11 +64,11 @@ Object_get_oid(Object *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyDoc_STRVAR(Object_get_hex__doc__,
|
PyDoc_STRVAR(Object_hex__doc__,
|
||||||
"Hexadecimal representation of the object id, a text string 40 chars long.");
|
"Hexadecimal representation of the object id, a text string 40 chars long.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Object_get_hex(Object *self)
|
Object_hex__get__(Object *self)
|
||||||
{
|
{
|
||||||
const git_oid *oid;
|
const git_oid *oid;
|
||||||
|
|
||||||
@ -79,12 +79,12 @@ Object_get_hex(Object *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyDoc_STRVAR(Object_get_type__doc__,
|
PyDoc_STRVAR(Object_type__doc__,
|
||||||
"One of the GIT_OBJ_COMMIT, GIT_OBJ_TREE, GIT_OBJ_BLOB or GIT_OBJ_TAG "
|
"One of the GIT_OBJ_COMMIT, GIT_OBJ_TREE, GIT_OBJ_BLOB or GIT_OBJ_TAG "
|
||||||
"constants.");
|
"constants.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Object_get_type(Object *self)
|
Object_type__get__(Object *self)
|
||||||
{
|
{
|
||||||
return PyInt_FromLong(git_object_type(self->obj));
|
return PyInt_FromLong(git_object_type(self->obj));
|
||||||
}
|
}
|
||||||
@ -116,15 +116,14 @@ Object_read_raw(Object *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyGetSetDef Object_getseters[] = {
|
PyGetSetDef Object_getseters[] = {
|
||||||
{"oid", (getter)Object_get_oid, NULL, Object_get_oid__doc__, NULL},
|
GETTER(Object, oid),
|
||||||
{"hex", (getter)Object_get_hex, NULL, Object_get_hex__doc__, NULL},
|
GETTER(Object, hex),
|
||||||
{"type", (getter)Object_get_type, NULL, Object_get_type__doc__, NULL},
|
GETTER(Object, type),
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
PyMethodDef Object_methods[] = {
|
PyMethodDef Object_methods[] = {
|
||||||
{"read_raw", (PyCFunction)Object_read_raw, METH_NOARGS,
|
METHOD(Object, read_raw, METH_NOARGS),
|
||||||
Object_read_raw__doc__},
|
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ PyDoc_STRVAR(Repository_head__doc__,
|
|||||||
"Current head reference of the repository.");
|
"Current head reference of the repository.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Repository_get_head(Repository *self)
|
Repository_head__get__(Repository *self)
|
||||||
{
|
{
|
||||||
git_reference *head;
|
git_reference *head;
|
||||||
const git_oid *oid;
|
const git_oid *oid;
|
||||||
@ -228,7 +228,7 @@ PyDoc_STRVAR(Repository_head_is_detached__doc__,
|
|||||||
"instead of a branch.");
|
"instead of a branch.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Repository_head_is_detached(Repository *self)
|
Repository_head_is_detached__get__(Repository *self)
|
||||||
{
|
{
|
||||||
if (git_repository_head_detached(self->repo) > 0)
|
if (git_repository_head_detached(self->repo) > 0)
|
||||||
Py_RETURN_TRUE;
|
Py_RETURN_TRUE;
|
||||||
@ -242,7 +242,7 @@ PyDoc_STRVAR(Repository_head_is_orphaned__doc__,
|
|||||||
"refs namespace, because it doesn't have any commit to point to.");
|
"refs namespace, because it doesn't have any commit to point to.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Repository_head_is_orphaned(Repository *self)
|
Repository_head_is_orphaned__get__(Repository *self)
|
||||||
{
|
{
|
||||||
if (git_repository_head_orphan(self->repo) > 0)
|
if (git_repository_head_orphan(self->repo) > 0)
|
||||||
Py_RETURN_TRUE;
|
Py_RETURN_TRUE;
|
||||||
@ -255,7 +255,7 @@ PyDoc_STRVAR(Repository_is_empty__doc__,
|
|||||||
"Check if a repository is empty.");
|
"Check if a repository is empty.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Repository_is_empty(Repository *self)
|
Repository_is_empty__get__(Repository *self)
|
||||||
{
|
{
|
||||||
if (git_repository_is_empty(self->repo) > 0)
|
if (git_repository_is_empty(self->repo) > 0)
|
||||||
Py_RETURN_TRUE;
|
Py_RETURN_TRUE;
|
||||||
@ -268,7 +268,7 @@ PyDoc_STRVAR(Repository_is_bare__doc__,
|
|||||||
"Check if a repository is a bare repository.");
|
"Check if a repository is a bare repository.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Repository_is_bare(Repository *self)
|
Repository_is_bare__get__(Repository *self)
|
||||||
{
|
{
|
||||||
if (git_repository_is_bare(self->repo) > 0)
|
if (git_repository_is_bare(self->repo) > 0)
|
||||||
Py_RETURN_TRUE;
|
Py_RETURN_TRUE;
|
||||||
@ -422,7 +422,7 @@ Repository_write(Repository *self, PyObject *args)
|
|||||||
PyDoc_STRVAR(Repository_index__doc__, "Index file.");
|
PyDoc_STRVAR(Repository_index__doc__, "Index file.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Repository_get_index(Repository *self, void *closure)
|
Repository_index__get__(Repository *self, void *closure)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
git_index *index;
|
git_index *index;
|
||||||
@ -457,7 +457,7 @@ PyDoc_STRVAR(Repository_path__doc__,
|
|||||||
"The normalized path to the git repository.");
|
"The normalized path to the git repository.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Repository_get_path(Repository *self, void *closure)
|
Repository_path__get__(Repository *self, void *closure)
|
||||||
{
|
{
|
||||||
return to_path(git_repository_path(self->repo));
|
return to_path(git_repository_path(self->repo));
|
||||||
}
|
}
|
||||||
@ -468,7 +468,7 @@ PyDoc_STRVAR(Repository_workdir__doc__,
|
|||||||
"If the repository is bare, None will be returned.");
|
"If the repository is bare, None will be returned.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Repository_get_workdir(Repository *self, void *closure)
|
Repository_workdir__get__(Repository *self, void *closure)
|
||||||
{
|
{
|
||||||
const char *c_path;
|
const char *c_path;
|
||||||
|
|
||||||
@ -487,7 +487,7 @@ PyDoc_STRVAR(Repository_config__doc__,
|
|||||||
"(if they are available).");
|
"(if they are available).");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
Repository_get_config(Repository *self, void *closure)
|
Repository_config__get__(Repository *self, void *closure)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
git_config *config;
|
git_config *config;
|
||||||
@ -998,54 +998,34 @@ Repository_TreeBuilder(Repository *self, PyObject *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyMethodDef Repository_methods[] = {
|
PyMethodDef Repository_methods[] = {
|
||||||
{"create_commit", (PyCFunction)Repository_create_commit, METH_VARARGS,
|
METHOD(Repository, create_blob, METH_VARARGS),
|
||||||
Repository_create_commit__doc__},
|
METHOD(Repository, create_blob_fromfile, METH_VARARGS),
|
||||||
{"create_tag", (PyCFunction)Repository_create_tag, METH_VARARGS,
|
METHOD(Repository, create_commit, METH_VARARGS),
|
||||||
Repository_create_tag__doc__},
|
METHOD(Repository, create_tag, METH_VARARGS),
|
||||||
{"walk", (PyCFunction)Repository_walk, METH_VARARGS,
|
METHOD(Repository, TreeBuilder, METH_VARARGS),
|
||||||
Repository_walk__doc__},
|
METHOD(Repository, walk, METH_VARARGS),
|
||||||
{"read", (PyCFunction)Repository_read, METH_O, Repository_read__doc__},
|
METHOD(Repository, read, METH_O),
|
||||||
{"write", (PyCFunction)Repository_write, METH_VARARGS,
|
METHOD(Repository, write, METH_VARARGS),
|
||||||
Repository_write__doc__},
|
METHOD(Repository, create_reference, METH_VARARGS|METH_KEYWORDS),
|
||||||
{"listall_references", (PyCFunction)Repository_listall_references,
|
METHOD(Repository, listall_references, METH_VARARGS),
|
||||||
METH_VARARGS, Repository_listall_references__doc__},
|
METHOD(Repository, lookup_reference, METH_O),
|
||||||
{"lookup_reference", (PyCFunction)Repository_lookup_reference, METH_O,
|
METHOD(Repository, packall_references, METH_NOARGS),
|
||||||
Repository_lookup_reference__doc__},
|
METHOD(Repository, revparse_single, METH_O),
|
||||||
{"revparse_single", (PyCFunction)Repository_revparse_single, METH_O,
|
METHOD(Repository, status, METH_NOARGS),
|
||||||
Repository_revparse_single__doc__},
|
METHOD(Repository, status_file, METH_O),
|
||||||
{"create_blob", (PyCFunction)Repository_create_blob, METH_VARARGS,
|
|
||||||
Repository_create_blob__doc__},
|
|
||||||
{"create_blob_fromfile", (PyCFunction)Repository_create_blob_fromfile,
|
|
||||||
METH_VARARGS, Repository_create_blob_fromfile__doc__},
|
|
||||||
{"create_reference", (PyCFunction)Repository_create_reference,
|
|
||||||
METH_VARARGS|METH_KEYWORDS, Repository_create_reference__doc__},
|
|
||||||
{"packall_references", (PyCFunction)Repository_packall_references,
|
|
||||||
METH_NOARGS, Repository_packall_references__doc__},
|
|
||||||
{"status", (PyCFunction)Repository_status, METH_NOARGS,
|
|
||||||
Repository_status__doc__},
|
|
||||||
{"status_file", (PyCFunction)Repository_status_file, METH_O,
|
|
||||||
Repository_status_file__doc__},
|
|
||||||
{"TreeBuilder", (PyCFunction)Repository_TreeBuilder, METH_VARARGS,
|
|
||||||
Repository_TreeBuilder__doc__},
|
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
PyGetSetDef Repository_getseters[] = {
|
PyGetSetDef Repository_getseters[] = {
|
||||||
{"index", (getter)Repository_get_index, NULL, Repository_index__doc__,
|
GETTER(Repository, index),
|
||||||
NULL},
|
GETTER(Repository, path),
|
||||||
{"path", (getter)Repository_get_path, NULL, Repository_path__doc__, NULL},
|
GETTER(Repository, head),
|
||||||
{"head", (getter)Repository_get_head, NULL, Repository_head__doc__, NULL},
|
GETTER(Repository, head_is_detached),
|
||||||
{"head_is_detached", (getter)Repository_head_is_detached, NULL,
|
GETTER(Repository, head_is_orphaned),
|
||||||
Repository_head_is_detached__doc__},
|
GETTER(Repository, is_empty),
|
||||||
{"head_is_orphaned", (getter)Repository_head_is_orphaned, NULL,
|
GETTER(Repository, is_bare),
|
||||||
Repository_head_is_orphaned__doc__},
|
GETTER(Repository, config),
|
||||||
{"is_empty", (getter)Repository_is_empty, NULL,
|
GETTER(Repository, workdir),
|
||||||
Repository_is_empty__doc__},
|
|
||||||
{"is_bare", (getter)Repository_is_bare, NULL, Repository_is_bare__doc__},
|
|
||||||
{"config", (getter)Repository_get_config, NULL, Repository_config__doc__,
|
|
||||||
NULL},
|
|
||||||
{"workdir", (getter)Repository_get_workdir, NULL,
|
|
||||||
Repository_workdir__doc__, NULL},
|
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user