Fix compiler warning due to missing function prototype.
[svn.git] / subversion / tests / libsvn_repos / dir-delta-editor.c
blob55e7871980b3e047c14bcc2240a0a2c41dfa4a1f
1 /*
2 * svn_tests_editor.c: a `dummy' editor implementation for testing
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 /* ==================================================================== */
24 #include <stdio.h>
26 #include <apr_pools.h>
27 #include <apr_file_io.h>
29 #include "svn_types.h"
30 #include "svn_error.h"
31 #include "svn_path.h"
32 #include "svn_delta.h"
33 #include "svn_fs.h"
35 #include "../svn_test.h"
36 #include "dir-delta-editor.h"
38 struct edit_baton
40 svn_fs_t *fs;
41 svn_fs_root_t *txn_root;
42 const char *root_path;
43 apr_pool_t *pool;
46 struct dir_baton
48 struct edit_baton *edit_baton;
49 const char *full_path;
53 struct file_baton
55 struct edit_baton *edit_baton;
56 const char *path;
61 static svn_error_t *
62 test_delete_entry(const char *path,
63 svn_revnum_t revision,
64 void *parent_baton,
65 apr_pool_t *pool)
67 struct dir_baton *pb = parent_baton;
69 /* Construct the full path of this entry and delete it from the txn. */
70 return svn_fs_delete(pb->edit_baton->txn_root,
71 svn_path_join(pb->edit_baton->root_path, path, pool),
72 pool);
76 static svn_error_t *
77 test_open_root(void *edit_baton,
78 svn_revnum_t base_revision,
79 apr_pool_t *dir_pool,
80 void **root_baton)
82 struct dir_baton *db = apr_pcalloc(dir_pool, sizeof(*db));
83 struct edit_baton *eb = edit_baton;
85 db->full_path = eb->root_path;
86 db->edit_baton = edit_baton;
88 *root_baton = db;
89 return SVN_NO_ERROR;
93 static svn_error_t *
94 test_open_directory(const char *path,
95 void *parent_baton,
96 svn_revnum_t base_revision,
97 apr_pool_t *dir_pool,
98 void **child_baton)
100 struct dir_baton *pb = parent_baton;
101 struct edit_baton *eb = pb->edit_baton;
102 struct dir_baton *db = apr_pcalloc(dir_pool, sizeof(*db));
103 svn_fs_root_t *rev_root = NULL;
105 /* Construct the full path of the new directory */
106 db->full_path = svn_path_join(eb->root_path, path, eb->pool);
107 db->edit_baton = eb;
109 SVN_ERR(svn_fs_revision_root(&rev_root, eb->fs, base_revision, dir_pool));
110 SVN_ERR(svn_fs_revision_link(rev_root, eb->txn_root, db->full_path,
111 dir_pool));
113 *child_baton = db;
114 return SVN_NO_ERROR;
118 static svn_error_t *
119 test_add_directory(const char *path,
120 void *parent_baton,
121 const char *copyfrom_path,
122 svn_revnum_t copyfrom_revision,
123 apr_pool_t *dir_pool,
124 void **child_baton)
126 struct dir_baton *pb = parent_baton;
127 struct edit_baton *eb = pb->edit_baton;
128 struct dir_baton *db = apr_pcalloc(dir_pool, sizeof(*db));
130 /* Construct the full path of the new directory */
131 db->full_path = svn_path_join(eb->root_path, path, eb->pool);
132 db->edit_baton = eb;
134 if (copyfrom_path) /* add with history */
136 svn_fs_root_t *rev_root = NULL;
138 SVN_ERR(svn_fs_revision_root(&rev_root,
139 eb->fs,
140 copyfrom_revision,
141 dir_pool));
143 SVN_ERR(svn_fs_copy(rev_root,
144 copyfrom_path,
145 eb->txn_root,
146 db->full_path,
147 dir_pool));
149 else /* add without history */
150 SVN_ERR(svn_fs_make_dir(eb->txn_root, db->full_path, dir_pool));
152 *child_baton = db;
153 return SVN_NO_ERROR;
157 static svn_error_t *
158 test_open_file(const char *path,
159 void *parent_baton,
160 svn_revnum_t base_revision,
161 apr_pool_t *file_pool,
162 void **file_baton)
164 struct dir_baton *pb = parent_baton;
165 struct edit_baton *eb = pb->edit_baton;
166 struct file_baton *fb = apr_pcalloc(file_pool, sizeof(*fb));
167 svn_fs_root_t *rev_root = NULL;
169 /* Fill in the file baton. */
170 fb->path = svn_path_join(eb->root_path, path, eb->pool);
171 fb->edit_baton = eb;
173 SVN_ERR(svn_fs_revision_root(&rev_root, eb->fs, base_revision, file_pool));
174 SVN_ERR(svn_fs_revision_link(rev_root, eb->txn_root, fb->path, file_pool));
176 *file_baton = fb;
177 return SVN_NO_ERROR;
181 static svn_error_t *
182 test_add_file(const char *path,
183 void *parent_baton,
184 const char *copyfrom_path,
185 svn_revnum_t copyfrom_revision,
186 apr_pool_t *file_pool,
187 void **file_baton)
189 struct dir_baton *db = parent_baton;
190 struct edit_baton *eb = db->edit_baton;
191 struct file_baton *fb = apr_pcalloc(file_pool, sizeof(*fb));
193 /* Fill in the file baton. */
194 fb->path = svn_path_join(eb->root_path, path, eb->pool);
195 fb->edit_baton = eb;
197 if (copyfrom_path) /* add with history */
199 svn_fs_root_t *rev_root = NULL;
201 SVN_ERR(svn_fs_revision_root(&rev_root,
202 eb->fs,
203 copyfrom_revision,
204 file_pool));
206 SVN_ERR(svn_fs_copy(rev_root,
207 copyfrom_path,
208 eb->txn_root,
209 fb->path,
210 file_pool));
212 else /* add without history */
213 SVN_ERR(svn_fs_make_file(eb->txn_root, fb->path, file_pool));
215 *file_baton = fb;
216 return SVN_NO_ERROR;
221 static svn_error_t *
222 test_apply_textdelta(void *file_baton,
223 const char *base_checksum,
224 apr_pool_t *pool,
225 svn_txdelta_window_handler_t *handler,
226 void **handler_baton)
228 struct file_baton *fb = file_baton;
230 return svn_fs_apply_textdelta(handler, handler_baton,
231 fb->edit_baton->txn_root,
232 fb->path,
233 base_checksum,
234 NULL,
235 pool);
239 static svn_error_t *
240 test_change_file_prop(void *file_baton,
241 const char *name, const svn_string_t *value,
242 apr_pool_t *pool)
244 struct file_baton *fb = file_baton;
246 return svn_fs_change_node_prop(fb->edit_baton->txn_root,
247 fb->path, name, value, pool);
251 static svn_error_t *
252 test_change_dir_prop(void *parent_baton,
253 const char *name, const svn_string_t *value,
254 apr_pool_t *pool)
256 struct dir_baton *db = parent_baton;
257 struct edit_baton *eb = db->edit_baton;
259 /* Construct the full path of this entry and change the property. */
260 return svn_fs_change_node_prop(eb->txn_root, db->full_path,
261 name, value, pool);
265 /*---------------------------------------------------------------*/
269 svn_error_t *
270 dir_delta_get_editor(const svn_delta_editor_t **editor,
271 void **edit_baton,
272 svn_fs_t *fs,
273 svn_fs_root_t *txn_root,
274 const char *path,
275 apr_pool_t *pool)
277 svn_delta_editor_t *my_editor;
278 struct edit_baton *my_edit_baton;
280 /* Wondering why we don't include test_close_directory,
281 test_close_file, test_absent_directory, and test_absent_file
282 here...? -kfogel, 3 Nov 2003 */
284 /* Set up the editor. */
285 my_editor = svn_delta_default_editor(pool);
286 my_editor->open_root = test_open_root;
287 my_editor->delete_entry = test_delete_entry;
288 my_editor->add_directory = test_add_directory;
289 my_editor->open_directory = test_open_directory;
290 my_editor->add_file = test_add_file;
291 my_editor->open_file = test_open_file;
292 my_editor->apply_textdelta = test_apply_textdelta;
293 my_editor->change_file_prop = test_change_file_prop;
294 my_editor->change_dir_prop = test_change_dir_prop;
296 /* Set up the edit baton. */
297 my_edit_baton = apr_pcalloc(pool, sizeof(*my_edit_baton));
298 my_edit_baton->root_path = apr_pstrdup(pool, path);
299 my_edit_baton->pool = pool;
300 my_edit_baton->fs = fs;
301 my_edit_baton->txn_root = txn_root;
303 *editor = my_editor;
304 *edit_baton = my_edit_baton;
306 return SVN_NO_ERROR;