2 * Copyright © 2008 Jelmer Vernooij <jelmer@jelmer.uk>
3 * -*- coding: utf-8 -*-
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation; either version 2.1 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #ifndef _SUBVERTPY_UTIL_H_
21 #define _SUBVERTPY_UTIL_H_
23 #include <svn_version.h>
24 #include <svn_io.h> /* for svn_stream_t */
26 #if SVN_VER_MAJOR != 1
27 #error "only svn 1.x is supported"
30 #ifdef SUBVERTPY_OVERRIDE_SVN_VER_MINOR
31 #define ONLY_SINCE_SVN(maj, min) (SUBVERTPY_OVERRIDE_SVN_VER_MINOR >= (min))
33 #define ONLY_SINCE_SVN(maj, min) (SVN_VER_MINOR >= (min))
36 #define ONLY_BEFORE_SVN(maj, min) (!(ONLY_SINCE_SVN(maj, min)))
39 #pragma GCC visibility push(hidden)
42 svn_error_t *py_cancel_check(void *cancel_baton);
43 __attribute__((warn_unused_result)) apr_pool_t *Pool(apr_pool_t *parent);
44 void handle_svn_error(svn_error_t *error);
45 bool string_list_to_apr_array(apr_pool_t *pool, PyObject *l, apr_array_header_t **);
46 bool relpath_list_to_apr_array(apr_pool_t *pool, PyObject *l, apr_array_header_t **);
47 PyObject *prop_hash_to_dict(apr_hash_t *props);
48 apr_hash_t *prop_dict_to_hash(apr_pool_t *pool, PyObject *py_props);
49 svn_error_t *py_svn_log_wrapper(
50 void *baton, apr_hash_t *changed_paths, long revision, const char *author,
51 const char *date, const char *message, apr_pool_t *pool);
52 __attribute__((warn_unused_result)) svn_error_t *py_svn_error(void);
53 void PyErr_SetSubversionException(svn_error_t *error);
54 PyTypeObject *PyErr_GetSubversionExceptionTypeObject(void);
56 #define RUN_SVN(cmd) { \
58 PyThreadState *_save; \
59 _save = PyEval_SaveThread(); \
61 PyEval_RestoreThread(_save); \
63 handle_svn_error(err); \
64 svn_error_clear(err); \
69 #define RUN_SVN_WITH_POOL(pool, cmd) { \
71 PyThreadState *_save; \
72 _save = PyEval_SaveThread(); \
74 PyEval_RestoreThread(_save); \
76 handle_svn_error(err); \
77 svn_error_clear(err); \
78 apr_pool_destroy(pool); \
83 PyObject *wrap_lock(svn_lock_t *lock);
84 apr_array_header_t *revnum_list_to_apr_array(apr_pool_t *pool, PyObject *l);
85 svn_stream_t *new_py_stream(apr_pool_t *pool, PyObject *py);
86 PyObject *PyErr_NewSubversionException(svn_error_t *error);
87 apr_hash_t *config_hash_from_object(PyObject *config, apr_pool_t *pool);
88 void PyErr_SetAprStatus(apr_status_t status);
89 PyObject *py_dirent(const svn_dirent_t *dirent, int dirent_fields);
90 PyObject *PyOS_tmpfile(void);
91 PyObject *pyify_changed_paths(apr_hash_t *changed_paths, bool node_kind, apr_pool_t *pool);
92 bool pyify_log_message(
93 apr_hash_t *changed_paths, const char *author,
94 const char *date, const char *message, bool node_kind,
95 apr_pool_t *pool, PyObject **py_changed_paths, PyObject **revprops);
96 #if ONLY_SINCE_SVN(1, 6)
97 PyObject *pyify_changed_paths2(apr_hash_t *changed_paths2, apr_pool_t *pool);
99 apr_file_t *apr_file_from_object(PyObject *object, apr_pool_t *pool);
101 #if ONLY_SINCE_SVN(1, 5)
102 svn_error_t *py_svn_log_entry_receiver(void *baton, svn_log_entry_t *log_entry, apr_pool_t *pool);
106 #pragma GCC visibility pop
109 #define CB_CHECK_PYRETVAL(ret) \
111 PyGILState_Release(state); \
112 return py_svn_error(); \
115 #if SVN_VER_MINOR < 5
116 typedef enum svn_depth_t {
117 svn_depth_unknown = -2,
118 svn_depth_exclude = -1,
121 svn_depth_immediates = 2,
122 svn_depth_infinity = 3
134 svn_stream_t *stream;
139 extern PyTypeObject Stream_Type;
141 #if ONLY_BEFORE_SVN(1, 7)
143 svn_uri_canonicalize(const char *uri,
144 apr_pool_t *result_pool);
146 svn_relpath_canonicalize(const char *relpath,
147 apr_pool_t *result_pool);
150 svn_dirent_canonicalize(const char *dirent,
151 apr_pool_t *result_pool);
154 const char *py_object_to_svn_uri(PyObject *obj, apr_pool_t *pool);
155 const char *py_object_to_svn_dirent(PyObject *obj, apr_pool_t *pool);
156 const char *py_object_to_svn_relpath(PyObject *obj, apr_pool_t *pool);
157 const char *py_object_to_svn_path_or_url(PyObject *obj, apr_pool_t *pool);
158 char *py_object_to_svn_string(PyObject *obj, apr_pool_t *pool);
159 const char *py_object_to_svn_abspath(PyObject *obj, apr_pool_t *pool);
160 #define py_object_from_svn_abspath PyBytes_FromString
162 #if PY_MAJOR_VERSION >= 3
163 #define PyRepr_FromFormat PyUnicode_FromFormat
165 #define PyRepr_FromFormat PyString_FromFormat
168 #if PY_MAJOR_VERSION >= 3
169 #define py_from_svn_revnum PyLong_FromLong
170 #define py_to_svn_revnum PyLong_AsLong
172 #define py_from_svn_revnum PyInt_FromLong
173 #define py_to_svn_revnum PyInt_AsLong
176 #endif /* _SUBVERTPY_UTIL_H_ */