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"
23 const svn_delta_editor_t
*wrapped_editor
;
24 void *wrapped_edit_baton
;
34 void *wrapped_dir_baton
;
40 void *wrapped_file_baton
;
44 write_indent(struct edit_baton
*eb
, apr_pool_t
*pool
)
48 for (i
= 0; i
< eb
->indent_level
; ++i
)
49 SVN_ERR(svn_stream_printf(eb
->out
, pool
, " "));
55 set_target_revision(void *edit_baton
,
56 svn_revnum_t target_revision
,
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",
65 SVN_ERR(eb
->wrapped_editor
->set_target_revision(eb
->wrapped_edit_baton
,
73 open_root(void *edit_baton
,
74 svn_revnum_t base_revision
,
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",
86 SVN_ERR(eb
->wrapped_editor
->open_root(eb
->wrapped_edit_baton
,
89 &dir_baton
->wrapped_dir_baton
));
91 dir_baton
->edit_baton
= edit_baton
;
93 *root_baton
= dir_baton
;
99 delete_entry(const char *path
,
100 svn_revnum_t base_revision
,
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
,
113 pb
->wrapped_dir_baton
,
120 add_directory(const char *path
,
122 const char *copyfrom_path
,
123 svn_revnum_t copyfrom_revision
,
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
));
137 SVN_ERR(eb
->wrapped_editor
->add_directory(path
,
138 pb
->wrapped_dir_baton
,
142 &b
->wrapped_dir_baton
));
151 open_directory(const char *path
,
153 svn_revnum_t base_revision
,
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
));
166 SVN_ERR(eb
->wrapped_editor
->open_directory(path
,
167 pb
->wrapped_dir_baton
,
170 &db
->wrapped_dir_baton
));
179 add_file(const char *path
,
181 const char *copyfrom_path
,
182 svn_revnum_t copyfrom_revision
,
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
));
197 SVN_ERR(eb
->wrapped_editor
->add_file(path
,
198 pb
->wrapped_dir_baton
,
202 &fb
->wrapped_file_baton
));
211 open_file(const char *path
,
213 svn_revnum_t base_revision
,
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
));
227 SVN_ERR(eb
->wrapped_editor
->open_file(path
,
228 pb
->wrapped_dir_baton
,
231 &fb
->wrapped_file_baton
));
240 apply_textdelta(void *file_baton
,
241 const char *base_checksum
,
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",
253 SVN_ERR(eb
->wrapped_editor
->apply_textdelta(fb
->wrapped_file_baton
,
263 close_file(void *file_baton
,
264 const char *text_checksum
,
267 struct file_baton
*fb
= file_baton
;
268 struct edit_baton
*eb
= fb
->edit_baton
;
272 SVN_ERR(write_indent(eb
, pool
));
273 SVN_ERR(svn_stream_printf(eb
->out
, pool
, "close_file : %s\n",
276 SVN_ERR(eb
->wrapped_editor
->close_file(fb
->wrapped_file_baton
,
277 text_checksum
, pool
));
283 absent_file(const char *path
,
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
,
300 close_directory(void *dir_baton
,
303 struct dir_baton
*db
= dir_baton
;
304 struct edit_baton
*eb
= db
->edit_baton
;
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
,
317 absent_directory(const char *path
,
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",
328 SVN_ERR(eb
->wrapped_editor
->absent_directory(path
, db
->wrapped_dir_baton
,
335 change_file_prop(void *file_baton
,
337 const svn_string_t
*value
,
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",
347 SVN_ERR(eb
->wrapped_editor
->change_file_prop(fb
->wrapped_file_baton
,
356 change_dir_prop(void *dir_baton
,
358 const svn_string_t
*value
,
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
,
376 close_edit(void *edit_baton
,
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
));
390 svn_delta__get_debug_editor(const svn_delta_editor_t
**editor
,
392 const svn_delta_editor_t
*wrapped_editor
,
393 void *wrapped_edit_baton
,
396 svn_delta_editor_t
*tree_editor
= svn_delta_default_editor(pool
);
397 struct edit_baton
*eb
= apr_palloc(pool
, sizeof(*eb
));
401 apr_status_t apr_err
= apr_file_open_stderr(&errfp
, pool
);
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
;
426 eb
->indent_level
= 0;
428 *editor
= tree_editor
;