2 * debug_editor.c : An editor that writes the operations it does to stderr.
4 * ====================================================================
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
21 * ====================================================================
26 #include "private/svn_delta_private.h"
30 const svn_delta_editor_t *wrapped_editor;
31 void *wrapped_edit_baton;
42 void *wrapped_dir_baton;
48 void *wrapped_file_baton;
52 write_indent(struct edit_baton *eb, apr_pool_t *pool)
56 SVN_ERR(svn_stream_puts(eb->out, eb->prefix));
57 for (i = 0; i < eb->indent_level; ++i)
58 SVN_ERR(svn_stream_puts(eb->out, " "));
64 set_target_revision(void *edit_baton,
65 svn_revnum_t target_revision,
68 struct edit_baton *eb = edit_baton;
70 SVN_ERR(write_indent(eb, pool));
71 SVN_ERR(svn_stream_printf(eb->out, pool, "set_target_revision : %ld\n",
74 if (eb->wrapped_editor)
75 SVN_ERR(eb->wrapped_editor->set_target_revision(eb->wrapped_edit_baton,
82 open_root(void *edit_baton,
83 svn_revnum_t base_revision,
87 struct edit_baton *eb = edit_baton;
88 struct dir_baton *dir_baton = apr_palloc(pool, sizeof(*dir_baton));
90 SVN_ERR(write_indent(eb, pool));
91 SVN_ERR(svn_stream_printf(eb->out, pool, "open_root : %ld\n",
95 if (eb->wrapped_editor)
96 SVN_ERR(eb->wrapped_editor->open_root(eb->wrapped_edit_baton,
99 &dir_baton->wrapped_dir_baton));
101 dir_baton->edit_baton = edit_baton;
103 *root_baton = dir_baton;
109 delete_entry(const char *path,
110 svn_revnum_t base_revision,
114 struct dir_baton *pb = parent_baton;
115 struct edit_baton *eb = pb->edit_baton;
117 SVN_ERR(write_indent(eb, pool));
118 SVN_ERR(svn_stream_printf(eb->out, pool, "delete_entry : %s:%ld\n",
119 path, base_revision));
121 if (eb->wrapped_editor)
122 SVN_ERR(eb->wrapped_editor->delete_entry(path,
124 pb->wrapped_dir_baton,
130 add_directory(const char *path,
132 const char *copyfrom_path,
133 svn_revnum_t copyfrom_revision,
137 struct dir_baton *pb = parent_baton;
138 struct edit_baton *eb = pb->edit_baton;
139 struct dir_baton *b = apr_palloc(pool, sizeof(*b));
141 SVN_ERR(write_indent(eb, pool));
142 SVN_ERR(svn_stream_printf(eb->out, pool,
143 "add_directory : '%s' [from '%s':%ld]\n",
144 path, copyfrom_path, copyfrom_revision));
147 if (eb->wrapped_editor)
148 SVN_ERR(eb->wrapped_editor->add_directory(path,
149 pb->wrapped_dir_baton,
153 &b->wrapped_dir_baton));
162 open_directory(const char *path,
164 svn_revnum_t base_revision,
168 struct dir_baton *pb = parent_baton;
169 struct edit_baton *eb = pb->edit_baton;
170 struct dir_baton *db = apr_palloc(pool, sizeof(*db));
172 SVN_ERR(write_indent(eb, pool));
173 SVN_ERR(svn_stream_printf(eb->out, pool, "open_directory : '%s':%ld\n",
174 path, base_revision));
177 if (eb->wrapped_editor)
178 SVN_ERR(eb->wrapped_editor->open_directory(path,
179 pb->wrapped_dir_baton,
182 &db->wrapped_dir_baton));
191 add_file(const char *path,
193 const char *copyfrom_path,
194 svn_revnum_t copyfrom_revision,
198 struct dir_baton *pb = parent_baton;
199 struct edit_baton *eb = pb->edit_baton;
200 struct file_baton *fb = apr_palloc(pool, sizeof(*fb));
202 SVN_ERR(write_indent(eb, pool));
203 SVN_ERR(svn_stream_printf(eb->out, pool,
204 "add_file : '%s' [from '%s':%ld]\n",
205 path, copyfrom_path, copyfrom_revision));
209 if (eb->wrapped_editor)
210 SVN_ERR(eb->wrapped_editor->add_file(path,
211 pb->wrapped_dir_baton,
215 &fb->wrapped_file_baton));
224 open_file(const char *path,
226 svn_revnum_t base_revision,
230 struct dir_baton *pb = parent_baton;
231 struct edit_baton *eb = pb->edit_baton;
232 struct file_baton *fb = apr_palloc(pool, sizeof(*fb));
234 SVN_ERR(write_indent(eb, pool));
235 SVN_ERR(svn_stream_printf(eb->out, pool, "open_file : '%s':%ld\n",
236 path, base_revision));
240 if (eb->wrapped_editor)
241 SVN_ERR(eb->wrapped_editor->open_file(path,
242 pb->wrapped_dir_baton,
245 &fb->wrapped_file_baton));
254 apply_textdelta(void *file_baton,
255 const char *base_checksum,
257 svn_txdelta_window_handler_t *handler,
258 void **handler_baton)
260 struct file_baton *fb = file_baton;
261 struct edit_baton *eb = fb->edit_baton;
263 SVN_ERR(write_indent(eb, pool));
264 SVN_ERR(svn_stream_printf(eb->out, pool, "apply_textdelta : %s\n",
267 if (eb->wrapped_editor)
268 SVN_ERR(eb->wrapped_editor->apply_textdelta(fb->wrapped_file_baton,
278 apply_textdelta_stream(const struct svn_delta_editor_t *editor,
280 const char *base_checksum,
281 svn_txdelta_stream_open_func_t open_func,
283 apr_pool_t *scratch_pool)
285 struct file_baton *fb = file_baton;
286 struct edit_baton *eb = fb->edit_baton;
288 SVN_ERR(write_indent(eb, scratch_pool));
289 SVN_ERR(svn_stream_printf(eb->out, scratch_pool,
290 "apply_textdelta_stream : %s\n",
293 if (eb->wrapped_editor)
294 SVN_ERR(eb->wrapped_editor->apply_textdelta_stream(eb->wrapped_editor,
295 fb->wrapped_file_baton,
297 open_func, open_baton,
304 close_file(void *file_baton,
305 const char *text_checksum,
308 struct file_baton *fb = file_baton;
309 struct edit_baton *eb = fb->edit_baton;
313 SVN_ERR(write_indent(eb, pool));
314 SVN_ERR(svn_stream_printf(eb->out, pool, "close_file : %s\n",
317 if (eb->wrapped_editor)
318 SVN_ERR(eb->wrapped_editor->close_file(fb->wrapped_file_baton,
319 text_checksum, pool));
325 absent_file(const char *path,
329 struct file_baton *fb = file_baton;
330 struct edit_baton *eb = fb->edit_baton;
332 SVN_ERR(write_indent(eb, pool));
333 SVN_ERR(svn_stream_printf(eb->out, pool, "absent_file : %s\n", path));
335 if (eb->wrapped_editor)
336 SVN_ERR(eb->wrapped_editor->absent_file(path, fb->wrapped_file_baton,
343 close_directory(void *dir_baton,
346 struct dir_baton *db = dir_baton;
347 struct edit_baton *eb = db->edit_baton;
350 SVN_ERR(write_indent(eb, pool));
351 SVN_ERR(svn_stream_printf(eb->out, pool, "close_directory\n"));
353 if (eb->wrapped_editor)
354 SVN_ERR(eb->wrapped_editor->close_directory(db->wrapped_dir_baton,
361 absent_directory(const char *path,
365 struct dir_baton *db = dir_baton;
366 struct edit_baton *eb = db->edit_baton;
368 SVN_ERR(write_indent(eb, pool));
369 SVN_ERR(svn_stream_printf(eb->out, pool, "absent_directory : %s\n",
372 if (eb->wrapped_editor)
373 SVN_ERR(eb->wrapped_editor->absent_directory(path, db->wrapped_dir_baton,
380 change_file_prop(void *file_baton,
382 const svn_string_t *value,
385 struct file_baton *fb = file_baton;
386 struct edit_baton *eb = fb->edit_baton;
388 SVN_ERR(write_indent(eb, pool));
389 SVN_ERR(svn_stream_printf(eb->out, pool, "change_file_prop : %s -> %s\n",
390 name, value ? value->data : "<deleted>"));
392 if (eb->wrapped_editor)
393 SVN_ERR(eb->wrapped_editor->change_file_prop(fb->wrapped_file_baton,
402 change_dir_prop(void *dir_baton,
404 const svn_string_t *value,
407 struct dir_baton *db = dir_baton;
408 struct edit_baton *eb = db->edit_baton;
410 SVN_ERR(write_indent(eb, pool));
411 SVN_ERR(svn_stream_printf(eb->out, pool, "change_dir_prop : %s -> %s\n",
412 name, value ? value->data : "<deleted>"));
414 if (eb->wrapped_editor)
415 SVN_ERR(eb->wrapped_editor->change_dir_prop(db->wrapped_dir_baton,
424 close_edit(void *edit_baton,
427 struct edit_baton *eb = edit_baton;
429 SVN_ERR(write_indent(eb, pool));
430 SVN_ERR(svn_stream_printf(eb->out, pool, "close_edit\n"));
432 if (eb->wrapped_editor)
433 SVN_ERR(eb->wrapped_editor->close_edit(eb->wrapped_edit_baton, pool));
439 abort_edit(void *edit_baton,
442 struct edit_baton *eb = edit_baton;
444 SVN_ERR(write_indent(eb, pool));
445 SVN_ERR(svn_stream_printf(eb->out, pool, "abort_edit\n"));
447 if (eb->wrapped_editor)
448 SVN_ERR(eb->wrapped_editor->abort_edit(eb->wrapped_edit_baton, pool));
454 svn_delta__get_debug_editor(const svn_delta_editor_t **editor,
456 const svn_delta_editor_t *wrapped_editor,
457 void *wrapped_edit_baton,
461 svn_delta_editor_t *tree_editor = svn_delta_default_editor(pool);
462 struct edit_baton *eb = apr_palloc(pool, sizeof(*eb));
466 apr_status_t apr_err = apr_file_open_stdout(&errfp, pool);
468 return svn_error_wrap_apr(apr_err, "Problem opening stderr");
470 out = svn_stream_from_aprfile2(errfp, TRUE, pool);
472 tree_editor->set_target_revision = set_target_revision;
473 tree_editor->open_root = open_root;
474 tree_editor->delete_entry = delete_entry;
475 tree_editor->add_directory = add_directory;
476 tree_editor->open_directory = open_directory;
477 tree_editor->change_dir_prop = change_dir_prop;
478 tree_editor->close_directory = close_directory;
479 tree_editor->absent_directory = absent_directory;
480 tree_editor->add_file = add_file;
481 tree_editor->open_file = open_file;
482 tree_editor->apply_textdelta = apply_textdelta;
483 tree_editor->apply_textdelta_stream = apply_textdelta_stream;
484 tree_editor->change_file_prop = change_file_prop;
485 tree_editor->close_file = close_file;
486 tree_editor->absent_file = absent_file;
487 tree_editor->close_edit = close_edit;
488 tree_editor->abort_edit = abort_edit;
490 eb->wrapped_editor = wrapped_editor;
491 eb->wrapped_edit_baton = wrapped_edit_baton;
493 eb->indent_level = 0;
494 /* This is DBG_FLAG from ../libsvn_subr/debug.c */
495 eb->prefix = apr_pstrcat(pool, "DBG: ", prefix, SVN_VA_NULL);
497 *editor = tree_editor;