From fcacea310bf38b2edf5660f09a8c9bee2ba76035 Mon Sep 17 00:00:00 2001 From: Martin Lenders Date: Fri, 8 Jun 2012 16:00:59 +0200 Subject: [PATCH] Implement addition of files to Config --- include/pygit2/config.h | 1 + src/pygit2/config.c | 21 +++++++++++++++++++++ test/test_config.py | 13 +++++++++++++ 3 files changed, 35 insertions(+) diff --git a/include/pygit2/config.h b/include/pygit2/config.h index 33b8465..d281902 100644 --- a/include/pygit2/config.h +++ b/include/pygit2/config.h @@ -7,5 +7,6 @@ PyObject* Config_get_global_config(void); PyObject* Config_get_system_config(void); +PyObject* Config_add_file(Config *self, PyObject *args); #endif diff --git a/src/pygit2/config.c b/src/pygit2/config.c index 57378af..d05f1a7 100644 --- a/src/pygit2/config.c +++ b/src/pygit2/config.c @@ -102,6 +102,25 @@ Config_get_system_config(void) return Config_open(path); } +PyObject * +Config_add_file(Config *self, PyObject *args) +{ + int err; + char *path; + int priority; + + if (!PyArg_ParseTuple(args, "si", &path, &priority)) + return NULL; + + err = git_config_add_file_ondisk(self->config, path, priority); + if (err < 0) { + Error_set_str(err, path); + return NULL; + } + + Py_RETURN_NONE; +} + PyMethodDef Config_methods[] = { {"get_system_config", (PyCFunction)Config_get_system_config, METH_NOARGS | METH_STATIC, @@ -109,6 +128,8 @@ PyMethodDef Config_methods[] = { {"get_global_config", (PyCFunction)Config_get_global_config, METH_NOARGS | METH_STATIC, "Return an object representing the global configuration file."}, + {"add_file", (PyCFunction)Config_add_file, METH_VARARGS, + "Add a config file instance to an existing config."}, {NULL} }; diff --git a/test/test_config.py b/test/test_config.py index cda8dea..e3ef10e 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -57,6 +57,19 @@ class ConfigTest(utils.RepoTestCase): self.assertNotEqual(config_write, None) + def test_add(self): + config = pygit2.Config.get_global_config() + + new_file = open(config_filename, "w") + new_file.write("[this]\n\tthat = true\n") + new_file.write("[something \"other\"]\n\there = false") + new_file.close() + + config.add_file(config_filename, 0) + + os.remove(config_filename) + + if __name__ == '__main__': unittest.main()