Beispiel #1
0
void test_config_read__iterator(void)
{
	git_config *cfg;
	git_config_iterator *iter;
	git_config_entry *entry;
	int count, ret;

	cl_git_pass(git_config_new(&cfg));
	cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
		GIT_CONFIG_LEVEL_SYSTEM, NULL, 0));
	cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
		GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));

	count = 0;
	cl_git_pass(git_config_iterator_new(&iter, cfg));

	while ((ret = git_config_next(&entry, iter)) == 0) {
		count++;
	}

	git_config_iterator_free(iter);
	cl_assert_equal_i(GIT_ITEROVER, ret);
	cl_assert_equal_i(7, count);

	count = 3;
	cl_git_pass(git_config_iterator_new(&iter, cfg));

	git_config_iterator_free(iter);
	git_config_free(cfg);
}
Beispiel #2
0
PyObject *
ConfigIter_iternext(ConfigIter *self)
{
    int err;
    git_config_entry *entry;

    if ((err = git_config_next(&entry, self->iter)) < 0)
        return Error_set(err);

    return Py_BuildValue("ss", entry->name, entry->value);
}
Beispiel #3
0
static void check_glob_iter(git_config *cfg, const char *regexp, int expected)
{
	git_config_iterator *iter;
	git_config_entry *entry;
	int count, error;

	cl_git_pass(git_config_iterator_glob_new(&iter, cfg, regexp));

	count = 0;
	while ((error = git_config_next(&entry, iter)) == 0)
		count++;

	cl_assert_equal_i(GIT_ITEROVER, error);
	cl_assert_equal_i(expected, count);
	git_config_iterator_free(iter);
}
Beispiel #4
0
PyObject *
Config_get_multivar(Config *self, PyObject *args)
{
    int err;
    PyObject *list;
    const char *name = NULL;
    const char *regex = NULL;
    git_config_iterator *iter;
    git_config_entry *entry;

    if (!PyArg_ParseTuple(args, "s|s", &name, &regex))
        return NULL;

    list = PyList_New(0);
    err = git_config_multivar_iterator_new(&iter, self->config, name, regex);
    if (err < 0)
        return Error_set(err);

    while ((err = git_config_next(&entry, iter)) == 0) {
        PyObject *item;

        item = to_unicode(entry->value, NULL, NULL);
        if (item == NULL) {
            git_config_iterator_free(iter);
            return NULL;
        }

        PyList_Append(list, item);
        Py_CLEAR(item);
    }

    git_config_iterator_free(iter);
    if (err == GIT_ITEROVER)
        err = 0;

    if (err < 0)
        return Error_set(err);

    return list;
}
Beispiel #5
0
void test_config_read__iterator(void)
{
	const char *keys[] = {
		"core.dummy2",
		"core.verylong",
		"core.dummy",
		"remote.ab.url",
		"remote.abba.url",
		"core.dummy2",
		"core.global"
	};
	git_config *cfg;
	git_config_iterator *iter;
	git_config_entry *entry;
	int count, ret;

	cl_git_pass(git_config_new(&cfg));
	cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
		GIT_CONFIG_LEVEL_SYSTEM, NULL, 0));
	cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
		GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));

	count = 0;
	cl_git_pass(git_config_iterator_new(&iter, cfg));

	while ((ret = git_config_next(&entry, iter)) == 0) {
		cl_assert_equal_s(entry->name, keys[count]);
		count++;
	}

	git_config_iterator_free(iter);
	cl_assert_equal_i(GIT_ITEROVER, ret);
	cl_assert_equal_i(7, count);

	count = 3;
	cl_git_pass(git_config_iterator_new(&iter, cfg));

	git_config_iterator_free(iter);
	git_config_free(cfg);
}