[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Wrap wcprop callbacks for svn_ra_callbacks_t

From: Eric Gillespie <epg_at_pretzelnet.org>
Date: 2007-05-04 20:58:21 CEST

[[[
* subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
  (ra_callbacks_open_tmp_file): Allow Python open_tmp_file callback to be
    None, as the C callback can be NULL.
  (ra_callbacks_get_wc_prop, ra_callbacks_invalidate_wc_props,
   ra_callbacks_set_wc_prop, ra_callbacks_push_wc_prop): New callback
    wrappers, also allowing the Python callback to be None.
  (ra_callbacks_push_or_set_wc_prop): New helper, the common implementation
    of ra_callbacks_set_wc_prop and ra_callbacks_push_wc_prop.
  (svn_swig_py_setup_ra_callbacks): Install wc_prop callbacks.
]]]

Index: subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
===================================================================
--- subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c (revision 24935)
+++ subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c (working copy)
@@ -2601,23 +2601,31 @@ ra_callbacks_open_tmp_file(apr_file_t **
                            apr_pool_t *pool)
 {
   PyObject *callbacks = (PyObject *)callback_baton;
- PyObject *result;
+ PyObject *py_callback, *result;
   svn_error_t *err = SVN_NO_ERROR;
 
+ *fp = NULL;
+
   svn_swig_py_acquire_py_lock();
 
- if ((result = PyObject_CallMethod(callbacks,
- "open_tmp_file",
- (char *)"O&",
- make_ob_pool, pool)) == NULL)
+ py_callback = PyObject_GetAttrString(callbacks, (char *)"open_tmp_file");
+ if (py_callback == NULL)
     {
       err = callback_exception_error();
+ goto finished;
     }
- else if (result == Py_None)
+ else if (py_callback == Py_None)
+ {
+ goto finished;
+ }
+
+ if ((result = PyObject_CallFunction(py_callback,
+ (char *)"O&",
+ make_ob_pool, pool)) == NULL)
     {
- *fp = NULL;
+ err = callback_exception_error();
     }
- else
+ else if (result != Py_None)
     {
       *fp = svn_swig_py_make_file(result, pool);
       if (*fp == NULL)
@@ -2627,6 +2635,171 @@ ra_callbacks_open_tmp_file(apr_file_t **
     }
 
   Py_XDECREF(result);
+finished:
+ Py_XDECREF(py_callback);
+ svn_swig_py_release_py_lock();
+ return err;
+}
+
+/* svn_ra_callbacks_t */
+static svn_error_t *
+ra_callbacks_get_wc_prop(void *baton,
+ const char *path,
+ const char *name,
+ const svn_string_t **value,
+ apr_pool_t *pool)
+{
+ PyObject *callbacks = (PyObject *)baton;
+ PyObject *py_callback, *result;
+ svn_error_t *err = SVN_NO_ERROR;
+
+ *value = NULL;
+
+ svn_swig_py_acquire_py_lock();
+
+ py_callback = PyObject_GetAttrString(callbacks, (char *)"get_wc_prop");
+ if (py_callback == NULL)
+ {
+ err = callback_exception_error();
+ goto finished;
+ }
+ else if (py_callback == Py_None)
+ {
+ goto finished;
+ }
+
+ if ((result = PyObject_CallFunction(py_callback,
+ (char *)"ssO&", path, name,
+ make_ob_pool, pool)) == NULL)
+ {
+ err = callback_exception_error();
+ }
+ else if (result != Py_None)
+ {
+ char *buf;
+ int len;
+ if (PyString_AsStringAndSize(result, &buf, &len) == -1)
+ {
+ err = callback_exception_error();
+ }
+ else
+ {
+ *value = svn_string_ncreate(buf, len, pool);
+ }
+ }
+
+ Py_XDECREF(result);
+finished:
+ Py_XDECREF(py_callback);
+ svn_swig_py_release_py_lock();
+ return err;
+}
+
+/* svn_ra_callbacks_t */
+static svn_error_t *
+ra_callbacks_push_or_set_wc_prop(const char *callback,
+ void *baton,
+ const char *path,
+ const char *name,
+ const svn_string_t *value,
+ apr_pool_t *pool)
+{
+ PyObject *callbacks = (PyObject *)baton;
+ PyObject *py_callback, *py_value, *result;
+ svn_error_t *err = SVN_NO_ERROR;
+
+ svn_swig_py_acquire_py_lock();
+
+ py_callback = PyObject_GetAttrString(callbacks, (char *)callback);
+ if (py_callback == NULL)
+ {
+ err = callback_exception_error();
+ goto finished;
+ }
+ else if (py_callback == Py_None)
+ {
+ goto finished;
+ }
+
+ if ((py_value = PyString_FromStringAndSize(value->data, value->len)) == NULL)
+ {
+ err = callback_exception_error();
+ goto finished;
+ }
+
+ if ((result = PyObject_CallFunction(py_callback,
+ (char *)"ssOO&", path, name, py_value,
+ make_ob_pool, pool)) == NULL)
+ {
+ err = callback_exception_error();
+ }
+
+ Py_XDECREF(result);
+finished:
+ Py_XDECREF(py_callback);
+ svn_swig_py_release_py_lock();
+ return err;
+}
+
+/* svn_ra_callbacks_t */
+static svn_error_t *
+ra_callbacks_set_wc_prop(void *baton,
+ const char *path,
+ const char *name,
+ const svn_string_t *value,
+ apr_pool_t *pool)
+{
+ return ra_callbacks_push_or_set_wc_prop("set_wc_prop", baton, path,
+ name, value, pool);
+}
+
+/* svn_ra_callbacks_t */
+static svn_error_t *
+ra_callbacks_push_wc_prop(void *baton,
+ const char *path,
+ const char *name,
+ const svn_string_t *value,
+ apr_pool_t *pool)
+{
+ return ra_callbacks_push_or_set_wc_prop("push_wc_prop", baton, path,
+ name, value, pool);
+}
+
+/* svn_ra_callbacks_t */
+static svn_error_t *
+ra_callbacks_invalidate_wc_props(void *baton,
+ const char *path,
+ const char *name,
+ apr_pool_t *pool)
+{
+ PyObject *callbacks = (PyObject *)baton;
+ PyObject *py_callback, *result;
+ svn_error_t *err = SVN_NO_ERROR;
+
+ svn_swig_py_acquire_py_lock();
+
+ py_callback = PyObject_GetAttrString(callbacks,
+ (char *)"invalidate_wc_prop");
+ if (py_callback == NULL)
+ {
+ err = callback_exception_error();
+ goto finished;
+ }
+ else if (py_callback == Py_None)
+ {
+ goto finished;
+ }
+
+ if ((result = PyObject_CallFunction(py_callback,
+ (char *)"ssO&", path, name,
+ make_ob_pool, pool)) == NULL)
+ {
+ err = callback_exception_error();
+ }
+
+ Py_XDECREF(result);
+finished:
+ Py_XDECREF(py_callback);
   svn_swig_py_release_py_lock();
   return err;
 }
@@ -2648,7 +2821,7 @@ svn_swig_py_setup_ra_callbacks(svn_ra_ca
 
   (*callbacks)->open_tmp_file = ra_callbacks_open_tmp_file;
 
- py_auth_baton = PyObject_GetAttrString(py_callbacks, "auth_baton");
+ py_auth_baton = PyObject_GetAttrString(py_callbacks, (char *)"auth_baton");
 
   if (svn_swig_ConvertPtrString(py_auth_baton,
                                 (void **)&((*callbacks)->auth_baton),
@@ -2662,6 +2835,11 @@ svn_swig_py_setup_ra_callbacks(svn_ra_ca
   
   Py_XDECREF(py_auth_baton);
 
+ (*callbacks)->get_wc_prop = ra_callbacks_get_wc_prop;
+ (*callbacks)->set_wc_prop = ra_callbacks_set_wc_prop;
+ (*callbacks)->push_wc_prop = ra_callbacks_push_wc_prop;
+ (*callbacks)->invalidate_wc_props = ra_callbacks_invalidate_wc_props;
+
   *baton = py_callbacks;
 }
 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri May 4 20:59:30 2007

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.