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 /* ==================================================================== */
26 #include <apr_pools.h>
27 #include <apr_file_io.h>
29 #include "svn_types.h"
30 #include "svn_error.h"
32 #include "svn_delta.h"
35 #include "../svn_test.h"
36 #include "dir-delta-editor.h"
41 svn_fs_root_t
*txn_root
;
42 const char *root_path
;
48 struct edit_baton
*edit_baton
;
49 const char *full_path
;
55 struct edit_baton
*edit_baton
;
62 test_delete_entry(const char *path
,
63 svn_revnum_t revision
,
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
),
77 test_open_root(void *edit_baton
,
78 svn_revnum_t base_revision
,
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
;
94 test_open_directory(const char *path
,
96 svn_revnum_t base_revision
,
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
);
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
,
119 test_add_directory(const char *path
,
121 const char *copyfrom_path
,
122 svn_revnum_t copyfrom_revision
,
123 apr_pool_t
*dir_pool
,
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
);
134 if (copyfrom_path
) /* add with history */
136 svn_fs_root_t
*rev_root
= NULL
;
138 SVN_ERR(svn_fs_revision_root(&rev_root
,
143 SVN_ERR(svn_fs_copy(rev_root
,
149 else /* add without history */
150 SVN_ERR(svn_fs_make_dir(eb
->txn_root
, db
->full_path
, dir_pool
));
158 test_open_file(const char *path
,
160 svn_revnum_t base_revision
,
161 apr_pool_t
*file_pool
,
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
);
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
));
182 test_add_file(const char *path
,
184 const char *copyfrom_path
,
185 svn_revnum_t copyfrom_revision
,
186 apr_pool_t
*file_pool
,
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
);
197 if (copyfrom_path
) /* add with history */
199 svn_fs_root_t
*rev_root
= NULL
;
201 SVN_ERR(svn_fs_revision_root(&rev_root
,
206 SVN_ERR(svn_fs_copy(rev_root
,
212 else /* add without history */
213 SVN_ERR(svn_fs_make_file(eb
->txn_root
, fb
->path
, file_pool
));
222 test_apply_textdelta(void *file_baton
,
223 const char *base_checksum
,
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
,
240 test_change_file_prop(void *file_baton
,
241 const char *name
, const svn_string_t
*value
,
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
);
252 test_change_dir_prop(void *parent_baton
,
253 const char *name
, const svn_string_t
*value
,
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
,
265 /*---------------------------------------------------------------*/
270 dir_delta_get_editor(const svn_delta_editor_t
**editor
,
273 svn_fs_root_t
*txn_root
,
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
;
304 *edit_baton
= my_edit_baton
;