Exemplo n.º 1
0
/**
 * ggit_config_foreach:
 * @config: a #GgitConfig.
 * @callback: (scope call): a #GgitConfigCallback.
 * @user_data: (allow-none): the user data for @callback.
 * @error: a #GError for error reporting, or %NULL.
 *
 * Call @callback for each configuration value.
 *
 * Returns: %TRUE if successfull, %FALSE otherwise
 *
 **/
gboolean
ggit_config_foreach (GgitConfig          *config,
                     GgitConfigCallback   callback,
                     gpointer             user_data,
                     GError             **error)
{
	gint ret;
	CallbackWrapperData wrapper_data;

	g_return_val_if_fail (GGIT_IS_CONFIG (config), FALSE);
	g_return_val_if_fail (callback != NULL, FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	wrapper_data.user_data = user_data;
	wrapper_data.callback = callback;

	ret = git_config_foreach (_ggit_native_get (config), callback_wrapper, &wrapper_data);

	if (ret != GIT_OK)
	{
		_ggit_error_set (error, ret);
		return FALSE;
	}

	return TRUE;
}
Exemplo n.º 2
0
void test_config_read__foreach(void)
{
	git_config *cfg;
	int count, ret;

	cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));

	count = 0;
	cl_git_pass(git_config_foreach(cfg, count_cfg_entries, &count));
	cl_assert_equal_i(5, count);

	count = 3;
	cl_git_fail(ret = git_config_foreach(cfg, cfg_callback_countdown, &count));
	cl_assert_equal_i(GIT_EUSER, ret);

	git_config_free(cfg);
}
Exemplo n.º 3
0
void test_config_read__foreach(void)
{
	git_config *cfg;
	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_foreach(cfg, count_cfg_entries_and_compare_levels, &count));
	cl_assert_equal_i(7, count);

	count = 3;
	cl_git_fail(ret = git_config_foreach(cfg, cfg_callback_countdown, &count));
	cl_assert_equal_i(-100, ret);

	git_config_free(cfg);
}
Exemplo n.º 4
0
void test_config_read__parent_dir_is_file(void)
{
	git_config *cfg;
	int count;

	cl_git_pass(git_config_new(&cfg));
	/*
	 * Verify we can add non-existing files when the parent directory is not
	 * a directory.
	 */
	cl_git_pass(git_config_add_file_ondisk(cfg, "/dev/null/.gitconfig",
		GIT_CONFIG_LEVEL_SYSTEM, NULL, 0));

	count = 0;
	cl_git_pass(git_config_foreach(cfg, count_cfg_entries_and_compare_levels, &count));
	cl_assert_equal_i(0, count);

	git_config_free(cfg);
}
Exemplo n.º 5
0
PyObject *
Config_foreach(Config *self, PyObject *args)
{
    int ret;
    PyObject *py_callback;
    PyObject *py_payload;

    if (!PyArg_ParseTuple(args, "O|O", &py_callback, &py_payload))
        return NULL;

    if (!PyCallable_Check(py_callback)) {
        PyErr_SetString(PyExc_TypeError,
                        "Argument 'callback' is not callable");
        return NULL;
    }

    ret = git_config_foreach(self->config, Config_foreach_callback_wrapper,
            (void *)args);

    return PyInt_FromLong((long)ret);
}
Exemplo n.º 6
0
/* This would ideally issue a warning, if we had a way to do so. */
void test_config_read__nosection(void)
{
	git_config *cfg;
	git_buf buf = GIT_BUF_INIT;
	int seen = 0;

	cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-nosection")));

	/*
	 * Given a key with no section, we do not allow reading it,
	 * but we do include it in an iteration over the config
	 * store. This appears to match how git's own APIs (and
	 * git-config(1)) behave.
	 */

	cl_git_fail_with(git_config_get_string_buf(&buf, cfg, "key"), GIT_EINVALIDSPEC);

	cl_git_pass(git_config_foreach(cfg, read_nosection_cb, &seen));
	cl_assert_equal_i(seen, 1);

	git_buf_dispose(&buf);
	git_config_free(cfg);
}
Exemplo n.º 7
0
int goCfgForEach(git_config *cfg, void *payload) {
	return git_config_foreach(cfg, go_cfg_foreach_callback2, payload);
}