Mark many merge tests as skip-against-old-server.
[svn.git] / subversion / libsvn_delta / cancel.c
blobde3095a92334c1eb5e1755630c56b4433508ac33
1 /*
2 * cancel.c: Routines to support cancellation of running subversion functions.
4 * ====================================================================
5 * Copyright (c) 2000-2006 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 #include "svn_delta.h"
21 struct edit_baton
23 const svn_delta_editor_t *wrapped_editor;
24 void *wrapped_edit_baton;
26 svn_cancel_func_t cancel_func;
27 void *cancel_baton;
30 struct dir_baton
32 void *edit_baton;
33 void *wrapped_dir_baton;
36 struct file_baton
38 void *edit_baton;
39 void *wrapped_file_baton;
42 static svn_error_t *
43 set_target_revision(void *edit_baton,
44 svn_revnum_t target_revision,
45 apr_pool_t *pool)
47 struct edit_baton *eb = edit_baton;
49 SVN_ERR(eb->cancel_func(eb->cancel_baton));
51 SVN_ERR(eb->wrapped_editor->set_target_revision(eb->wrapped_edit_baton,
52 target_revision,
53 pool));
55 return SVN_NO_ERROR;
58 static svn_error_t *
59 open_root(void *edit_baton,
60 svn_revnum_t base_revision,
61 apr_pool_t *pool,
62 void **root_baton)
64 struct edit_baton *eb = edit_baton;
65 struct dir_baton *dir_baton = apr_palloc(pool, sizeof(*dir_baton));
67 SVN_ERR(eb->cancel_func(eb->cancel_baton));
69 SVN_ERR(eb->wrapped_editor->open_root(eb->wrapped_edit_baton,
70 base_revision,
71 pool,
72 &dir_baton->wrapped_dir_baton));
74 dir_baton->edit_baton = edit_baton;
76 *root_baton = dir_baton;
78 return SVN_NO_ERROR;
81 static svn_error_t *
82 delete_entry(const char *path,
83 svn_revnum_t base_revision,
84 void *parent_baton,
85 apr_pool_t *pool)
87 struct dir_baton *pb = parent_baton;
88 struct edit_baton *eb = pb->edit_baton;
90 SVN_ERR(eb->cancel_func(eb->cancel_baton));
92 SVN_ERR(eb->wrapped_editor->delete_entry(path,
93 base_revision,
94 pb->wrapped_dir_baton,
95 pool));
97 return SVN_NO_ERROR;
100 static svn_error_t *
101 add_directory(const char *path,
102 void *parent_baton,
103 const char *copyfrom_path,
104 svn_revnum_t copyfrom_revision,
105 apr_pool_t *pool,
106 void **child_baton)
108 struct dir_baton *pb = parent_baton;
109 struct edit_baton *eb = pb->edit_baton;
110 struct dir_baton *b = apr_palloc(pool, sizeof(*b));
112 SVN_ERR(eb->cancel_func(eb->cancel_baton));
114 SVN_ERR(eb->wrapped_editor->add_directory(path,
115 pb->wrapped_dir_baton,
116 copyfrom_path,
117 copyfrom_revision,
118 pool,
119 &b->wrapped_dir_baton));
121 b->edit_baton = eb;
122 *child_baton = b;
124 return SVN_NO_ERROR;
127 static svn_error_t *
128 open_directory(const char *path,
129 void *parent_baton,
130 svn_revnum_t base_revision,
131 apr_pool_t *pool,
132 void **child_baton)
134 struct dir_baton *pb = parent_baton;
135 struct edit_baton *eb = pb->edit_baton;
136 struct dir_baton *db = apr_palloc(pool, sizeof(*db));
138 SVN_ERR(eb->cancel_func(eb->cancel_baton));
140 SVN_ERR(eb->wrapped_editor->open_directory(path,
141 pb->wrapped_dir_baton,
142 base_revision,
143 pool,
144 &db->wrapped_dir_baton));
146 db->edit_baton = eb;
147 *child_baton = db;
149 return SVN_NO_ERROR;
152 static svn_error_t *
153 add_file(const char *path,
154 void *parent_baton,
155 const char *copyfrom_path,
156 svn_revnum_t copyfrom_revision,
157 apr_pool_t *pool,
158 void **file_baton)
160 struct dir_baton *pb = parent_baton;
161 struct edit_baton *eb = pb->edit_baton;
162 struct file_baton *fb = apr_palloc(pool, sizeof(*fb));
164 SVN_ERR(eb->cancel_func(eb->cancel_baton));
166 SVN_ERR(eb->wrapped_editor->add_file(path,
167 pb->wrapped_dir_baton,
168 copyfrom_path,
169 copyfrom_revision,
170 pool,
171 &fb->wrapped_file_baton));
173 fb->edit_baton = eb;
174 *file_baton = fb;
176 return SVN_NO_ERROR;
179 static svn_error_t *
180 open_file(const char *path,
181 void *parent_baton,
182 svn_revnum_t base_revision,
183 apr_pool_t *pool,
184 void **file_baton)
186 struct dir_baton *pb = parent_baton;
187 struct edit_baton *eb = pb->edit_baton;
188 struct file_baton *fb = apr_palloc(pool, sizeof(*fb));
190 SVN_ERR(eb->cancel_func(eb->cancel_baton));
192 SVN_ERR(eb->wrapped_editor->open_file(path,
193 pb->wrapped_dir_baton,
194 base_revision,
195 pool,
196 &fb->wrapped_file_baton));
198 fb->edit_baton = eb;
199 *file_baton = fb;
201 return SVN_NO_ERROR;
204 static svn_error_t *
205 apply_textdelta(void *file_baton,
206 const char *base_checksum,
207 apr_pool_t *pool,
208 svn_txdelta_window_handler_t *handler,
209 void **handler_baton)
211 struct file_baton *fb = file_baton;
212 struct edit_baton *eb = fb->edit_baton;
214 SVN_ERR(eb->cancel_func(eb->cancel_baton));
216 SVN_ERR(eb->wrapped_editor->apply_textdelta(fb->wrapped_file_baton,
217 base_checksum,
218 pool,
219 handler,
220 handler_baton));
222 return SVN_NO_ERROR;
225 static svn_error_t *
226 close_file(void *file_baton,
227 const char *text_checksum,
228 apr_pool_t *pool)
230 struct file_baton *fb = file_baton;
231 struct edit_baton *eb = fb->edit_baton;
233 SVN_ERR(eb->cancel_func(eb->cancel_baton));
235 SVN_ERR(eb->wrapped_editor->close_file(fb->wrapped_file_baton,
236 text_checksum, pool));
238 return SVN_NO_ERROR;
241 static svn_error_t *
242 absent_file(const char *path,
243 void *file_baton,
244 apr_pool_t *pool)
246 struct file_baton *fb = file_baton;
247 struct edit_baton *eb = fb->edit_baton;
249 SVN_ERR(eb->cancel_func(eb->cancel_baton));
251 SVN_ERR(eb->wrapped_editor->absent_file(path, fb->wrapped_file_baton,
252 pool));
254 return SVN_NO_ERROR;
257 static svn_error_t *
258 close_directory(void *dir_baton,
259 apr_pool_t *pool)
261 struct dir_baton *db = dir_baton;
262 struct edit_baton *eb = db->edit_baton;
264 SVN_ERR(eb->cancel_func(eb->cancel_baton));
266 SVN_ERR(eb->wrapped_editor->close_directory(db->wrapped_dir_baton,
267 pool));
269 return SVN_NO_ERROR;
272 static svn_error_t *
273 absent_directory(const char *path,
274 void *dir_baton,
275 apr_pool_t *pool)
277 struct dir_baton *db = dir_baton;
278 struct edit_baton *eb = db->edit_baton;
280 SVN_ERR(eb->cancel_func(eb->cancel_baton));
282 SVN_ERR(eb->wrapped_editor->absent_directory(path, db->wrapped_dir_baton,
283 pool));
285 return SVN_NO_ERROR;
288 static svn_error_t *
289 change_file_prop(void *file_baton,
290 const char *name,
291 const svn_string_t *value,
292 apr_pool_t *pool)
294 struct file_baton *fb = file_baton;
295 struct edit_baton *eb = fb->edit_baton;
297 SVN_ERR(eb->cancel_func(eb->cancel_baton));
299 SVN_ERR(eb->wrapped_editor->change_file_prop(fb->wrapped_file_baton,
300 name,
301 value,
302 pool));
304 return SVN_NO_ERROR;
307 static svn_error_t *
308 change_dir_prop(void *dir_baton,
309 const char *name,
310 const svn_string_t *value,
311 apr_pool_t *pool)
313 struct dir_baton *db = dir_baton;
314 struct edit_baton *eb = db->edit_baton;
316 SVN_ERR(eb->cancel_func(eb->cancel_baton));
318 SVN_ERR(eb->wrapped_editor->change_dir_prop(db->wrapped_dir_baton,
319 name,
320 value,
321 pool));
323 return SVN_NO_ERROR;
326 static svn_error_t *
327 close_edit(void *edit_baton,
328 apr_pool_t *pool)
330 struct edit_baton *eb = edit_baton;
332 SVN_ERR(eb->cancel_func(eb->cancel_baton));
334 SVN_ERR(eb->wrapped_editor->close_edit(eb->wrapped_edit_baton, pool));
336 return SVN_NO_ERROR;
339 static svn_error_t *
340 abort_edit(void *edit_baton,
341 apr_pool_t *pool)
343 struct edit_baton *eb = edit_baton;
345 SVN_ERR(eb->cancel_func(eb->cancel_baton));
347 SVN_ERR(eb->wrapped_editor->abort_edit(eb->wrapped_edit_baton, pool));
349 return SVN_NO_ERROR;
352 svn_error_t *
353 svn_delta_get_cancellation_editor(svn_cancel_func_t cancel_func,
354 void *cancel_baton,
355 const svn_delta_editor_t *wrapped_editor,
356 void *wrapped_edit_baton,
357 const svn_delta_editor_t **editor,
358 void **edit_baton,
359 apr_pool_t *pool)
361 if (cancel_func)
363 svn_delta_editor_t *tree_editor = svn_delta_default_editor(pool);
364 struct edit_baton *eb = apr_palloc(pool, sizeof(*eb));
366 tree_editor->set_target_revision = set_target_revision;
367 tree_editor->open_root = open_root;
368 tree_editor->delete_entry = delete_entry;
369 tree_editor->add_directory = add_directory;
370 tree_editor->open_directory = open_directory;
371 tree_editor->change_dir_prop = change_dir_prop;
372 tree_editor->close_directory = close_directory;
373 tree_editor->absent_directory = absent_directory;
374 tree_editor->add_file = add_file;
375 tree_editor->open_file = open_file;
376 tree_editor->apply_textdelta = apply_textdelta;
377 tree_editor->change_file_prop = change_file_prop;
378 tree_editor->close_file = close_file;
379 tree_editor->absent_file = absent_file;
380 tree_editor->close_edit = close_edit;
381 tree_editor->abort_edit = abort_edit;
383 eb->wrapped_editor = wrapped_editor;
384 eb->wrapped_edit_baton = wrapped_edit_baton;
385 eb->cancel_func = cancel_func;
386 eb->cancel_baton = cancel_baton;
388 *editor = tree_editor;
389 *edit_baton = eb;
391 else
393 *editor = wrapped_editor;
394 *edit_baton = wrapped_edit_baton;
397 return SVN_NO_ERROR;