int Config_setitem(Config *self, PyObject *py_key, PyObject *py_value) { int err; const char *key, *value; PyObject *tkey, *tvalue; key = py_str_borrow_c_str(&tkey, py_key, NULL); if (key == NULL) return -1; if (py_value == NULL) err = git_config_delete_entry(self->config, key); else if (PyBool_Check(py_value)) { err = git_config_set_bool(self->config, key, (int)PyObject_IsTrue(py_value)); } else if (PyLong_Check(py_value)) { err = git_config_set_int64(self->config, key, (int64_t)PyLong_AsLong(py_value)); } else { value = py_str_borrow_c_str(&tvalue, py_value, NULL); err = git_config_set_string(self->config, key, value); Py_DECREF(tvalue); } Py_DECREF(tkey); if (err < 0) { Error_set(err); return -1; } return 0; }
int Config_setitem(Config *self, PyObject *py_key, PyObject *py_value) { int err; char *c_key; char *py_str; if (!(c_key = py_str_to_c_str(py_key,NULL))) return -1; if (!py_value) { err = git_config_delete_entry(self->config, c_key); } else if (PyBool_Check(py_value)) { err = git_config_set_bool(self->config, c_key, (int)PyObject_IsTrue(py_value)); } else if (PyInt_Check(py_value)) { err = git_config_set_int64(self->config, c_key, (int64_t)PyInt_AsLong(py_value)); } else { py_value = PyObject_Str(py_value); py_str = py_str_to_c_str(py_value,NULL); err = git_config_set_string(self->config, c_key, py_str); free(py_str); } free(c_key); if (err < 0) { Error_set(err); return -1; } return 0; }
void test_config_write__replace_value(void) { git_config *cfg; int i; int64_t l, expected = +9223372036854775803; /* By freeing the config, we make sure we flush the values */ cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_set_int32(cfg, "core.dummy", 5)); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy")); cl_assert(i == 5); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_set_int32(cfg, "core.dummy", 1)); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_set_int64(cfg, "core.verylong", expected)); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_get_int64(&l, cfg, "core.verylong")); cl_assert(l == expected); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_must_fail(git_config_get_int32(&i, cfg, "core.verylong")); git_config_free(cfg); cl_git_pass(git_config_open_ondisk(&cfg, "config9")); cl_git_pass(git_config_set_int64(cfg, "core.verylong", 1)); git_config_free(cfg); }
/** * ggit_config_set_int64: * @config: a #GgitConfig. * @name: the name of the configuration value. * @value: the new value. * @error: a #GError for error reporting, or %NULL. * * Set a int64 value. * * Returns: %TRUE if the value was successfully set, %FALSE otherwise. * **/ gboolean ggit_config_set_int64 (GgitConfig *config, const gchar *name, gint64 value, GError **error) { gint ret; g_return_val_if_fail (GGIT_IS_CONFIG (config), FALSE); g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); ret = git_config_set_int64 (_ggit_native_get (config), name, value); if (ret != GIT_OK) { _ggit_error_set (error, ret); return FALSE; } return TRUE; }
void test_config_write__add_value_at_specific_level(void) { git_config *cfg, *cfg_specific; int i; int64_t l, expected = +9223372036854775803; git_buf buf = GIT_BUF_INIT; // open config15 as global level config file cl_git_pass(git_config_new(&cfg)); cl_git_pass(git_config_add_file_ondisk(cfg, "config9", GIT_CONFIG_LEVEL_LOCAL, 0)); cl_git_pass(git_config_add_file_ondisk(cfg, "config15", GIT_CONFIG_LEVEL_GLOBAL, 0)); cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL)); cl_git_pass(git_config_set_int32(cfg_specific, "core.int32global", 28)); cl_git_pass(git_config_set_int64(cfg_specific, "core.int64global", expected)); cl_git_pass(git_config_set_bool(cfg_specific, "core.boolglobal", true)); cl_git_pass(git_config_set_string(cfg_specific, "core.stringglobal", "I'm a global config value!")); git_config_free(cfg_specific); git_config_free(cfg); // open config15 as local level config file cl_git_pass(git_config_open_ondisk(&cfg, "config15")); cl_git_pass(git_config_get_int32(&i, cfg, "core.int32global")); cl_assert_equal_i(28, i); cl_git_pass(git_config_get_int64(&l, cfg, "core.int64global")); cl_assert(l == expected); cl_git_pass(git_config_get_bool(&i, cfg, "core.boolglobal")); cl_assert_equal_b(true, i); cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.stringglobal")); cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf)); git_buf_free(&buf); git_config_free(cfg); }
int git_config_set_int32(git_config *cfg, const char *name, int32_t value) { return git_config_set_int64(cfg, name, (int64_t)value); }