← Back to team overview

subvertpy-users team mailing list archive

[PATCH 2 of 3] Turn RemoteAccess.url into a descriptor

 

# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr@xxxxxxxxx>
# Date 1284483778 -7200
# Node ID f11c9e3595a00e2e32bc713cd92f46275b1fe6f9
# Parent  25a25762a53f54431bfa7c723ff80cddb4a700c4
Turn RemoteAccess.url into a descriptor.

diff --git a/subvertpy/_ra.c b/subvertpy/_ra.c
--- a/subvertpy/_ra.c
+++ b/subvertpy/_ra.c
@@ -45,6 +45,9 @@ extern PyTypeObject AuthProvider_Type;
 extern PyTypeObject CredentialsIter_Type;
 extern PyTypeObject TxDeltaWindowHandler_Type;
 
+static PyObject *ra_get_url(PyObject *self, void *closure);
+static int ra_set_url(PyObject *self, PyObject *arg, void *closure);
+
 static bool ra_check_svn_path(char *path)
 {
     /* svn_ra_check_path will raise an assertion error if the path has a
@@ -898,25 +901,9 @@ static PyObject *ra_get_uuid(PyObject *s
 }
 
 /** Switch to a different url. */
-static PyObject *ra_reparent(PyObject *self, PyObject *args)
+static PyObject *ra_reparent(PyObject *self, PyObject *arg)
 {
-	char *url;
-	apr_pool_t *temp_pool;
-	RemoteAccessObject *ra = (RemoteAccessObject *)self;
-
-	if (!PyArg_ParseTuple(args, "s", &url))
-		return NULL;
-
-	if (ra_check_busy(ra))
-		return NULL;
-
-	temp_pool = Pool(NULL);
-	if (temp_pool == NULL)
-		return NULL;
-	ra->url = svn_path_canonicalize(url, ra->pool);
-	RUN_RA_WITH_POOL(temp_pool, ra, svn_ra_reparent(ra->ra, ra->url, temp_pool));
-	apr_pool_destroy(temp_pool);
-	Py_RETURN_NONE;
+	return ra_set_url(self, arg, NULL) == 0 ? Py_None : NULL;
 }
 
 /**
@@ -2105,7 +2092,72 @@ static int ra_set_progress_func(PyObject
 	return 0;
 }
 
+static PyObject *ra_get_url(PyObject *self, void *closure)
+{
+	const char *url;
+	apr_pool_t *temp_pool;
+	PyObject *r;
+	RemoteAccessObject *ra = (RemoteAccessObject *)self;
+
+	if (ra_check_busy(ra))
+		return NULL;
+
+	temp_pool = Pool(NULL);
+
+	RUN_RA_WITH_POOL(temp_pool, ra,
+	                 svn_ra_get_session_url(ra->ra, &url, temp_pool));
+
+	r = PyString_FromString(url);
+
+	apr_pool_destroy(temp_pool);
+
+	return r;
+}
+
+static int ra_set_url(PyObject *self, PyObject *arg, void *closure)
+{
+	char *url;
+	int r;
+	apr_pool_t *temp_pool;
+	RemoteAccessObject *ra = (RemoteAccessObject *)self;
+
+	if (!(url = PyString_AsString(arg)))
+		return -1;
+
+	if (ra_check_busy(ra))
+		return -1;
+
+	temp_pool = Pool(NULL);
+	if (temp_pool == NULL)
+		return -1;
+	ra->url = svn_path_canonicalize(url, ra->pool);
+
+	/* based on RUN_RA_WITH_POOL() -- we can't use it due to this function
+	 * returning an int */
+	{
+		svn_error_t *err;
+		PyThreadState *_save;
+
+		_save = PyEval_SaveThread();
+		err = svn_ra_reparent(ra->ra, ra->url, temp_pool);
+		PyEval_RestoreThread(_save);
+
+		r = check_error(err) ? 0 : -1;
+
+		apr_pool_destroy(temp_pool);
+		ra->busy = false;
+        }
+
+	return r;
+}
+
 static PyGetSetDef ra_getsetters[] = { 
+	{ "url",
+		ra_get_url,
+		ra_set_url,
+		"The URL of this repository; assigning to it reparents the "
+		"repository.",
+	},
 	{ "progress_func", NULL, ra_set_progress_func, NULL },
 	{ NULL }
 };
@@ -2188,7 +2240,8 @@ static PyMethodDef ra_methods[] = {
 		"Return the last revision committed in the repository." },
 	{ "reparent", ra_reparent, METH_VARARGS, 
 		"S.reparent(url)\n"
-		"Reparent to a new URL" },
+		"Reparent to a new URL.\n"
+		"(Deprecated; please assign to the url instead.)" },
 	{ "get_uuid", (PyCFunction)ra_get_uuid, METH_NOARGS, 
 		"S.get_uuid() -> uuid\n"
 		"Return the UUID of the repository." },
@@ -2198,8 +2251,6 @@ static PyMethodDef ra_methods[] = {
 static PyMemberDef ra_members[] = {
 	{ "busy", T_BYTE, offsetof(RemoteAccessObject, busy), READONLY, 
 		"Whether this connection is in use at the moment" },
-	{ "url", T_STRING, offsetof(RemoteAccessObject, url), READONLY, 
-		"URL this connection is to" },
 	{ NULL, }
 };
 



Follow ups

References