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 "debug_editor.h"
30 const svn_delta_editor_t *wrapped_editor;
31 void *wrapped_edit_baton;
41 void *wrapped_dir_baton;
47 void *wrapped_file_baton;
51 write_indent(struct edit_baton *eb, apr_pool_t *pool)
55 /* This is DBG_FLAG from ../libsvn_subr/debug.c */
56 SVN_ERR(svn_stream_puts(eb->out, "DBG:"));
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 return eb->wrapped_editor->set_target_revision(eb->wrapped_edit_baton,
80 open_root(void *edit_baton,
81 svn_revnum_t base_revision,
85 struct edit_baton *eb = edit_baton;
86 struct dir_baton *dir_baton = apr_palloc(pool, sizeof(*dir_baton));
88 SVN_ERR(write_indent(eb, pool));
89 SVN_ERR(svn_stream_printf(eb->out, pool, "open_root : %ld\n",
93 SVN_ERR(eb->wrapped_editor->open_root(eb->wrapped_edit_baton,
96 &dir_baton->wrapped_dir_baton));
98 dir_baton->edit_baton = edit_baton;
100 *root_baton = dir_baton;
106 delete_entry(const char *path,
107 svn_revnum_t base_revision,
111 struct dir_baton *pb = parent_baton;
112 struct edit_baton *eb = pb->edit_baton;
114 SVN_ERR(write_indent(eb, pool));
115 SVN_ERR(svn_stream_printf(eb->out, pool, "delete_entry : %s:%ld\n",
116 path, base_revision));
118 return eb->wrapped_editor->delete_entry(path,
120 pb->wrapped_dir_baton,
125 add_directory(const char *path,
127 const char *copyfrom_path,
128 svn_revnum_t copyfrom_revision,
132 struct dir_baton *pb = parent_baton;
133 struct edit_baton *eb = pb->edit_baton;
134 struct dir_baton *b = apr_palloc(pool, sizeof(*b));
136 SVN_ERR(write_indent(eb, pool));
137 SVN_ERR(svn_stream_printf(eb->out, pool,
138 "add_directory : '%s' [from '%s':%ld]\n",
139 path, copyfrom_path, copyfrom_revision));
142 SVN_ERR(eb->wrapped_editor->add_directory(path,
143 pb->wrapped_dir_baton,
147 &b->wrapped_dir_baton));
156 open_directory(const char *path,
158 svn_revnum_t base_revision,
162 struct dir_baton *pb = parent_baton;
163 struct edit_baton *eb = pb->edit_baton;
164 struct dir_baton *db = apr_palloc(pool, sizeof(*db));
166 SVN_ERR(write_indent(eb, pool));
167 SVN_ERR(svn_stream_printf(eb->out, pool, "open_directory : '%s':%ld\n",
168 path, base_revision));
171 SVN_ERR(eb->wrapped_editor->open_directory(path,
172 pb->wrapped_dir_baton,
175 &db->wrapped_dir_baton));
184 add_file(const char *path,
186 const char *copyfrom_path,
187 svn_revnum_t copyfrom_revision,
191 struct dir_baton *pb = parent_baton;
192 struct edit_baton *eb = pb->edit_baton;
193 struct file_baton *fb = apr_palloc(pool, sizeof(*fb));
195 SVN_ERR(write_indent(eb, pool));
196 SVN_ERR(svn_stream_printf(eb->out, pool,
197 "add_file : '%s' [from '%s':%ld]\n",
198 path, copyfrom_path, copyfrom_revision));
202 SVN_ERR(eb->wrapped_editor->add_file(path,
203 pb->wrapped_dir_baton,
207 &fb->wrapped_file_baton));
216 open_file(const char *path,
218 svn_revnum_t base_revision,
222 struct dir_baton *pb = parent_baton;
223 struct edit_baton *eb = pb->edit_baton;
224 struct file_baton *fb = apr_palloc(pool, sizeof(*fb));
226 SVN_ERR(write_indent(eb, pool));
227 SVN_ERR(svn_stream_printf(eb->out, pool, "open_file : '%s':%ld\n",
228 path, base_revision));
232 SVN_ERR(eb->wrapped_editor->open_file(path,
233 pb->wrapped_dir_baton,
236 &fb->wrapped_file_baton));
245 apply_textdelta(void *file_baton,
246 const char *base_checksum,
248 svn_txdelta_window_handler_t *handler,
249 void **handler_baton)
251 struct file_baton *fb = file_baton;
252 struct edit_baton *eb = fb->edit_baton;
254 SVN_ERR(write_indent(eb, pool));
255 SVN_ERR(svn_stream_printf(eb->out, pool, "apply_textdelta : %s\n",
258 SVN_ERR(eb->wrapped_editor->apply_textdelta(fb->wrapped_file_baton,
268 close_file(void *file_baton,
269 const char *text_checksum,
272 struct file_baton *fb = file_baton;
273 struct edit_baton *eb = fb->edit_baton;
277 SVN_ERR(write_indent(eb, pool));
278 SVN_ERR(svn_stream_printf(eb->out, pool, "close_file : %s\n",
281 SVN_ERR(eb->wrapped_editor->close_file(fb->wrapped_file_baton,
282 text_checksum, pool));
288 absent_file(const char *path,
292 struct file_baton *fb = file_baton;
293 struct edit_baton *eb = fb->edit_baton;
295 SVN_ERR(write_indent(eb, pool));
296 SVN_ERR(svn_stream_printf(eb->out, pool, "absent_file : %s\n", path));
298 SVN_ERR(eb->wrapped_editor->absent_file(path, fb->wrapped_file_baton,
305 close_directory(void *dir_baton,
308 struct dir_baton *db = dir_baton;
309 struct edit_baton *eb = db->edit_baton;
312 SVN_ERR(write_indent(eb, pool));
313 SVN_ERR(svn_stream_printf(eb->out, pool, "close_directory\n"));
315 SVN_ERR(eb->wrapped_editor->close_directory(db->wrapped_dir_baton,
322 absent_directory(const char *path,
326 struct dir_baton *db = dir_baton;
327 struct edit_baton *eb = db->edit_baton;
329 SVN_ERR(write_indent(eb, pool));
330 SVN_ERR(svn_stream_printf(eb->out, pool, "absent_directory : %s\n",
333 SVN_ERR(eb->wrapped_editor->absent_directory(path, db->wrapped_dir_baton,
340 change_file_prop(void *file_baton,
342 const svn_string_t *value,
345 struct file_baton *fb = file_baton;
346 struct edit_baton *eb = fb->edit_baton;
348 SVN_ERR(write_indent(eb, pool));
349 SVN_ERR(svn_stream_printf(eb->out, pool, "change_file_prop : %s\n",
352 SVN_ERR(eb->wrapped_editor->change_file_prop(fb->wrapped_file_baton,
361 change_dir_prop(void *dir_baton,
363 const svn_string_t *value,
366 struct dir_baton *db = dir_baton;
367 struct edit_baton *eb = db->edit_baton;
369 SVN_ERR(write_indent(eb, pool));
370 SVN_ERR(svn_stream_printf(eb->out, pool, "change_dir_prop : %s\n", name));
372 SVN_ERR(eb->wrapped_editor->change_dir_prop(db->wrapped_dir_baton,
381 close_edit(void *edit_baton,
384 struct edit_baton *eb = edit_baton;
386 SVN_ERR(write_indent(eb, pool));
387 SVN_ERR(svn_stream_printf(eb->out, pool, "close_edit\n"));
389 SVN_ERR(eb->wrapped_editor->close_edit(eb->wrapped_edit_baton, pool));
395 svn_delta__get_debug_editor(const svn_delta_editor_t **editor,
397 const svn_delta_editor_t *wrapped_editor,
398 void *wrapped_edit_baton,
401 svn_delta_editor_t *tree_editor = svn_delta_default_editor(pool);
402 struct edit_baton *eb = apr_palloc(pool, sizeof(*eb));
406 apr_status_t apr_err = apr_file_open_stderr(&errfp, pool);
408 return svn_error_wrap_apr(apr_err, "Problem opening stderr");
410 out = svn_stream_from_aprfile2(errfp, TRUE, pool);
412 tree_editor->set_target_revision = set_target_revision;
413 tree_editor->open_root = open_root;
414 tree_editor->delete_entry = delete_entry;
415 tree_editor->add_directory = add_directory;
416 tree_editor->open_directory = open_directory;
417 tree_editor->change_dir_prop = change_dir_prop;
418 tree_editor->close_directory = close_directory;
419 tree_editor->absent_directory = absent_directory;
420 tree_editor->add_file = add_file;
421 tree_editor->open_file = open_file;
422 tree_editor->apply_textdelta = apply_textdelta;
423 tree_editor->change_file_prop = change_file_prop;
424 tree_editor->close_file = close_file;
425 tree_editor->absent_file = absent_file;
426 tree_editor->close_edit = close_edit;
428 eb->wrapped_editor = wrapped_editor;
429 eb->wrapped_edit_baton = wrapped_edit_baton;
431 eb->indent_level = 0;
433 *editor = tree_editor;