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 <wking@tremily.us>
This commit is contained in:
W. Trevor King
2012-10-25 13:52:15 -04:00
parent ebdb85e754
commit 4660c9c149
2 changed files with 9 additions and 6 deletions

View File

@@ -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);

View File

@@ -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'' "