Fix unit test in config
This commit is contained in:
48
src/config.c
48
src/config.c
@@ -75,11 +75,10 @@ Config_init(Config *self, PyObject *args, PyObject *kwds)
|
|||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
git_config_free(self->config);
|
git_config_free(self->config);
|
||||||
|
|
||||||
if (err == GIT_ENOTFOUND) {
|
if (err == GIT_ENOTFOUND)
|
||||||
Error_set_exc(PyExc_IOError);
|
Error_set_exc(PyExc_IOError);
|
||||||
} else {
|
else
|
||||||
Error_set(err);
|
Error_set(err);
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -187,11 +186,11 @@ Config_getitem(Config *self, PyObject *py_key)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (git_config_parse_int64(&value_int, value_str) == 0)
|
if (git_config_parse_int64(&value_int, value_str) == 0)
|
||||||
py_value = PyLong_FromLongLong(value_int);
|
py_value = PyLong_FromLongLong(value_int);
|
||||||
else if(git_config_parse_bool(&value_bool, value_str) == 0)
|
else if(git_config_parse_bool(&value_bool, value_str) == 0)
|
||||||
py_value = PyBool_FromLong(value_bool);
|
py_value = PyBool_FromLong(value_bool);
|
||||||
else
|
else
|
||||||
py_value = to_unicode(value_str, NULL, NULL);
|
py_value = to_unicode(value_str, NULL, NULL);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
free(key);
|
free(key);
|
||||||
@@ -323,10 +322,8 @@ Config_add_file(Config *self, PyObject *args, PyObject *kwds)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
err = git_config_add_file_ondisk(self->config, path, level, force);
|
err = git_config_add_file_ondisk(self->config, path, level, force);
|
||||||
if (err < 0) {
|
if (err < 0)
|
||||||
Error_set_str(err, path);
|
return Error_set_str(err, path);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
@@ -342,15 +339,21 @@ PyDoc_STRVAR(Config_get_multivar__doc__,
|
|||||||
int
|
int
|
||||||
Config_get_multivar_fn_wrapper(const git_config_entry *value, void *data)
|
Config_get_multivar_fn_wrapper(const git_config_entry *value, void *data)
|
||||||
{
|
{
|
||||||
PyObject *item = NULL;
|
PyObject *item;
|
||||||
|
|
||||||
if (!(item = to_unicode(value->value, NULL, NULL)))
|
item = to_unicode(value->value, NULL, NULL);
|
||||||
|
if (item == NULL)
|
||||||
|
/* FIXME Right now there is no way to forward errors through the
|
||||||
|
* libgit2 API, open an issue or pull-request to libgit2.
|
||||||
|
*
|
||||||
|
* See libgit2/src/config_file.c:443 (config_get_multivar).
|
||||||
|
* Comment says "early termination by the user is not an error".
|
||||||
|
* That's wrong.
|
||||||
|
*/
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
PyList_Append((PyObject *)data, item);
|
PyList_Append((PyObject *)data, item);
|
||||||
|
|
||||||
Py_CLEAR(item);
|
Py_CLEAR(item);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,6 +362,7 @@ Config_get_multivar(Config *self, PyObject *args)
|
|||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
PyObject *list;
|
PyObject *list;
|
||||||
|
Py_ssize_t size;
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
const char *regex = NULL;
|
const char *regex = NULL;
|
||||||
|
|
||||||
@@ -369,14 +373,16 @@ Config_get_multivar(Config *self, PyObject *args)
|
|||||||
err = git_config_get_multivar(self->config, name, regex,
|
err = git_config_get_multivar(self->config, name, regex,
|
||||||
Config_get_multivar_fn_wrapper,
|
Config_get_multivar_fn_wrapper,
|
||||||
(void *)list);
|
(void *)list);
|
||||||
if (err < 0) {
|
|
||||||
Py_CLEAR(list);
|
|
||||||
|
|
||||||
if (err == GIT_ENOTFOUND)
|
if (err < 0) {
|
||||||
Error_set(err);
|
/* XXX The return value of git_config_get_multivar is not reliable,
|
||||||
else
|
* see https://github.com/libgit2/libgit2/pull/1712
|
||||||
PyErr_SetNone(PyExc_TypeError);
|
* Once libgit2 0.20 is released, we will remove this test. */
|
||||||
return NULL;
|
if (err == GIT_ENOTFOUND && PyList_Size(list) != 0)
|
||||||
|
return list;
|
||||||
|
|
||||||
|
Py_CLEAR(list);
|
||||||
|
return Error_set(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
@@ -85,7 +85,8 @@
|
|||||||
|
|
||||||
PYGIT2_FN_UNUSED
|
PYGIT2_FN_UNUSED
|
||||||
Py_LOCAL_INLINE(PyObject*)
|
Py_LOCAL_INLINE(PyObject*)
|
||||||
to_unicode_n(const char *value, size_t len, const char *encoding, const char *errors)
|
to_unicode_n(const char *value, size_t len, const char *encoding,
|
||||||
|
const char *errors)
|
||||||
{
|
{
|
||||||
if (encoding == NULL) {
|
if (encoding == NULL) {
|
||||||
/* If the encoding is not explicit, it may not be UTF-8, so it
|
/* If the encoding is not explicit, it may not be UTF-8, so it
|
||||||
|
Reference in New Issue
Block a user