2 * dump_editor.c: The svn_delta_editor_t editor used by svnrdump to
5 * ====================================================================
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership. The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
22 * ====================================================================
25 #include "svn_types.h"
26 #include "svn_props.h"
29 #include "svn_delta.h"
31 #include "private/svn_repos_private.h"
32 #include "private/svn_editor.h"
38 /* The baton used by the dump editor. */
39 struct dump_edit_baton
{
40 /* A backdoor ra session to fetch additional information during the edit. */
41 svn_ra_session_t
*ra_session
;
43 /* The revision we're currently dumping. */
44 svn_revnum_t current_revision
;
48 fetch_base_func(const char **filename
,
51 svn_revnum_t base_revision
,
52 apr_pool_t
*result_pool
,
53 apr_pool_t
*scratch_pool
)
55 struct dump_edit_baton
*eb
= baton
;
56 svn_stream_t
*fstream
;
62 if (! SVN_IS_VALID_REVNUM(base_revision
))
63 base_revision
= eb
->current_revision
- 1;
65 SVN_ERR(svn_stream_open_unique(&fstream
, filename
, NULL
,
66 svn_io_file_del_on_pool_cleanup
,
67 result_pool
, scratch_pool
));
69 err
= svn_ra_get_file(eb
->ra_session
, path
, base_revision
,
70 fstream
, NULL
, NULL
, scratch_pool
);
71 if (err
&& err
->apr_err
== SVN_ERR_FS_NOT_FOUND
)
74 SVN_ERR(svn_stream_close(fstream
));
80 return svn_error_trace(err
);
82 SVN_ERR(svn_stream_close(fstream
));
88 fetch_props_func(apr_hash_t
**props
,
91 svn_revnum_t base_revision
,
92 apr_pool_t
*result_pool
,
93 apr_pool_t
*scratch_pool
)
95 struct dump_edit_baton
*eb
= baton
;
96 svn_node_kind_t node_kind
;
101 if (! SVN_IS_VALID_REVNUM(base_revision
))
102 base_revision
= eb
->current_revision
- 1;
104 SVN_ERR(svn_ra_check_path(eb
->ra_session
, path
, base_revision
, &node_kind
,
107 if (node_kind
== svn_node_file
)
109 SVN_ERR(svn_ra_get_file(eb
->ra_session
, path
, base_revision
,
110 NULL
, NULL
, props
, result_pool
));
112 else if (node_kind
== svn_node_dir
)
114 apr_array_header_t
*tmp_props
;
116 SVN_ERR(svn_ra_get_dir2(eb
->ra_session
, NULL
, NULL
, props
, path
,
117 base_revision
, 0 /* Dirent fields */,
119 tmp_props
= svn_prop_hash_to_array(*props
, result_pool
);
120 SVN_ERR(svn_categorize_props(tmp_props
, NULL
, NULL
, &tmp_props
,
122 *props
= svn_prop_array_to_hash(tmp_props
, result_pool
);
126 *props
= apr_hash_make(result_pool
);
133 fetch_kind_func(svn_node_kind_t
*kind
,
136 svn_revnum_t base_revision
,
137 apr_pool_t
*scratch_pool
)
139 struct dump_edit_baton
*eb
= baton
;
144 if (! SVN_IS_VALID_REVNUM(base_revision
))
145 base_revision
= eb
->current_revision
- 1;
147 SVN_ERR(svn_ra_check_path(eb
->ra_session
, path
, base_revision
, kind
,
154 svn_rdump__get_dump_editor(const svn_delta_editor_t
**editor
,
156 svn_revnum_t revision
,
157 svn_stream_t
*stream
,
158 svn_ra_session_t
*ra_session
,
159 const char *update_anchor_relpath
,
160 svn_cancel_func_t cancel_func
,
164 struct dump_edit_baton
*eb
;
165 svn_delta_shim_callbacks_t
*shim_callbacks
=
166 svn_delta_shim_callbacks_default(pool
);
168 eb
= apr_pcalloc(pool
, sizeof(struct dump_edit_baton
));
169 eb
->ra_session
= ra_session
;
170 eb
->current_revision
= revision
;
172 SVN_ERR(svn_repos__get_dump_editor(editor
, edit_baton
,
173 stream
, update_anchor_relpath
, pool
));
175 /* Wrap this editor in a cancellation editor. */
176 SVN_ERR(svn_delta_get_cancellation_editor(cancel_func
, cancel_baton
,
177 *editor
, *edit_baton
,
181 shim_callbacks
->fetch_base_func
= fetch_base_func
;
182 shim_callbacks
->fetch_props_func
= fetch_props_func
;
183 shim_callbacks
->fetch_kind_func
= fetch_kind_func
;
184 shim_callbacks
->fetch_baton
= eb
;
186 SVN_ERR(svn_editor__insert_shims(editor
, edit_baton
, *editor
, *edit_baton
,
187 NULL
, NULL
, shim_callbacks
, pool
, pool
));