From 4660c9c149ac8c11edba7165f7d36925087c49a6 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 25 Oct 2012 13:52:15 -0400 Subject: [PATCH] config: extend Config.add_file() accept keyword arguments. This provides backward compatibility with older code that does not specify `force`. Signed-off-by: W. Trevor King --- include/pygit2/config.h | 2 +- src/pygit2/config.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/pygit2/config.h b/include/pygit2/config.h index b07849e..62dbc83 100644 --- a/include/pygit2/config.h +++ b/include/pygit2/config.h @@ -34,7 +34,7 @@ PyObject* Config_get_global_config(void); PyObject* Config_get_system_config(void); -PyObject* Config_add_file(Config *self, PyObject *args); +PyObject* Config_add_file(Config *self, PyObject *args, PyObject *kwds); PyObject* Config_getitem(Config *self, PyObject *key); PyObject* Config_foreach(Config *self, PyObject *args); PyObject* Config_get_multivar(Config *self, PyObject *args); diff --git a/src/pygit2/config.c b/src/pygit2/config.c index 6f3bb9e..1c052a4 100644 --- a/src/pygit2/config.c +++ b/src/pygit2/config.c @@ -263,14 +263,17 @@ Config_foreach(Config *self, PyObject *args) } PyObject * -Config_add_file(Config *self, PyObject *args) +Config_add_file(Config *self, PyObject *args, PyObject *kwds) { + char *keywords[] = {"path", "level", "force", NULL}; int err; char *path; - unsigned int level; - int force; + unsigned int level = 0; + int force = 0; - if (!PyArg_ParseTuple(args, "sIi", &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); @@ -353,7 +356,7 @@ PyMethodDef Config_methods[] = { "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, + {"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'' "