* subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
[svn.git] / subversion / bindings / swig / python / libsvn_swig_py / swigutil_py.c
blob81e3e56b8ae5d562d5106c5ef04dce180e5cf162
1 /*
2 * swigutil_py.c: utility functions for the SWIG Python bindings
4 * ====================================================================
5 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
19 /* Tell swigutil_py.h that we're inside the implementation */
20 #define SVN_SWIG_SWIGUTIL_PY_C
22 #include <Python.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <fcntl.h>
28 #include <apr_pools.h>
29 #include <apr_hash.h>
30 #include <apr_portable.h>
31 #include <apr_thread_proc.h>
33 #include "svn_client.h"
34 #include "svn_string.h"
35 #include "svn_opt.h"
36 #include "svn_delta.h"
37 #include "svn_auth.h"
38 #include "svn_pools.h"
39 #include "svn_mergeinfo.h"
40 #include "svn_types.h"
42 #include "svn_private_config.h" /* for SVN_APR_INT64_T_PYCFMT */
44 #include "swig_python_external_runtime.swg"
45 #include "swigutil_py.h"
47 /* Define handy Python 2.4 macro if this is older Python. */
48 #ifndef Py_RETURN_NONE
49 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
50 #endif
54 /*** Manage the Global Interpreter Lock ***/
56 /* If both Python and APR have threads available, we can optimize ourselves
57 * by releasing the global interpreter lock when we drop into our SVN calls.
59 * In svn_types.i, svn_swig_py_release_py_lock is called before every
60 * function, then svn_swig_py_acquire_py_lock is called after every
61 * function. So, if these functions become no-ops, then Python will
62 * start to block...
64 * The Subversion libraries can be assumed to be thread-safe *only* when
65 * APR_HAS_THREAD is 1. The APR pool allocations aren't thread-safe unless
66 * APR_HAS_THREAD is 1.
69 #if defined(WITH_THREAD) && APR_HAS_THREADS
70 #define ACQUIRE_PYTHON_LOCK
71 #endif
73 #ifdef ACQUIRE_PYTHON_LOCK
74 static apr_threadkey_t *_saved_thread_key = NULL;
75 static apr_pool_t *_saved_thread_pool = NULL;
76 #endif
78 void svn_swig_py_release_py_lock(void)
80 #ifdef ACQUIRE_PYTHON_LOCK
81 PyThreadState *thread_state;
83 if (_saved_thread_key == NULL)
85 /* Obviously, creating a top-level pool for this is pretty stupid. */
86 apr_pool_create(&_saved_thread_pool, NULL);
87 apr_threadkey_private_create(&_saved_thread_key, NULL,
88 _saved_thread_pool);
91 thread_state = PyEval_SaveThread();
92 apr_threadkey_private_set(thread_state, _saved_thread_key);
93 #endif
96 void svn_swig_py_acquire_py_lock(void)
98 #ifdef ACQUIRE_PYTHON_LOCK
99 void *val;
100 PyThreadState *thread_state;
101 apr_threadkey_private_get(&val, _saved_thread_key);
102 thread_state = val;
103 PyEval_RestoreThread(thread_state);
104 #endif
109 /*** Automatic Pool Management Functions ***/
111 /* The application pool */
112 static apr_pool_t *application_pool = NULL;
113 static PyObject *application_py_pool = NULL;
114 static char assertValid[] = "assert_valid";
115 static char markValid[] = "_mark_valid";
116 static char parentPool[] = "_parent_pool";
117 static char wrap[] = "_wrap";
118 static char unwrap[] = "_unwrap";
119 static char setParentPool[] = "set_parent_pool";
120 static char emptyTuple[] = "()";
121 static char objectTuple[] = "(O)";
124 apr_status_t svn_swig_py_initialize(void)
126 apr_status_t status;
128 if ((status = apr_initialize()) != APR_SUCCESS)
129 return status;
130 if (atexit(apr_terminate) != 0)
131 return APR_EGENERAL;
132 return APR_SUCCESS;
135 int svn_swig_py_get_pool_arg(PyObject *args, swig_type_info *type,
136 PyObject **py_pool, apr_pool_t **pool)
138 int argnum = PyTuple_GET_SIZE(args) - 1;
140 if (argnum >= 0)
142 PyObject *input = PyTuple_GET_ITEM(args, argnum);
143 if (input != Py_None && PyObject_HasAttrString(input, markValid))
145 *pool = svn_swig_MustGetPtr(input, type, argnum+1);
146 if (*pool == NULL)
147 return 1;
148 *py_pool = input;
149 Py_INCREF(input);
150 return 0;
154 /* We couldn't find a pool argument, so we'll create a subpool */
155 *pool = svn_pool_create(application_pool);
156 *py_pool = svn_swig_NewPointerObj(*pool, type, application_py_pool,
157 NULL);
158 if (*py_pool == NULL)
159 return 1;
161 return 0;
164 int svn_swig_py_get_parent_pool(PyObject *args, swig_type_info *type,
165 PyObject **py_pool, apr_pool_t **pool)
167 PyObject *proxy = PyTuple_GetItem(args, 0);
169 if (proxy == NULL)
170 return 1;
172 *py_pool = PyObject_GetAttrString(proxy, parentPool);
174 if (*py_pool == NULL)
176 PyErr_SetString(PyExc_TypeError,
177 "Unexpected NULL parent pool on proxy object");
178 return 1;
181 Py_DECREF(*py_pool);
183 *pool = svn_swig_MustGetPtr(*py_pool, type, 1);
185 if (*pool == NULL)
186 return 1;
188 return 0;
191 /* Set the application pool */
192 void svn_swig_py_set_application_pool(PyObject *py_pool, apr_pool_t *pool)
194 application_pool = pool;
195 application_py_pool = py_pool;
198 /* Clear the application pool */
199 void svn_swig_py_clear_application_pool()
201 application_pool = NULL;
202 application_py_pool = NULL;
205 /* Set the parent pool of a proxy object */
206 static int proxy_set_pool(PyObject **proxy, PyObject *pool)
208 PyObject *result;
210 if (*proxy != NULL)
212 if (pool == NULL)
214 if (PyObject_HasAttrString(*proxy, setParentPool))
216 result = PyObject_CallMethod(*proxy, setParentPool, emptyTuple);
217 if (result == NULL)
218 return 1;
219 Py_DECREF(result);
222 else
224 result = PyObject_CallMethod(pool, wrap, objectTuple, *proxy);
225 Py_DECREF(*proxy);
226 *proxy = result;
230 return 0;
234 /* Wrapper for SWIG_TypeQuery */
235 #define svn_swig_TypeQuery(x) SWIG_TypeQuery(x)
237 /** Wrapper for SWIG_NewPointerObj */
238 PyObject *svn_swig_NewPointerObj(void *obj, swig_type_info *type,
239 PyObject *pool, PyObject *args)
241 PyObject *proxy = SWIG_NewPointerObj(obj, type, 0);
243 if (proxy == NULL)
244 return NULL;
246 if (pool == NULL && args != NULL)
248 apr_pool_t *tmp;
249 if (svn_swig_py_get_parent_pool(args,
250 svn_swig_TypeQuery("apr_pool_t *"), &pool, &tmp))
251 PyErr_Clear();
254 if (proxy_set_pool(&proxy, pool))
256 Py_DECREF(proxy);
257 return NULL;
260 return proxy;
263 /** svn_swig_NewPointerObj, except a string is used to describe the type */
264 static PyObject *svn_swig_NewPointerObjString(void *ptr, const char *type,
265 PyObject *py_pool)
267 swig_type_info *typeinfo = svn_swig_TypeQuery(type);
268 if (typeinfo == NULL)
270 PyErr_SetString(PyExc_TypeError, "Cannot find required typeobject");
271 return NULL;
274 /* ### cache the swig_type_info at some point? */
275 return svn_swig_NewPointerObj(ptr, typeinfo, py_pool, NULL);
278 /** Wrapper for SWIG_ConvertPtr */
279 int svn_swig_ConvertPtr(PyObject *input, void **obj, swig_type_info *type)
281 if (PyObject_HasAttrString(input, assertValid))
283 PyObject *result = PyObject_CallMethod(input, assertValid, emptyTuple);
284 if (result == NULL)
285 return 1;
286 Py_DECREF(result);
288 if (PyObject_HasAttrString(input, unwrap))
290 input = PyObject_CallMethod(input, unwrap, emptyTuple);
291 if (input == NULL)
292 return 1;
293 Py_DECREF(input);
296 return SWIG_ConvertPtr(input, obj, type, SWIG_POINTER_EXCEPTION | 0);
299 /** svn_swig_ConvertPtr, except a string is used to describe the type */
300 static int svn_swig_ConvertPtrString(PyObject *input,
301 void **obj, const char *type)
303 return svn_swig_ConvertPtr(input, obj, svn_swig_TypeQuery(type));
306 /** Wrapper for SWIG_MustGetPtr */
307 void *svn_swig_MustGetPtr(void *input, swig_type_info *type, int argnum)
309 if (PyObject_HasAttrString(input, assertValid))
311 PyObject *result = PyObject_CallMethod(input, assertValid, emptyTuple);
312 if (result == NULL)
313 return NULL;
314 Py_DECREF(result);
317 if (PyObject_HasAttrString(input, unwrap))
319 input = PyObject_CallMethod(input, unwrap, emptyTuple);
320 if (input == NULL)
321 return NULL;
322 Py_DECREF((PyObject *) input);
325 return SWIG_MustGetPtr(input, type, argnum, SWIG_POINTER_EXCEPTION | 0);
330 /*** Custom SubversionException stuffs. ***/
332 void svn_swig_py_svn_exception(svn_error_t *error_chain)
334 PyObject *args_list, *args, *apr_err_ob, *message_ob, *file_ob, *line_ob;
335 PyObject *svn_module, *exc_class, *exc_ob;
336 svn_error_t *err;
338 if (error_chain == NULL)
339 return;
341 /* Start with no references. */
342 args_list = args = apr_err_ob = message_ob = file_ob = line_ob = NULL;
343 svn_module = exc_class = exc_ob = NULL;
345 if ((args_list = PyList_New(0)) == NULL)
346 goto finished;
348 for (err = error_chain; err; err = err->child)
350 int i;
352 if ((args = PyTuple_New(4)) == NULL)
353 goto finished;
355 /* Convert the fields of the svn_error_t to Python objects. */
356 if ((apr_err_ob = PyInt_FromLong(err->apr_err)) == NULL)
357 goto finished;
358 if (err->message == NULL)
360 Py_INCREF(Py_None);
361 message_ob = Py_None;
363 else if ((message_ob = PyString_FromString(err->message)) == NULL)
364 goto finished;
365 if (err->file == NULL)
367 Py_INCREF(Py_None);
368 file_ob = Py_None;
370 else if ((file_ob = PyString_FromString(err->file)) == NULL)
371 goto finished;
372 if ((line_ob = PyInt_FromLong(err->line)) == NULL)
373 goto finished;
375 /* Store the objects in the tuple. */
376 i = 0;
377 #define append(item) \
378 if (PyTuple_SetItem(args, i++, item) == 0) \
379 /* tuple stole our reference, so don't DECREF */ \
380 item = NULL; \
381 else \
382 goto finished;
383 append(apr_err_ob);
384 append(message_ob);
385 append(file_ob);
386 append(line_ob);
387 #undef append
389 /* Append the tuple to the args list. */
390 if (PyList_Append(args_list, args) == -1)
391 goto finished;
392 /* The list takes its own reference, so release ours. */
393 Py_DECREF(args);
394 /* Let's not decref in 'finished:' after the final iteration. */
395 args = NULL;
397 svn_error_clear(error_chain);
399 /* Create the exception object chain. */
400 if ((svn_module = PyImport_ImportModule((char *)"svn.core")) == NULL)
401 goto finished;
402 if ((exc_class = PyObject_GetAttrString(svn_module,
403 (char *)"SubversionException")) == NULL)
404 goto finished;
405 if ((exc_ob = PyObject_CallMethod(exc_class, (char *)"_new_from_err_list",
406 (char *)"O", args_list)) == NULL)
407 goto finished;
409 /* Raise the exception. */
410 PyErr_SetObject(exc_class, exc_ob);
412 finished:
413 /* Release any references. */
414 Py_XDECREF(args_list);
415 Py_XDECREF(args);
416 Py_XDECREF(apr_err_ob);
417 Py_XDECREF(message_ob);
418 Py_XDECREF(file_ob);
419 Py_XDECREF(line_ob);
420 Py_XDECREF(svn_module);
421 Py_XDECREF(exc_class);
422 Py_XDECREF(exc_ob);
427 /*** Helper/Conversion Routines ***/
429 /* Functions for making Python wrappers around Subversion structs */
430 static PyObject *make_ob_pool(void *pool)
432 /* Return a brand new default pool to Python. This pool isn't
433 * normally used for anything. It's just here for compatibility
434 * with Subversion 1.2. */
435 apr_pool_t *new_pool = svn_pool_create(application_pool);
436 PyObject *new_py_pool = svn_swig_NewPointerObj(new_pool,
437 svn_swig_TypeQuery("apr_pool_t *"), application_py_pool, NULL);
438 (void) pool; /* Silence compiler warnings about unused parameter. */
439 return new_py_pool;
441 static PyObject *make_ob_fs_root(svn_fs_root_t *ptr, PyObject *py_pool)
443 return svn_swig_NewPointerObjString(ptr, "svn_fs_root_t *", py_pool);
445 /***/
447 /* Conversion from Python single objects (not hashes/lists/etc.) to
448 Subversion types. */
449 static const char *make_string_from_ob(PyObject *ob, apr_pool_t *pool)
451 if (ob == Py_None)
452 return NULL;
453 if (! PyString_Check(ob))
455 PyErr_SetString(PyExc_TypeError, "not a string");
456 return NULL;
458 return apr_pstrdup(pool, PyString_AS_STRING(ob));
460 static svn_string_t *make_svn_string_from_ob(PyObject *ob, apr_pool_t *pool)
462 if (ob == Py_None)
463 return NULL;
464 if (! PyString_Check(ob))
466 PyErr_SetString(PyExc_TypeError, "not a string");
467 return NULL;
469 return svn_string_create(PyString_AS_STRING(ob), pool);
473 /***/
475 static PyObject *convert_hash(apr_hash_t *hash,
476 PyObject * (*converter_func)(void *value,
477 void *ctx,
478 PyObject *py_pool),
479 void *ctx, PyObject *py_pool)
481 apr_hash_index_t *hi;
482 PyObject *dict;
484 if (hash == NULL)
485 Py_RETURN_NONE;
487 if ((dict = PyDict_New()) == NULL)
488 return NULL;
490 for (hi = apr_hash_first(NULL, hash); hi; hi = apr_hash_next(hi))
492 const void *key;
493 void *val;
494 PyObject *value;
496 apr_hash_this(hi, &key, NULL, &val);
497 value = (*converter_func)(val, ctx, py_pool);
498 if (value == NULL)
500 Py_DECREF(dict);
501 return NULL;
503 /* ### gotta cast this thing cuz Python doesn't use "const" */
504 if (PyDict_SetItemString(dict, (char *)key, value) == -1)
506 Py_DECREF(value);
507 Py_DECREF(dict);
508 return NULL;
510 Py_DECREF(value);
513 return dict;
516 static PyObject *convert_to_swigtype(void *value, void *ctx, PyObject *py_pool)
518 /* ctx is a 'swig_type_info *' */
519 return svn_swig_NewPointerObj(value, ctx, py_pool, NULL);
522 static PyObject *convert_svn_string_t(void *value, void *ctx,
523 PyObject *py_pool)
525 /* ctx is unused */
527 const svn_string_t *s = value;
529 /* ### gotta cast this thing cuz Python doesn't use "const" */
530 return PyString_FromStringAndSize((void *)s->data, s->len);
533 static PyObject *convert_svn_client_commit_item3_t(void *value, void *ctx)
535 PyObject *list;
536 PyObject *path, *kind, *url, *rev, *cf_url, *cf_rev, *state,
537 *incoming_prop_changes, *outgoing_prop_changes;
538 svn_client_commit_item3_t *item = value;
540 /* ctx is unused */
542 list = PyList_New(9);
544 if (item->path)
545 path = PyString_FromString(item->path);
546 else
548 path = Py_None;
549 Py_INCREF(Py_None);
552 if (item->url)
553 url = PyString_FromString(item->url);
554 else
556 url = Py_None;
557 Py_INCREF(Py_None);
560 if (item->copyfrom_url)
561 cf_url = PyString_FromString(item->copyfrom_url);
562 else
564 cf_url = Py_None;
565 Py_INCREF(Py_None);
568 kind = PyInt_FromLong(item->kind);
569 rev = PyInt_FromLong(item->revision);
570 cf_rev = PyInt_FromLong(item->copyfrom_rev);
571 state = PyInt_FromLong(item->state_flags);
573 if (item->incoming_prop_changes)
574 incoming_prop_changes =
575 svn_swig_py_array_to_list(item->incoming_prop_changes);
576 else
578 incoming_prop_changes = Py_None;
579 Py_INCREF(Py_None);
582 if (item->outgoing_prop_changes)
583 outgoing_prop_changes =
584 svn_swig_py_array_to_list(item->outgoing_prop_changes);
585 else
587 outgoing_prop_changes = Py_None;
588 Py_INCREF(Py_None);
591 if (! (list && path && kind && url && rev && cf_url && cf_rev && state &&
592 incoming_prop_changes && outgoing_prop_changes))
594 Py_XDECREF(list);
595 Py_XDECREF(path);
596 Py_XDECREF(kind);
597 Py_XDECREF(url);
598 Py_XDECREF(rev);
599 Py_XDECREF(cf_url);
600 Py_XDECREF(cf_rev);
601 Py_XDECREF(state);
602 Py_XDECREF(incoming_prop_changes);
603 Py_XDECREF(outgoing_prop_changes);
604 return NULL;
607 PyList_SET_ITEM(list, 0, path);
608 PyList_SET_ITEM(list, 1, kind);
609 PyList_SET_ITEM(list, 2, url);
610 PyList_SET_ITEM(list, 3, rev);
611 PyList_SET_ITEM(list, 4, cf_url);
612 PyList_SET_ITEM(list, 5, cf_rev);
613 PyList_SET_ITEM(list, 6, state);
614 PyList_SET_ITEM(list, 7, incoming_prop_changes);
615 PyList_SET_ITEM(list, 8, outgoing_prop_changes);
616 return list;
619 PyObject *svn_swig_py_prophash_to_dict(apr_hash_t *hash)
621 return convert_hash(hash, convert_svn_string_t, NULL, NULL);
624 static PyObject *convert_string(void *value, void *ctx,
625 PyObject *py_pool)
627 /* ### gotta cast this thing cuz Python doesn't use "const" */
628 return PyString_FromString((const char *)value);
631 PyObject *svn_swig_py_stringhash_to_dict(apr_hash_t *hash)
633 return convert_hash(hash, convert_string, NULL, NULL);
636 static PyObject *convert_rangelist(void *value, void *ctx, PyObject *py_pool)
638 int i;
639 PyObject *list;
640 apr_array_header_t *array = value;
642 list = PyList_New(0);
643 for (i = 0; i < array->nelts; i++)
645 svn_merge_range_t *range = APR_ARRAY_IDX(array, i, svn_merge_range_t *);
646 if (PyList_Append(list, convert_to_swigtype(range, ctx, py_pool)) == -1)
647 goto error;
649 return list;
650 error:
651 Py_DECREF(list);
652 return NULL;
655 PyObject *svn_swig_py_rangelist_to_list(apr_array_header_t *rangelist,
656 swig_type_info *type,
657 PyObject *py_pool)
659 return convert_rangelist(rangelist, type, py_pool);
662 PyObject *svn_swig_py_mergeinfo_to_dict(apr_hash_t *hash,
663 swig_type_info *type,
664 PyObject *py_pool)
666 return convert_hash(hash, convert_rangelist, type, py_pool);
669 static PyObject *convert_mergeinfo_hash(void *value, void *ctx,
670 PyObject *py_pool)
672 return svn_swig_py_mergeinfo_to_dict(value, ctx, py_pool);
675 PyObject *svn_swig_py_mergeinfo_catalog_to_dict(apr_hash_t *hash,
676 swig_type_info *type,
677 PyObject *py_pool)
679 return convert_hash(hash, convert_mergeinfo_hash, type, py_pool);
682 PyObject *svn_swig_py_proparray_to_dict(const apr_array_header_t *array)
684 PyObject *dict = PyDict_New();
685 int i;
687 if (dict == NULL)
688 return NULL;
690 for (i = 0; i < array->nelts; ++i)
692 svn_prop_t prop;
693 PyObject *py_key, *py_value;
695 prop = APR_ARRAY_IDX(array, i, svn_prop_t);
697 py_key = PyString_FromString(prop.name);
698 if (py_key == NULL)
699 goto error;
701 if (prop.value == NULL)
703 py_value = Py_None;
704 Py_INCREF(Py_None);
706 else
708 py_value = PyString_FromStringAndSize((void *)prop.value->data,
709 prop.value->len);
710 if (py_value == NULL)
712 Py_DECREF(py_key);
713 goto error;
717 PyDict_SetItem(dict, py_key, py_value);
720 return dict;
722 error:
723 Py_DECREF(dict);
724 return NULL;
728 PyObject *svn_swig_py_locationhash_to_dict(apr_hash_t *hash)
730 /* Need special code for this because of the darned svn_revnum_t
731 keys. */
732 apr_hash_index_t *hi;
733 PyObject *dict = PyDict_New();
735 if (dict == NULL)
736 return NULL;
738 for (hi = apr_hash_first(NULL, hash); hi; hi = apr_hash_next(hi))
740 const void *k;
741 void *v;
742 PyObject *key, *value;
744 apr_hash_this(hi, &k, NULL, &v);
745 key = PyLong_FromLong(*(svn_revnum_t *)k);
746 if (key == NULL)
748 Py_DECREF(dict);
749 return NULL;
751 value = PyString_FromString((char *)v);
752 if (value == NULL)
754 Py_DECREF(key);
755 Py_DECREF(dict);
756 return NULL;
758 if (PyDict_SetItem(dict, key, value) == -1)
760 Py_DECREF(value);
761 Py_DECREF(dict);
762 return NULL;
764 Py_DECREF(value);
765 Py_DECREF(key);
767 return dict;
770 PyObject *svn_swig_py_convert_hash(apr_hash_t *hash, swig_type_info *type,
771 PyObject *py_pool)
773 return convert_hash(hash, convert_to_swigtype, type, py_pool);
776 #define DECLARE_SWIG_CONSTRUCTOR(type, dup) \
777 static PyObject *make_ob_##type(void *value) \
779 apr_pool_t *new_pool = svn_pool_create(application_pool); \
780 PyObject *new_py_pool = svn_swig_NewPointerObj(new_pool, \
781 svn_swig_TypeQuery("apr_pool_t *"), application_py_pool, NULL); \
782 svn_##type##_t *new_value = dup(value, new_pool); \
783 PyObject *obj = svn_swig_NewPointerObjString(new_value, "svn_" #type "_t *", \
784 new_py_pool); \
785 Py_XDECREF(new_py_pool); \
786 return obj; \
789 DECLARE_SWIG_CONSTRUCTOR(txdelta_window, svn_txdelta_window_dup)
790 DECLARE_SWIG_CONSTRUCTOR(log_changed_path, svn_log_changed_path_dup)
791 DECLARE_SWIG_CONSTRUCTOR(wc_status, svn_wc_dup_status)
792 DECLARE_SWIG_CONSTRUCTOR(lock, svn_lock_dup)
793 DECLARE_SWIG_CONSTRUCTOR(auth_ssl_server_cert_info,
794 svn_auth_ssl_server_cert_info_dup)
795 DECLARE_SWIG_CONSTRUCTOR(info, svn_info_dup)
796 DECLARE_SWIG_CONSTRUCTOR(location_segment, svn_location_segment_dup)
797 DECLARE_SWIG_CONSTRUCTOR(commit_info, svn_commit_info_dup)
798 DECLARE_SWIG_CONSTRUCTOR(wc_notify, svn_wc_dup_notify)
800 static PyObject *convert_log_changed_path(void *value, void *ctx,
801 PyObject *py_pool)
803 return make_ob_log_changed_path(value);
806 PyObject *svn_swig_py_c_strings_to_list(char **strings)
808 PyObject *list = PyList_New(0);
809 char *s;
811 while ((s = *strings++) != NULL)
813 PyObject *ob = PyString_FromString(s);
815 if (ob == NULL)
816 goto error;
817 if (PyList_Append(list, ob) == -1)
818 goto error;
821 return list;
823 error:
824 Py_DECREF(list);
825 return NULL;
828 PyObject *svn_swig_py_changed_path_hash_to_dict(apr_hash_t *hash)
830 apr_hash_index_t *hi;
831 PyObject *dict;
833 if (hash == NULL)
834 Py_RETURN_NONE;
836 if ((dict = PyDict_New()) == NULL)
837 return NULL;
839 for (hi = apr_hash_first(NULL, hash); hi; hi = apr_hash_next(hi))
841 const void *key;
842 void *val;
843 PyObject *value;
845 apr_hash_this(hi, &key, NULL, &val);
846 value = make_ob_log_changed_path(val);
847 if (value == NULL)
849 Py_DECREF(dict);
850 return NULL;
852 if (PyDict_SetItemString(dict, (char *)key, value) == -1)
854 Py_DECREF(value);
855 Py_DECREF(dict);
856 return NULL;
858 Py_DECREF(value);
861 return dict;
864 apr_array_header_t *svn_swig_py_rangelist_to_array(PyObject *list,
865 apr_pool_t *pool)
867 int targlen;
868 apr_array_header_t *temp;
870 if (!PySequence_Check(list)) {
871 PyErr_SetString(PyExc_TypeError, "not a sequence");
872 return NULL;
874 targlen = PySequence_Length(list);
875 temp = apr_array_make(pool, targlen, sizeof(svn_merge_range_t *));
876 /* APR_ARRAY_IDX doesn't actually increment the array item count
877 (like, say, apr_array_push would). */
878 temp->nelts = targlen;
879 while (targlen--) {
880 PyObject *o = PySequence_GetItem(list, targlen);
881 svn_merge_range_t *range;
882 svn_merge_range_t *newrange;
884 if (o == NULL)
885 return NULL;
886 if (svn_swig_ConvertPtrString(o, (void **)&range,
887 "svn_merge_range_t *"))
889 PyErr_SetString(PyExc_TypeError,
890 "list values are not svn_merge_range_t *'s");
891 Py_DECREF(list);
892 return NULL;
894 newrange = svn_merge_range_dup(range, pool);
896 APR_ARRAY_IDX(temp, targlen, svn_merge_range_t *) = newrange;
897 Py_DECREF(o);
899 return temp;
902 apr_hash_t *svn_swig_py_stringhash_from_dict(PyObject *dict,
903 apr_pool_t *pool)
905 apr_hash_t *hash;
906 PyObject *keys;
907 int i, num_keys;
909 if (dict == Py_None)
910 return NULL;
912 if (!PyDict_Check(dict))
914 PyErr_SetString(PyExc_TypeError, "not a dictionary");
915 return NULL;
918 hash = apr_hash_make(pool);
919 keys = PyDict_Keys(dict);
920 num_keys = PyList_Size(keys);
921 for (i = 0; i < num_keys; i++)
923 PyObject *key = PyList_GetItem(keys, i);
924 PyObject *value = PyDict_GetItem(dict, key);
925 const char *propname = make_string_from_ob(key, pool);
926 const char *propval = make_string_from_ob(value, pool);
927 if (! (propname && propval))
929 PyErr_SetString(PyExc_TypeError,
930 "dictionary keys/values aren't strings");
931 Py_DECREF(keys);
932 return NULL;
934 apr_hash_set(hash, propname, APR_HASH_KEY_STRING, propval);
936 Py_DECREF(keys);
937 return hash;
940 apr_hash_t *svn_swig_py_mergeinfo_from_dict(PyObject *dict,
941 apr_pool_t *pool)
943 apr_hash_t *hash;
944 PyObject *keys;
945 int i, num_keys;
947 if (dict == Py_None)
948 return NULL;
950 if (!PyDict_Check(dict)) {
951 PyErr_SetString(PyExc_TypeError, "not a dictionary");
952 return NULL;
955 hash = apr_hash_make(pool);
956 keys = PyDict_Keys(dict);
957 num_keys = PyList_Size(keys);
958 for (i = 0; i < num_keys; i++)
960 PyObject *key = PyList_GetItem(keys, i);
961 PyObject *value = PyDict_GetItem(dict, key);
962 const char *pathname = make_string_from_ob(key, pool);
963 apr_array_header_t *ranges = svn_swig_py_rangelist_to_array(value, pool);
965 if (! (pathname && ranges))
967 PyErr_SetString(PyExc_TypeError,
968 "dictionary keys aren't strings or values aren't svn_merge_range_t *'s");
969 Py_DECREF(keys);
970 return NULL;
972 apr_hash_set(hash, pathname, APR_HASH_KEY_STRING, ranges);
974 Py_DECREF(keys);
975 return hash;
978 apr_array_header_t *svn_swig_py_proparray_from_dict(PyObject *dict,
979 apr_pool_t *pool)
981 apr_array_header_t *array;
982 PyObject *keys;
983 int i, num_keys;
985 if (dict == Py_None)
986 return NULL;
988 if (!PyDict_Check(dict))
990 PyErr_SetString(PyExc_TypeError, "not a dictionary");
991 return NULL;
994 keys = PyDict_Keys(dict);
995 num_keys = PyList_Size(keys);
996 array = apr_array_make(pool, num_keys, sizeof(svn_prop_t *));
997 for (i = 0; i < num_keys; i++)
999 PyObject *key = PyList_GetItem(keys, i);
1000 PyObject *value = PyDict_GetItem(dict, key);
1001 svn_prop_t *prop = apr_palloc(pool, sizeof(*prop));
1002 prop->name = make_string_from_ob(key, pool);
1003 prop->value = make_svn_string_from_ob(value, pool);
1004 if (! (prop->name && prop->value))
1006 PyErr_SetString(PyExc_TypeError,
1007 "dictionary keys/values aren't strings");
1008 Py_DECREF(keys);
1009 return NULL;
1011 APR_ARRAY_PUSH(array, svn_prop_t *) = prop;
1013 Py_DECREF(keys);
1014 return array;
1017 apr_hash_t *svn_swig_py_prophash_from_dict(PyObject *dict,
1018 apr_pool_t *pool)
1020 apr_hash_t *hash;
1021 PyObject *keys;
1022 int i, num_keys;
1024 if (dict == Py_None)
1025 return NULL;
1027 if (!PyDict_Check(dict))
1029 PyErr_SetString(PyExc_TypeError, "not a dictionary");
1030 return NULL;
1033 hash = apr_hash_make(pool);
1034 keys = PyDict_Keys(dict);
1035 num_keys = PyList_Size(keys);
1036 for (i = 0; i < num_keys; i++)
1038 PyObject *key = PyList_GetItem(keys, i);
1039 PyObject *value = PyDict_GetItem(dict, key);
1040 const char *propname = make_string_from_ob(key, pool);
1041 svn_string_t *propval = make_svn_string_from_ob(value, pool);
1042 if (! (propname && propval))
1044 PyErr_SetString(PyExc_TypeError,
1045 "dictionary keys/values aren't strings");
1046 Py_DECREF(keys);
1047 return NULL;
1049 apr_hash_set(hash, propname, APR_HASH_KEY_STRING, propval);
1051 Py_DECREF(keys);
1052 return hash;
1055 apr_hash_t *svn_swig_py_path_revs_hash_from_dict(PyObject *dict,
1056 apr_pool_t *pool)
1058 apr_hash_t *hash;
1059 PyObject *keys;
1060 int i, num_keys;
1062 if (dict == Py_None)
1063 return NULL;
1065 if (!PyDict_Check(dict))
1067 PyErr_SetString(PyExc_TypeError, "not a dictionary");
1068 return NULL;
1071 hash = apr_hash_make(pool);
1072 keys = PyDict_Keys(dict);
1073 num_keys = PyList_Size(keys);
1074 for (i = 0; i < num_keys; i++)
1076 PyObject *key = PyList_GetItem(keys, i);
1077 PyObject *value = PyDict_GetItem(dict, key);
1078 const char *path = make_string_from_ob(key, pool);
1079 svn_revnum_t *revnum;
1081 if (!(path))
1083 PyErr_SetString(PyExc_TypeError,
1084 "dictionary keys aren't strings");
1085 Py_DECREF(keys);
1086 return NULL;
1089 revnum = apr_palloc(pool, sizeof(svn_revnum_t));
1091 if (PyInt_Check(value))
1092 *revnum = PyInt_AsLong(value);
1093 else if (PyLong_Check(value))
1094 *revnum = PyLong_AsLong(value);
1095 else
1097 PyErr_SetString(PyExc_TypeError, "dictionary values aren't revnums");
1098 Py_DECREF(keys);
1099 return NULL;
1102 apr_hash_set(hash, path, APR_HASH_KEY_STRING, revnum);
1104 Py_DECREF(keys);
1105 return hash;
1108 apr_hash_t *svn_swig_py_changed_path_hash_from_dict(PyObject *dict,
1109 apr_pool_t *pool)
1111 apr_hash_t *hash;
1112 PyObject *keys;
1113 int i, num_keys;
1115 if (dict == Py_None)
1116 return NULL;
1118 if (!PyDict_Check(dict))
1120 PyErr_SetString(PyExc_TypeError, "not a dictionary");
1121 return NULL;
1124 hash = apr_hash_make(pool);
1125 keys = PyDict_Keys(dict);
1126 num_keys = PyList_Size(keys);
1127 for (i = 0; i < num_keys; i++)
1129 PyObject *key = PyList_GetItem(keys, i);
1130 PyObject *py_changed_path = PyDict_GetItem(dict, key);
1131 const char *path = make_string_from_ob(key, pool);
1132 svn_log_changed_path_t *changed_path;
1133 if (!path)
1135 PyErr_SetString(PyExc_TypeError,
1136 "dictionary keys aren't strings");
1137 Py_DECREF(keys);
1138 return NULL;
1140 svn_swig_ConvertPtrString(py_changed_path, (void *)&changed_path,
1141 "svn_log_changed_path_t *");
1142 if (!changed_path)
1144 PyErr_SetString(PyExc_TypeError,
1145 "dictionary values aren't svn_log_changed_path_t");
1146 Py_DECREF(keys);
1147 return NULL;
1149 apr_hash_set(hash, path, APR_HASH_KEY_STRING, changed_path);
1151 Py_DECREF(keys);
1152 return hash;
1155 const apr_array_header_t *svn_swig_py_strings_to_array(PyObject *source,
1156 apr_pool_t *pool)
1158 int targlen;
1159 apr_array_header_t *temp;
1161 if (source == Py_None)
1162 return NULL;
1164 if (!PySequence_Check(source))
1166 PyErr_SetString(PyExc_TypeError, "not a sequence");
1167 return NULL;
1169 targlen = PySequence_Length(source);
1170 temp = apr_array_make(pool, targlen, sizeof(const char *));
1171 /* APR_ARRAY_IDX doesn't actually increment the array item count
1172 (like, say, apr_array_push would). */
1173 temp->nelts = targlen;
1174 while (targlen--)
1176 PyObject *o = PySequence_GetItem(source, targlen);
1177 if (o == NULL)
1178 return NULL;
1179 if (!PyString_Check(o))
1181 Py_DECREF(o);
1182 PyErr_SetString(PyExc_TypeError, "not a string");
1183 return NULL;
1185 APR_ARRAY_IDX(temp, targlen, const char *) = PyString_AS_STRING(o);
1186 Py_DECREF(o);
1188 return temp;
1192 const apr_array_header_t *svn_swig_py_revnums_to_array(PyObject *source,
1193 apr_pool_t *pool)
1195 int targlen;
1196 apr_array_header_t *temp;
1198 if (!PySequence_Check(source))
1200 PyErr_SetString(PyExc_TypeError, "not a sequence");
1201 return NULL;
1203 targlen = PySequence_Length(source);
1204 temp = apr_array_make(pool, targlen, sizeof(svn_revnum_t));
1205 /* APR_ARRAY_IDX doesn't actually increment the array item count
1206 (like, say, apr_array_push would). */
1207 temp->nelts = targlen;
1208 while (targlen--)
1210 PyObject *o = PySequence_GetItem(source, targlen);
1211 if (o == NULL)
1212 return NULL;
1213 if (PyLong_Check(o))
1215 APR_ARRAY_IDX(temp, targlen, svn_revnum_t) =
1216 (svn_revnum_t)PyLong_AsLong(o);
1218 else if (PyInt_Check(o))
1220 APR_ARRAY_IDX(temp, targlen, svn_revnum_t) =
1221 (svn_revnum_t)PyInt_AsLong(o);
1223 else
1225 Py_DECREF(o);
1226 PyErr_SetString(PyExc_TypeError, "not an integer type");
1227 return NULL;
1229 Py_DECREF(o);
1231 return temp;
1236 /*** apr_array_header_t conversions. To create a new type of
1237 converter, simply copy-n-paste one of these function and tweak
1238 the creation of the PyObject *ob. ***/
1240 PyObject *svn_swig_py_array_to_list(const apr_array_header_t *array)
1242 PyObject *list = PyList_New(array->nelts);
1243 int i;
1245 for (i = 0; i < array->nelts; ++i)
1247 PyObject *ob =
1248 PyString_FromString(APR_ARRAY_IDX(array, i, const char *));
1249 if (ob == NULL)
1250 goto error;
1251 PyList_SET_ITEM(list, i, ob);
1253 return list;
1255 error:
1256 Py_DECREF(list);
1257 return NULL;
1260 PyObject *svn_swig_py_revarray_to_list(const apr_array_header_t *array)
1262 PyObject *list = PyList_New(array->nelts);
1263 int i;
1265 for (i = 0; i < array->nelts; ++i)
1267 PyObject *ob
1268 = PyInt_FromLong(APR_ARRAY_IDX(array, i, svn_revnum_t));
1269 if (ob == NULL)
1270 goto error;
1271 PyList_SET_ITEM(list, i, ob);
1273 return list;
1275 error:
1276 Py_DECREF(list);
1277 return NULL;
1280 static PyObject *
1281 commit_item_array_to_list(const apr_array_header_t *array)
1283 PyObject *list = PyList_New(array->nelts);
1284 int i;
1286 for (i = 0; i < array->nelts; ++i)
1288 PyObject *ob = convert_svn_client_commit_item3_t
1289 (APR_ARRAY_IDX(array, i, svn_client_commit_item3_t *), NULL);
1290 if (ob == NULL)
1291 goto error;
1292 PyList_SET_ITEM(list, i, ob);
1294 return list;
1296 error:
1297 Py_DECREF(list);
1298 return NULL;
1303 /*** Errors ***/
1305 /* Return a Subversion error about a failed callback. */
1306 static svn_error_t *callback_exception_error(void)
1308 return svn_error_create(SVN_ERR_SWIG_PY_EXCEPTION_SET, NULL,
1309 "Python callback raised an exception");
1312 /* Raise a TypeError exception with MESSAGE, and return a Subversion
1313 error about an invalid return from a callback. */
1314 static svn_error_t *callback_bad_return_error(const char *message)
1316 PyErr_SetString(PyExc_TypeError, message);
1317 return svn_error_create(APR_EGENERAL, NULL,
1318 "Python callback returned an invalid object");
1321 /* Return a generic error about not being able to map types. */
1322 static svn_error_t *type_conversion_error(const char *datatype)
1324 return svn_error_createf(APR_EGENERAL, NULL,
1325 "Error converting object of type '%s'", datatype);
1330 /*** Editor Wrapping ***/
1332 /* this baton is used for the editor, directory, and file batons. */
1333 typedef struct {
1334 PyObject *editor; /* the editor handling the callbacks */
1335 PyObject *baton; /* the dir/file baton (or NULL for edit baton) */
1336 } item_baton;
1338 static item_baton *make_baton(apr_pool_t *pool,
1339 PyObject *editor,
1340 PyObject *baton)
1342 item_baton *newb = apr_palloc(pool, sizeof(*newb));
1344 /* Note: We steal the caller's reference to 'baton'. Also, to avoid
1345 memory leaks, we borrow the caller's reference to 'editor'. In this
1346 case, borrowing the reference to 'editor' is safe because the contents
1347 of an item_baton struct are only used by functino calls which operate on
1348 the editor itself. */
1349 newb->editor = editor;
1350 newb->baton = baton;
1352 return newb;
1355 static svn_error_t *close_baton(void *baton,
1356 const char *method)
1358 item_baton *ib = baton;
1359 PyObject *result;
1360 svn_error_t *err;
1362 svn_swig_py_acquire_py_lock();
1364 /* If there is no baton object, then it is an edit_baton, and we should
1365 not bother to pass an object. Note that we still shove a NULL onto
1366 the stack, but the format specified just won't reference it. */
1367 /* ### python doesn't have 'const' on the method name and format */
1368 if ((result = PyObject_CallMethod(ib->editor, (char *)method,
1369 ib->baton ? (char *)"(O)" : NULL,
1370 ib->baton)) == NULL)
1372 err = callback_exception_error();
1373 goto finished;
1376 /* there is no return value, so just toss this object (probably Py_None) */
1377 Py_DECREF(result);
1379 /* We're now done with the baton. Since there isn't really a free, all
1380 we need to do is note that its objects are no longer referenced by
1381 the baton. */
1382 Py_XDECREF(ib->baton);
1384 #ifdef SVN_DEBUG
1385 ib->editor = ib->baton = NULL;
1386 #endif
1388 err = SVN_NO_ERROR;
1390 finished:
1391 svn_swig_py_release_py_lock();
1392 return err;
1395 static svn_error_t *set_target_revision(void *edit_baton,
1396 svn_revnum_t target_revision,
1397 apr_pool_t *pool)
1399 item_baton *ib = edit_baton;
1400 PyObject *result;
1401 svn_error_t *err;
1403 svn_swig_py_acquire_py_lock();
1405 /* ### python doesn't have 'const' on the method name and format */
1406 if ((result = PyObject_CallMethod(ib->editor, (char *)"set_target_revision",
1407 (char *)"l", target_revision)) == NULL)
1409 err = callback_exception_error();
1410 goto finished;
1413 /* there is no return value, so just toss this object (probably Py_None) */
1414 Py_DECREF(result);
1415 err = SVN_NO_ERROR;
1417 finished:
1418 svn_swig_py_release_py_lock();
1419 return err;
1422 static svn_error_t *open_root(void *edit_baton,
1423 svn_revnum_t base_revision,
1424 apr_pool_t *dir_pool,
1425 void **root_baton)
1427 item_baton *ib = edit_baton;
1428 PyObject *result;
1429 svn_error_t *err;
1431 svn_swig_py_acquire_py_lock();
1433 /* ### python doesn't have 'const' on the method name and format */
1434 if ((result = PyObject_CallMethod(ib->editor, (char *)"open_root",
1435 (char *)"lO&", base_revision,
1436 make_ob_pool, dir_pool)) == NULL)
1438 err = callback_exception_error();
1439 goto finished;
1442 /* make_baton takes our 'result' reference */
1443 *root_baton = make_baton(dir_pool, ib->editor, result);
1444 err = SVN_NO_ERROR;
1446 finished:
1447 svn_swig_py_release_py_lock();
1448 return err;
1451 static svn_error_t *delete_entry(const char *path,
1452 svn_revnum_t revision,
1453 void *parent_baton,
1454 apr_pool_t *pool)
1456 item_baton *ib = parent_baton;
1457 PyObject *result;
1458 svn_error_t *err;
1460 svn_swig_py_acquire_py_lock();
1462 /* ### python doesn't have 'const' on the method name and format */
1463 if ((result = PyObject_CallMethod(ib->editor, (char *)"delete_entry",
1464 (char *)"slOO&", path, revision, ib->baton,
1465 make_ob_pool, pool)) == NULL)
1467 err = callback_exception_error();
1468 goto finished;
1471 /* there is no return value, so just toss this object (probably Py_None) */
1472 Py_DECREF(result);
1473 err = SVN_NO_ERROR;
1475 finished:
1476 svn_swig_py_release_py_lock();
1477 return err;
1480 static svn_error_t *add_directory(const char *path,
1481 void *parent_baton,
1482 const char *copyfrom_path,
1483 svn_revnum_t copyfrom_revision,
1484 apr_pool_t *dir_pool,
1485 void **child_baton)
1487 item_baton *ib = parent_baton;
1488 PyObject *result;
1489 svn_error_t *err;
1491 svn_swig_py_acquire_py_lock();
1493 /* ### python doesn't have 'const' on the method name and format */
1494 if ((result = PyObject_CallMethod(ib->editor, (char *)"add_directory",
1495 (char *)"sOslO&", path, ib->baton,
1496 copyfrom_path, copyfrom_revision,
1497 make_ob_pool, dir_pool)) == NULL)
1499 err = callback_exception_error();
1500 goto finished;
1503 /* make_baton takes our 'result' reference */
1504 *child_baton = make_baton(dir_pool, ib->editor, result);
1505 err = SVN_NO_ERROR;
1507 finished:
1508 svn_swig_py_release_py_lock();
1509 return err;
1512 static svn_error_t *open_directory(const char *path,
1513 void *parent_baton,
1514 svn_revnum_t base_revision,
1515 apr_pool_t *dir_pool,
1516 void **child_baton)
1518 item_baton *ib = parent_baton;
1519 PyObject *result;
1520 svn_error_t *err;
1522 svn_swig_py_acquire_py_lock();
1524 /* ### python doesn't have 'const' on the method name and format */
1525 if ((result = PyObject_CallMethod(ib->editor, (char *)"open_directory",
1526 (char *)"sOlO&", path, ib->baton,
1527 base_revision,
1528 make_ob_pool, dir_pool)) == NULL)
1530 err = callback_exception_error();
1531 goto finished;
1534 /* make_baton takes our 'result' reference */
1535 *child_baton = make_baton(dir_pool, ib->editor, result);
1536 err = SVN_NO_ERROR;
1538 finished:
1539 svn_swig_py_release_py_lock();
1540 return err;
1543 static svn_error_t *change_dir_prop(void *dir_baton,
1544 const char *name,
1545 const svn_string_t *value,
1546 apr_pool_t *pool)
1548 item_baton *ib = dir_baton;
1549 PyObject *result;
1550 svn_error_t *err;
1552 svn_swig_py_acquire_py_lock();
1554 /* ### python doesn't have 'const' on the method name and format */
1555 if ((result = PyObject_CallMethod(ib->editor, (char *)"change_dir_prop",
1556 (char *)"Oss#O&", ib->baton, name,
1557 value ? value->data : NULL,
1558 value ? value->len : 0,
1559 make_ob_pool, pool)) == NULL)
1561 err = callback_exception_error();
1562 goto finished;
1565 /* there is no return value, so just toss this object (probably Py_None) */
1566 Py_DECREF(result);
1567 err = SVN_NO_ERROR;
1569 finished:
1570 svn_swig_py_release_py_lock();
1571 return err;
1574 static svn_error_t *close_directory(void *dir_baton,
1575 apr_pool_t *pool)
1577 return close_baton(dir_baton, "close_directory");
1580 static svn_error_t *add_file(const char *path,
1581 void *parent_baton,
1582 const char *copyfrom_path,
1583 svn_revnum_t copyfrom_revision,
1584 apr_pool_t *file_pool,
1585 void **file_baton)
1587 item_baton *ib = parent_baton;
1588 PyObject *result;
1589 svn_error_t *err;
1591 svn_swig_py_acquire_py_lock();
1593 /* ### python doesn't have 'const' on the method name and format */
1594 if ((result = PyObject_CallMethod(ib->editor, (char *)"add_file",
1595 (char *)"sOslO&", path, ib->baton,
1596 copyfrom_path, copyfrom_revision,
1597 make_ob_pool, file_pool)) == NULL)
1599 err = callback_exception_error();
1600 goto finished;
1603 /* make_baton takes our 'result' reference */
1604 *file_baton = make_baton(file_pool, ib->editor, result);
1606 err = SVN_NO_ERROR;
1608 finished:
1609 svn_swig_py_release_py_lock();
1610 return err;
1613 static svn_error_t *open_file(const char *path,
1614 void *parent_baton,
1615 svn_revnum_t base_revision,
1616 apr_pool_t *file_pool,
1617 void **file_baton)
1619 item_baton *ib = parent_baton;
1620 PyObject *result;
1621 svn_error_t *err;
1623 svn_swig_py_acquire_py_lock();
1625 /* ### python doesn't have 'const' on the method name and format */
1626 if ((result = PyObject_CallMethod(ib->editor, (char *)"open_file",
1627 (char *)"sOlO&", path, ib->baton,
1628 base_revision,
1629 make_ob_pool, file_pool)) == NULL)
1631 err = callback_exception_error();
1632 goto finished;
1635 /* make_baton takes our 'result' reference */
1636 *file_baton = make_baton(file_pool, ib->editor, result);
1637 err = SVN_NO_ERROR;
1639 finished:
1640 svn_swig_py_release_py_lock();
1641 return err;
1644 static svn_error_t *window_handler(svn_txdelta_window_t *window,
1645 void *baton)
1647 PyObject *handler = baton;
1648 PyObject *result;
1649 svn_error_t *err;
1651 svn_swig_py_acquire_py_lock();
1653 if (window == NULL)
1655 /* the last call; it closes the handler */
1657 /* invoke the handler with None for the window */
1658 /* ### python doesn't have 'const' on the format */
1659 result = PyObject_CallFunction(handler, (char *)"O", Py_None);
1661 /* we no longer need to refer to the handler object */
1662 Py_DECREF(handler);
1664 else
1666 /* invoke the handler with the window */
1667 /* ### python doesn't have 'const' on the format */
1668 result = PyObject_CallFunction(handler, (char *)"O&",
1669 make_ob_txdelta_window, window);
1672 if (result == NULL)
1674 err = callback_exception_error();
1675 goto finished;
1678 /* there is no return value, so just toss this object (probably Py_None) */
1679 Py_DECREF(result);
1680 err = SVN_NO_ERROR;
1682 finished:
1683 svn_swig_py_release_py_lock();
1684 return err;
1687 static svn_error_t *apply_textdelta(void *file_baton,
1688 const char *base_checksum,
1689 apr_pool_t *pool,
1690 svn_txdelta_window_handler_t *handler,
1691 void **h_baton)
1693 item_baton *ib = file_baton;
1694 PyObject *result;
1695 svn_error_t *err;
1697 svn_swig_py_acquire_py_lock();
1699 /* ### python doesn't have 'const' on the method name and format */
1700 if ((result = PyObject_CallMethod(ib->editor, (char *)"apply_textdelta",
1701 (char *)"(Os)", ib->baton,
1702 base_checksum)) == NULL)
1704 err = callback_exception_error();
1705 goto finished;
1708 /* Interpret None to mean svn_delta_noop_window_handler. This is much
1709 easier/faster than making code always have to write a NOOP handler
1710 in Python. */
1711 if (result == Py_None)
1713 Py_DECREF(result);
1715 *handler = svn_delta_noop_window_handler;
1716 *h_baton = NULL;
1718 else
1720 /* return the thunk for invoking the handler. the baton takes our
1721 'result' reference, which is the handler. */
1722 *handler = window_handler;
1723 *h_baton = result;
1726 err = SVN_NO_ERROR;
1728 finished:
1729 svn_swig_py_release_py_lock();
1730 return err;
1733 static svn_error_t *change_file_prop(void *file_baton,
1734 const char *name,
1735 const svn_string_t *value,
1736 apr_pool_t *pool)
1738 item_baton *ib = file_baton;
1739 PyObject *result;
1740 svn_error_t *err;
1742 svn_swig_py_acquire_py_lock();
1744 /* ### python doesn't have 'const' on the method name and format */
1745 if ((result = PyObject_CallMethod(ib->editor, (char *)"change_file_prop",
1746 (char *)"Oss#O&", ib->baton, name,
1747 value ? value->data : NULL,
1748 value ? value->len : 0,
1749 make_ob_pool, pool)) == NULL)
1751 err = callback_exception_error();
1752 goto finished;
1755 /* there is no return value, so just toss this object (probably Py_None) */
1756 Py_DECREF(result);
1757 err = SVN_NO_ERROR;
1759 finished:
1760 svn_swig_py_release_py_lock();
1761 return err;
1764 static svn_error_t *close_file(void *file_baton,
1765 const char *text_checksum,
1766 apr_pool_t *pool)
1768 item_baton *ib = file_baton;
1769 PyObject *result;
1770 svn_error_t *err;
1772 svn_swig_py_acquire_py_lock();
1774 /* ### python doesn't have 'const' on the method name and format */
1775 if ((result = PyObject_CallMethod(ib->editor, (char *)"close_file",
1776 (char *)"(Os)", ib->baton,
1777 text_checksum)) == NULL)
1779 err = callback_exception_error();
1780 goto finished;
1783 /* there is no return value, so just toss this object (probably Py_None) */
1784 Py_DECREF(result);
1786 /* We're now done with the baton. Since there isn't really a free, all
1787 we need to do is note that its objects are no longer referenced by
1788 the baton. */
1789 Py_XDECREF(ib->baton);
1791 #ifdef SVN_DEBUG
1792 ib->editor = ib->baton = NULL;
1793 #endif
1795 err = SVN_NO_ERROR;
1797 finished:
1798 svn_swig_py_release_py_lock();
1799 return err;
1802 static svn_error_t *close_edit(void *edit_baton,
1803 apr_pool_t *pool)
1805 return close_baton(edit_baton, "close_edit");
1808 static svn_error_t *abort_edit(void *edit_baton,
1809 apr_pool_t *pool)
1811 return close_baton(edit_baton, "abort_edit");
1814 void svn_swig_py_make_editor(const svn_delta_editor_t **editor,
1815 void **edit_baton,
1816 PyObject *py_editor,
1817 apr_pool_t *pool)
1819 svn_delta_editor_t *thunk_editor = svn_delta_default_editor(pool);
1821 thunk_editor->set_target_revision = set_target_revision;
1822 thunk_editor->open_root = open_root;
1823 thunk_editor->delete_entry = delete_entry;
1824 thunk_editor->add_directory = add_directory;
1825 thunk_editor->open_directory = open_directory;
1826 thunk_editor->change_dir_prop = change_dir_prop;
1827 thunk_editor->close_directory = close_directory;
1828 thunk_editor->add_file = add_file;
1829 thunk_editor->open_file = open_file;
1830 thunk_editor->apply_textdelta = apply_textdelta;
1831 thunk_editor->change_file_prop = change_file_prop;
1832 thunk_editor->close_file = close_file;
1833 thunk_editor->close_edit = close_edit;
1834 thunk_editor->abort_edit = abort_edit;
1836 *editor = thunk_editor;
1837 *edit_baton = make_baton(pool, py_editor, NULL);
1842 /*** Other Wrappers for SVN Functions ***/
1845 apr_file_t *svn_swig_py_make_file(PyObject *py_file,
1846 apr_pool_t *pool)
1848 apr_file_t *apr_file = NULL;
1849 apr_status_t apr_err;
1851 if (py_file == NULL || py_file == Py_None)
1852 return NULL;
1854 if (PyString_Check(py_file))
1856 /* input is a path -- just open an apr_file_t */
1857 char* fname = PyString_AS_STRING(py_file);
1858 apr_err = apr_file_open(&apr_file, fname,
1859 APR_CREATE | APR_READ | APR_WRITE,
1860 APR_OS_DEFAULT, pool);
1861 if (apr_err)
1863 char buf[256];
1864 apr_strerror(apr_err, buf, sizeof(buf));
1865 PyErr_Format(PyExc_IOError, "apr_file_open failed: %s: '%s'",
1866 buf, fname);
1867 return NULL;
1870 else if (PyFile_Check(py_file))
1872 FILE *file;
1873 apr_os_file_t osfile;
1875 /* input is a file object -- convert to apr_file_t */
1876 file = PyFile_AsFile(py_file);
1877 #ifdef WIN32
1878 osfile = (apr_os_file_t)_get_osfhandle(_fileno(file));
1879 #else
1880 osfile = (apr_os_file_t)fileno(file);
1881 #endif
1882 apr_err = apr_os_file_put(&apr_file, &osfile, O_CREAT | O_WRONLY, pool);
1883 if (apr_err)
1885 char buf[256];
1886 apr_strerror(apr_err, buf, sizeof(buf));
1887 PyErr_Format(PyExc_IOError, "apr_os_file_put failed: %s", buf);
1888 return NULL;
1891 return apr_file;
1895 static svn_error_t *
1896 read_handler_pyio(void *baton, char *buffer, apr_size_t *len)
1898 PyObject *result;
1899 PyObject *py_io = baton;
1900 apr_size_t bytes;
1901 svn_error_t *err = SVN_NO_ERROR;
1903 if (py_io == Py_None)
1905 /* Return the empty string to indicate a short read */
1906 *buffer = '\0';
1907 *len = 0;
1908 return SVN_NO_ERROR;
1911 svn_swig_py_acquire_py_lock();
1912 if ((result = PyObject_CallMethod(py_io, (char *)"read",
1913 (char *)"i", *len)) == NULL)
1915 err = callback_exception_error();
1917 else if (PyString_Check(result))
1919 bytes = PyString_GET_SIZE(result);
1920 if (bytes > *len)
1922 err = callback_bad_return_error("Too many bytes");
1924 else
1926 /* Writeback, in case this was a short read, indicating EOF */
1927 *len = bytes;
1928 memcpy(buffer, PyString_AS_STRING(result), *len);
1931 else
1933 err = callback_bad_return_error("Not a string");
1935 Py_XDECREF(result);
1936 svn_swig_py_release_py_lock();
1938 return err;
1941 static svn_error_t *
1942 write_handler_pyio(void *baton, const char *data, apr_size_t *len)
1944 PyObject *result;
1945 PyObject *py_io = baton;
1946 svn_error_t *err = SVN_NO_ERROR;
1948 if (data != NULL && py_io != Py_None)
1950 svn_swig_py_acquire_py_lock();
1951 if ((result = PyObject_CallMethod(py_io, (char *)"write",
1952 (char *)"s#", data, *len)) == NULL)
1954 err = callback_exception_error();
1956 Py_XDECREF(result);
1957 svn_swig_py_release_py_lock();
1960 return err;
1963 static svn_error_t *
1964 close_handler_pyio(void *baton)
1966 PyObject *py_io = baton;
1967 svn_swig_py_acquire_py_lock();
1968 Py_DECREF(py_io);
1969 svn_swig_py_release_py_lock();
1970 return SVN_NO_ERROR;
1973 svn_stream_t *
1974 svn_swig_py_make_stream(PyObject *py_io, apr_pool_t *pool)
1976 svn_stream_t *stream;
1978 stream = svn_stream_create(py_io, pool);
1979 svn_stream_set_read(stream, read_handler_pyio);
1980 svn_stream_set_write(stream, write_handler_pyio);
1981 svn_stream_set_close(stream, close_handler_pyio);
1982 Py_INCREF(py_io);
1984 return stream;
1988 void svn_swig_py_notify_func(void *baton,
1989 const char *path,
1990 svn_wc_notify_action_t action,
1991 svn_node_kind_t kind,
1992 const char *mime_type,
1993 svn_wc_notify_state_t content_state,
1994 svn_wc_notify_state_t prop_state,
1995 svn_revnum_t revision)
1997 PyObject *function = baton;
1998 PyObject *result;
1999 svn_error_t *err = SVN_NO_ERROR;
2001 if (function == NULL || function == Py_None)
2002 return;
2004 svn_swig_py_acquire_py_lock();
2005 if ((result = PyObject_CallFunction(function,
2006 (char *)"(siisiii)",
2007 path, action, kind,
2008 mime_type,
2009 content_state, prop_state,
2010 revision)) == NULL)
2012 err = callback_exception_error();
2014 else
2016 /* The callback shouldn't be returning anything. */
2017 if (result != Py_None)
2018 err = callback_bad_return_error("Not None");
2019 Py_DECREF(result);
2022 /* Our error has no place to go. :-( */
2023 svn_error_clear(err);
2025 svn_swig_py_release_py_lock();
2029 void svn_swig_py_notify_func2(void *baton,
2030 const svn_wc_notify_t *notify,
2031 apr_pool_t *pool)
2033 PyObject *function = baton;
2034 PyObject *result;
2035 svn_error_t *err = SVN_NO_ERROR;
2037 if (function == NULL || function == Py_None)
2038 return;
2040 svn_swig_py_acquire_py_lock();
2042 if ((result = PyObject_CallFunction(function,
2043 (char *)"(O&O&)",
2044 make_ob_wc_notify, notify,
2045 make_ob_pool, pool)) == NULL)
2047 err = callback_exception_error();
2049 else
2051 /* The callback shouldn't be returning anything. */
2052 if (result != Py_None)
2053 err = callback_bad_return_error("Not None");
2054 Py_DECREF(result);
2057 /* Our error has no place to go. :-( */
2058 svn_error_clear(err);
2060 svn_swig_py_release_py_lock();
2063 void svn_swig_py_status_func(void *baton,
2064 const char *path,
2065 svn_wc_status_t *status)
2067 PyObject *function = baton;
2068 PyObject *result;
2069 svn_error_t *err = SVN_NO_ERROR;
2071 if (function == NULL || function == Py_None)
2072 return;
2074 svn_swig_py_acquire_py_lock();
2075 if ((result = PyObject_CallFunction(function, (char *)"sO&", path,
2076 make_ob_wc_status, status)) == NULL)
2078 err = callback_exception_error();
2080 else
2082 /* The callback shouldn't be returning anything. */
2083 if (result != Py_None)
2084 err = callback_bad_return_error("Not None");
2085 Py_DECREF(result);
2088 /* Our error has no place to go. :-( */
2089 svn_error_clear(err);
2091 svn_swig_py_release_py_lock();
2095 svn_error_t *svn_swig_py_delta_path_driver_cb_func(void **dir_baton,
2096 void *parent_baton,
2097 void *callback_baton,
2098 const char *path,
2099 apr_pool_t *pool)
2101 PyObject *function = callback_baton;
2102 PyObject *result;
2103 svn_error_t *err = SVN_NO_ERROR;
2105 if (function == NULL || function == Py_None)
2106 return err;
2108 svn_swig_py_acquire_py_lock();
2109 result = PyObject_CallFunction(function, (char *)"OsO&",
2110 svn_swig_NewPointerObjString(parent_baton,
2111 "void *",
2112 application_py_pool),
2113 path, make_ob_pool, pool);
2114 if (result == NULL)
2116 err = callback_exception_error();
2118 else if (result == Py_None)
2120 *dir_baton = NULL;
2122 else
2124 if (svn_swig_ConvertPtrString(result, dir_baton, "void *") == -1)
2126 err = type_conversion_error("void *");
2130 svn_swig_py_release_py_lock();
2131 return err;
2135 void svn_swig_py_status_func2(void *baton,
2136 const char *path,
2137 svn_wc_status2_t *status)
2139 PyObject *function = baton;
2140 PyObject *result;
2141 svn_error_t *err = SVN_NO_ERROR;
2143 if (function == NULL || function == Py_None)
2144 return;
2146 svn_swig_py_acquire_py_lock();
2147 if ((result = PyObject_CallFunction(function, (char *)"sO&", path,
2148 make_ob_wc_status, status)) == NULL)
2150 err = callback_exception_error();
2152 else
2154 /* The callback shouldn't be returning anything. */
2155 if (result != Py_None)
2156 err = callback_bad_return_error("Not None");
2157 Py_DECREF(result);
2160 /* Our error has no place to go. :-( */
2161 if (err)
2162 svn_error_clear(err);
2164 svn_swig_py_release_py_lock();
2168 svn_error_t *svn_swig_py_cancel_func(void *cancel_baton)
2170 PyObject *function = cancel_baton;
2171 PyObject *result;
2172 svn_error_t *err = SVN_NO_ERROR;
2174 if (function == NULL || function == Py_None)
2175 return SVN_NO_ERROR;
2177 svn_swig_py_acquire_py_lock();
2178 if ((result = PyObject_CallFunction(function, NULL)) == NULL)
2180 err = callback_exception_error();
2182 else
2184 if (PyInt_Check(result))
2186 if (PyInt_AsLong(result))
2187 err = svn_error_create(SVN_ERR_CANCELLED, 0, NULL);
2189 else if (PyLong_Check(result))
2191 if (PyLong_AsLong(result))
2192 err = svn_error_create(SVN_ERR_CANCELLED, 0, NULL);
2194 else if (result != Py_None)
2196 err = callback_bad_return_error("Not an integer or None");
2198 Py_DECREF(result);
2200 svn_swig_py_release_py_lock();
2201 return err;
2204 svn_error_t *svn_swig_py_fs_get_locks_func(void *baton,
2205 svn_lock_t *lock,
2206 apr_pool_t *pool)
2208 PyObject *function = baton;
2209 PyObject *result;
2210 svn_error_t *err = SVN_NO_ERROR;
2212 if (function == NULL || function == Py_None)
2213 return SVN_NO_ERROR;
2215 svn_swig_py_acquire_py_lock();
2217 if ((result = PyObject_CallFunction(function, (char *)"O&O&",
2218 make_ob_lock, lock,
2219 make_ob_pool, pool)) == NULL)
2221 err = callback_exception_error();
2223 else
2225 /* The callback shouldn't be returning anything. */
2226 if (result != Py_None)
2227 err = callback_bad_return_error("Not None");
2228 Py_DECREF(result);
2231 svn_swig_py_release_py_lock();
2232 return err;
2235 svn_error_t *svn_swig_py_get_commit_log_func(const char **log_msg,
2236 const char **tmp_file,
2237 const apr_array_header_t *
2238 commit_items,
2239 void *baton,
2240 apr_pool_t *pool)
2242 PyObject *function = baton;
2243 PyObject *result;
2244 PyObject *cmt_items;
2245 svn_error_t *err;
2247 *log_msg = NULL;
2248 *tmp_file = NULL;
2250 /* ### todo: for now, just ignore the whole tmp_file thing. */
2252 if ((function == NULL) || (function == Py_None))
2253 return SVN_NO_ERROR;
2255 svn_swig_py_acquire_py_lock();
2257 if (commit_items)
2259 cmt_items = commit_item_array_to_list(commit_items);
2261 else
2263 cmt_items = Py_None;
2264 Py_INCREF(Py_None);
2267 if ((result = PyObject_CallFunction(function,
2268 (char *)"OO&",
2269 cmt_items,
2270 make_ob_pool, pool)) == NULL)
2272 Py_DECREF(cmt_items);
2273 err = callback_exception_error();
2274 goto finished;
2277 Py_DECREF(cmt_items);
2279 if (result == Py_None)
2281 Py_DECREF(result);
2282 *log_msg = NULL;
2283 err = SVN_NO_ERROR;
2285 else if (PyString_Check(result))
2287 *log_msg = apr_pstrdup(pool, PyString_AS_STRING(result));
2288 Py_DECREF(result);
2289 err = SVN_NO_ERROR;
2291 else
2293 Py_DECREF(result);
2294 err = callback_bad_return_error("Not a string");
2297 finished:
2298 svn_swig_py_release_py_lock();
2299 return err;
2303 svn_error_t *svn_swig_py_repos_authz_func(svn_boolean_t *allowed,
2304 svn_fs_root_t *root,
2305 const char *path,
2306 void *baton,
2307 apr_pool_t *pool)
2309 PyObject *function = baton;
2310 PyObject *result;
2311 PyObject *py_pool, *py_root;
2312 svn_error_t *err = SVN_NO_ERROR;
2314 *allowed = TRUE;
2316 if (function == NULL || function == Py_None)
2317 return SVN_NO_ERROR;
2319 svn_swig_py_acquire_py_lock();
2321 py_pool = make_ob_pool(pool);
2322 if (py_pool == NULL)
2324 err = callback_exception_error();
2325 goto finished;
2327 py_root = make_ob_fs_root(root, py_pool);
2328 if (py_root == NULL)
2330 Py_DECREF(py_pool);
2331 err = callback_exception_error();
2332 goto finished;
2335 if ((result = PyObject_CallFunction(function,
2336 (char *)"OsO",
2337 py_root, path, py_pool)) == NULL)
2339 err = callback_exception_error();
2341 else
2343 if (PyInt_Check(result))
2344 *allowed = PyInt_AsLong(result);
2345 else if (PyLong_Check(result))
2346 *allowed = PyLong_AsLong(result);
2347 else
2348 err = callback_bad_return_error("Not an integer");
2349 Py_DECREF(result);
2351 Py_DECREF(py_root);
2352 Py_DECREF(py_pool);
2353 finished:
2354 svn_swig_py_release_py_lock();
2355 return err;
2359 svn_error_t *svn_swig_py_repos_history_func(void *baton,
2360 const char *path,
2361 svn_revnum_t revision,
2362 apr_pool_t *pool)
2364 PyObject *function = baton;
2365 PyObject *result;
2366 svn_error_t *err = SVN_NO_ERROR;
2368 if (function == NULL || function == Py_None)
2369 return SVN_NO_ERROR;
2371 svn_swig_py_acquire_py_lock();
2372 if ((result = PyObject_CallFunction(function,
2373 (char *)"slO&",
2374 path, revision,
2375 make_ob_pool, pool)) == NULL)
2377 err = callback_exception_error();
2379 else
2381 if (result != Py_None)
2382 err = callback_bad_return_error("Not None");
2383 Py_DECREF(result);
2385 svn_swig_py_release_py_lock();
2386 return err;
2390 svn_error_t *svn_swig_py_log_receiver(void *baton,
2391 apr_hash_t *changed_paths,
2392 svn_revnum_t rev,
2393 const char *author,
2394 const char *date,
2395 const char *msg,
2396 apr_pool_t *pool)
2398 PyObject *receiver = baton;
2399 PyObject *result, *py_pool;
2400 PyObject *chpaths;
2401 svn_error_t *err = SVN_NO_ERROR;
2403 if ((receiver == NULL) || (receiver == Py_None))
2404 return SVN_NO_ERROR;
2406 svn_swig_py_acquire_py_lock();
2408 py_pool = make_ob_pool(pool);
2409 if (py_pool == NULL)
2411 err = callback_exception_error();
2412 goto finished;
2415 if (changed_paths)
2417 chpaths = convert_hash(changed_paths, convert_log_changed_path,
2418 NULL, NULL);
2420 else
2422 chpaths = Py_None;
2423 Py_INCREF(Py_None);
2426 if ((result = PyObject_CallFunction(receiver,
2427 (char *)"OlsssO",
2428 chpaths, rev, author, date, msg,
2429 py_pool)) == NULL)
2431 err = callback_exception_error();
2433 else
2435 if (result != Py_None)
2436 err = callback_bad_return_error("Not None");
2437 Py_DECREF(result);
2440 Py_DECREF(chpaths);
2441 Py_DECREF(py_pool);
2442 finished:
2443 svn_swig_py_release_py_lock();
2444 return err;
2447 svn_error_t *svn_swig_py_log_entry_receiver(void *baton,
2448 svn_log_entry_t *log_entry,
2449 apr_pool_t *pool)
2451 PyObject *receiver = baton;
2452 PyObject *result, *py_pool;
2453 svn_error_t *err = SVN_NO_ERROR;
2454 PyObject *py_log_entry;
2456 if ((receiver == NULL) || (receiver == Py_None))
2457 return SVN_NO_ERROR;
2459 svn_swig_py_acquire_py_lock();
2461 py_pool = make_ob_pool(pool);
2462 if (py_pool == NULL)
2464 err = callback_exception_error();
2465 goto finished;
2468 py_log_entry = svn_swig_NewPointerObjString(log_entry, "svn_log_entry_t *",
2469 py_pool);
2470 if ((result = PyObject_CallFunction(receiver,
2471 (char *)"OO", py_log_entry,
2472 py_pool)) == NULL)
2474 err = callback_exception_error();
2476 else
2478 if (result != Py_None)
2479 err = callback_bad_return_error("Not None");
2480 Py_DECREF(result);
2483 Py_DECREF(py_log_entry);
2484 Py_DECREF(py_pool);
2485 finished:
2486 svn_swig_py_release_py_lock();
2487 return err;
2490 svn_error_t *svn_swig_py_info_receiver_func(void *baton,
2491 const char *path,
2492 const svn_info_t *info,
2493 apr_pool_t *pool)
2495 PyObject *receiver = baton;
2496 PyObject *result;
2497 svn_error_t *err = SVN_NO_ERROR;
2499 if ((receiver == NULL) || (receiver == Py_None))
2500 return SVN_NO_ERROR;
2502 svn_swig_py_acquire_py_lock();
2504 if ((result = PyObject_CallFunction(receiver,
2505 (char *)"sO&O&",
2506 path, make_ob_info, info,
2507 make_ob_pool, pool)) == NULL)
2509 err = callback_exception_error();
2511 else
2513 if (result != Py_None)
2514 err = callback_bad_return_error("Not None");
2515 Py_DECREF(result);
2518 svn_swig_py_release_py_lock();
2520 return err;
2523 svn_error_t *
2524 svn_swig_py_location_segment_receiver_func(svn_location_segment_t *segment,
2525 void *baton,
2526 apr_pool_t *pool)
2528 PyObject *receiver = baton;
2529 PyObject *result;
2530 svn_error_t *err = SVN_NO_ERROR;
2532 if ((receiver == NULL) || (receiver == Py_None))
2533 return SVN_NO_ERROR;
2535 svn_swig_py_acquire_py_lock();
2537 if ((result = PyObject_CallFunction(receiver,
2538 (char *)"O&O&",
2539 make_ob_location_segment, segment,
2540 make_ob_pool, pool)) == NULL)
2542 err = callback_exception_error();
2544 else
2546 if (result != Py_None)
2547 err = callback_bad_return_error("Not None");
2548 Py_DECREF(result);
2551 svn_swig_py_release_py_lock();
2553 return err;
2556 svn_error_t *svn_swig_py_client_blame_receiver_func(void *baton,
2557 apr_int64_t line_no,
2558 svn_revnum_t revision,
2559 const char *author,
2560 const char *date,
2561 const char *line,
2562 apr_pool_t *pool)
2564 PyObject *receiver = baton;
2565 PyObject *result;
2566 svn_error_t *err = SVN_NO_ERROR;
2568 if ((receiver == NULL) || (receiver == Py_None))
2569 return SVN_NO_ERROR;
2571 svn_swig_py_acquire_py_lock();
2573 if ((result = PyObject_CallFunction(receiver,
2574 (char *)
2575 (SVN_APR_INT64_T_PYCFMT "lsssO&"),
2576 line_no, revision, author, date, line,
2577 make_ob_pool, pool)) == NULL)
2579 err = callback_exception_error();
2581 else
2583 if (result != Py_None)
2584 err = callback_bad_return_error("Not None");
2585 Py_DECREF(result);
2588 svn_swig_py_release_py_lock();
2589 return err;
2592 svn_error_t *svn_swig_py_changelist_receiver_func(void *baton,
2593 const char *path,
2594 const char *changelist,
2595 apr_pool_t *pool)
2597 PyObject *receiver = baton;
2598 PyObject *result;
2599 svn_error_t *err = SVN_NO_ERROR;
2601 if ((receiver == NULL) || (receiver == Py_None))
2602 return SVN_NO_ERROR;
2604 svn_swig_py_acquire_py_lock();
2606 if ((result = PyObject_CallFunction(receiver,
2607 (char *)"ssO&",
2608 path, changelist,
2609 make_ob_pool, pool)) == NULL)
2611 err = callback_exception_error();
2613 else
2615 if (result != Py_None)
2616 err = callback_bad_return_error("Not None");
2617 Py_DECREF(result);
2620 svn_swig_py_release_py_lock();
2621 return err;
2624 svn_error_t *
2625 svn_swig_py_auth_simple_prompt_func(svn_auth_cred_simple_t **cred,
2626 void *baton,
2627 const char *realm,
2628 const char *username,
2629 svn_boolean_t may_save,
2630 apr_pool_t *pool)
2632 PyObject *function = baton;
2633 PyObject *result;
2634 svn_auth_cred_simple_t *creds = NULL;
2635 svn_error_t *err = SVN_NO_ERROR;
2637 if ((function == NULL) || (function == Py_None))
2638 return SVN_NO_ERROR;
2640 svn_swig_py_acquire_py_lock();
2642 if ((result = PyObject_CallFunction(function,
2643 (char *)"sslO&",
2644 realm, username, may_save,
2645 make_ob_pool, pool)) == NULL)
2647 err = callback_exception_error();
2649 else
2651 if (result != Py_None)
2653 svn_auth_cred_simple_t *tmp_creds = NULL;
2654 if (svn_swig_ConvertPtrString(result, (void **)&tmp_creds,
2655 "svn_auth_cred_simple_t *"))
2657 err = type_conversion_error("svn_auth_cred_simple_t *");
2659 else
2661 creds = apr_pcalloc(pool, sizeof(*creds));
2662 creds->username = tmp_creds->username ?
2663 apr_pstrdup(pool, tmp_creds->username) : NULL;
2664 creds->password = tmp_creds->password ?
2665 apr_pstrdup(pool, tmp_creds->password) : NULL;
2666 creds->may_save = tmp_creds->may_save;
2669 Py_DECREF(result);
2671 svn_swig_py_release_py_lock();
2672 *cred = creds;
2673 return err;
2676 svn_error_t *
2677 svn_swig_py_auth_username_prompt_func(svn_auth_cred_username_t **cred,
2678 void *baton,
2679 const char *realm,
2680 svn_boolean_t may_save,
2681 apr_pool_t *pool)
2683 PyObject *function = baton;
2684 PyObject *result;
2685 svn_auth_cred_username_t *creds = NULL;
2686 svn_error_t *err = SVN_NO_ERROR;
2688 if ((function == NULL) || (function == Py_None))
2689 return SVN_NO_ERROR;
2691 svn_swig_py_acquire_py_lock();
2693 if ((result = PyObject_CallFunction(function,
2694 (char *)"slO&",
2695 realm, may_save,
2696 make_ob_pool, pool)) == NULL)
2698 err = callback_exception_error();
2700 else
2702 if (result != Py_None)
2704 svn_auth_cred_username_t *tmp_creds = NULL;
2705 if (svn_swig_ConvertPtrString(result, (void **)&tmp_creds,
2706 "svn_auth_cred_username_t *"))
2708 err = type_conversion_error("svn_auth_cred_username_t *");
2710 else
2712 creds = apr_pcalloc(pool, sizeof(*creds));
2713 creds->username = tmp_creds->username ?
2714 apr_pstrdup(pool, tmp_creds->username) : NULL;
2715 creds->may_save = tmp_creds->may_save;
2718 Py_DECREF(result);
2720 svn_swig_py_release_py_lock();
2721 *cred = creds;
2722 return err;
2726 svn_error_t *
2727 svn_swig_py_auth_ssl_server_trust_prompt_func(
2728 svn_auth_cred_ssl_server_trust_t **cred,
2729 void *baton,
2730 const char *realm,
2731 apr_uint32_t failures,
2732 const svn_auth_ssl_server_cert_info_t *cert_info,
2733 svn_boolean_t may_save,
2734 apr_pool_t *pool)
2736 PyObject *function = baton;
2737 PyObject *result;
2738 svn_auth_cred_ssl_server_trust_t *creds = NULL;
2739 svn_error_t *err = SVN_NO_ERROR;
2741 if ((function == NULL) || (function == Py_None))
2742 return SVN_NO_ERROR;
2744 svn_swig_py_acquire_py_lock();
2746 if ((result = PyObject_CallFunction(function, (char *)"slO&lO&",
2747 realm, failures, make_ob_auth_ssl_server_cert_info,
2748 cert_info, may_save, make_ob_pool, pool)) == NULL)
2750 err = callback_exception_error();
2752 else
2754 if (result != Py_None)
2756 svn_auth_cred_ssl_server_trust_t *tmp_creds = NULL;
2757 if (svn_swig_ConvertPtrString
2758 (result, (void **)&tmp_creds,
2759 "svn_auth_cred_ssl_server_trust_t *"))
2761 err = type_conversion_error
2762 ("svn_auth_cred_ssl_server_trust_t *");
2764 else
2766 creds = apr_pcalloc(pool, sizeof(*creds));
2767 *creds = *tmp_creds;
2770 Py_DECREF(result);
2773 svn_swig_py_release_py_lock();
2774 *cred = creds;
2775 return err;
2778 svn_error_t *
2779 svn_swig_py_auth_ssl_client_cert_prompt_func(
2780 svn_auth_cred_ssl_client_cert_t **cred,
2781 void *baton,
2782 const char *realm,
2783 svn_boolean_t may_save,
2784 apr_pool_t *pool)
2786 PyObject *function = baton;
2787 PyObject *result;
2788 svn_auth_cred_ssl_client_cert_t *creds = NULL;
2789 svn_error_t *err = SVN_NO_ERROR;
2791 if ((function == NULL) || (function == Py_None))
2792 return SVN_NO_ERROR;
2794 svn_swig_py_acquire_py_lock();
2796 if ((result = PyObject_CallFunction(function,
2797 (char *)"slO&",
2798 realm, may_save,
2799 make_ob_pool, pool)) == NULL)
2801 err = callback_exception_error();
2803 else
2805 if (result != Py_None)
2807 svn_auth_cred_ssl_client_cert_t *tmp_creds = NULL;
2808 if (svn_swig_ConvertPtrString
2809 (result, (void **)&tmp_creds,
2810 "svn_auth_cred_ssl_client_cert_t *"))
2812 err = type_conversion_error("svn_auth_cred_ssl_client_cert_t *");
2814 else
2816 creds = apr_pcalloc(pool, sizeof(*creds));
2817 creds->cert_file = tmp_creds->cert_file ?
2818 apr_pstrdup(pool, tmp_creds->cert_file) : NULL;
2819 creds->may_save = tmp_creds->may_save;
2822 Py_DECREF(result);
2824 svn_swig_py_release_py_lock();
2825 *cred = creds;
2826 return err;
2829 svn_error_t *
2830 svn_swig_py_auth_ssl_client_cert_pw_prompt_func(
2831 svn_auth_cred_ssl_client_cert_pw_t **cred,
2832 void *baton,
2833 const char *realm,
2834 svn_boolean_t may_save,
2835 apr_pool_t *pool)
2837 PyObject *function = baton;
2838 PyObject *result;
2839 svn_auth_cred_ssl_client_cert_pw_t *creds = NULL;
2840 svn_error_t *err = SVN_NO_ERROR;
2842 if ((function == NULL) || (function == Py_None))
2843 return SVN_NO_ERROR;
2845 svn_swig_py_acquire_py_lock();
2847 if ((result = PyObject_CallFunction(function,
2848 (char *)"slO&",
2849 realm, may_save,
2850 make_ob_pool, pool)) == NULL)
2852 err = callback_exception_error();
2854 else
2856 if (result != Py_None)
2858 svn_auth_cred_ssl_client_cert_pw_t *tmp_creds = NULL;
2859 if (svn_swig_ConvertPtrString
2860 (result, (void **)&tmp_creds,
2861 "svn_auth_cred_ssl_client_cert_pw_t *"))
2863 err = type_conversion_error
2864 ("svn_auth_cred_ssl_client_cert_pw_t *");
2866 else
2868 creds = apr_pcalloc(pool, sizeof(*creds));
2869 creds->password = tmp_creds->password ?
2870 apr_pstrdup(pool, tmp_creds->password) : NULL;
2871 creds->may_save = tmp_creds->may_save;
2874 Py_DECREF(result);
2876 svn_swig_py_release_py_lock();
2877 *cred = creds;
2878 return err;
2881 /* svn_ra_callbacks_t */
2882 static svn_error_t *
2883 ra_callbacks_open_tmp_file(apr_file_t **fp,
2884 void *callback_baton,
2885 apr_pool_t *pool)
2887 PyObject *callbacks = (PyObject *)callback_baton;
2888 PyObject *py_callback, *result;
2889 svn_error_t *err = SVN_NO_ERROR;
2891 *fp = NULL;
2893 svn_swig_py_acquire_py_lock();
2895 py_callback = PyObject_GetAttrString(callbacks, (char *)"open_tmp_file");
2896 if (py_callback == NULL)
2898 err = callback_exception_error();
2899 goto finished;
2901 else if (py_callback == Py_None)
2903 goto finished;
2906 if ((result = PyObject_CallFunction(py_callback,
2907 (char *)"O&",
2908 make_ob_pool, pool)) == NULL)
2910 err = callback_exception_error();
2912 else if (result != Py_None)
2914 *fp = svn_swig_py_make_file(result, pool);
2915 if (*fp == NULL)
2917 err = callback_exception_error();
2921 Py_XDECREF(result);
2922 finished:
2923 Py_XDECREF(py_callback);
2924 svn_swig_py_release_py_lock();
2925 return err;
2928 /* svn_ra_callbacks_t */
2929 static svn_error_t *
2930 ra_callbacks_get_wc_prop(void *baton,
2931 const char *path,
2932 const char *name,
2933 const svn_string_t **value,
2934 apr_pool_t *pool)
2936 PyObject *callbacks = (PyObject *)baton;
2937 PyObject *py_callback, *result;
2938 svn_error_t *err = SVN_NO_ERROR;
2940 *value = NULL;
2942 svn_swig_py_acquire_py_lock();
2944 py_callback = PyObject_GetAttrString(callbacks, (char *)"get_wc_prop");
2945 if (py_callback == NULL)
2947 err = callback_exception_error();
2948 goto finished;
2950 else if (py_callback == Py_None)
2952 goto finished;
2955 if ((result = PyObject_CallFunction(py_callback,
2956 (char *)"ssO&", path, name,
2957 make_ob_pool, pool)) == NULL)
2959 err = callback_exception_error();
2961 else if (result != Py_None)
2963 char *buf;
2964 int len;
2965 if (PyString_AsStringAndSize(result, &buf, &len) == -1)
2967 err = callback_exception_error();
2969 else
2971 *value = svn_string_ncreate(buf, len, pool);
2975 Py_XDECREF(result);
2976 finished:
2977 Py_XDECREF(py_callback);
2978 svn_swig_py_release_py_lock();
2979 return err;
2982 /* svn_ra_callbacks_t */
2983 static svn_error_t *
2984 ra_callbacks_push_or_set_wc_prop(const char *callback,
2985 void *baton,
2986 const char *path,
2987 const char *name,
2988 const svn_string_t *value,
2989 apr_pool_t *pool)
2991 PyObject *callbacks = (PyObject *)baton;
2992 PyObject *py_callback, *py_value, *result;
2993 svn_error_t *err = SVN_NO_ERROR;
2995 svn_swig_py_acquire_py_lock();
2997 py_callback = PyObject_GetAttrString(callbacks, (char *)callback);
2998 if (py_callback == NULL)
3000 err = callback_exception_error();
3001 goto finished;
3003 else if (py_callback == Py_None)
3005 goto finished;
3008 if ((py_value = PyString_FromStringAndSize(value->data, value->len)) == NULL)
3010 err = callback_exception_error();
3011 goto finished;
3014 if ((result = PyObject_CallFunction(py_callback,
3015 (char *)"ssOO&", path, name, py_value,
3016 make_ob_pool, pool)) == NULL)
3018 err = callback_exception_error();
3021 Py_XDECREF(result);
3022 finished:
3023 Py_XDECREF(py_callback);
3024 svn_swig_py_release_py_lock();
3025 return err;
3028 /* svn_ra_callbacks_t */
3029 static svn_error_t *
3030 ra_callbacks_set_wc_prop(void *baton,
3031 const char *path,
3032 const char *name,
3033 const svn_string_t *value,
3034 apr_pool_t *pool)
3036 return ra_callbacks_push_or_set_wc_prop("set_wc_prop", baton, path,
3037 name, value, pool);
3040 /* svn_ra_callbacks_t */
3041 static svn_error_t *
3042 ra_callbacks_push_wc_prop(void *baton,
3043 const char *path,
3044 const char *name,
3045 const svn_string_t *value,
3046 apr_pool_t *pool)
3048 return ra_callbacks_push_or_set_wc_prop("push_wc_prop", baton, path,
3049 name, value, pool);
3052 /* svn_ra_callbacks_t */
3053 static svn_error_t *
3054 ra_callbacks_invalidate_wc_props(void *baton,
3055 const char *path,
3056 const char *name,
3057 apr_pool_t *pool)
3059 PyObject *callbacks = (PyObject *)baton;
3060 PyObject *py_callback, *result;
3061 svn_error_t *err = SVN_NO_ERROR;
3063 svn_swig_py_acquire_py_lock();
3065 py_callback = PyObject_GetAttrString(callbacks,
3066 (char *)"invalidate_wc_props");
3067 if (py_callback == NULL)
3069 err = callback_exception_error();
3070 goto finished;
3072 else if (py_callback == Py_None)
3074 goto finished;
3077 if ((result = PyObject_CallFunction(py_callback,
3078 (char *)"ssO&", path, name,
3079 make_ob_pool, pool)) == NULL)
3081 err = callback_exception_error();
3084 Py_XDECREF(result);
3085 finished:
3086 Py_XDECREF(py_callback);
3087 svn_swig_py_release_py_lock();
3088 return err;
3091 /* svn_ra_callbacks_t */
3092 static void
3093 ra_callbacks_progress_func(apr_off_t progress,
3094 apr_off_t total,
3095 void *baton,
3096 apr_pool_t *pool)
3098 PyObject *callbacks = (PyObject *)baton;
3099 PyObject *py_callback, *py_progress, *py_total, *result;
3101 py_progress = py_total = NULL;
3103 svn_swig_py_acquire_py_lock();
3105 py_callback = PyObject_GetAttrString(callbacks,
3106 (char *)"progress_func");
3107 if (py_callback == NULL)
3109 /* Ouch, no way to pass on exceptions! */
3110 /* err = callback_exception_error(); */
3111 goto finished;
3113 else if (py_callback == Py_None)
3115 goto finished;
3118 /* Create PyLongs for progress and total up-front, rather than
3119 passing them directly, so we don't have to worry about the size
3120 (if apr_off_t is 4 bytes, we'd better use the l specifier; if 8
3121 bytes, better use L...) */
3122 if ((py_progress = PyLong_FromLongLong(progress)) == NULL)
3124 /* Ouch, no way to pass on exceptions! */
3125 /* err = callback_exception_error(); */
3126 goto finished;
3128 if ((py_total = PyLong_FromLongLong(total)) == NULL)
3130 /* Ouch, no way to pass on exceptions! */
3131 /* err = callback_exception_error(); */
3132 goto finished;
3134 if ((result = PyObject_CallFunction(py_callback,
3135 (char *)"OOO&", py_progress, py_total,
3136 make_ob_pool, pool)) == NULL)
3138 /* Ouch, no way to pass on exceptions! */
3139 /* err = callback_exception_error(); */
3142 Py_XDECREF(result);
3143 finished:
3144 Py_XDECREF(py_callback);
3145 Py_XDECREF(py_progress);
3146 Py_XDECREF(py_total);
3147 svn_swig_py_release_py_lock();
3148 /* Sure hope nothing went wrong... */
3149 /* return err; */
3152 /* svn_ra_callbacks_t */
3153 static svn_error_t *
3154 ra_callbacks_cancel_func(void *baton)
3156 PyObject *callbacks = (PyObject *)baton;
3157 PyObject *py_callback;
3159 svn_swig_py_acquire_py_lock();
3160 py_callback = PyObject_GetAttrString(callbacks,
3161 (char *)"cancel_func");
3162 svn_swig_py_release_py_lock();
3163 return svn_swig_py_cancel_func(py_callback);
3166 /* svn_ra_callbacks_t */
3167 static svn_error_t *
3168 ra_callbacks_get_client_string(void *baton,
3169 const char **name,
3170 apr_pool_t *pool)
3172 PyObject *callbacks = (PyObject *)baton;
3173 PyObject *py_callback, *result;
3174 svn_error_t *err = SVN_NO_ERROR;
3176 *name = NULL;
3178 svn_swig_py_acquire_py_lock();
3180 py_callback = PyObject_GetAttrString(callbacks, (char *)"get_client_string");
3181 if (py_callback == NULL)
3183 err = callback_exception_error();
3184 goto finished;
3186 else if (py_callback == Py_None)
3188 goto finished;
3191 if ((result = PyObject_CallFunction(py_callback,
3192 (char *)"O&",
3193 make_ob_pool, pool)) == NULL)
3195 err = callback_exception_error();
3197 else if (result != Py_None)
3199 if ((*name = PyString_AsString(result)) == NULL)
3201 err = callback_exception_error();
3205 Py_XDECREF(result);
3206 finished:
3207 Py_XDECREF(py_callback);
3208 svn_swig_py_release_py_lock();
3209 return err;
3212 void
3213 svn_swig_py_setup_ra_callbacks(svn_ra_callbacks2_t **callbacks,
3214 void **baton,
3215 PyObject *py_callbacks,
3216 apr_pool_t *pool)
3218 svn_error_t *err = svn_ra_create_callbacks(callbacks, pool);
3219 PyObject *py_auth_baton;
3221 if (err)
3223 svn_swig_py_svn_exception(err);
3224 return;
3227 (*callbacks)->open_tmp_file = ra_callbacks_open_tmp_file;
3229 py_auth_baton = PyObject_GetAttrString(py_callbacks, (char *)"auth_baton");
3231 if (svn_swig_ConvertPtrString(py_auth_baton,
3232 (void **)&((*callbacks)->auth_baton),
3233 "svn_auth_baton_t *"))
3235 err = type_conversion_error("svn_auth_baton_t *");
3236 svn_swig_py_svn_exception(err);
3237 Py_XDECREF(py_auth_baton);
3238 return;
3241 Py_XDECREF(py_auth_baton);
3243 (*callbacks)->get_wc_prop = ra_callbacks_get_wc_prop;
3244 (*callbacks)->set_wc_prop = ra_callbacks_set_wc_prop;
3245 (*callbacks)->push_wc_prop = ra_callbacks_push_wc_prop;
3246 (*callbacks)->invalidate_wc_props = ra_callbacks_invalidate_wc_props;
3247 (*callbacks)->progress_func = ra_callbacks_progress_func;
3248 (*callbacks)->progress_baton = py_callbacks;
3249 (*callbacks)->cancel_func = ra_callbacks_cancel_func;
3250 (*callbacks)->get_client_string = ra_callbacks_get_client_string;
3252 *baton = py_callbacks;
3255 svn_error_t *svn_swig_py_commit_callback2(const svn_commit_info_t *commit_info,
3256 void *baton,
3257 apr_pool_t *pool)
3259 PyObject *receiver = baton;
3260 PyObject *result;
3261 svn_error_t *err = SVN_NO_ERROR;
3263 if ((receiver == NULL) || (receiver == Py_None))
3264 return SVN_NO_ERROR;
3266 svn_swig_py_acquire_py_lock();
3268 if ((result = PyObject_CallFunction(receiver,
3269 (char *)"O&O&",
3270 make_ob_commit_info, commit_info,
3271 make_ob_pool, pool)) == NULL)
3273 err = callback_exception_error();
3275 else
3277 if (result != Py_None)
3278 err = callback_bad_return_error("Not None");
3279 Py_DECREF(result);
3282 svn_swig_py_release_py_lock();
3284 return err;
3287 svn_error_t *svn_swig_py_commit_callback(svn_revnum_t new_revision,
3288 const char *date,
3289 const char *author,
3290 void *baton)
3292 PyObject *receiver = baton;
3293 PyObject *result;
3294 svn_error_t *err = SVN_NO_ERROR;
3296 if ((receiver == NULL) || (receiver == Py_None))
3297 return SVN_NO_ERROR;
3299 svn_swig_py_acquire_py_lock();
3301 if ((result = PyObject_CallFunction(receiver,
3302 (char *)"lss",
3303 new_revision, date, author)) == NULL)
3305 err = callback_exception_error();
3307 else
3309 if (result != Py_None)
3310 err = callback_bad_return_error("Not None");
3311 Py_DECREF(result);
3314 svn_swig_py_release_py_lock();
3316 return err;
3319 svn_error_t *svn_swig_py_ra_file_rev_handler_func(
3320 void *baton,
3321 const char *path,
3322 svn_revnum_t rev,
3323 apr_hash_t *rev_props,
3324 svn_txdelta_window_handler_t *delta_handler,
3325 void **delta_baton,
3326 apr_array_header_t *prop_diffs,
3327 apr_pool_t *pool)
3329 PyObject *handler = baton;
3330 PyObject *result, *py_rev_props = NULL, *py_prop_diffs = NULL;
3331 svn_error_t *err = SVN_NO_ERROR;
3333 if ((handler == NULL) || (handler == Py_None))
3334 return SVN_NO_ERROR;
3336 svn_swig_py_acquire_py_lock();
3338 py_rev_props = svn_swig_py_prophash_to_dict(rev_props);
3339 if (py_rev_props == NULL)
3341 err = type_conversion_error("apr_hash_t *");
3342 goto error;
3345 py_prop_diffs = svn_swig_py_proparray_to_dict(prop_diffs);
3347 if (py_prop_diffs == NULL)
3349 err = type_conversion_error("apr_array_header_t *");
3350 goto error;
3353 if ((result = PyObject_CallFunction(handler,
3354 (char *)"slOOO&",
3355 path, rev, py_rev_props, py_prop_diffs,
3356 make_ob_pool, pool)) == NULL)
3358 err = callback_exception_error();
3360 else
3362 if (result != Py_None)
3363 err = callback_bad_return_error("Not None");
3365 /* FIXME: Support returned TxDeltaWindow object and
3366 * set delta_handler and delta_baton */
3367 *delta_handler = NULL;
3368 *delta_baton = NULL;
3370 Py_XDECREF(result);
3373 error:
3375 Py_XDECREF(py_rev_props);
3376 Py_XDECREF(py_prop_diffs);
3378 svn_swig_py_release_py_lock();
3380 return err;
3383 svn_error_t *svn_swig_py_ra_lock_callback(
3384 void *baton,
3385 const char *path,
3386 svn_boolean_t do_lock,
3387 const svn_lock_t *lock,
3388 svn_error_t *ra_err,
3389 apr_pool_t *pool)
3391 svn_error_t *err = SVN_NO_ERROR;
3392 PyObject *py_callback = baton, *result;
3394 if (py_callback == NULL || py_callback == Py_None)
3395 return SVN_NO_ERROR;
3397 svn_swig_py_acquire_py_lock();
3399 if ((result = PyObject_CallFunction(py_callback,
3400 (char *)"sbO&O&",
3401 path, do_lock,
3402 make_ob_lock, lock,
3403 make_ob_pool, pool)) == NULL)
3405 err = callback_exception_error();
3407 else if (result != Py_None)
3409 err = callback_bad_return_error("Not None");
3412 Py_XDECREF(result);
3414 svn_swig_py_release_py_lock();
3416 return err;
3419 static svn_error_t *reporter_set_path(void *report_baton,
3420 const char *path,
3421 svn_revnum_t revision,
3422 svn_boolean_t start_empty,
3423 const char *lock_token,
3424 apr_pool_t *pool)
3426 svn_error_t *err = SVN_NO_ERROR;
3427 PyObject *py_reporter = report_baton, *result;
3429 if (py_reporter == NULL || py_reporter == Py_None)
3430 return SVN_NO_ERROR;
3432 svn_swig_py_acquire_py_lock();
3434 if ((result = PyObject_CallMethod(py_reporter,
3435 (char *)"set_path",
3436 (char *)"slbsO&",
3437 path, revision,
3438 start_empty, lock_token,
3439 make_ob_pool, pool)) == NULL)
3441 err = callback_exception_error();
3443 else if (result != Py_None)
3445 err = callback_bad_return_error("Not None");
3448 Py_XDECREF(result);
3450 svn_swig_py_release_py_lock();
3452 return err;
3455 static svn_error_t *reporter_delete_path(void *report_baton,
3456 const char *path,
3457 apr_pool_t *pool)
3459 svn_error_t *err = SVN_NO_ERROR;
3460 PyObject *py_reporter = report_baton, *result;
3462 if (py_reporter == NULL || py_reporter == Py_None)
3463 return SVN_NO_ERROR;
3465 svn_swig_py_acquire_py_lock();
3467 if ((result = PyObject_CallMethod(py_reporter,
3468 (char *)"delete_path",
3469 (char *)"sO&",
3470 path,
3471 make_ob_pool, pool)) == NULL)
3473 err = callback_exception_error();
3475 else if (result != Py_None)
3477 err = callback_bad_return_error("Not None");
3480 Py_XDECREF(result);
3482 svn_swig_py_release_py_lock();
3484 return err;
3487 static svn_error_t *reporter_link_path(void *report_baton,
3488 const char *path,
3489 const char *url,
3490 svn_revnum_t revision,
3491 svn_boolean_t start_empty,
3492 const char *lock_token,
3493 apr_pool_t *pool)
3495 svn_error_t *err = SVN_NO_ERROR;
3496 PyObject *py_reporter = report_baton, *result;
3498 if (py_reporter == NULL || py_reporter == Py_None)
3499 return SVN_NO_ERROR;
3501 svn_swig_py_acquire_py_lock();
3503 if ((result = PyObject_CallMethod(py_reporter,
3504 (char *)"link_path",
3505 (char *)"sslbsO&",
3506 path, url, revision,
3507 start_empty, lock_token,
3508 make_ob_pool, pool)) == NULL)
3510 err = callback_exception_error();
3512 else if (result != Py_None)
3514 err = callback_bad_return_error("Not None");
3517 Py_XDECREF(result);
3519 svn_swig_py_release_py_lock();
3521 return err;
3524 static svn_error_t *reporter_finish_report(void *report_baton,
3525 apr_pool_t *pool)
3527 svn_error_t *err = SVN_NO_ERROR;
3529 PyObject *py_reporter = report_baton, *result;
3531 if (py_reporter == NULL || py_reporter == Py_None)
3532 return SVN_NO_ERROR;
3534 svn_swig_py_acquire_py_lock();
3536 if ((result = PyObject_CallMethod(py_reporter,
3537 (char *)"finish_report",
3538 (char *)"O&",
3539 make_ob_pool, pool)) == NULL)
3541 err = callback_exception_error();
3543 else if (result != Py_None)
3545 err = callback_bad_return_error("Not None");
3548 Py_XDECREF(result);
3550 svn_swig_py_release_py_lock();
3552 return err;
3555 static svn_error_t *reporter_abort_report(void *report_baton,
3556 apr_pool_t *pool)
3558 svn_error_t *err = SVN_NO_ERROR;
3560 PyObject *py_reporter = report_baton, *result;
3562 if (py_reporter == NULL || py_reporter == Py_None)
3563 return SVN_NO_ERROR;
3565 svn_swig_py_acquire_py_lock();
3567 if ((result = PyObject_CallMethod(py_reporter,
3568 (char *)"abort_report",
3569 (char *)"O&",
3570 make_ob_pool, pool)) == NULL)
3572 err = callback_exception_error();
3574 else if (result != Py_None)
3576 err = callback_bad_return_error("Not None");
3579 Py_XDECREF(result);
3581 svn_swig_py_release_py_lock();
3583 return err;
3586 const svn_ra_reporter2_t swig_py_ra_reporter2 = {
3587 reporter_set_path,
3588 reporter_delete_path,
3589 reporter_link_path,
3590 reporter_finish_report,
3591 reporter_abort_report