1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
/*
* export-cmd.c -- Subversion export command
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
/* ==================================================================== */
/*** Includes. ***/
#include "svn_client.h"
#include "svn_error.h"
#include "svn_dirent_uri.h"
#include "svn_path.h"
#include "svn_cmdline.h"
#include "cl.h"
#include "svn_private_config.h"
#include "private/svn_string_private.h"
#include "private/svn_client_private.h"
/*** The export editor code. ***/
/* ---------------------------------------------------------------------- */
/*** A dedicated 'export' editor, which does no .svn/ accounting. ***/
typedef struct edit_baton_t
{
apr_int64_t file_count;
apr_int64_t dir_count;
apr_int64_t byte_count;
apr_int64_t prop_count;
apr_int64_t prop_byte_count;
} edit_baton_t;
static svn_error_t *
set_target_revision(void *edit_baton,
svn_revnum_t target_revision,
apr_pool_t *pool)
{
return SVN_NO_ERROR;
}
/* Just ensure that the main export directory exists. */
static svn_error_t *
open_root(void *edit_baton,
svn_revnum_t base_revision,
apr_pool_t *pool,
void **root_baton)
{
*root_baton = edit_baton;
return SVN_NO_ERROR;
}
/* Ensure the directory exists, and send feedback. */
static svn_error_t *
add_directory(const char *path,
void *parent_baton,
const char *copyfrom_path,
svn_revnum_t copyfrom_revision,
apr_pool_t *pool,
void **baton)
{
edit_baton_t *eb = parent_baton;
eb->dir_count++;
*baton = parent_baton;
return SVN_NO_ERROR;
}
/* Build a file baton. */
static svn_error_t *
add_file(const char *path,
void *parent_baton,
const char *copyfrom_path,
svn_revnum_t copyfrom_revision,
apr_pool_t *pool,
void **baton)
{
edit_baton_t *eb = parent_baton;
eb->file_count++;
*baton = parent_baton;
return SVN_NO_ERROR;
}
static svn_error_t *
window_handler(svn_txdelta_window_t *window, void *baton)
{
edit_baton_t *eb = baton;
if (window != NULL)
eb->byte_count += window->tview_len;
return SVN_NO_ERROR;
}
/* Write incoming data into the tmpfile stream */
static svn_error_t *
apply_textdelta(void *file_baton,
const char *base_checksum,
apr_pool_t *pool,
svn_txdelta_window_handler_t *handler,
void **handler_baton)
{
*handler_baton = file_baton;
*handler = window_handler;
return SVN_NO_ERROR;
}
static svn_error_t *
change_file_prop(void *file_baton,
const char *name,
const svn_string_t *value,
apr_pool_t *pool)
{
edit_baton_t *eb = file_baton;
eb->prop_count++;
eb->prop_byte_count += value->len;
return SVN_NO_ERROR;
}
static svn_error_t *
change_dir_prop(void *dir_baton,
const char *name,
const svn_string_t *value,
apr_pool_t *pool)
{
edit_baton_t *eb = dir_baton;
eb->prop_count++;
return SVN_NO_ERROR;
}
static svn_error_t *
close_file(void *file_baton,
const char *text_checksum,
apr_pool_t *pool)
{
return SVN_NO_ERROR;
}
/*** Public Interfaces ***/
static svn_error_t *
bench_null_export(svn_revnum_t *result_rev,
const char *from_path_or_url,
svn_opt_revision_t *peg_revision,
svn_opt_revision_t *revision,
svn_depth_t depth,
void *baton,
svn_client_ctx_t *ctx,
svn_boolean_t quiet,
apr_pool_t *pool)
{
svn_revnum_t edit_revision = SVN_INVALID_REVNUM;
svn_boolean_t from_is_url = svn_path_is_url(from_path_or_url);
SVN_ERR_ASSERT(peg_revision != NULL);
SVN_ERR_ASSERT(revision != NULL);
if (peg_revision->kind == svn_opt_revision_unspecified)
peg_revision->kind = svn_path_is_url(from_path_or_url)
? svn_opt_revision_head
: svn_opt_revision_working;
if (revision->kind == svn_opt_revision_unspecified)
revision = peg_revision;
if (from_is_url || ! SVN_CLIENT__REVKIND_IS_LOCAL_TO_WC(revision->kind))
{
svn_client__pathrev_t *loc;
svn_ra_session_t *ra_session;
svn_node_kind_t kind;
/* Get the RA connection. */
SVN_ERR(svn_client__ra_session_from_path2(&ra_session, &loc,
from_path_or_url, NULL,
peg_revision,
revision, ctx, pool));
SVN_ERR(svn_ra_check_path(ra_session, "", loc->rev, &kind, pool));
if (kind == svn_node_file)
{
apr_hash_t *props;
/* Since you cannot actually root an editor at a file, we
* manually drive a few functions of our editor. */
/* Step outside the editor-likeness for a moment, to actually talk
* to the repository. */
/* ### note: the stream will not be closed */
SVN_ERR(svn_ra_get_file(ra_session, "", loc->rev,
svn_stream_empty(pool),
NULL, &props, pool));
}
else if (kind == svn_node_dir)
{
void *edit_baton = NULL;
const svn_delta_editor_t *export_editor = NULL;
const svn_ra_reporter3_t *reporter;
void *report_baton;
svn_delta_editor_t *editor = svn_delta_default_editor(pool);
editor->set_target_revision = set_target_revision;
editor->open_root = open_root;
editor->add_directory = add_directory;
editor->add_file = add_file;
editor->apply_textdelta = apply_textdelta;
editor->close_file = close_file;
editor->change_file_prop = change_file_prop;
editor->change_dir_prop = change_dir_prop;
/* for ra_svn, we don't need an editior in quiet mode */
if (!quiet || strncmp(loc->repos_root_url, "svn:", 4))
SVN_ERR(svn_delta_get_cancellation_editor(ctx->cancel_func,
ctx->cancel_baton,
editor,
baton,
&export_editor,
&edit_baton,
pool));
/* Manufacture a basic 'report' to the update reporter. */
SVN_ERR(svn_ra_do_update3(ra_session,
&reporter, &report_baton,
loc->rev,
"", /* no sub-target */
depth,
FALSE, /* don't want copyfrom-args */
FALSE, /* don't want ignore_ancestry */
export_editor, edit_baton,
pool, pool));
SVN_ERR(reporter->set_path(report_baton, "", loc->rev,
/* Depth is irrelevant, as we're
passing start_empty=TRUE anyway. */
svn_depth_infinity,
TRUE, /* "help, my dir is empty!" */
NULL, pool));
SVN_ERR(reporter->finish_report(report_baton, pool));
}
else if (kind == svn_node_none)
{
return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL,
_("URL '%s' doesn't exist"),
from_path_or_url);
}
/* kind == svn_node_unknown not handled */
}
if (result_rev)
*result_rev = edit_revision;
return SVN_NO_ERROR;
}
/*** Code. ***/
/* This implements the `svn_opt_subcommand_t' interface. */
svn_error_t *
svn_cl__null_export(apr_getopt_t *os,
void *baton,
apr_pool_t *pool)
{
svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
const char *from;
apr_array_header_t *targets;
svn_error_t *err;
svn_opt_revision_t peg_revision;
const char *truefrom;
edit_baton_t eb = { 0 };
SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
opt_state->targets,
ctx, FALSE, pool));
/* We want exactly 1 or 2 targets for this subcommand. */
if (targets->nelts < 1)
return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
if (targets->nelts > 2)
return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, 0, NULL);
/* The first target is the `from' path. */
from = APR_ARRAY_IDX(targets, 0, const char *);
/* Get the peg revision if present. */
SVN_ERR(svn_opt_parse_path(&peg_revision, &truefrom, from, pool));
if (opt_state->depth == svn_depth_unknown)
opt_state->depth = svn_depth_infinity;
/* Do the export. */
err = bench_null_export(NULL, truefrom, &peg_revision,
&(opt_state->start_revision),
opt_state->depth,
&eb,
ctx, opt_state->quiet, pool);
if (!opt_state->quiet)
SVN_ERR(svn_cmdline_printf(pool,
_("%15s directories\n"
"%15s files\n"
"%15s bytes in files\n"
"%15s properties\n"
"%15s bytes in properties\n"),
svn__ui64toa_sep(eb.dir_count, ',', pool),
svn__ui64toa_sep(eb.file_count, ',', pool),
svn__ui64toa_sep(eb.byte_count, ',', pool),
svn__ui64toa_sep(eb.prop_count, ',', pool),
svn__ui64toa_sep(eb.prop_byte_count, ',', pool)));
return svn_error_trace(err);
}
|