* subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
[svn.git] / subversion / bindings / swig / svn_delta.i
blobb8e348910c3c3a12b310c5182fb50cd9e840b0b0
1 /*
2 * ====================================================================
3 * Copyright (c) 2000-2006 CollabNet. All rights reserved.
5 * This software is licensed as described in the file COPYING, which
6 * you should have received as part of this distribution. The terms
7 * are also available at http://subversion.tigris.org/license-1.html.
8 * If newer versions of this license are posted there, you may use a
9 * newer version instead, at your option.
11 * This software consists of voluntary contributions made by many
12 * individuals. For exact contribution history, see the revision
13 * history and logs, available at http://subversion.tigris.org/.
14 * ====================================================================
16 * svn_delta.i: SWIG interface file for svn_delta.h
19 #if defined(SWIGPYTHON)
20 %module(package="libsvn") delta
21 #elif defined(SWIGPERL)
22 %module "SVN::_Delta"
23 #elif defined(SWIGRUBY)
24 %module "svn::ext::delta"
25 #endif
27 %include svn_global.swg
28 %import core.i
30 /* -----------------------------------------------------------------------
31 %apply-ing of typemaps defined elsewhere
34 %apply const char *MAY_BE_NULL {
35 const char *error_info,
36 const char *copyfrom_path,
37 const char *copy_path,
38 const char *base_checksum,
39 const char *text_checksum
42 #ifdef SWIGPYTHON
43 %apply svn_stream_t *WRAPPED_STREAM { svn_stream_t * };
44 #endif
46 /* -----------------------------------------------------------------------
47 mark window.new_data as readonly since we would need a pool to set it
48 properly (e.g. to allocate an svn_string_t structure).
50 %immutable svn_txdelta_window_t::new_data;
52 /* -----------------------------------------------------------------------
53 thunk editors for the various language bindings.
56 #ifdef SWIGPYTHON
57 void svn_swig_py_make_editor(const svn_delta_editor_t **editor,
58 void **edit_baton,
59 PyObject *py_editor,
60 apr_pool_t *pool);
61 #endif
63 #ifdef SWIGPERL
64 %typemap(in) (const svn_delta_editor_t *EDITOR, void *BATON) {
65 svn_delta_make_editor(&$1, &$2, $input, _global_pool);
68 void svn_delta_wrap_window_handler(svn_txdelta_window_handler_t *handler,
69 void **handler_baton,
70 SV *callback,
71 apr_pool_t *pool);
73 #endif
75 #ifdef SWIGRUBY
76 %typemap(in) (const svn_delta_editor_t *EDITOR, void *BATON)
78 if (RTEST(rb_obj_is_kind_of($input,
79 svn_swig_rb_svn_delta_editor()))) {
80 $1 = svn_swig_rb_to_swig_type($input,
81 "svn_delta_editor_t *",
82 _global_pool);
83 $2 = svn_swig_rb_to_swig_type(rb_funcall($input, rb_intern("baton"), 0),
84 "void *", _global_pool);
85 } else {
86 svn_swig_rb_make_delta_editor(&$1, &$2, $input, _global_pool);
89 #endif
91 #ifndef SWIGPYTHON
92 /* Python users have to use svn_swig_py_make_editor manually, which sucks.
93 Maybe we could allow people to pass a python object in the editor parameter,
94 and None as the baton, and automatically invoke svn_swig_py_make_editor,
95 rather than forcing the svn_swig_py_make_editor to be done manually.
96 Of course, ideally, the baton parameter would vanish from the python
97 side entirely, but we can't kill compatibility like that until 2.0.
99 %apply (const svn_delta_editor_t *EDITOR, void *BATON)
101 (const svn_delta_editor_t *editor, void *baton),
102 (const svn_delta_editor_t *editor, void *edit_baton),
103 (const svn_delta_editor_t *editor, void *file_baton),
104 (const svn_delta_editor_t *diff_editor, void *diff_baton),
105 (const svn_delta_editor_t *update_editor, void *update_baton),
106 (const svn_delta_editor_t *switch_editor, void *switch_baton),
107 (const svn_delta_editor_t *status_editor, void *status_baton)
109 #endif
111 /* -----------------------------------------------------------------------
112 handle svn_txdelta_window_handler_t/baton pair.
115 #ifdef SWIGRUBY
116 %typemap(in) (svn_txdelta_window_handler_t handler,
117 void *handler_baton)
119 if (RTEST(rb_obj_is_kind_of($input,
120 svn_swig_rb_svn_delta_text_delta_window_handler()))) {
121 $1 = svn_swig_rb_to_swig_type($input,
122 "svn_txdelta_window_handler_t",
123 _global_pool);
124 $2 = svn_swig_rb_to_swig_type(rb_funcall($input, rb_intern("baton"), 0),
125 "void *", _global_pool);
126 } else {
127 $1 = svn_swig_rb_txdelta_window_handler;
128 $2 = (void *)svn_swig_rb_make_baton($input, _global_svn_swig_rb_pool);
131 #endif
133 /* -----------------------------------------------------------------------
134 handle svn_delta_path_driver().
137 #ifndef SWIGPERL
138 %callback_typemap(svn_delta_path_driver_cb_func_t callback_func,
139 void *callback_baton,
140 svn_swig_py_delta_path_driver_cb_func,
142 svn_swig_rb_delta_path_driver_cb_func)
143 #endif
145 /* ----------------------------------------------------------------------- */
148 #include "svn_md5.h"
151 /* -----------------------------------------------------------------------
152 handle svn_txdelta_window_t::ops
154 #ifdef SWIGRUBY
155 %ignore svn_txdelta_window_t::ops;
156 %inline %{
157 static VALUE
158 svn_txdelta_window_t_ops_get(svn_txdelta_window_t *window)
160 return svn_swig_rb_txdelta_window_t_ops_get(window);
163 #endif
166 %include svn_delta_h.swg
168 #ifdef SWIGRUBY
169 %inline %{
170 static VALUE
171 svn_swig_rb_delta_editor_get_target_revision(VALUE editor)
173 static ID id_target_revision_address = 0;
174 VALUE rb_target_address;
175 svn_revnum_t *target_address;
177 if (id_target_revision_address == 0)
178 id_target_revision_address = rb_intern("@target_revision_address");
180 if (!RTEST(rb_ivar_defined(editor, id_target_revision_address)))
181 return Qnil;
183 rb_target_address = rb_ivar_get(editor, id_target_revision_address);
184 if (NIL_P(rb_target_address))
185 return Qnil;
187 target_address = (svn_revnum_t *)(NUM2LONG(rb_target_address));
188 if (!target_address)
189 return Qnil;
191 return LONG2NUM(*target_address);
194 #endif
196 /* -----------------------------------------------------------------------
197 handle svn_txdelta_apply_instructions()
199 #ifdef SWIGRUBY
200 %inline %{
201 static VALUE
202 svn_swig_rb_txdelta_apply_instructions(svn_txdelta_window_t *window,
203 const char *sbuf)
205 char *tbuf;
206 apr_size_t tlen;
208 tlen = window->tview_len + 1;
209 tbuf = ALLOCA_N(char, tlen);
210 svn_txdelta_apply_instructions(window, sbuf, tbuf, &tlen);
212 return rb_str_new(tbuf, tlen);
215 #endif
217 /* -----------------------------------------------------------------------
218 handle svn_txdelta_to_svndiff().
220 #ifdef SWIGRUBY
221 %inline %{
222 static void
223 svn_txdelta_apply_wrapper(svn_stream_t *source,
224 svn_stream_t *target,
225 unsigned char *result_digest,
226 const char *error_info,
227 svn_txdelta_window_handler_t *handler,
228 void **handler_baton,
229 apr_pool_t *pool)
231 svn_txdelta_apply(source, target, result_digest, error_info,
232 pool, handler, handler_baton);
235 static svn_error_t *
236 svn_delta_editor_invoke_open_root_wrapper(svn_delta_editor_t *editor,
237 void *edit_baton,
238 svn_revnum_t base_revision,
239 void **root_baton,
240 apr_pool_t *dir_pool)
242 return svn_delta_editor_invoke_open_root(editor, edit_baton,
243 base_revision, dir_pool, root_baton);
246 static svn_error_t *
247 svn_delta_editor_invoke_add_directory_wrapper(svn_delta_editor_t *editor,
248 const char *path,
249 void *parent_baton,
250 const char *copyfrom_path,
251 svn_revnum_t copyfrom_revision,
252 void **child_baton,
253 apr_pool_t *dir_pool)
255 return svn_delta_editor_invoke_add_directory(editor, path, parent_baton,
256 copyfrom_path, copyfrom_revision,
257 dir_pool, child_baton);
260 static svn_error_t *
261 svn_delta_editor_invoke_open_directory_wrapper(svn_delta_editor_t *editor,
262 const char *path,
263 void *parent_baton,
264 svn_revnum_t base_revision,
265 void **child_baton,
266 apr_pool_t *dir_pool)
268 return svn_delta_editor_invoke_open_directory(editor, path, parent_baton,
269 base_revision, dir_pool,
270 child_baton);
273 static svn_error_t *
274 svn_delta_editor_invoke_add_file_wrapper(svn_delta_editor_t *editor,
275 const char *path,
276 void *parent_baton,
277 const char *copyfrom_path,
278 svn_revnum_t copyfrom_revision,
279 void **file_baton,
280 apr_pool_t *file_pool)
282 return svn_delta_editor_invoke_add_file(editor, path, parent_baton,
283 copyfrom_path,
284 copyfrom_revision,
285 file_pool, file_baton);
288 static svn_error_t *
289 svn_delta_editor_invoke_open_file_wrapper(svn_delta_editor_t *editor,
290 const char *path,
291 void *parent_baton,
292 svn_revnum_t base_revision,
293 void **file_baton,
294 apr_pool_t *file_pool)
296 return svn_delta_editor_invoke_open_file(editor, path, parent_baton,
297 base_revision,
298 file_pool, file_baton);
301 static svn_error_t *
302 svn_delta_editor_invoke_apply_textdelta_wrapper(svn_delta_editor_t *editor,
303 void *file_baton,
304 const char *base_checksum,
305 svn_txdelta_window_handler_t *handler,
306 void **handler_baton,
307 apr_pool_t *pool)
309 return svn_delta_editor_invoke_apply_textdelta(editor, file_baton,
310 base_checksum, pool,
311 handler, handler_baton);
314 static svn_error_t *
315 svn_txdelta_invoke_window_handler_wrapper(VALUE obj,
316 svn_txdelta_window_t *window,
317 apr_pool_t *pool)
319 return svn_swig_rb_invoke_txdelta_window_handler_wrapper(obj, window, pool);
322 static svn_error_t *
323 svn_txdelta_editor_invoke_apply_textdelta_wrapper(VALUE obj,
324 svn_txdelta_window_t *window,
325 apr_pool_t *pool)
327 return svn_swig_rb_invoke_txdelta_window_handler_wrapper(obj, window, pool);
330 static const char *
331 svn_txdelta_md5_digest_as_cstring(svn_txdelta_stream_t *stream,
332 apr_pool_t *pool)
334 const unsigned char *digest;
336 digest = svn_txdelta_md5_digest(stream);
338 if (digest) {
339 return svn_md5_digest_to_cstring(digest, pool);
340 } else {
341 return NULL;
346 #endif