allow for keyword args in init_repository
This implements five ways to init a repo: import pygit2 as git git.init_repository("/tmp/foo/") git.init_repository("/tmp/foo/", True) git.init_repository("/tmp/foo/", False) git.init_repository("/tmp/foo/", bare=True) git.init_repository("/tmp/foo/", bare=False) Since one is still able to pass the bare as a positional argument, this change is perfectly backwards compatible. All existing code will continue to work.
This commit is contained in:
parent
276a6dbe2a
commit
25947338b8
12
src/pygit2.c
12
src/pygit2.c
@ -62,20 +62,20 @@ extern PyTypeObject RemoteType;
|
|||||||
|
|
||||||
|
|
||||||
PyDoc_STRVAR(init_repository__doc__,
|
PyDoc_STRVAR(init_repository__doc__,
|
||||||
"init_repository(path, bare) -> Repository\n"
|
"init_repository(path, bare=False) -> Repository\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Creates a new Git repository in the given path.");
|
"Creates a new Git repository in the given path.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
init_repository(PyObject *self, PyObject *args)
|
init_repository(PyObject *self, PyObject *args, PyObject *kw) {
|
||||||
{
|
|
||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
Repository *py_repo;
|
Repository *py_repo;
|
||||||
const char *path;
|
const char *path;
|
||||||
unsigned int bare;
|
unsigned int bare = 0;
|
||||||
int err;
|
int err;
|
||||||
|
static char * kwlist[] = {"path", "bare", NULL};
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "sI", &path, &bare))
|
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|I", kwlist, &path, &bare))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
err = git_repository_init(&repo, path, bare);
|
err = git_repository_init(&repo, path, bare);
|
||||||
@ -168,7 +168,7 @@ hash(PyObject *self, PyObject *args)
|
|||||||
|
|
||||||
|
|
||||||
PyMethodDef module_methods[] = {
|
PyMethodDef module_methods[] = {
|
||||||
{"init_repository", init_repository, METH_VARARGS, init_repository__doc__},
|
{"init_repository", init_repository, METH_VARARGS|METH_KEYWORDS, init_repository__doc__},
|
||||||
{"discover_repository", discover_repository, METH_VARARGS,
|
{"discover_repository", discover_repository, METH_VARARGS,
|
||||||
discover_repository__doc__},
|
discover_repository__doc__},
|
||||||
{"hashfile", hashfile, METH_VARARGS, hashfile__doc__},
|
{"hashfile", hashfile, METH_VARARGS, hashfile__doc__},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user