Factor out ra_get_log_prepare() to share with get_log() and iter_log()
authorJelmer Vernooij <jelmer@samba.org>
Wed, 4 Sep 2013 07:31:08 +0000 (07:31 +0000)
committerJelmer Vernooij <jelmer@jelmer.uk>
Thu, 7 Jul 2016 23:35:00 +0000 (23:35 +0000)
Patch by Martin Panter.

subvertpy/_ra.c
subvertpy/_ra_iter_log.c

index decdaf81a2f1c4c8e242aa8a19cf2b822674d642..cd3f48784ab19db557caca7141f1cf5e81a66389 100644 (file)
@@ -731,52 +731,37 @@ static PyObject *ra_get_latest_revnum(PyObject *self)
        return PyInt_FromLong(latest_revnum);
 }
 
-static PyObject *ra_get_log(PyObject *self, PyObject *args, PyObject *kwargs)
-{
-       char *kwnames[] = { "callback", "paths", "start", "end", "limit",
-               "discover_changed_paths", "strict_node_history", "include_merged_revisions", "revprops", NULL };
-       PyObject *callback, *paths;
-       svn_revnum_t start = 0, end = 0;
-       int limit=0; 
-       bool discover_changed_paths=false, strict_node_history=true,include_merged_revisions=false;
-       RemoteAccessObject *ra = (RemoteAccessObject *)self;
-       PyObject *revprops = Py_None;
-       apr_pool_t *temp_pool;
-       apr_array_header_t *apr_paths;
-       apr_array_header_t *apr_revprops;
-
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOll|ibbbO:get_log", kwnames, 
-                                                &callback, &paths, &start, &end, &limit,
-                                                &discover_changed_paths, &strict_node_history,
-                                                &include_merged_revisions, &revprops))
-               return NULL;
 
+static bool ra_get_log_prepare(RemoteAccessObject *ra, PyObject *paths,
+bool include_merged_revisions, PyObject *revprops, apr_pool_t **pool,
+apr_array_header_t **apr_paths, apr_array_header_t **apr_revprops)
+{
        if (ra_check_busy(ra))
-               return NULL;
+               return false;
 
-       temp_pool = Pool(NULL);
-       if (temp_pool == NULL)
-               return NULL;
+       *pool = Pool(NULL);
+       if (*pool == NULL)
+               return false;
        if (paths == Py_None) {
                /* The subversion libraries don't behave as expected, 
                 * so tweak our own parameters a bit. */
-               apr_paths = apr_array_make(temp_pool, 1, sizeof(char *));
-               APR_ARRAY_PUSH(apr_paths, char *) = apr_pstrdup(temp_pool, "");
-       } else if (!path_list_to_apr_array(temp_pool, paths, &apr_paths)) {
-               apr_pool_destroy(temp_pool);
-               return NULL;
+               *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)) {
+               apr_pool_destroy(*pool);
+               return false;
        }
 
 #if ONLY_BEFORE_SVN(1, 5)
        if (revprops == Py_None) {
                PyErr_SetString(PyExc_NotImplementedError,
                        "fetching all revision properties not supported");
-               apr_pool_destroy(temp_pool);
-               return NULL;
+               apr_pool_destroy(*pool);
+               return false;
        } else if (!PySequence_Check(revprops)) {
                PyErr_SetString(PyExc_TypeError, "revprops should be a sequence");
-               apr_pool_destroy(temp_pool);
-               return NULL;
+               apr_pool_destroy(*pool);
+               return false;
        } else {
                int i;
                for (i = 0; i < PySequence_Size(revprops); i++) {
@@ -786,8 +771,8 @@ static PyObject *ra_get_log(PyObject *self, PyObject *args, PyObject *kwargs)
                                strcmp(SVN_PROP_REVISION_DATE, n)) {
                                PyErr_SetString(PyExc_NotImplementedError, 
                                                                "fetching custom revision properties not supported");
-                               apr_pool_destroy(temp_pool);
-                               return NULL;
+                               apr_pool_destroy(*pool);
+                               return false;
                        }
                }
        }
@@ -795,13 +780,41 @@ static PyObject *ra_get_log(PyObject *self, PyObject *args, PyObject *kwargs)
        if (include_merged_revisions) {
                PyErr_SetString(PyExc_NotImplementedError, 
                        "include_merged_revisions not supported in Subversion 1.4");
-               apr_pool_destroy(temp_pool);
-               return NULL;
+               apr_pool_destroy(*pool);
+               return false;
        }
 #endif
 
-       if (!string_list_to_apr_array(temp_pool, revprops, &apr_revprops)) {
-               apr_pool_destroy(temp_pool);
+       if (!string_list_to_apr_array(*pool, revprops, apr_revprops)) {
+               apr_pool_destroy(*pool);
+               return false;
+       }
+       
+       return true;
+}
+
+static PyObject *ra_get_log(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+       char *kwnames[] = { "callback", "paths", "start", "end", "limit",
+               "discover_changed_paths", "strict_node_history", "include_merged_revisions", "revprops", NULL };
+       PyObject *callback, *paths;
+       svn_revnum_t start = 0, end = 0;
+       int limit=0; 
+       bool discover_changed_paths=false, strict_node_history=true,include_merged_revisions=false;
+       RemoteAccessObject *ra = (RemoteAccessObject *)self;
+       PyObject *revprops = Py_None;
+       apr_pool_t *temp_pool;
+       apr_array_header_t *apr_paths;
+       apr_array_header_t *apr_revprops;
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOll|ibbbO:get_log", kwnames, 
+                                                &callback, &paths, &start, &end, &limit,
+                                                &discover_changed_paths, &strict_node_history,
+                                                &include_merged_revisions, &revprops))
+               return NULL;
+
+       if (!ra_get_log_prepare(ra, paths, include_merged_revisions,
+       revprops, &temp_pool, &apr_paths, &apr_revprops)) {
                return NULL;
        }
 
index 27ead01284f0e32e485fb69b4ac76eff719e706b..b2fcf41e63a6e9b6a7f0e902b4ef7ddc927d9849 100644 (file)
@@ -316,57 +316,8 @@ PyObject *ra_iter_log(PyObject *self, PyObject *args, PyObject *kwargs)
                                                 &include_merged_revisions, &revprops))
                return NULL;
 
-       if (ra_check_busy(ra))
-               return NULL;
-
-       pool = Pool(ra->pool);
-       if (pool == NULL)
-               return NULL;
-       if (paths == Py_None) {
-               /* The subversion libraries don't behave as expected, 
-                * 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)) {
-               apr_pool_destroy(pool);
-               return NULL;
-       }
-
-#if ONLY_BEFORE_SVN(1, 5)
-       if (revprops == Py_None) {
-               PyErr_SetString(PyExc_NotImplementedError,
-               "fetching all revision properties not supported");
-               apr_pool_destroy(pool);
-               return NULL;
-       } else if (!PySequence_Check(revprops)) {
-               PyErr_SetString(PyExc_TypeError, "revprops should be a sequence");
-               apr_pool_destroy(pool);
-               return NULL;
-       } else {
-               int i;
-               for (i = 0; i < PySequence_Size(revprops); i++) {
-                       const char *n = PyString_AsString(PySequence_GetItem(revprops, i));
-                       if (strcmp(SVN_PROP_REVISION_LOG, n) &&
-                               strcmp(SVN_PROP_REVISION_AUTHOR, n) &&
-                               strcmp(SVN_PROP_REVISION_DATE, n)) {
-                               PyErr_SetString(PyExc_NotImplementedError,
-                                                               "fetching custom revision properties not supported");
-                               apr_pool_destroy(pool);
-                               return NULL;
-                       }
-               }
-       }
-
-       if (include_merged_revisions) {
-               PyErr_SetString(PyExc_NotImplementedError, 
-                       "include_merged_revisions not supported in Subversion 1.4");
-               apr_pool_destroy(pool);
-               return NULL;
-       }
-#endif
-
-       if (!string_list_to_apr_array(pool, revprops, &apr_revprops)) {
-               apr_pool_destroy(pool);
+       if (!ra_get_log_prepare(ra, paths, include_merged_revisions,
+       revprops, &pool, &apr_paths, &apr_revprops)) {
                return NULL;
        }