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)
|
||||
|
||||
|
||||
/* 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)\
|
||||
{#attr, (getter) type ## _ ## attr ## __get__, NULL,\
|
||||
type ## _ ## attr ## __doc__, NULL}
|
||||
|
@ -46,8 +46,7 @@ Index_init(Index *self, PyObject *args, PyObject *kwds)
|
||||
int err;
|
||||
|
||||
if (kwds) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Index takes no keyword arguments");
|
||||
PyErr_SetString(PyExc_TypeError, "Index takes no keyword arguments");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -79,6 +78,7 @@ Index_traverse(Index *self, visitproc visit, void *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
PyDoc_STRVAR(Index_add__doc__,
|
||||
"add(path)\n\n"
|
||||
"Add or update an index entry from a file in disk.");
|
||||
@ -99,6 +99,7 @@ Index_add(Index *self, PyObject *args)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
PyDoc_STRVAR(Index_clear__doc__,
|
||||
"clear()\n\n"
|
||||
"Clear the contents (all the entries) of an index object.");
|
||||
@ -160,13 +161,14 @@ Index_diff(Index *self, PyObject *args)
|
||||
return (PyObject*)py_diff;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(Index_find__doc__,
|
||||
|
||||
PyDoc_STRVAR(Index__find__doc__,
|
||||
"_find(path) -> integer\n\n"
|
||||
"Find the first index of any entries which point to given path in the "
|
||||
"index file.");
|
||||
|
||||
PyObject *
|
||||
Index_find(Index *self, PyObject *py_path)
|
||||
Index__find(Index *self, PyObject *py_path)
|
||||
{
|
||||
char *path;
|
||||
size_t idx;
|
||||
@ -416,17 +418,15 @@ Index_write_tree(Index *self)
|
||||
}
|
||||
|
||||
PyMethodDef Index_methods[] = {
|
||||
{"add", (PyCFunction)Index_add, METH_VARARGS, Index_add__doc__},
|
||||
{"remove", (PyCFunction)Index_remove, METH_VARARGS, Index_remove__doc__},
|
||||
{"clear", (PyCFunction)Index_clear, METH_NOARGS, Index_clear__doc__},
|
||||
{"diff", (PyCFunction)Index_diff, METH_VARARGS, Index_diff__doc__},
|
||||
{"_find", (PyCFunction)Index_find, METH_O, Index_find__doc__},
|
||||
{"read", (PyCFunction)Index_read, METH_NOARGS, Index_read__doc__},
|
||||
{"write", (PyCFunction)Index_write, METH_NOARGS, Index_write__doc__},
|
||||
{"read_tree", (PyCFunction)Index_read_tree, METH_O,
|
||||
Index_read_tree__doc__},
|
||||
{"write_tree", (PyCFunction)Index_write_tree, METH_NOARGS,
|
||||
Index_write_tree__doc__},
|
||||
METHOD(Index, add, METH_VARARGS),
|
||||
METHOD(Index, remove, METH_VARARGS),
|
||||
METHOD(Index, clear, METH_NOARGS),
|
||||
METHOD(Index, diff, METH_VARARGS),
|
||||
METHOD(Index, _find, METH_O),
|
||||
METHOD(Index, read, METH_NOARGS),
|
||||
METHOD(Index, write, METH_NOARGS),
|
||||
METHOD(Index, read_tree, METH_O),
|
||||
METHOD(Index, write_tree, METH_NOARGS),
|
||||
{NULL}
|
||||
};
|
||||
|
||||
@ -550,43 +550,47 @@ IndexEntry_dealloc(IndexEntry *self)
|
||||
PyObject_Del(self);
|
||||
}
|
||||
|
||||
|
||||
PyDoc_STRVAR(IndexEntry_mode__doc__, "Mode.");
|
||||
|
||||
PyObject *
|
||||
IndexEntry_get_mode(IndexEntry *self)
|
||||
IndexEntry_mode__get__(IndexEntry *self)
|
||||
{
|
||||
return PyInt_FromLong(self->entry->mode);
|
||||
}
|
||||
|
||||
|
||||
PyDoc_STRVAR(IndexEntry_path__doc__, "Path.");
|
||||
|
||||
PyObject *
|
||||
IndexEntry_get_path(IndexEntry *self)
|
||||
IndexEntry_path__get__(IndexEntry *self)
|
||||
{
|
||||
return to_path(self->entry->path);
|
||||
}
|
||||
|
||||
|
||||
PyDoc_STRVAR(IndexEntry_oid__doc__, "Object id.");
|
||||
|
||||
PyObject *
|
||||
IndexEntry_get_oid(IndexEntry *self)
|
||||
IndexEntry_oid__get__(IndexEntry *self)
|
||||
{
|
||||
return git_oid_to_python(self->entry->oid.id);
|
||||
}
|
||||
|
||||
|
||||
PyDoc_STRVAR(IndexEntry_hex__doc__, "Hex id.");
|
||||
|
||||
PyObject *
|
||||
IndexEntry_get_hex(IndexEntry *self)
|
||||
IndexEntry_hex__get__(IndexEntry *self)
|
||||
{
|
||||
return git_oid_to_py_str(&self->entry->oid);
|
||||
}
|
||||
|
||||
PyGetSetDef IndexEntry_getseters[] = {
|
||||
{"mode", (getter)IndexEntry_get_mode, NULL, IndexEntry_mode__doc__, NULL},
|
||||
{"path", (getter)IndexEntry_get_path, NULL, IndexEntry_path__doc__, NULL},
|
||||
{"oid", (getter)IndexEntry_get_oid, NULL, IndexEntry_oid__doc__, NULL},
|
||||
{"hex", (getter)IndexEntry_get_hex, NULL, IndexEntry_hex__doc__, NULL},
|
||||
GETTER(IndexEntry, mode),
|
||||
GETTER(IndexEntry, path),
|
||||
GETTER(IndexEntry, oid),
|
||||
GETTER(IndexEntry, hex),
|
||||
{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.");
|
||||
|
||||
PyObject *
|
||||
Object_get_oid(Object *self)
|
||||
Object_oid__get__(Object *self)
|
||||
{
|
||||
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.");
|
||||
|
||||
PyObject *
|
||||
Object_get_hex(Object *self)
|
||||
Object_hex__get__(Object *self)
|
||||
{
|
||||
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 "
|
||||
"constants.");
|
||||
|
||||
PyObject *
|
||||
Object_get_type(Object *self)
|
||||
Object_type__get__(Object *self)
|
||||
{
|
||||
return PyInt_FromLong(git_object_type(self->obj));
|
||||
}
|
||||
@ -116,15 +116,14 @@ Object_read_raw(Object *self)
|
||||
}
|
||||
|
||||
PyGetSetDef Object_getseters[] = {
|
||||
{"oid", (getter)Object_get_oid, NULL, Object_get_oid__doc__, NULL},
|
||||
{"hex", (getter)Object_get_hex, NULL, Object_get_hex__doc__, NULL},
|
||||
{"type", (getter)Object_get_type, NULL, Object_get_type__doc__, NULL},
|
||||
GETTER(Object, oid),
|
||||
GETTER(Object, hex),
|
||||
GETTER(Object, type),
|
||||
{NULL}
|
||||
};
|
||||
|
||||
PyMethodDef Object_methods[] = {
|
||||
{"read_raw", (PyCFunction)Object_read_raw, METH_NOARGS,
|
||||
Object_read_raw__doc__},
|
||||
METHOD(Object, read_raw, METH_NOARGS),
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
@ -199,7 +199,7 @@ PyDoc_STRVAR(Repository_head__doc__,
|
||||
"Current head reference of the repository.");
|
||||
|
||||
PyObject *
|
||||
Repository_get_head(Repository *self)
|
||||
Repository_head__get__(Repository *self)
|
||||
{
|
||||
git_reference *head;
|
||||
const git_oid *oid;
|
||||
@ -228,7 +228,7 @@ PyDoc_STRVAR(Repository_head_is_detached__doc__,
|
||||
"instead of a branch.");
|
||||
|
||||
PyObject *
|
||||
Repository_head_is_detached(Repository *self)
|
||||
Repository_head_is_detached__get__(Repository *self)
|
||||
{
|
||||
if (git_repository_head_detached(self->repo) > 0)
|
||||
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.");
|
||||
|
||||
PyObject *
|
||||
Repository_head_is_orphaned(Repository *self)
|
||||
Repository_head_is_orphaned__get__(Repository *self)
|
||||
{
|
||||
if (git_repository_head_orphan(self->repo) > 0)
|
||||
Py_RETURN_TRUE;
|
||||
@ -255,7 +255,7 @@ PyDoc_STRVAR(Repository_is_empty__doc__,
|
||||
"Check if a repository is empty.");
|
||||
|
||||
PyObject *
|
||||
Repository_is_empty(Repository *self)
|
||||
Repository_is_empty__get__(Repository *self)
|
||||
{
|
||||
if (git_repository_is_empty(self->repo) > 0)
|
||||
Py_RETURN_TRUE;
|
||||
@ -268,7 +268,7 @@ PyDoc_STRVAR(Repository_is_bare__doc__,
|
||||
"Check if a repository is a bare repository.");
|
||||
|
||||
PyObject *
|
||||
Repository_is_bare(Repository *self)
|
||||
Repository_is_bare__get__(Repository *self)
|
||||
{
|
||||
if (git_repository_is_bare(self->repo) > 0)
|
||||
Py_RETURN_TRUE;
|
||||
@ -422,7 +422,7 @@ Repository_write(Repository *self, PyObject *args)
|
||||
PyDoc_STRVAR(Repository_index__doc__, "Index file.");
|
||||
|
||||
PyObject *
|
||||
Repository_get_index(Repository *self, void *closure)
|
||||
Repository_index__get__(Repository *self, void *closure)
|
||||
{
|
||||
int err;
|
||||
git_index *index;
|
||||
@ -457,7 +457,7 @@ PyDoc_STRVAR(Repository_path__doc__,
|
||||
"The normalized path to the git repository.");
|
||||
|
||||
PyObject *
|
||||
Repository_get_path(Repository *self, void *closure)
|
||||
Repository_path__get__(Repository *self, void *closure)
|
||||
{
|
||||
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.");
|
||||
|
||||
PyObject *
|
||||
Repository_get_workdir(Repository *self, void *closure)
|
||||
Repository_workdir__get__(Repository *self, void *closure)
|
||||
{
|
||||
const char *c_path;
|
||||
|
||||
@ -487,7 +487,7 @@ PyDoc_STRVAR(Repository_config__doc__,
|
||||
"(if they are available).");
|
||||
|
||||
PyObject *
|
||||
Repository_get_config(Repository *self, void *closure)
|
||||
Repository_config__get__(Repository *self, void *closure)
|
||||
{
|
||||
int err;
|
||||
git_config *config;
|
||||
@ -998,54 +998,34 @@ Repository_TreeBuilder(Repository *self, PyObject *args)
|
||||
}
|
||||
|
||||
PyMethodDef Repository_methods[] = {
|
||||
{"create_commit", (PyCFunction)Repository_create_commit, METH_VARARGS,
|
||||
Repository_create_commit__doc__},
|
||||
{"create_tag", (PyCFunction)Repository_create_tag, METH_VARARGS,
|
||||
Repository_create_tag__doc__},
|
||||
{"walk", (PyCFunction)Repository_walk, METH_VARARGS,
|
||||
Repository_walk__doc__},
|
||||
{"read", (PyCFunction)Repository_read, METH_O, Repository_read__doc__},
|
||||
{"write", (PyCFunction)Repository_write, METH_VARARGS,
|
||||
Repository_write__doc__},
|
||||
{"listall_references", (PyCFunction)Repository_listall_references,
|
||||
METH_VARARGS, Repository_listall_references__doc__},
|
||||
{"lookup_reference", (PyCFunction)Repository_lookup_reference, METH_O,
|
||||
Repository_lookup_reference__doc__},
|
||||
{"revparse_single", (PyCFunction)Repository_revparse_single, METH_O,
|
||||
Repository_revparse_single__doc__},
|
||||
{"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__},
|
||||
METHOD(Repository, create_blob, METH_VARARGS),
|
||||
METHOD(Repository, create_blob_fromfile, METH_VARARGS),
|
||||
METHOD(Repository, create_commit, METH_VARARGS),
|
||||
METHOD(Repository, create_tag, METH_VARARGS),
|
||||
METHOD(Repository, TreeBuilder, METH_VARARGS),
|
||||
METHOD(Repository, walk, METH_VARARGS),
|
||||
METHOD(Repository, read, METH_O),
|
||||
METHOD(Repository, write, METH_VARARGS),
|
||||
METHOD(Repository, create_reference, METH_VARARGS|METH_KEYWORDS),
|
||||
METHOD(Repository, listall_references, METH_VARARGS),
|
||||
METHOD(Repository, lookup_reference, METH_O),
|
||||
METHOD(Repository, packall_references, METH_NOARGS),
|
||||
METHOD(Repository, revparse_single, METH_O),
|
||||
METHOD(Repository, status, METH_NOARGS),
|
||||
METHOD(Repository, status_file, METH_O),
|
||||
{NULL}
|
||||
};
|
||||
|
||||
PyGetSetDef Repository_getseters[] = {
|
||||
{"index", (getter)Repository_get_index, NULL, Repository_index__doc__,
|
||||
NULL},
|
||||
{"path", (getter)Repository_get_path, NULL, Repository_path__doc__, NULL},
|
||||
{"head", (getter)Repository_get_head, NULL, Repository_head__doc__, NULL},
|
||||
{"head_is_detached", (getter)Repository_head_is_detached, NULL,
|
||||
Repository_head_is_detached__doc__},
|
||||
{"head_is_orphaned", (getter)Repository_head_is_orphaned, NULL,
|
||||
Repository_head_is_orphaned__doc__},
|
||||
{"is_empty", (getter)Repository_is_empty, NULL,
|
||||
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},
|
||||
GETTER(Repository, index),
|
||||
GETTER(Repository, path),
|
||||
GETTER(Repository, head),
|
||||
GETTER(Repository, head_is_detached),
|
||||
GETTER(Repository, head_is_orphaned),
|
||||
GETTER(Repository, is_empty),
|
||||
GETTER(Repository, is_bare),
|
||||
GETTER(Repository, config),
|
||||
GETTER(Repository, workdir),
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user