diff options
author | Jelmer Vernooij <jelmer@jelmer.uk> | 2016-07-24 16:20:15 +0000 |
---|---|---|
committer | Jelmer Vernooij <jelmer@jelmer.uk> | 2016-07-24 16:20:15 +0000 |
commit | a11c569858b50fb7314bb80b9ea8f32fae5c3691 (patch) | |
tree | eaab462289c5a0cf4a4699984ffe707827f2d1e8 /subvertpy | |
parent | 05887003d3af4a02b9ed9f8577c35548bc1eeebb (diff) |
Split out path_list_to_apr_array.
Diffstat (limited to 'subvertpy')
-rw-r--r-- | subvertpy/_ra.c | 4 | ||||
-rw-r--r-- | subvertpy/client.c | 71 | ||||
-rw-r--r-- | subvertpy/util.c | 6 | ||||
-rw-r--r-- | subvertpy/util.h | 2 |
4 files changed, 56 insertions, 27 deletions
diff --git a/subvertpy/_ra.c b/subvertpy/_ra.c index 1afbd41d..90ee6b29 100644 --- a/subvertpy/_ra.c +++ b/subvertpy/_ra.c @@ -765,7 +765,7 @@ apr_array_header_t **apr_paths, apr_array_header_t **apr_revprops) * so tweak our own parameters a bit. */ *apr_paths = apr_array_make(*pool, 1, sizeof(char *)); APR_ARRAY_PUSH(*apr_paths, char *) = apr_pstrdup(*pool, ""); - } else if (!path_list_to_apr_array(*pool, paths, apr_paths)) { + } else if (!relpath_list_to_apr_array(*pool, paths, apr_paths)) { goto fail_prep; } @@ -2057,7 +2057,7 @@ static PyObject *ra_mergeinfo(PyObject *self, PyObject *args) if (temp_pool == NULL) return NULL; - if (!path_list_to_apr_array(temp_pool, paths, &apr_paths)) { + if (!relpath_list_to_apr_array(temp_pool, paths, &apr_paths)) { apr_pool_destroy(temp_pool); return NULL; } diff --git a/subvertpy/client.c b/subvertpy/client.c index 53e9580e..26f96d07 100644 --- a/subvertpy/client.c +++ b/subvertpy/client.c @@ -73,6 +73,35 @@ typedef struct { static int client_set_auth(PyObject *self, PyObject *auth, void *closure); static int client_set_config(PyObject *self, PyObject *auth, void *closure); +static bool client_path_list_to_apr_array(apr_pool_t *pool, PyObject *l, apr_array_header_t **ret) +{ + int i; + if (l == Py_None) { + *ret = NULL; + return true; + } + if (PyString_Check(l)) { + *ret = apr_array_make(pool, 1, sizeof(char *)); + APR_ARRAY_PUSH(*ret, const char *) = svn_path_canonicalize(PyString_AsString(l), pool); + } else if (PyList_Check(l)) { + *ret = apr_array_make(pool, PyList_Size(l), sizeof(char *)); + for (i = 0; i < PyList_GET_SIZE(l); i++) { + PyObject *item = PyList_GET_ITEM(l, i); + if (!PyString_Check(item)) { + PyErr_Format(PyExc_TypeError, "Expected list of strings, item was %s", item->ob_type->tp_name); + return false; + } + APR_ARRAY_PUSH(*ret, const char *) = svn_path_canonicalize(PyString_AsString(item), pool); + } + } else { + PyErr_Format(PyExc_TypeError, "Expected list of strings, got: %s", + l->ob_type->tp_name); + return false; + } + + return true; +} + static bool to_opt_revision(PyObject *arg, svn_opt_revision_t *ret) { if (PyLong_Check(arg)) { @@ -699,7 +728,7 @@ static PyObject *client_commit(PyObject *self, PyObject *args, PyObject *kwargs) if (temp_pool == NULL) { return NULL; } - if (!path_list_to_apr_array(temp_pool, targets, &apr_targets)) { + if (!client_path_list_to_apr_array(temp_pool, targets, &apr_targets)) { apr_pool_destroy(temp_pool); return NULL; } @@ -823,24 +852,24 @@ static PyObject *client_cat(PyObject *self, PyObject *args, PyObject *kwargs) static PyObject *client_delete(PyObject *self, PyObject *args) { - PyObject *paths; - bool force=false, keep_local=false; - apr_pool_t *temp_pool; - svn_commit_info_t *commit_info = NULL; - PyObject *ret; - apr_array_header_t *apr_paths; - ClientObject *client = (ClientObject *)self; + PyObject *paths; + bool force=false, keep_local=false; + apr_pool_t *temp_pool; + svn_commit_info_t *commit_info = NULL; + PyObject *ret; + apr_array_header_t *apr_paths; + ClientObject *client = (ClientObject *)self; - if (!PyArg_ParseTuple(args, "O|bb", &paths, &force, &keep_local)) - return NULL; + if (!PyArg_ParseTuple(args, "O|bb", &paths, &force, &keep_local)) + return NULL; - temp_pool = Pool(NULL); - if (temp_pool == NULL) - return NULL; - if (!path_list_to_apr_array(temp_pool, paths, &apr_paths)) { - apr_pool_destroy(temp_pool); - return NULL; - } + temp_pool = Pool(NULL); + if (temp_pool == NULL) + return NULL; + if (!client_path_list_to_apr_array(temp_pool, paths, &apr_paths)) { + apr_pool_destroy(temp_pool); + return NULL; + } #if ONLY_SINCE_SVN(1, 5) RUN_SVN_WITH_POOL(temp_pool, svn_client_delete3(&commit_info, @@ -882,7 +911,7 @@ static PyObject *client_mkdir(PyObject *self, PyObject *args) temp_pool = Pool(NULL); if (temp_pool == NULL) return NULL; - if (!path_list_to_apr_array(temp_pool, paths, &apr_paths)) { + if (!client_path_list_to_apr_array(temp_pool, paths, &apr_paths)) { apr_pool_destroy(temp_pool); return NULL; } @@ -1308,7 +1337,7 @@ static PyObject *client_update(PyObject *self, PyObject *args, PyObject *kwargs) temp_pool = Pool(NULL); if (temp_pool == NULL) return NULL; - if (!path_list_to_apr_array(temp_pool, paths, &apr_paths)) { + if (!client_path_list_to_apr_array(temp_pool, paths, &apr_paths)) { apr_pool_destroy(temp_pool); return NULL; } @@ -1577,13 +1606,13 @@ static PyObject *client_log(PyObject *self, PyObject *args, PyObject *kwargs) } #endif - if (!path_list_to_apr_array(temp_pool, paths, &apr_paths)) { + if (!client_path_list_to_apr_array(temp_pool, paths, &apr_paths)) { apr_pool_destroy(temp_pool); return NULL; } if (revprops) { - if (!path_list_to_apr_array(temp_pool, revprops, &apr_revprops)) { + if (!string_list_to_apr_array(temp_pool, revprops, &apr_revprops)) { apr_pool_destroy(temp_pool); return NULL; } diff --git a/subvertpy/util.c b/subvertpy/util.c index b564f86a..568a69e6 100644 --- a/subvertpy/util.c +++ b/subvertpy/util.c @@ -348,7 +348,7 @@ bool string_list_to_apr_array(apr_pool_t *pool, PyObject *l, apr_array_header_t return true; } -bool path_list_to_apr_array(apr_pool_t *pool, PyObject *l, apr_array_header_t **ret) +bool relpath_list_to_apr_array(apr_pool_t *pool, PyObject *l, apr_array_header_t **ret) { int i; if (l == Py_None) { @@ -357,7 +357,7 @@ bool path_list_to_apr_array(apr_pool_t *pool, PyObject *l, apr_array_header_t ** } if (PyString_Check(l)) { *ret = apr_array_make(pool, 1, sizeof(char *)); - APR_ARRAY_PUSH(*ret, const char *) = svn_path_canonicalize(PyString_AsString(l), pool); + APR_ARRAY_PUSH(*ret, const char *) = py_object_to_svn_relpath(l, pool); } else if (PyList_Check(l)) { *ret = apr_array_make(pool, PyList_Size(l), sizeof(char *)); for (i = 0; i < PyList_GET_SIZE(l); i++) { @@ -366,7 +366,7 @@ bool path_list_to_apr_array(apr_pool_t *pool, PyObject *l, apr_array_header_t ** PyErr_Format(PyExc_TypeError, "Expected list of strings, item was %s", item->ob_type->tp_name); return false; } - APR_ARRAY_PUSH(*ret, const char *) = svn_path_canonicalize(PyString_AsString(item), pool); + APR_ARRAY_PUSH(*ret, const char *) = py_object_to_svn_relpath(item, pool); } } else { PyErr_Format(PyExc_TypeError, "Expected list of strings, got: %s", diff --git a/subvertpy/util.h b/subvertpy/util.h index ba6a5e3a..b78c8995 100644 --- a/subvertpy/util.h +++ b/subvertpy/util.h @@ -42,7 +42,7 @@ svn_error_t *py_cancel_check(void *cancel_baton); __attribute__((warn_unused_result)) apr_pool_t *Pool(apr_pool_t *parent); void handle_svn_error(svn_error_t *error); bool string_list_to_apr_array(apr_pool_t *pool, PyObject *l, apr_array_header_t **); -bool path_list_to_apr_array(apr_pool_t *pool, PyObject *l, apr_array_header_t **); +bool relpath_list_to_apr_array(apr_pool_t *pool, PyObject *l, apr_array_header_t **); PyObject *prop_hash_to_dict(apr_hash_t *props); apr_hash_t *prop_dict_to_hash(apr_pool_t *pool, PyObject *py_props); svn_error_t *py_svn_log_wrapper(void *baton, apr_hash_t *changed_paths, |