Python API already sets exceptions on error
This commit is contained in:
38
src/remote.c
38
src/remote.c
@@ -103,16 +103,13 @@ get_pylist_from_git_strarray(git_strarray *strarray)
|
|||||||
PyObject *new_list;
|
PyObject *new_list;
|
||||||
|
|
||||||
new_list = PyList_New(strarray->count);
|
new_list = PyList_New(strarray->count);
|
||||||
|
|
||||||
if (new_list == NULL)
|
if (new_list == NULL)
|
||||||
return Error_set(GITERR_NOMEMORY);
|
return NULL;
|
||||||
|
|
||||||
for (index = 0; index < strarray->count; (index)++ ) {
|
for (index = 0; index < strarray->count; index++)
|
||||||
PyList_SET_ITEM(
|
PyList_SET_ITEM(new_list, index,
|
||||||
new_list,
|
|
||||||
index,
|
|
||||||
to_unicode(strarray->strings[index], NULL, NULL));
|
to_unicode(strarray->strings[index], NULL, NULL));
|
||||||
}
|
|
||||||
return new_list;
|
return new_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +125,6 @@ Remote_get_fetch_refspecs(Remote *self)
|
|||||||
PyObject *new_list;
|
PyObject *new_list;
|
||||||
|
|
||||||
err = git_remote_get_fetch_refspecs(&refspecs, self->remote);
|
err = git_remote_get_fetch_refspecs(&refspecs, self->remote);
|
||||||
|
|
||||||
if (err != GIT_OK)
|
if (err != GIT_OK)
|
||||||
return Error_set(err);
|
return Error_set(err);
|
||||||
|
|
||||||
@@ -150,7 +146,6 @@ Remote_get_push_refspecs(Remote *self)
|
|||||||
PyObject *new_list;
|
PyObject *new_list;
|
||||||
|
|
||||||
err = git_remote_get_push_refspecs(&refspecs, self->remote);
|
err = git_remote_get_push_refspecs(&refspecs, self->remote);
|
||||||
|
|
||||||
if (err != GIT_OK)
|
if (err != GIT_OK)
|
||||||
return Error_set(err);
|
return Error_set(err);
|
||||||
|
|
||||||
@@ -166,16 +161,18 @@ get_strarraygit_from_pylist(git_strarray *array, PyObject *pylist)
|
|||||||
{
|
{
|
||||||
long index, n;
|
long index, n;
|
||||||
PyObject *item;
|
PyObject *item;
|
||||||
|
void *ptr;
|
||||||
|
|
||||||
n = PyObject_Length(pylist);
|
n = PyObject_Length(pylist);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
goto error;
|
return -1;
|
||||||
|
|
||||||
/* allocate new git_strarray */
|
/* allocate new git_strarray */
|
||||||
void *ptr = calloc(n, sizeof(char *));
|
ptr = calloc(n, sizeof(char *));
|
||||||
|
if (!ptr) {
|
||||||
if (!ptr)
|
PyErr_SetNone(PyExc_MemoryError);
|
||||||
goto error;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
array->strings = ptr;
|
array->strings = ptr;
|
||||||
array->count = n;
|
array->count = n;
|
||||||
@@ -186,10 +183,6 @@ get_strarraygit_from_pylist(git_strarray *array, PyObject *pylist)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return GIT_OK;
|
return GIT_OK;
|
||||||
|
|
||||||
error:
|
|
||||||
Error_set(GITERR_NOMEMORY);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -206,18 +199,16 @@ Remote_set_fetch_refspecs(Remote *self, PyObject *args)
|
|||||||
git_strarray fetch_refspecs;
|
git_strarray fetch_refspecs;
|
||||||
|
|
||||||
if (! PyArg_Parse(args, "O", &pyrefspecs))
|
if (! PyArg_Parse(args, "O", &pyrefspecs))
|
||||||
return Error_set(GITERR_INVALID);
|
return NULL;
|
||||||
|
|
||||||
if (get_strarraygit_from_pylist(&fetch_refspecs, pyrefspecs) != GIT_OK)
|
if (get_strarraygit_from_pylist(&fetch_refspecs, pyrefspecs) != GIT_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
err = git_remote_set_fetch_refspecs(self->remote, &fetch_refspecs);
|
err = git_remote_set_fetch_refspecs(self->remote, &fetch_refspecs);
|
||||||
|
|
||||||
git_strarray_free(&fetch_refspecs);
|
git_strarray_free(&fetch_refspecs);
|
||||||
|
|
||||||
if (err != GIT_OK) {
|
if (err != GIT_OK)
|
||||||
return Error_set(err);
|
return Error_set(err);
|
||||||
}
|
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
@@ -236,13 +227,12 @@ Remote_set_push_refspecs(Remote *self, PyObject *args)
|
|||||||
git_strarray push_refspecs;
|
git_strarray push_refspecs;
|
||||||
|
|
||||||
if (! PyArg_Parse(args, "O", &pyrefspecs))
|
if (! PyArg_Parse(args, "O", &pyrefspecs))
|
||||||
return Error_set(GITERR_INVALID);
|
return NULL;
|
||||||
|
|
||||||
if (get_strarraygit_from_pylist(&push_refspecs, pyrefspecs) != 0)
|
if (get_strarraygit_from_pylist(&push_refspecs, pyrefspecs) != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
err = git_remote_set_push_refspecs(self->remote, &push_refspecs);
|
err = git_remote_set_push_refspecs(self->remote, &push_refspecs);
|
||||||
|
|
||||||
git_strarray_free(&push_refspecs);
|
git_strarray_free(&push_refspecs);
|
||||||
|
|
||||||
if (err != GIT_OK)
|
if (err != GIT_OK)
|
||||||
|
Reference in New Issue
Block a user