diff --git a/include/pygit2/types.h b/include/pygit2/types.h index e4e4f5d..97f83cf 100644 --- a/include/pygit2/types.h +++ b/include/pygit2/types.h @@ -116,7 +116,7 @@ typedef struct { PyObject *oid_old; PyObject *oid_new; PyObject *committer; - char *msg; + char *message; } RefLogEntry; typedef struct { diff --git a/include/pygit2/utils.h b/include/pygit2/utils.h index 903966a..d6ffc81 100644 --- a/include/pygit2/utils.h +++ b/include/pygit2/utils.h @@ -101,8 +101,21 @@ char * py_str_to_c_str(PyObject *value, const char *encoding); {#name, (PyCFunction) type ## _ ## name, args, type ## _ ## name ## __doc__} #define GETTER(type, attr)\ - {#attr, (getter) type ## _ ## attr ## __get__, NULL,\ - type ## _ ## attr ## __doc__, NULL} + { #attr,\ + (getter) type ## _ ## attr ## __get__,\ + NULL,\ + type ## _ ## attr ## __doc__,\ + NULL} + +#define GETSET(type, attr)\ + { #attr,\ + (getter) type ## _ ## attr ## __get__,\ + (setter) type ## _ ## attr ## __set__,\ + type ## _ ## attr ## __doc__,\ + NULL} + +#define MEMBER(type, attr, attr_type, docstr)\ + {#attr, attr_type, offsetof(type, attr), 0, PyDoc_STR(docstr)} #endif diff --git a/src/blob.c b/src/blob.c index 9ec60dd..bac8184 100644 --- a/src/blob.c +++ b/src/blob.c @@ -31,22 +31,31 @@ #include #include + +PyDoc_STRVAR(Blob_size__doc__, "Size."); + PyObject * -Blob_get_size(Blob *self) +Blob_size__get__(Blob *self) { return PyInt_FromLong(git_blob_rawsize(self->blob)); } +PyDoc_STRVAR(Blob_data__doc__, + "Raw data. This is the same as Blob.read_raw()"); + PyGetSetDef Blob_getseters[] = { - {"data", (getter)Object_read_raw, NULL, "raw data", NULL}, - {"size", (getter)Blob_get_size, NULL, "size", NULL}, + GETTER(Blob, size), + {"data", (getter)Object_read_raw, NULL, Blob_data__doc__, NULL}, {NULL} }; + +PyDoc_STRVAR(Blob__doc__, "Blob objects."); + PyTypeObject BlobType = { PyVarObject_HEAD_INIT(NULL, 0) - "_pygit2.Blob", /* tp_name */ + "_pygit2.Blob", /* tp_name */ sizeof(Blob), /* tp_basicsize */ 0, /* tp_itemsize */ 0, /* tp_dealloc */ @@ -65,7 +74,7 @@ PyTypeObject BlobType = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "Blob objects", /* tp_doc */ + Blob__doc__, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -84,4 +93,3 @@ PyTypeObject BlobType = { 0, /* tp_alloc */ 0, /* tp_new */ }; - diff --git a/src/config.c b/src/config.c index 6a84f63..847f9f8 100644 --- a/src/config.c +++ b/src/config.c @@ -98,6 +98,11 @@ Config_open(char *c_path) { return (PyObject *)config; } + +PyDoc_STRVAR(Config_get_global_config__doc__, + "get_global_config() -> Config\n\n" + "Return an object representing the global configuration file."); + PyObject * Config_get_global_config(void) { @@ -116,6 +121,11 @@ Config_get_global_config(void) return Config_open(path); } + +PyDoc_STRVAR(Config_get_system_config__doc__, + "get_system_config() -> Config\n\n" + "Return an object representing the system configuration file."); + PyObject * Config_get_system_config(void) { @@ -254,6 +264,15 @@ Config_foreach_callback_wrapper(const git_config_entry *entry, void *c_payload) return c_result; } + +PyDoc_STRVAR(Config_foreach__doc__, + "foreach(callback[, payload]) -> int\n\n" + "Perform an operation on each config variable.\n\n" + "The callback must be of type Callable and receives the normalized name " + "and value of each variable in the config backend, and an optional payload " + "passed to this method. As soon as one of the callbacks returns an integer " + "other than 0, this function returns that value."); + PyObject * Config_foreach(Config *self, PyObject *args) { @@ -261,13 +280,12 @@ Config_foreach(Config *self, PyObject *args) PyObject *py_callback; PyObject *py_payload; - if (!PyArg_ParseTuple(args, "O|O", &py_callback, &py_payload)) return NULL; - if (!PyCallable_Check(py_callback)) { - PyErr_SetString(PyExc_TypeError,"Argument 'callback' is not callable"); + PyErr_SetString(PyExc_TypeError, + "Argument 'callback' is not callable"); return NULL; } @@ -277,6 +295,11 @@ Config_foreach(Config *self, PyObject *args) return PyInt_FromLong((long)ret); } + +PyDoc_STRVAR(Config_add_file__doc__, + "add_file(path, level=0, force=0)\n\n" + "Add a config file instance to an existing config."); + PyObject * Config_add_file(Config *self, PyObject *args, PyObject *kwds) { @@ -286,9 +309,8 @@ Config_add_file(Config *self, PyObject *args, PyObject *kwds) unsigned int level = 0; int force = 0; - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "s|Ii", keywords, - &path, &level, &force)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|Ii", keywords, + &path, &level, &force)) return NULL; err = git_config_add_file_ondisk(self->config, path, level, force); @@ -300,6 +322,13 @@ Config_add_file(Config *self, PyObject *args, PyObject *kwds) Py_RETURN_NONE; } + +PyDoc_STRVAR(Config_get_multivar__doc__, + "get_multivar(name[, regex]) -> [str, ...]\n\n" + "Get each value of a multivar ''name'' as a list. The optional ''regex'' " + "parameter is expected to be a regular expression to filter the variables " + " we're interested in."); + int Config_get_multivar_fn_wrapper(const git_config_entry *value, void *data) { @@ -325,8 +354,10 @@ Config_get_multivar(Config *self, PyObject *args) if (!PyArg_ParseTuple(args, "s|s", &name, ®ex)) return NULL; - if ((err = git_config_get_multivar(self->config, name, regex, - Config_get_multivar_fn_wrapper, (void *)list)) < 0) { + err = git_config_get_multivar(self->config, name, regex, + Config_get_multivar_fn_wrapper, + (void *)list); + if (err < 0) { if (err == GIT_ENOTFOUND) Error_set(err); else @@ -337,6 +368,12 @@ Config_get_multivar(Config *self, PyObject *args) return list; } + +PyDoc_STRVAR(Config_set_multivar__doc__, + "set_multivar(name, regex, value)\n\n" + "Set a multivar ''name'' to ''value''. ''regexp'' is a regular expression " + "to indicate which values to replace"); + PyObject * Config_set_multivar(Config *self, PyObject *args) { @@ -347,7 +384,9 @@ Config_set_multivar(Config *self, PyObject *args) if (!PyArg_ParseTuple(args, "sss", &name, ®ex, &value)) return NULL; - if ((err = git_config_set_multivar(self->config, name, regex, value)) < 0) { + + err = git_config_set_multivar(self->config, name, regex, value); + if (err < 0) { if (err == GIT_ENOTFOUND) Error_set(err); else @@ -359,27 +398,12 @@ Config_set_multivar(Config *self, PyObject *args) } PyMethodDef Config_methods[] = { - {"get_system_config", (PyCFunction)Config_get_system_config, - METH_NOARGS | METH_STATIC, - "Return an object representing the system configuration file."}, - {"get_global_config", (PyCFunction)Config_get_global_config, - METH_NOARGS | METH_STATIC, - "Return an object representing the global configuration file."}, - {"foreach", (PyCFunction)Config_foreach, METH_VARARGS, - "Perform an operation on each config variable.\n\n" - "The callback must be of type Callable and receives the normalized name " - "and value of each variable in the config backend, and an optional " - "payload passed to this method. As soon as one of the callbacks returns " - "an integer other than 0, this function returns that value."}, - {"add_file", (PyCFunction)Config_add_file, METH_VARARGS | METH_KEYWORDS, - "Add a config file instance to an existing config."}, - {"get_multivar", (PyCFunction)Config_get_multivar, METH_VARARGS, - "Get each value of a multivar ''name'' as a list. The optional ''regex'' " - "parameter is expected to be a regular expression to filter the which " - "variables we're interested in."}, - {"set_multivar", (PyCFunction)Config_set_multivar, METH_VARARGS, - "Set a multivar ''name'' to ''value''. ''regexp'' is a regular expression " - "to indicate which values to replace"}, + METHOD(Config, get_system_config, METH_NOARGS | METH_STATIC), + METHOD(Config, get_global_config, METH_NOARGS | METH_STATIC), + METHOD(Config, foreach, METH_VARARGS), + METHOD(Config, add_file, METH_VARARGS | METH_KEYWORDS), + METHOD(Config, get_multivar, METH_VARARGS), + METHOD(Config, set_multivar, METH_VARARGS), {NULL} }; @@ -400,6 +424,9 @@ PyMappingMethods Config_as_mapping = { (objobjargproc)Config_setitem, /* mp_ass_subscript */ }; + +PyDoc_STRVAR(Config__doc__, "Configuration management."); + PyTypeObject ConfigType = { PyVarObject_HEAD_INIT(NULL, 0) "_pygit2.Config", /* tp_name */ @@ -420,9 +447,8 @@ PyTypeObject ConfigType = { 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | - Py_TPFLAGS_HAVE_GC, /* tp_flags */ - "Configuration management", /* tp_doc */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ + Config__doc__, /* tp_doc */ (traverseproc)Config_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ diff --git a/src/diff.c b/src/diff.c index e31a08b..94eb6a9 100644 --- a/src/diff.c +++ b/src/diff.c @@ -163,8 +163,8 @@ static int diff_hunk_cb( return 0; }; -static int diff_file_cb(const git_diff_delta *delta, float progress, -void *cb_data) +static int +diff_file_cb(const git_diff_delta *delta, float progress, void *cb_data) { PyObject *files, *file; @@ -193,8 +193,11 @@ void *cb_data) return 0; } + +PyDoc_STRVAR(Diff_changes__doc__, "Raw changes."); + PyObject * -Diff_changes(Diff *self) +Diff_changes__get__(Diff *self) { if (self->diff_changes == NULL) { @@ -226,8 +229,11 @@ static int diff_print_cb( return 0; } + +PyDoc_STRVAR(Diff_patch__doc__, "Patch."); + PyObject * -Diff_patch(Diff *self) +Diff_patch__get__(Diff *self) { PyObject *patch = PyBytes_FromString(""); @@ -280,21 +286,24 @@ Hunk_dealloc(Hunk *self) } PyMemberDef Hunk_members[] = { - {"header", T_STRING, offsetof(Hunk, header), 0, "header"}, - {"old_start", T_INT, offsetof(Hunk, old_start), 0, "old start"}, - {"old_lines", T_INT, offsetof(Hunk, old_lines), 0, "old lines"}, - {"old_mode", T_INT, offsetof(Hunk, old_mode), 0, "old mode"}, - {"old_file", T_STRING, offsetof(Hunk, old_file), 0, "old file"}, - {"old_oid", T_OBJECT, offsetof(Hunk, old_oid), 0, "old_oid"}, - {"new_start", T_INT, offsetof(Hunk, new_start), 0, "new start"}, - {"new_lines", T_INT, offsetof(Hunk, new_lines), 0, "new lines"}, - {"new_mode", T_INT, offsetof(Hunk, new_mode), 0, "new mode"}, - {"new_file", T_STRING, offsetof(Hunk, new_file), 0, "old file"}, - {"new_oid", T_OBJECT, offsetof(Hunk, new_oid), 0, "new_oid"}, - {"data", T_OBJECT, offsetof(Hunk, data), 0, "data"}, + MEMBER(Hunk, header, T_STRING, "Header."), + MEMBER(Hunk, old_start, T_INT, "Old start."), + MEMBER(Hunk, old_lines, T_INT, "Old lines."), + MEMBER(Hunk, old_mode, T_INT, "Old mode."), + MEMBER(Hunk, old_file, T_STRING, "Old file."), + MEMBER(Hunk, old_oid, T_OBJECT, "Old oid."), + MEMBER(Hunk, new_start, T_INT, "New start."), + MEMBER(Hunk, new_lines, T_INT, "New lines."), + MEMBER(Hunk, new_mode, T_INT, "New mode."), + MEMBER(Hunk, new_file, T_STRING, "New file."), + MEMBER(Hunk, new_oid, T_OBJECT, "New oid."), + MEMBER(Hunk, data, T_OBJECT, "Data."), {NULL} }; + +PyDoc_STRVAR(Hunk__doc__, "Hunk object."); + PyTypeObject HunkType = { PyVarObject_HEAD_INIT(NULL, 0) "_pygit2.Hunk", /* tp_name */ @@ -316,7 +325,7 @@ PyTypeObject HunkType = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "Hunk object", /* tp_doc */ + Hunk__doc__, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -336,6 +345,11 @@ PyTypeObject HunkType = { 0, /* tp_new */ }; + +PyDoc_STRVAR(Diff_merge__doc__, + "merge(diff)\n\n" + "Merge one diff into another."); + PyObject * Diff_merge(Diff *self, PyObject *args) { @@ -356,6 +370,11 @@ Diff_merge(Diff *self, PyObject *args) Py_RETURN_NONE; } + +PyDoc_STRVAR(Diff_find_similar__doc__, + "find_similar([flags])\n\n" + "Find renamed files in diff."); + PyObject * Diff_find_similar(Diff *self, PyObject *args) { @@ -384,22 +403,23 @@ Diff_dealloc(Diff *self) } PyGetSetDef Diff_getseters[] = { - {"changes", (getter)Diff_changes, NULL, "raw changes", NULL}, - {"patch", (getter)Diff_patch, NULL, "patch", NULL}, + GETTER(Diff, changes), + GETTER(Diff, patch), {NULL} }; static PyMethodDef Diff_methods[] = { - {"merge", (PyCFunction)Diff_merge, METH_VARARGS, - "Merge one diff into another."}, - {"find_similar", (PyCFunction)Diff_find_similar, METH_VARARGS, - "Find renamed files in diff."}, - {NULL, NULL, 0, NULL} + METHOD(Diff, merge, METH_VARARGS), + METHOD(Diff, find_similar, METH_VARARGS), + {NULL} }; + +PyDoc_STRVAR(Diff__doc__, "Diff objects."); + PyTypeObject DiffType = { PyVarObject_HEAD_INIT(NULL, 0) - "_pygit2.Diff", /* tp_name */ + "_pygit2.Diff", /* tp_name */ sizeof(Diff), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)Diff_dealloc, /* tp_dealloc */ @@ -418,7 +438,7 @@ PyTypeObject DiffType = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "Diff objects", /* tp_doc */ + Diff__doc__, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ diff --git a/src/index.c b/src/index.c index afb79f9..2c6793b 100644 --- a/src/index.c +++ b/src/index.c @@ -513,35 +513,37 @@ IndexIter_iternext(IndexIter *self) return wrap_index_entry(index_entry, self->owner); } + +PyDoc_STRVAR(IndexIter__doc__, "Index iterator."); + PyTypeObject IndexIterType = { PyVarObject_HEAD_INIT(NULL, 0) - "_pygit2.IndexIter", /* tp_name */ - sizeof(IndexIter), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)IndexIter_dealloc , /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | - Py_TPFLAGS_BASETYPE, /* tp_flags */ - 0, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - PyObject_SelfIter, /* tp_iter */ - (iternextfunc)IndexIter_iternext, /* tp_iternext */ + "_pygit2.IndexIter", /* tp_name */ + sizeof(IndexIter), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)IndexIter_dealloc , /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + IndexIter__doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + PyObject_SelfIter, /* tp_iter */ + (iternextfunc)IndexIter_iternext, /* tp_iternext */ }; void diff --git a/src/reference.c b/src/reference.c index be572b4..cccbfdb 100644 --- a/src/reference.c +++ b/src/reference.c @@ -51,17 +51,16 @@ void RefLogIter_dealloc(RefLogIter *self) PyObject* RefLogIter_iternext(PyObject *self) { RefLogIter *p = (RefLogIter *) self; + const git_reflog_entry *entry; + char oid_old[40], oid_new[40]; if (p->i < p->size) { - char oid_old[40], oid_new[40]; RefLogEntry *py_entry; git_signature *signature; - const git_reflog_entry *entry = git_reflog_entry_byindex(p->reflog, p->i); - - py_entry = (RefLogEntry*) PyType_GenericNew( - &RefLogEntryType, NULL, NULL - ); + 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)); @@ -69,7 +68,7 @@ PyObject* RefLogIter_iternext(PyObject *self) py_entry->oid_new = PyUnicode_FromStringAndSize(oid_new, 40); py_entry->oid_old = PyUnicode_FromStringAndSize(oid_old, 40); - py_entry->msg = strdup(git_reflog_entry_message(entry)); + py_entry->message = strdup(git_reflog_entry_message(entry)); signature = git_signature_dup( git_reflog_entry_committer(entry) @@ -90,37 +89,37 @@ PyObject* RefLogIter_iternext(PyObject *self) return NULL; } + +PyDoc_STRVAR(RefLogIterType__doc__, "Internal reflog iterator object."); + PyTypeObject RefLogIterType = { PyVarObject_HEAD_INIT(NULL, 0) - "_libgit2.RefLogIter", /*tp_name*/ - sizeof(RefLogIter), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)RefLogIter_dealloc, /* tp_dealloc */ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | - Py_TPFLAGS_BASETYPE, /* tp_flags */ - /* tp_flags: Py_TPFLAGS_HAVE_ITER tells python to - use tp_iter and tp_iternext fields. */ - "Internal reflog iterator object.", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - PyObject_SelfIter, /* tp_iter: __iter__() method */ - (iternextfunc) RefLogIter_iternext /* tp_iternext: next() method */ + "_libgit2.RefLogIter", /* tp_name */ + sizeof(RefLogIter), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)RefLogIter_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + RefLogIterType__doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + PyObject_SelfIter, /* tp_iter */ + (iternextfunc)RefLogIter_iternext /* tp_iternext */ }; void @@ -130,6 +129,11 @@ Reference_dealloc(Reference *self) PyObject_Del(self); } + +PyDoc_STRVAR(Reference_delete__doc__, + "delete()\n\n" + "Delete this reference. It will no longer be valid!"); + PyObject * Reference_delete(Reference *self, PyObject *args) { @@ -143,9 +147,14 @@ Reference_delete(Reference *self, PyObject *args) return Error_set(err); self->reference = NULL; /* Invalidate the pointer */ - Py_RETURN_NONE; /* Return None */ + Py_RETURN_NONE; } + +PyDoc_STRVAR(Reference_rename__doc__, + "rename(new_name)\n\n" + "Rename the reference."); + PyObject * Reference_rename(Reference *self, PyObject *py_name) { @@ -165,9 +174,14 @@ Reference_rename(Reference *self, PyObject *py_name) if (err < 0) return Error_set(err); - Py_RETURN_NONE; /* Return None */ + Py_RETURN_NONE; } + +PyDoc_STRVAR(Reference_reload__doc__, + "reload()\n\n" + "Reload the reference from the file-system."); + PyObject * Reference_reload(Reference *self) { @@ -185,6 +199,10 @@ Reference_reload(Reference *self) } +PyDoc_STRVAR(Reference_resolve__doc__, + "resolve() -> Reference\n\n" + "Resolve a symbolic reference and return a direct reference."); + PyObject * Reference_resolve(Reference *self, PyObject *args) { @@ -212,8 +230,11 @@ Reference_resolve(Reference *self, PyObject *args) return wrap_reference(c_reference); } + +PyDoc_STRVAR(Reference_target__doc__, "Target."); + PyObject * -Reference_get_target(Reference *self) +Reference_target__get__(Reference *self) { const char * c_name; @@ -235,7 +256,7 @@ Reference_get_target(Reference *self) } int -Reference_set_target(Reference *self, PyObject *py_name) +Reference_target__set__(Reference *self, PyObject *py_name) { char *c_name; int err; @@ -258,15 +279,21 @@ Reference_set_target(Reference *self, PyObject *py_name) return 0; } + +PyDoc_STRVAR(Reference_name__doc__, "The full name of a reference."); + PyObject * -Reference_get_name(Reference *self) +Reference_name__get__(Reference *self) { CHECK_REFERENCE(self); return to_path(git_reference_name(self->reference)); } + +PyDoc_STRVAR(Reference_oid__doc__, "Object id."); + PyObject * -Reference_get_oid(Reference *self) +Reference_oid__get__(Reference *self) { const git_oid *oid; @@ -286,7 +313,7 @@ Reference_get_oid(Reference *self) } int -Reference_set_oid(Reference *self, PyObject *py_hex) +Reference_oid__set__(Reference *self, PyObject *py_hex) { git_oid oid; int err; @@ -294,7 +321,8 @@ Reference_set_oid(Reference *self, PyObject *py_hex) CHECK_REFERENCE_INT(self); /* Get the oid */ - err = py_str_to_git_oid_expand(git_reference_owner(self->reference), py_hex, &oid); + err = py_str_to_git_oid_expand(git_reference_owner(self->reference), + py_hex, &oid); if (err < 0) { Error_set(err); return -1; @@ -310,8 +338,11 @@ Reference_set_oid(Reference *self, PyObject *py_hex) return 0; } + +PyDoc_STRVAR(Reference_hex__doc__, "Hex oid."); + PyObject * -Reference_get_hex(Reference *self) +Reference_hex__get__(Reference *self) { const git_oid *oid; @@ -330,8 +361,12 @@ Reference_get_hex(Reference *self) return git_oid_to_py_str(oid); } + +PyDoc_STRVAR(Reference_type__doc__, + "Type (GIT_REF_OID, GIT_REF_SYMBOLIC or GIT_REF_PACKED)."); + PyObject * -Reference_get_type(Reference *self) +Reference_type__get__(Reference *self) { git_ref_t c_type; @@ -340,6 +375,11 @@ Reference_get_type(Reference *self) return PyInt_FromLong(c_type); } + +PyDoc_STRVAR(Reference_log__doc__, + "log() -> RefLogIter\n\n" + "Retrieves the current reference log."); + PyObject * Reference_log(Reference *self) { @@ -365,7 +405,7 @@ RefLogEntry_init(RefLogEntry *self, PyObject *args, PyObject *kwds) { self->oid_old = Py_None; self->oid_new = Py_None; - self->msg = ""; + self->message = ""; self->committer = Py_None; return 0; @@ -378,24 +418,27 @@ RefLogEntry_dealloc(RefLogEntry *self) Py_XDECREF(self->oid_old); Py_XDECREF(self->oid_new); Py_XDECREF(self->committer); - free(self->msg); + free(self->message); PyObject_Del(self); } PyMemberDef RefLogEntry_members[] = { - {"oid_new", T_OBJECT, offsetof(RefLogEntry, oid_new), 0, "new oid"}, - {"oid_old", T_OBJECT, offsetof(RefLogEntry, oid_old), 0, "old oid"}, - {"message", T_STRING, offsetof(RefLogEntry, msg), 0, "message"}, - {"committer", T_OBJECT, offsetof(RefLogEntry, committer), 0, "committer"}, + MEMBER(RefLogEntry, oid_new, T_OBJECT, "New oid."), + MEMBER(RefLogEntry, oid_old, T_OBJECT, "Old oid."), + MEMBER(RefLogEntry, message, T_STRING, "Message."), + MEMBER(RefLogEntry, committer, T_OBJECT, "Committer."), {NULL} }; + +PyDoc_STRVAR(RefLogEntry__doc__, "Reference log object."); + PyTypeObject RefLogEntryType = { PyVarObject_HEAD_INIT(NULL, 0) - "_pygit2.RefLogEntry", /* tp_name */ - sizeof(RefLogEntry), /* tp_basicsize */ + "_pygit2.RefLogEntry", /* tp_name */ + sizeof(RefLogEntry), /* tp_basicsize */ 0, /* tp_itemsize */ - (destructor)RefLogEntry_dealloc, /* tp_dealloc */ + (destructor)RefLogEntry_dealloc, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ @@ -411,7 +454,7 @@ PyTypeObject RefLogEntryType = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ - "ReferenceLog object", /* tp_doc */ + RefLogEntry__doc__, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -419,48 +462,42 @@ PyTypeObject RefLogEntryType = { 0, /* tp_iter */ 0, /* tp_iternext */ 0, /* tp_methods */ - RefLogEntry_members, /* tp_members */ + RefLogEntry_members, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)RefLogEntry_init, /* tp_init */ + (initproc)RefLogEntry_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; PyMethodDef Reference_methods[] = { - {"delete", (PyCFunction)Reference_delete, METH_NOARGS, - "Delete this reference. It will no longer be valid!"}, - {"rename", (PyCFunction)Reference_rename, METH_O, - "Rename the reference."}, - {"reload", (PyCFunction)Reference_reload, METH_NOARGS, - "Reload the reference from the file-system."}, - {"resolve", (PyCFunction)Reference_resolve, METH_NOARGS, - "Resolve a symbolic reference and return a direct reference."}, - {"log", (PyCFunction)Reference_log, METH_NOARGS, - "Retrieves the current reference log."}, + METHOD(Reference, delete, METH_NOARGS), + METHOD(Reference, rename, METH_O), + METHOD(Reference, reload, METH_NOARGS), + METHOD(Reference, resolve, METH_NOARGS), + METHOD(Reference, log, METH_NOARGS), {NULL} }; PyGetSetDef Reference_getseters[] = { - {"name", (getter)Reference_get_name, NULL, - "The full name of a reference.", NULL}, - {"oid", (getter)Reference_get_oid, (setter)Reference_set_oid, "object id", - NULL}, - {"hex", (getter)Reference_get_hex, NULL, "hex oid", NULL}, - {"target", (getter)Reference_get_target, (setter)Reference_set_target, - "target", NULL}, - {"type", (getter)Reference_get_type, NULL, - "type (GIT_REF_OID, GIT_REF_SYMBOLIC or GIT_REF_PACKED).", NULL}, + GETTER(Reference, name), + GETSET(Reference, oid), + GETTER(Reference, hex), + GETSET(Reference, target), + GETTER(Reference, type), {NULL} }; + +PyDoc_STRVAR(Reference__doc__, "Reference."); + PyTypeObject ReferenceType = { PyVarObject_HEAD_INIT(NULL, 0) - "_pygit2.Reference", /* tp_name */ + "_pygit2.Reference", /* tp_name */ sizeof(Reference), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)Reference_dealloc, /* tp_dealloc */ @@ -479,7 +516,7 @@ PyTypeObject ReferenceType = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ - "Reference", /* tp_doc */ + Reference__doc__, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ diff --git a/src/tag.c b/src/tag.c index d4745d2..5651c3b 100644 --- a/src/tag.c +++ b/src/tag.c @@ -34,8 +34,11 @@ #include #include + +PyDoc_STRVAR(Tag_target__doc__, "Tagged object."); + PyObject * -Tag_get_target(Tag *self) +Tag_target__get__(Tag *self) { const git_oid *oid; @@ -43,8 +46,11 @@ Tag_get_target(Tag *self) return git_oid_to_python(oid->id); } + +PyDoc_STRVAR(Tag_name__doc__, "Tag name."); + PyObject * -Tag_get_name(Tag *self) +Tag_name__get__(Tag *self) { const char *name; name = git_tag_name(self->tag); @@ -53,8 +59,11 @@ Tag_get_name(Tag *self) return to_unicode(name, "utf-8", "strict"); } + +PyDoc_STRVAR(Tag_tagger__doc__, "Tagger."); + PyObject * -Tag_get_tagger(Tag *self) +Tag_tagger__get__(Tag *self) { const git_signature *signature = git_tag_tagger(self->tag); if (!signature) @@ -63,8 +72,11 @@ Tag_get_tagger(Tag *self) return build_signature((Object*)self, signature, "utf-8"); } + +PyDoc_STRVAR(Tag_message__doc__, "Tag message."); + PyObject * -Tag_get_message(Tag *self) +Tag_message__get__(Tag *self) { const char *message; message = git_tag_message(self->tag); @@ -73,24 +85,30 @@ Tag_get_message(Tag *self) return to_unicode(message, "utf-8", "strict"); } + +PyDoc_STRVAR(Tag__message__doc__, "Tag message (bytes)."); + PyObject * -Tag_get_raw_message(Tag *self) +Tag__message__get__(Tag *self) { return PyString_FromString(git_tag_message(self->tag)); } PyGetSetDef Tag_getseters[] = { - {"target", (getter)Tag_get_target, NULL, "tagged object", NULL}, - {"name", (getter)Tag_get_name, NULL, "tag name", NULL}, - {"tagger", (getter)Tag_get_tagger, NULL, "tagger", NULL}, - {"message", (getter)Tag_get_message, NULL, "tag message", NULL}, - {"_message", (getter)Tag_get_raw_message, NULL, "tag message (bytes)", NULL}, + GETTER(Tag, target), + GETTER(Tag, name), + GETTER(Tag, tagger), + GETTER(Tag, message), + GETTER(Tag, _message), {NULL} }; + +PyDoc_STRVAR(Tag__doc__, "Tag objects."); + PyTypeObject TagType = { PyVarObject_HEAD_INIT(NULL, 0) - "_pygit2.Tag", /* tp_name */ + "_pygit2.Tag", /* tp_name */ sizeof(Tag), /* tp_basicsize */ 0, /* tp_itemsize */ 0, /* tp_dealloc */ @@ -109,7 +127,7 @@ PyTypeObject TagType = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "Tag objects", /* tp_doc */ + Tag__doc__, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ diff --git a/src/tree.c b/src/tree.c index 195bd69..feb9a1a 100644 --- a/src/tree.c +++ b/src/tree.c @@ -433,36 +433,39 @@ TreeIter_iternext(TreeIter *self) return NULL; self->i += 1; - return (TreeEntry*)wrap_tree_entry(git_tree_entry_dup(tree_entry), self->owner); + return (TreeEntry*)wrap_tree_entry(git_tree_entry_dup(tree_entry), + self->owner); } + +PyDoc_STRVAR(TreeIter__doc__, "Tree iterator."); + PyTypeObject TreeIterType = { PyVarObject_HEAD_INIT(NULL, 0) - "_pygit2.TreeIter", /* tp_name */ - sizeof(TreeIter), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)TreeIter_dealloc , /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | - Py_TPFLAGS_BASETYPE, /* tp_flags */ - 0, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - PyObject_SelfIter, /* tp_iter */ - (iternextfunc)TreeIter_iternext, /* tp_iternext */ + "_pygit2.TreeIter", /* tp_name */ + sizeof(TreeIter), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)TreeIter_dealloc , /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + TreeIter__doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + PyObject_SelfIter, /* tp_iter */ + (iternextfunc)TreeIter_iternext, /* tp_iternext */ }; diff --git a/src/treebuilder.c b/src/treebuilder.c index 0d8fdac..c1acb9a 100644 --- a/src/treebuilder.c +++ b/src/treebuilder.c @@ -42,6 +42,11 @@ TreeBuilder_dealloc(TreeBuilder *self) PyObject_Del(self); } + +PyDoc_STRVAR(TreeBuilder_insert__doc__, + "insert(name, oid, attr)\n\n" + "Insert or replace an entry in the treebuilder."); + PyObject * TreeBuilder_insert(TreeBuilder *self, PyObject *args) { @@ -68,6 +73,11 @@ TreeBuilder_insert(TreeBuilder *self, PyObject *args) Py_RETURN_NONE; } + +PyDoc_STRVAR(TreeBuilder_write__doc__, + "write() -> bytes\n\n" + "Write the tree to the given repository."); + PyObject * TreeBuilder_write(TreeBuilder *self) { @@ -81,6 +91,11 @@ TreeBuilder_write(TreeBuilder *self) return git_oid_to_python(&oid); } + +PyDoc_STRVAR(TreeBuilder_remove__doc__, + "remove(name)\n\n" + "Remove an entry from the builder."); + PyObject * TreeBuilder_remove(TreeBuilder *self, PyObject *py_filename) { @@ -98,6 +113,11 @@ TreeBuilder_remove(TreeBuilder *self, PyObject *py_filename) Py_RETURN_NONE; } + +PyDoc_STRVAR(TreeBuilder_clear__doc__, + "clear()\n\n" + "Clear all the entries in the builder."); + PyObject * TreeBuilder_clear(TreeBuilder *self) { @@ -106,17 +126,16 @@ TreeBuilder_clear(TreeBuilder *self) } PyMethodDef TreeBuilder_methods[] = { - {"insert", (PyCFunction)TreeBuilder_insert, METH_VARARGS, - "Insert or replace an entry in the treebuilder"}, - {"write", (PyCFunction)TreeBuilder_write, METH_NOARGS, - "Write the tree to the given repository"}, - {"remove", (PyCFunction)TreeBuilder_remove, METH_O, - "Remove an entry from the builder"}, - {"clear", (PyCFunction)TreeBuilder_clear, METH_NOARGS, - "Clear all the entries in the builder"}, - {NULL, NULL, 0, NULL} + METHOD(TreeBuilder, insert, METH_VARARGS), + METHOD(TreeBuilder, write, METH_NOARGS), + METHOD(TreeBuilder, remove, METH_O), + METHOD(TreeBuilder, clear, METH_NOARGS), + {NULL} }; + +PyDoc_STRVAR(TreeBuilder__doc__, "TreeBuilder objects"); + PyTypeObject TreeBuilderType = { PyVarObject_HEAD_INIT(NULL, 0) "_pygit2.TreeBuilder", /* tp_name */ @@ -138,7 +157,7 @@ PyTypeObject TreeBuilderType = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - "TreeBuilder objects", /* tp_doc */ + TreeBuilder__doc__, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ diff --git a/src/walker.c b/src/walker.c index 3069e9e..f7f0b14 100644 --- a/src/walker.c +++ b/src/walker.c @@ -43,6 +43,11 @@ Walker_dealloc(Walker *self) PyObject_Del(self); } + +PyDoc_STRVAR(Walker_hide__doc__, + "hide(oid)\n\n" + "Mark a commit (and its ancestors) uninteresting for the output."); + PyObject * Walker_hide(Walker *self, PyObject *py_hex) { @@ -50,7 +55,6 @@ Walker_hide(Walker *self, PyObject *py_hex) git_oid oid; err = py_str_to_git_oid_expand(self->repo->repo, py_hex, &oid); - if (err < 0) return Error_set(err); @@ -61,6 +65,11 @@ Walker_hide(Walker *self, PyObject *py_hex) Py_RETURN_NONE; } + +PyDoc_STRVAR(Walker_push__doc__, + "push(oid)\n\n" + "Mark a commit to start traversal from."); + PyObject * Walker_push(Walker *self, PyObject *py_hex) { @@ -78,6 +87,11 @@ Walker_push(Walker *self, PyObject *py_hex) Py_RETURN_NONE; } + +PyDoc_STRVAR(Walker_sort__doc__, + "sort(mode)\n\n" + "Change the sorting mode (this resets the walker)."); + PyObject * Walker_sort(Walker *self, PyObject *py_sort_mode) { @@ -92,6 +106,11 @@ Walker_sort(Walker *self, PyObject *py_sort_mode) Py_RETURN_NONE; } + +PyDoc_STRVAR(Walker_reset__doc__, + "reset()\n\n" + "Reset the walking machinery for reuse."); + PyObject * Walker_reset(Walker *self) { @@ -132,17 +151,16 @@ Walker_iternext(Walker *self) } PyMethodDef Walker_methods[] = { - {"hide", (PyCFunction)Walker_hide, METH_O, - "Mark a commit (and its ancestors) uninteresting for the output."}, - {"push", (PyCFunction)Walker_push, METH_O, - "Mark a commit to start traversal from."}, - {"reset", (PyCFunction)Walker_reset, METH_NOARGS, - "Reset the walking machinery for reuse."}, - {"sort", (PyCFunction)Walker_sort, METH_O, - "Change the sorting mode (this resets the walker)."}, + METHOD(Walker, hide, METH_O), + METHOD(Walker, push, METH_O), + METHOD(Walker, reset, METH_NOARGS), + METHOD(Walker, sort, METH_O), {NULL} }; + +PyDoc_STRVAR(Walker__doc__, "Revision walker."); + PyTypeObject WalkerType = { PyVarObject_HEAD_INIT(NULL, 0) "_pygit2.Walker", /* tp_name */ @@ -164,7 +182,7 @@ PyTypeObject WalkerType = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ - "Revision walker", /* tp_doc */ + Walker__doc__, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */