* subversion/mod_dav_svn/reports/replay.c
[svn.git] / subversion / libsvn_delta / debug_editor.c
blob0153ddf312057672edcd888aa210d6cb7df8df7f
1 /*
2 * debug_editor.c : An editor that writes the operations it does to stderr.
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 #include "debug_editor.h"
21 struct edit_baton
23 const svn_delta_editor_t *wrapped_editor;
24 void *wrapped_edit_baton;
26 int indent_level;
28 svn_stream_t *out;
31 struct dir_baton
33 void *edit_baton;
34 void *wrapped_dir_baton;
37 struct file_baton
39 void *edit_baton;
40 void *wrapped_file_baton;
43 static svn_error_t *
44 write_indent(struct edit_baton *eb, apr_pool_t *pool)
46 int i;
48 for (i = 0; i < eb->indent_level; ++i)
49 SVN_ERR(svn_stream_printf(eb->out, pool, " "));
51 return SVN_NO_ERROR;
54 static svn_error_t *
55 set_target_revision(void *edit_baton,
56 svn_revnum_t target_revision,
57 apr_pool_t *pool)
59 struct edit_baton *eb = edit_baton;
61 SVN_ERR(write_indent(eb, pool));
62 SVN_ERR(svn_stream_printf(eb->out, pool, "set_target_revision : %ld\n",
63 target_revision));
65 SVN_ERR(eb->wrapped_editor->set_target_revision(eb->wrapped_edit_baton,
66 target_revision,
67 pool));
69 return SVN_NO_ERROR;
72 static svn_error_t *
73 open_root(void *edit_baton,
74 svn_revnum_t base_revision,
75 apr_pool_t *pool,
76 void **root_baton)
78 struct edit_baton *eb = edit_baton;
79 struct dir_baton *dir_baton = apr_palloc(pool, sizeof(*dir_baton));
81 SVN_ERR(write_indent(eb, pool));
82 SVN_ERR(svn_stream_printf(eb->out, pool, "open_root : %ld\n",
83 base_revision));
84 eb->indent_level++;
86 SVN_ERR(eb->wrapped_editor->open_root(eb->wrapped_edit_baton,
87 base_revision,
88 pool,
89 &dir_baton->wrapped_dir_baton));
91 dir_baton->edit_baton = edit_baton;
93 *root_baton = dir_baton;
95 return SVN_NO_ERROR;
98 static svn_error_t *
99 delete_entry(const char *path,
100 svn_revnum_t base_revision,
101 void *parent_baton,
102 apr_pool_t *pool)
104 struct dir_baton *pb = parent_baton;
105 struct edit_baton *eb = pb->edit_baton;
107 SVN_ERR(write_indent(eb, pool));
108 SVN_ERR(svn_stream_printf(eb->out, pool, "delete_entry : %s:%ld\n",
109 path, base_revision));
111 SVN_ERR(eb->wrapped_editor->delete_entry(path,
112 base_revision,
113 pb->wrapped_dir_baton,
114 pool));
116 return SVN_NO_ERROR;
119 static svn_error_t *
120 add_directory(const char *path,
121 void *parent_baton,
122 const char *copyfrom_path,
123 svn_revnum_t copyfrom_revision,
124 apr_pool_t *pool,
125 void **child_baton)
127 struct dir_baton *pb = parent_baton;
128 struct edit_baton *eb = pb->edit_baton;
129 struct dir_baton *b = apr_palloc(pool, sizeof(*b));
131 SVN_ERR(write_indent(eb, pool));
132 SVN_ERR(svn_stream_printf(eb->out, pool,
133 "add_directory : '%s' [from '%s':%ld]\n",
134 path, copyfrom_path, copyfrom_revision));
135 eb->indent_level++;
137 SVN_ERR(eb->wrapped_editor->add_directory(path,
138 pb->wrapped_dir_baton,
139 copyfrom_path,
140 copyfrom_revision,
141 pool,
142 &b->wrapped_dir_baton));
144 b->edit_baton = eb;
145 *child_baton = b;
147 return SVN_NO_ERROR;
150 static svn_error_t *
151 open_directory(const char *path,
152 void *parent_baton,
153 svn_revnum_t base_revision,
154 apr_pool_t *pool,
155 void **child_baton)
157 struct dir_baton *pb = parent_baton;
158 struct edit_baton *eb = pb->edit_baton;
159 struct dir_baton *db = apr_palloc(pool, sizeof(*db));
161 SVN_ERR(write_indent(eb, pool));
162 SVN_ERR(svn_stream_printf(eb->out, pool, "open_directory : '%s':%ld\n",
163 path, base_revision));
164 eb->indent_level++;
166 SVN_ERR(eb->wrapped_editor->open_directory(path,
167 pb->wrapped_dir_baton,
168 base_revision,
169 pool,
170 &db->wrapped_dir_baton));
172 db->edit_baton = eb;
173 *child_baton = db;
175 return SVN_NO_ERROR;
178 static svn_error_t *
179 add_file(const char *path,
180 void *parent_baton,
181 const char *copyfrom_path,
182 svn_revnum_t copyfrom_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(write_indent(eb, pool));
191 SVN_ERR(svn_stream_printf(eb->out, pool,
192 "add_file : '%s' [from '%s':%ld]\n",
193 path, copyfrom_path, copyfrom_revision));
195 eb->indent_level++;
197 SVN_ERR(eb->wrapped_editor->add_file(path,
198 pb->wrapped_dir_baton,
199 copyfrom_path,
200 copyfrom_revision,
201 pool,
202 &fb->wrapped_file_baton));
204 fb->edit_baton = eb;
205 *file_baton = fb;
207 return SVN_NO_ERROR;
210 static svn_error_t *
211 open_file(const char *path,
212 void *parent_baton,
213 svn_revnum_t base_revision,
214 apr_pool_t *pool,
215 void **file_baton)
217 struct dir_baton *pb = parent_baton;
218 struct edit_baton *eb = pb->edit_baton;
219 struct file_baton *fb = apr_palloc(pool, sizeof(*fb));
221 SVN_ERR(write_indent(eb, pool));
222 SVN_ERR(svn_stream_printf(eb->out, pool, "open_file : '%s':%ld\n",
223 path, base_revision));
225 eb->indent_level++;
227 SVN_ERR(eb->wrapped_editor->open_file(path,
228 pb->wrapped_dir_baton,
229 base_revision,
230 pool,
231 &fb->wrapped_file_baton));
233 fb->edit_baton = eb;
234 *file_baton = fb;
236 return SVN_NO_ERROR;
239 static svn_error_t *
240 apply_textdelta(void *file_baton,
241 const char *base_checksum,
242 apr_pool_t *pool,
243 svn_txdelta_window_handler_t *handler,
244 void **handler_baton)
246 struct file_baton *fb = file_baton;
247 struct edit_baton *eb = fb->edit_baton;
249 SVN_ERR(write_indent(eb, pool));
250 SVN_ERR(svn_stream_printf(eb->out, pool, "apply_textdelta : %s\n",
251 base_checksum));
253 SVN_ERR(eb->wrapped_editor->apply_textdelta(fb->wrapped_file_baton,
254 base_checksum,
255 pool,
256 handler,
257 handler_baton));
259 return SVN_NO_ERROR;
262 static svn_error_t *
263 close_file(void *file_baton,
264 const char *text_checksum,
265 apr_pool_t *pool)
267 struct file_baton *fb = file_baton;
268 struct edit_baton *eb = fb->edit_baton;
270 eb->indent_level--;
272 SVN_ERR(write_indent(eb, pool));
273 SVN_ERR(svn_stream_printf(eb->out, pool, "close_file : %s\n",
274 text_checksum));
276 SVN_ERR(eb->wrapped_editor->close_file(fb->wrapped_file_baton,
277 text_checksum, pool));
279 return SVN_NO_ERROR;
282 static svn_error_t *
283 absent_file(const char *path,
284 void *file_baton,
285 apr_pool_t *pool)
287 struct file_baton *fb = file_baton;
288 struct edit_baton *eb = fb->edit_baton;
290 SVN_ERR(write_indent(eb, pool));
291 SVN_ERR(svn_stream_printf(eb->out, pool, "absent_file : %s\n", path));
293 SVN_ERR(eb->wrapped_editor->absent_file(path, fb->wrapped_file_baton,
294 pool));
296 return SVN_NO_ERROR;
299 static svn_error_t *
300 close_directory(void *dir_baton,
301 apr_pool_t *pool)
303 struct dir_baton *db = dir_baton;
304 struct edit_baton *eb = db->edit_baton;
306 eb->indent_level--;
307 SVN_ERR(write_indent(eb, pool));
308 SVN_ERR(svn_stream_printf(eb->out, pool, "close_directory\n"));
310 SVN_ERR(eb->wrapped_editor->close_directory(db->wrapped_dir_baton,
311 pool));
313 return SVN_NO_ERROR;
316 static svn_error_t *
317 absent_directory(const char *path,
318 void *dir_baton,
319 apr_pool_t *pool)
321 struct dir_baton *db = dir_baton;
322 struct edit_baton *eb = db->edit_baton;
324 SVN_ERR(write_indent(eb, pool));
325 SVN_ERR(svn_stream_printf(eb->out, pool, "absent_directory : %s\n",
326 path));
328 SVN_ERR(eb->wrapped_editor->absent_directory(path, db->wrapped_dir_baton,
329 pool));
331 return SVN_NO_ERROR;
334 static svn_error_t *
335 change_file_prop(void *file_baton,
336 const char *name,
337 const svn_string_t *value,
338 apr_pool_t *pool)
340 struct file_baton *fb = file_baton;
341 struct edit_baton *eb = fb->edit_baton;
343 SVN_ERR(write_indent(eb, pool));
344 SVN_ERR(svn_stream_printf(eb->out, pool, "change_file_prop : %s\n",
345 name));
347 SVN_ERR(eb->wrapped_editor->change_file_prop(fb->wrapped_file_baton,
348 name,
349 value,
350 pool));
352 return SVN_NO_ERROR;
355 static svn_error_t *
356 change_dir_prop(void *dir_baton,
357 const char *name,
358 const svn_string_t *value,
359 apr_pool_t *pool)
361 struct dir_baton *db = dir_baton;
362 struct edit_baton *eb = db->edit_baton;
364 SVN_ERR(write_indent(eb, pool));
365 SVN_ERR(svn_stream_printf(eb->out, pool, "change_dir_prop : %s\n", name));
367 SVN_ERR(eb->wrapped_editor->change_dir_prop(db->wrapped_dir_baton,
368 name,
369 value,
370 pool));
372 return SVN_NO_ERROR;
375 static svn_error_t *
376 close_edit(void *edit_baton,
377 apr_pool_t *pool)
379 struct edit_baton *eb = edit_baton;
381 SVN_ERR(write_indent(eb, pool));
382 SVN_ERR(svn_stream_printf(eb->out, pool, "close_edit\n"));
384 SVN_ERR(eb->wrapped_editor->close_edit(eb->wrapped_edit_baton, pool));
386 return SVN_NO_ERROR;
389 svn_error_t *
390 svn_delta__get_debug_editor(const svn_delta_editor_t **editor,
391 void **edit_baton,
392 const svn_delta_editor_t *wrapped_editor,
393 void *wrapped_edit_baton,
394 apr_pool_t *pool)
396 svn_delta_editor_t *tree_editor = svn_delta_default_editor(pool);
397 struct edit_baton *eb = apr_palloc(pool, sizeof(*eb));
398 apr_file_t *errfp;
399 svn_stream_t *out;
401 apr_status_t apr_err = apr_file_open_stderr(&errfp, pool);
402 if (apr_err)
403 return svn_error_wrap_apr(apr_err, "Problem opening stderr");
405 out = svn_stream_from_aprfile(errfp, pool);
407 tree_editor->set_target_revision = set_target_revision;
408 tree_editor->open_root = open_root;
409 tree_editor->delete_entry = delete_entry;
410 tree_editor->add_directory = add_directory;
411 tree_editor->open_directory = open_directory;
412 tree_editor->change_dir_prop = change_dir_prop;
413 tree_editor->close_directory = close_directory;
414 tree_editor->absent_directory = absent_directory;
415 tree_editor->add_file = add_file;
416 tree_editor->open_file = open_file;
417 tree_editor->apply_textdelta = apply_textdelta;
418 tree_editor->change_file_prop = change_file_prop;
419 tree_editor->close_file = close_file;
420 tree_editor->absent_file = absent_file;
421 tree_editor->close_edit = close_edit;
423 eb->wrapped_editor = wrapped_editor;
424 eb->wrapped_edit_baton = wrapped_edit_baton;
425 eb->out = out;
426 eb->indent_level = 0;
428 *editor = tree_editor;
429 *edit_baton = eb;
431 return SVN_NO_ERROR;