2 * reporter.c : `reporter' vtable routines for updates.
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 * ====================================================================
24 #include "svn_dirent_uri.h"
27 #include "svn_types.h"
28 #include "svn_error.h"
29 #include "svn_error_codes.h"
31 #include "svn_repos.h"
32 #include "svn_pools.h"
33 #include "svn_props.h"
35 #include "svn_private_config.h"
37 #include "private/svn_dep_compat.h"
38 #include "private/svn_fspath.h"
39 #include "private/svn_subr_private.h"
40 #include "private/svn_string_private.h"
42 #define NUM_CACHED_SOURCE_ROOTS 4
44 /* Theory of operation: we write report operations out to a spill-buffer
45 as we receive them. When the report is finished, we read the
46 operations back out again, using them to guide the progression of
47 the delta between the source and target revs.
49 Spill-buffer content format: we use a simple ad-hoc format to store the
50 report operations. Each report operation is the concatention of
51 the following ("+/-" indicates the single character '+' or '-';
52 <length> and <revnum> are written out as decimal strings):
54 +/- '-' marks the end of the report
56 <length>:<bytes> Length-counted path string
57 +/- '+' indicates the presence of link_path
59 <length>:<bytes> Length-counted link_path string
60 +/- '+' indicates presence of revnum
62 <revnum>: Revnum of set_path or link_path
63 +/- '+' indicates depth other than svn_depth_infinity
65 <depth>: "X","E","F","M" =>
66 svn_depth_{exclude,empty,files,immediates}
67 +/- '+' indicates start_empty field set
68 +/- '+' indicates presence of lock_token field.
70 <length>:<bytes> Length-counted lock_token string
72 Terminology: for brevity, this file frequently uses the prefixes
73 "s_" for source, "t_" for target, and "e_" for editor. Also, to
74 avoid overloading the word "target", we talk about the source
75 "anchor and operand", rather than the usual "anchor and target". */
77 /* Describes the state of a working copy subtree, as given by a
78 report. Because we keep a lookahead pathinfo, we need to allocate
79 each one of these things in a subpool of the report baton and free
81 typedef struct path_info_t
83 const char *path; /* path, munged to be anchor-relative */
84 const char *link_path; /* NULL for set_path or delete_path */
85 svn_revnum_t rev; /* SVN_INVALID_REVNUM for delete_path */
86 svn_depth_t depth; /* Depth of this path, meaningless for files */
87 svn_boolean_t start_empty; /* Meaningless for delete_path */
88 const char *lock_token; /* NULL if no token */
89 apr_pool_t *pool; /* Container pool */
92 /* Describes the standard revision properties that are relevant for
93 reports. Since a particular revision will often show up more than
94 once in the report, we cache these properties for the time of the
96 typedef struct revision_info_t
98 svn_revnum_t rev; /* revision number */
99 svn_string_t* date; /* revision timestamp */
100 svn_string_t* author; /* name of the revisions' author */
103 /* A structure used by the routines within the `reporter' vtable,
104 driven by the client as it describes its working copy revisions. */
105 typedef struct report_baton_t
107 /* Parameters remembered from svn_repos_begin_report3 */
109 const char *fs_base; /* fspath corresponding to wc anchor */
110 const char *s_operand; /* anchor-relative wc target (may be empty) */
111 svn_revnum_t t_rev; /* Revnum which the edit will bring the wc to */
112 const char *t_path; /* FS path the edit will bring the wc to */
113 svn_boolean_t text_deltas; /* Whether to report text deltas */
114 apr_size_t zero_copy_limit; /* Max item size that will be sent using
115 the zero-copy code path. */
117 /* If the client requested a specific depth, record it here; if the
118 client did not, then this is svn_depth_unknown, and the depth of
119 information transmitted from server to client will be governed
120 strictly by the path-associated depths recorded in the report. */
121 svn_depth_t requested_depth;
123 svn_boolean_t ignore_ancestry;
124 svn_boolean_t send_copyfrom_args;
125 svn_boolean_t is_switch;
126 const svn_delta_editor_t *editor;
128 svn_repos_authz_func_t authz_read_func;
129 void *authz_read_baton;
131 /* The spill-buffer holding the report. */
132 svn_spillbuf_reader_t *reader;
134 /* For the actual editor drive, we'll need a lookahead path info
135 entry, a cache of FS roots, and a pool to store them. */
136 path_info_t *lookahead;
137 svn_fs_root_t *t_root;
138 svn_fs_root_t *s_roots[NUM_CACHED_SOURCE_ROOTS];
140 /* Cache for revision properties. This is used to eliminate redundant
142 apr_hash_t *revision_infos;
144 /* This will not change. So, fetch it once and reuse it. */
145 svn_string_t *repos_uuid;
149 /* The type of a function that accepts changes to an object's property
150 list. OBJECT is the object whose properties are being changed.
151 NAME is the name of the property to change. VALUE is the new value
152 for the property, or zero if the property should be deleted. */
153 typedef svn_error_t *proplist_change_fn_t(report_baton_t *b, void *object,
155 const svn_string_t *value,
158 static svn_error_t *delta_dirs(report_baton_t *b, svn_revnum_t s_rev,
159 const char *s_path, const char *t_path,
160 void *dir_baton, const char *e_path,
161 svn_boolean_t start_empty,
162 svn_depth_t wc_depth,
163 svn_depth_t requested_depth,
166 /* --- READING PREVIOUSLY STORED REPORT INFORMATION --- */
169 read_number(apr_uint64_t *num, svn_spillbuf_reader_t *reader, apr_pool_t *pool)
176 SVN_ERR(svn_spillbuf__reader_getc(&c, reader, pool));
179 *num = *num * 10 + (c - '0');
185 read_string(const char **str, svn_spillbuf_reader_t *reader, apr_pool_t *pool)
192 SVN_ERR(read_number(&len, reader, pool));
194 /* Len can never be less than zero. But could len be so large that
195 len + 1 wraps around and we end up passing 0 to apr_palloc(),
196 thus getting a pointer to no storage? Probably not (16 exabyte
197 string, anyone?) but let's be future-proof anyway. */
198 if (len + 1 < len || len + 1 > APR_SIZE_MAX)
200 /* xgettext doesn't expand preprocessor definitions, so we must
201 pass translatable string to apr_psprintf() function to create
202 intermediate string with appropriate format specifier. */
203 return svn_error_createf(SVN_ERR_REPOS_BAD_REVISION_REPORT, NULL,
205 _("Invalid length (%%%s) when "
206 "about to read a string"),
211 size = (apr_size_t)len;
212 buf = apr_palloc(pool, size+1);
215 SVN_ERR(svn_spillbuf__reader_read(&amt, reader, buf, size, pool));
216 SVN_ERR_ASSERT(amt == size);
224 read_rev(svn_revnum_t *rev, svn_spillbuf_reader_t *reader, apr_pool_t *pool)
229 SVN_ERR(svn_spillbuf__reader_getc(&c, reader, pool));
232 SVN_ERR(read_number(&num, reader, pool));
233 *rev = (svn_revnum_t) num;
236 *rev = SVN_INVALID_REVNUM;
240 /* Read a single character to set *DEPTH (having already read '+')
241 from READER. PATH is the path to which the depth applies, and is
242 used for error reporting only. */
244 read_depth(svn_depth_t *depth, svn_spillbuf_reader_t *reader, const char *path,
249 SVN_ERR(svn_spillbuf__reader_getc(&c, reader, pool));
253 *depth = svn_depth_exclude;
256 *depth = svn_depth_empty;
259 *depth = svn_depth_files;
262 *depth = svn_depth_immediates;
265 /* Note that we do not tolerate explicit representation of
266 svn_depth_infinity here, because that's not how
267 write_path_info() writes it. */
269 return svn_error_createf(SVN_ERR_REPOS_BAD_REVISION_REPORT, NULL,
270 _("Invalid depth (%c) for path '%s'"), c, path);
276 /* Read a report operation *PI out of READER. Set *PI to NULL if we
277 have reached the end of the report. */
279 read_path_info(path_info_t **pi,
280 svn_spillbuf_reader_t *reader,
285 SVN_ERR(svn_spillbuf__reader_getc(&c, reader, pool));
292 *pi = apr_palloc(pool, sizeof(**pi));
293 SVN_ERR(read_string(&(*pi)->path, reader, pool));
294 SVN_ERR(svn_spillbuf__reader_getc(&c, reader, pool));
296 SVN_ERR(read_string(&(*pi)->link_path, reader, pool));
298 (*pi)->link_path = NULL;
299 SVN_ERR(read_rev(&(*pi)->rev, reader, pool));
300 SVN_ERR(svn_spillbuf__reader_getc(&c, reader, pool));
302 SVN_ERR(read_depth(&((*pi)->depth), reader, (*pi)->path, pool));
304 (*pi)->depth = svn_depth_infinity;
305 SVN_ERR(svn_spillbuf__reader_getc(&c, reader, pool));
306 (*pi)->start_empty = (c == '+');
307 SVN_ERR(svn_spillbuf__reader_getc(&c, reader, pool));
309 SVN_ERR(read_string(&(*pi)->lock_token, reader, pool));
311 (*pi)->lock_token = NULL;
316 /* Return true if PI's path is a child of PREFIX (which has length PLEN). */
318 relevant(path_info_t *pi, const char *prefix, apr_size_t plen)
320 return (pi && strncmp(pi->path, prefix, plen) == 0 &&
321 (!*prefix || pi->path[plen] == '/'));
324 /* Fetch the next pathinfo from B->reader for a descendant of
325 PREFIX. If the next pathinfo is for an immediate child of PREFIX,
326 set *ENTRY to the path component of the report information and
327 *INFO to the path information for that entry. If the next pathinfo
328 is for a grandchild or other more remote descendant of PREFIX, set
329 *ENTRY to the immediate child corresponding to that descendant and
330 set *INFO to NULL. If the next pathinfo is not for a descendant of
331 PREFIX, or if we reach the end of the report, set both *ENTRY and
334 At all times, B->lookahead is presumed to be the next pathinfo not
335 yet returned as an immediate child, or NULL if we have reached the
336 end of the report. Because we use a lookahead element, we can't
337 rely on the usual nested pool lifetimes, so allocate each pathinfo
338 in a subpool of the report baton's pool. The caller should delete
339 (*INFO)->pool when it is done with the information. */
341 fetch_path_info(report_baton_t *b, const char **entry, path_info_t **info,
342 const char *prefix, apr_pool_t *pool)
344 apr_size_t plen = strlen(prefix);
345 const char *relpath, *sep;
348 if (!relevant(b->lookahead, prefix, plen))
350 /* No more entries relevant to prefix. */
356 /* Take a look at the prefix-relative part of the path. */
357 relpath = b->lookahead->path + (*prefix ? plen + 1 : 0);
358 sep = strchr(relpath, '/');
361 /* Return the immediate child part; do not advance. */
362 *entry = apr_pstrmemdup(pool, relpath, sep - relpath);
367 /* This is an immediate child; return it and advance. */
369 *info = b->lookahead;
370 subpool = svn_pool_create(b->pool);
371 SVN_ERR(read_path_info(&b->lookahead, b->reader, subpool));
377 /* Skip all path info entries relevant to *PREFIX. Call this when the
378 editor drive skips a directory. */
380 skip_path_info(report_baton_t *b, const char *prefix)
382 apr_size_t plen = strlen(prefix);
385 while (relevant(b->lookahead, prefix, plen))
387 svn_pool_destroy(b->lookahead->pool);
388 subpool = svn_pool_create(b->pool);
389 SVN_ERR(read_path_info(&b->lookahead, b->reader, subpool));
394 /* Return true if there is at least one path info entry relevant to *PREFIX. */
396 any_path_info(report_baton_t *b, const char *prefix)
398 return relevant(b->lookahead, prefix, strlen(prefix));
401 /* --- DRIVING THE EDITOR ONCE THE REPORT IS FINISHED --- */
403 /* While driving the editor, the target root will remain constant, but
404 we may have to jump around between source roots depending on the
405 state of the working copy. If we were to open a root each time we
406 revisit a rev, we would get no benefit from node-id caching; on the
407 other hand, if we hold open all the roots we ever visit, we'll use
408 an unbounded amount of memory. As a compromise, we maintain a
409 fixed-size LRU cache of source roots. get_source_root retrieves a
410 root from the cache, using POOL to allocate the new root if
411 necessary. Be careful not to hold onto the root for too long,
412 particularly after recursing, since another call to get_source_root
415 get_source_root(report_baton_t *b, svn_fs_root_t **s_root, svn_revnum_t rev)
418 svn_fs_root_t *root, *prev = NULL;
420 /* Look for the desired root in the cache, sliding all the unmatched
421 entries backwards a slot to make room for the right one. */
422 for (i = 0; i < NUM_CACHED_SOURCE_ROOTS; i++)
424 root = b->s_roots[i];
425 b->s_roots[i] = prev;
426 if (root && svn_fs_revision_root_revision(root) == rev)
431 /* If we didn't find it, throw out the oldest root and open a new one. */
432 if (i == NUM_CACHED_SOURCE_ROOTS)
435 svn_fs_close_root(prev);
436 SVN_ERR(svn_fs_revision_root(&root, b->repos->fs, rev, b->pool));
439 /* Assign the desired root to the first cache slot and hand it back. */
440 b->s_roots[0] = root;
445 /* Call the directory property-setting function of B->editor to set
446 the property NAME to VALUE on DIR_BATON. */
448 change_dir_prop(report_baton_t *b, void *dir_baton, const char *name,
449 const svn_string_t *value, apr_pool_t *pool)
451 return svn_error_trace(b->editor->change_dir_prop(dir_baton, name, value,
455 /* Call the file property-setting function of B->editor to set the
456 property NAME to VALUE on FILE_BATON. */
458 change_file_prop(report_baton_t *b, void *file_baton, const char *name,
459 const svn_string_t *value, apr_pool_t *pool)
461 return svn_error_trace(b->editor->change_file_prop(file_baton, name, value,
465 /* For the report B, return the relevant revprop data of revision REV in
466 REVISION_INFO. The revision info will be allocated in b->pool.
467 Temporaries get allocated on SCRATCH_POOL. */
469 get_revision_info(report_baton_t *b,
471 revision_info_t** revision_info,
472 apr_pool_t *scratch_pool)
475 svn_string_t *cdate, *author;
476 revision_info_t* info;
478 /* Try to find the info in the report's cache */
479 info = apr_hash_get(b->revision_infos, &rev, sizeof(rev));
482 /* Info is not available, yet.
484 SVN_ERR(svn_fs_revision_proplist(&r_props,
489 /* Extract the committed-date. */
490 cdate = svn_hash_gets(r_props, SVN_PROP_REVISION_DATE);
492 /* Extract the last-author. */
493 author = svn_hash_gets(r_props, SVN_PROP_REVISION_AUTHOR);
495 /* Create a result object */
496 info = apr_palloc(b->pool, sizeof(*info));
498 info->date = cdate ? svn_string_dup(cdate, b->pool) : NULL;
499 info->author = author ? svn_string_dup(author, b->pool) : NULL;
502 apr_hash_set(b->revision_infos, &info->rev, sizeof(rev), info);
505 *revision_info = info;
510 /* Generate the appropriate property editing calls to turn the
511 properties of S_REV/S_PATH into those of B->t_root/T_PATH. If
512 S_PATH is NULL, this is an add, so assume the target starts with no
513 properties. Pass OBJECT on to the editor function wrapper
516 delta_proplists(report_baton_t *b, svn_revnum_t s_rev, const char *s_path,
517 const char *t_path, const char *lock_token,
518 proplist_change_fn_t *change_fn,
519 void *object, apr_pool_t *pool)
521 svn_fs_root_t *s_root;
522 apr_hash_t *s_props = NULL, *t_props;
523 apr_array_header_t *prop_diffs;
526 revision_info_t *revision_info;
527 svn_boolean_t changed;
528 const svn_prop_t *pc;
530 apr_hash_index_t *hi;
532 /* Fetch the created-rev and send entry props. */
533 SVN_ERR(svn_fs_node_created_rev(&crev, b->t_root, t_path, pool));
534 if (SVN_IS_VALID_REVNUM(crev))
536 /* convert committed-rev to string */
537 char buf[SVN_INT64_BUFFER_SIZE];
540 cr_str.len = svn__i64toa(buf, crev);
542 /* Transmit the committed-rev. */
543 SVN_ERR(change_fn(b, object,
544 SVN_PROP_ENTRY_COMMITTED_REV, &cr_str, pool));
546 SVN_ERR(get_revision_info(b, crev, &revision_info, pool));
548 /* Transmit the committed-date. */
549 if (revision_info->date || s_path)
550 SVN_ERR(change_fn(b, object, SVN_PROP_ENTRY_COMMITTED_DATE,
551 revision_info->date, pool));
553 /* Transmit the last-author. */
554 if (revision_info->author || s_path)
555 SVN_ERR(change_fn(b, object, SVN_PROP_ENTRY_LAST_AUTHOR,
556 revision_info->author, pool));
558 /* Transmit the UUID. */
559 SVN_ERR(change_fn(b, object, SVN_PROP_ENTRY_UUID,
560 b->repos_uuid, pool));
563 /* Update lock properties. */
566 SVN_ERR(svn_fs_get_lock(&lock, b->repos->fs, t_path, pool));
568 /* Delete a defunct lock. */
569 if (! lock || strcmp(lock_token, lock->token) != 0)
570 SVN_ERR(change_fn(b, object, SVN_PROP_ENTRY_LOCK_TOKEN,
576 SVN_ERR(get_source_root(b, &s_root, s_rev));
578 /* Is this deltification worth our time? */
579 SVN_ERR(svn_fs_props_changed(&changed, b->t_root, t_path, s_root,
584 /* If so, go ahead and get the source path's properties. */
585 SVN_ERR(svn_fs_node_proplist(&s_props, s_root, s_path, pool));
588 /* Get the target path's properties */
589 SVN_ERR(svn_fs_node_proplist(&t_props, b->t_root, t_path, pool));
591 if (s_props && apr_hash_count(s_props))
593 /* Now transmit the differences. */
594 SVN_ERR(svn_prop_diffs(&prop_diffs, t_props, s_props, pool));
595 for (i = 0; i < prop_diffs->nelts; i++)
597 pc = &APR_ARRAY_IDX(prop_diffs, i, svn_prop_t);
598 SVN_ERR(change_fn(b, object, pc->name, pc->value, pool));
601 else if (apr_hash_count(t_props))
603 /* So source, i.e. all new. Transmit all target props. */
604 for (hi = apr_hash_first(pool, t_props); hi; hi = apr_hash_next(hi))
609 apr_hash_this(hi, &key, NULL, &val);
610 SVN_ERR(change_fn(b, object, key, val, pool));
617 /* Baton type to be passed into send_zero_copy_delta.
619 typedef struct zero_copy_baton_t
621 /* don't process data larger than this limit */
622 apr_size_t zero_copy_limit;
624 /* window handler and baton to send the data to */
625 svn_txdelta_window_handler_t dhandler;
628 /* return value: will be set to TRUE, if the data was processed. */
629 svn_boolean_t zero_copy_succeeded;
632 /* Implement svn_fs_process_contents_func_t. If LEN is smaller than the
633 * limit given in *BATON, send the CONTENTS as an delta windows to the
634 * handler given in BATON and set the ZERO_COPY_SUCCEEDED flag in that
635 * BATON. Otherwise, reset it to FALSE.
636 * Use POOL for temporary allocations.
639 send_zero_copy_delta(const unsigned char *contents,
644 zero_copy_baton_t *zero_copy_baton = baton;
646 /* if the item is too large, the caller must revert to traditional
648 if (len > zero_copy_baton->zero_copy_limit)
650 zero_copy_baton->zero_copy_succeeded = FALSE;
654 SVN_ERR(svn_txdelta_send_contents(contents, len,
655 zero_copy_baton->dhandler,
656 zero_copy_baton->dbaton, pool));
659 zero_copy_baton->zero_copy_succeeded = TRUE;
664 /* Make the appropriate edits on FILE_BATON to change its contents and
665 properties from those in S_REV/S_PATH to those in B->t_root/T_PATH,
666 possibly using LOCK_TOKEN to determine if the client's lock on the file
669 delta_files(report_baton_t *b, void *file_baton, svn_revnum_t s_rev,
670 const char *s_path, const char *t_path, const char *lock_token,
673 svn_boolean_t changed;
674 svn_fs_root_t *s_root = NULL;
675 svn_txdelta_stream_t *dstream = NULL;
676 svn_checksum_t *s_checksum;
677 const char *s_hex_digest = NULL;
678 svn_txdelta_window_handler_t dhandler;
681 /* Compare the files' property lists. */
682 SVN_ERR(delta_proplists(b, s_rev, s_path, t_path, lock_token,
683 change_file_prop, file_baton, pool));
687 SVN_ERR(get_source_root(b, &s_root, s_rev));
689 /* We're not interested in the theoretical difference between "has
690 contents which have not changed with respect to" and "has the same
691 actual contents as" when sending text-deltas. If we know the
692 delta is an empty one, we avoiding sending it in either case. */
693 SVN_ERR(svn_repos__compare_files(&changed, b->t_root, t_path,
694 s_root, s_path, pool));
699 SVN_ERR(svn_fs_file_checksum(&s_checksum, svn_checksum_md5, s_root,
700 s_path, TRUE, pool));
701 s_hex_digest = svn_checksum_to_cstring(s_checksum, pool);
704 /* Send the delta stream if desired, or just a NULL window if not. */
705 SVN_ERR(b->editor->apply_textdelta(file_baton, s_hex_digest, pool,
706 &dhandler, &dbaton));
708 if (dhandler != svn_delta_noop_window_handler)
712 /* if we send deltas against empty streams, we may use our
714 if (b->zero_copy_limit > 0 && s_path == NULL)
716 zero_copy_baton_t baton;
717 svn_boolean_t called = FALSE;
719 baton.zero_copy_limit = b->zero_copy_limit;
720 baton.dhandler = dhandler;
721 baton.dbaton = dbaton;
722 baton.zero_copy_succeeded = FALSE;
723 SVN_ERR(svn_fs_try_process_file_contents(&called,
725 send_zero_copy_delta,
728 /* data has been available and small enough,
729 i.e. been processed? */
730 if (called && baton.zero_copy_succeeded)
734 SVN_ERR(svn_fs_get_file_delta_stream(&dstream, s_root, s_path,
735 b->t_root, t_path, pool));
736 SVN_ERR(svn_txdelta_send_txstream(dstream, dhandler, dbaton, pool));
739 SVN_ERR(dhandler(NULL, dbaton));
745 /* Determine if the user is authorized to view B->t_root/PATH. */
747 check_auth(report_baton_t *b, svn_boolean_t *allowed, const char *path,
750 if (b->authz_read_func)
751 return svn_error_trace(b->authz_read_func(allowed, b->t_root, path,
752 b->authz_read_baton, pool));
757 /* Create a dirent in *ENTRY for the given ROOT and PATH. We use this to
758 replace the source or target dirent when a report pathinfo tells us to
759 change paths or revisions. */
761 fake_dirent(const svn_fs_dirent_t **entry, svn_fs_root_t *root,
762 const char *path, apr_pool_t *pool)
764 svn_node_kind_t kind;
765 svn_fs_dirent_t *ent;
767 SVN_ERR(svn_fs_check_path(&kind, root, path, pool));
768 if (kind == svn_node_none)
772 ent = apr_palloc(pool, sizeof(**entry));
773 /* ### All callers should be updated to pass just one of these
775 ent->name = (*path == '/') ? svn_fspath__basename(path, pool)
776 : svn_relpath_basename(path, pool);
777 SVN_ERR(svn_fs_node_id(&ent->id, root, path, pool));
785 /* Given REQUESTED_DEPTH, WC_DEPTH and the current entry's KIND,
786 determine whether we need to send the whole entry, not just deltas.
787 Please refer to delta_dirs' docstring for an explanation of the
788 conditionals below. */
790 is_depth_upgrade(svn_depth_t wc_depth,
791 svn_depth_t requested_depth,
792 svn_node_kind_t kind)
794 if (requested_depth == svn_depth_unknown
795 || requested_depth <= wc_depth
796 || wc_depth == svn_depth_immediates)
799 if (kind == svn_node_file
800 && wc_depth == svn_depth_files)
803 if (kind == svn_node_dir
804 && wc_depth == svn_depth_empty
805 && requested_depth == svn_depth_files)
812 /* Call the B->editor's add_file() function to create PATH as a child
813 of PARENT_BATON, returning a new baton in *NEW_FILE_BATON.
814 However, make an attempt to send 'copyfrom' arguments if they're
815 available, by examining the closest copy of the original file
816 O_PATH within B->t_root. If any copyfrom args are discovered,
817 return those in *COPYFROM_PATH and *COPYFROM_REV; otherwise leave
818 those return args untouched. */
820 add_file_smartly(report_baton_t *b,
824 void **new_file_baton,
825 const char **copyfrom_path,
826 svn_revnum_t *copyfrom_rev,
829 /* ### TODO: use a subpool to do this work, clear it at the end? */
830 svn_fs_t *fs = svn_repos_fs(b->repos);
831 svn_fs_root_t *closest_copy_root = NULL;
832 const char *closest_copy_path = NULL;
834 /* Pre-emptively assume no copyfrom args exist. */
835 *copyfrom_path = NULL;
836 *copyfrom_rev = SVN_INVALID_REVNUM;
838 if (b->send_copyfrom_args)
840 /* Find the destination of the nearest 'copy event' which may have
841 caused o_path@t_root to exist. svn_fs_closest_copy only returns paths
842 starting with '/', so make sure o_path always starts with a '/'
845 o_path = apr_pstrcat(pool, "/", o_path, (char *)NULL);
847 SVN_ERR(svn_fs_closest_copy(&closest_copy_root, &closest_copy_path,
848 b->t_root, o_path, pool));
849 if (closest_copy_root != NULL)
851 /* If the destination of the copy event is the same path as
852 o_path, then we've found something interesting that should
853 have 'copyfrom' history. */
854 if (strcmp(closest_copy_path, o_path) == 0)
856 SVN_ERR(svn_fs_copied_from(copyfrom_rev, copyfrom_path,
857 closest_copy_root, closest_copy_path,
859 if (b->authz_read_func)
861 svn_boolean_t allowed;
862 svn_fs_root_t *copyfrom_root;
863 SVN_ERR(svn_fs_revision_root(©from_root, fs,
864 *copyfrom_rev, pool));
865 SVN_ERR(b->authz_read_func(&allowed, copyfrom_root,
866 *copyfrom_path, b->authz_read_baton,
870 *copyfrom_path = NULL;
871 *copyfrom_rev = SVN_INVALID_REVNUM;
878 return svn_error_trace(b->editor->add_file(path, parent_baton,
879 *copyfrom_path, *copyfrom_rev,
880 pool, new_file_baton));
884 /* Emit a series of editing operations to transform a source entry to
887 S_REV and S_PATH specify the source entry. S_ENTRY contains the
888 already-looked-up information about the node-revision existing at
889 that location. S_PATH and S_ENTRY may be NULL if the entry does
890 not exist in the source. S_PATH may be non-NULL and S_ENTRY may be
891 NULL if the caller expects INFO to modify the source to an existing
894 B->t_root and T_PATH specify the target entry. T_ENTRY contains
895 the already-looked-up information about the node-revision existing
896 at that location. T_PATH and T_ENTRY may be NULL if the entry does
897 not exist in the target.
899 DIR_BATON and E_PATH contain the parameters which should be passed
900 to the editor calls--DIR_BATON for the parent directory baton and
901 E_PATH for the pathname. (E_PATH is the anchor-relative working
902 copy pathname, which may differ from the source and target
903 pathnames if the report contains a link_path.)
905 INFO contains the report information for this working copy path, or
906 NULL if there is none. This function will internally modify the
907 source and target entries as appropriate based on the report
910 WC_DEPTH and REQUESTED_DEPTH are propagated to delta_dirs() if
911 necessary. Refer to delta_dirs' docstring to find out what
912 should happen for various combinations of WC_DEPTH/REQUESTED_DEPTH. */
914 update_entry(report_baton_t *b, svn_revnum_t s_rev, const char *s_path,
915 const svn_fs_dirent_t *s_entry, const char *t_path,
916 const svn_fs_dirent_t *t_entry, void *dir_baton,
917 const char *e_path, path_info_t *info, svn_depth_t wc_depth,
918 svn_depth_t requested_depth, apr_pool_t *pool)
920 svn_fs_root_t *s_root;
921 svn_boolean_t allowed, related;
923 svn_checksum_t *checksum;
924 const char *hex_digest;
926 /* For non-switch operations, follow link_path in the target. */
927 if (info && info->link_path && !b->is_switch)
929 t_path = info->link_path;
930 SVN_ERR(fake_dirent(&t_entry, b->t_root, t_path, pool));
933 if (info && !SVN_IS_VALID_REVNUM(info->rev))
935 /* Delete this entry in the source. */
939 else if (info && s_path)
941 /* Follow the rev and possibly path in this entry. */
942 s_path = (info->link_path) ? info->link_path : s_path;
944 SVN_ERR(get_source_root(b, &s_root, s_rev));
945 SVN_ERR(fake_dirent(&s_entry, s_root, s_path, pool));
948 /* Don't let the report carry us somewhere nonexistent. */
949 if (s_path && !s_entry)
950 return svn_error_createf(SVN_ERR_FS_NOT_FOUND, NULL,
951 _("Working copy path '%s' does not exist in "
952 "repository"), e_path);
954 /* If the source and target both exist and are of the same kind,
955 then find out whether they're related. If they're exactly the
956 same, then we don't have to do anything (unless the report has
957 changes to the source). If we're ignoring ancestry, then any two
958 nodes of the same type are related enough for us. */
960 if (s_entry && t_entry && s_entry->kind == t_entry->kind)
962 int distance = svn_fs_compare_ids(s_entry->id, t_entry->id);
963 if (distance == 0 && !any_path_info(b, e_path)
964 && (requested_depth <= wc_depth || t_entry->kind == svn_node_file))
969 if (!info->start_empty)
973 if (!info->lock_token)
976 SVN_ERR(svn_fs_get_lock(&lock, b->repos->fs, t_path, pool));
977 if (lock && (strcmp(lock->token, info->lock_token) == 0))
982 related = (distance != -1 || b->ignore_ancestry);
985 /* If there's a source and it's not related to the target, nuke it. */
986 if (s_entry && !related)
988 svn_revnum_t deleted_rev;
990 SVN_ERR(svn_repos_deleted_rev(svn_fs_root_fs(b->t_root), t_path,
991 s_rev, b->t_rev, &deleted_rev,
994 if (!SVN_IS_VALID_REVNUM(deleted_rev))
996 /* Two possibilities: either the thing doesn't exist in S_REV; or
997 it wasn't deleted between S_REV and B->T_REV. In the first case,
998 I think we should leave DELETED_REV as SVN_INVALID_REVNUM, but
999 in the second, it should be set to B->T_REV-1 for the call to
1000 delete_entry() below. */
1001 svn_node_kind_t kind;
1003 SVN_ERR(svn_fs_check_path(&kind, b->t_root, t_path, pool));
1004 if (kind != svn_node_none)
1005 deleted_rev = b->t_rev - 1;
1008 SVN_ERR(b->editor->delete_entry(e_path, deleted_rev, dir_baton,
1013 /* If there's no target, we have nothing more to do. */
1015 return svn_error_trace(skip_path_info(b, e_path));
1017 /* Check if the user is authorized to find out about the target. */
1018 SVN_ERR(check_auth(b, &allowed, t_path, pool));
1021 if (t_entry->kind == svn_node_dir)
1022 SVN_ERR(b->editor->absent_directory(e_path, dir_baton, pool));
1024 SVN_ERR(b->editor->absent_file(e_path, dir_baton, pool));
1025 return svn_error_trace(skip_path_info(b, e_path));
1028 if (t_entry->kind == svn_node_dir)
1031 SVN_ERR(b->editor->open_directory(e_path, dir_baton, s_rev, pool,
1034 SVN_ERR(b->editor->add_directory(e_path, dir_baton, NULL,
1035 SVN_INVALID_REVNUM, pool,
1038 SVN_ERR(delta_dirs(b, s_rev, s_path, t_path, new_baton, e_path,
1039 info ? info->start_empty : FALSE,
1040 wc_depth, requested_depth, pool));
1041 return svn_error_trace(b->editor->close_directory(new_baton, pool));
1047 SVN_ERR(b->editor->open_file(e_path, dir_baton, s_rev, pool,
1049 SVN_ERR(delta_files(b, new_baton, s_rev, s_path, t_path,
1050 info ? info->lock_token : NULL, pool));
1054 svn_revnum_t copyfrom_rev = SVN_INVALID_REVNUM;
1055 const char *copyfrom_path = NULL;
1056 SVN_ERR(add_file_smartly(b, e_path, dir_baton, t_path, &new_baton,
1057 ©from_path, ©from_rev, pool));
1058 if (! copyfrom_path)
1059 /* Send txdelta between empty file (s_path@s_rev doesn't
1060 exist) and added file (t_path@t_root). */
1061 SVN_ERR(delta_files(b, new_baton, s_rev, s_path, t_path,
1062 info ? info->lock_token : NULL, pool));
1064 /* Send txdelta between copied file (copyfrom_path@copyfrom_rev)
1065 and added file (tpath@t_root). */
1066 SVN_ERR(delta_files(b, new_baton, copyfrom_rev, copyfrom_path,
1067 t_path, info ? info->lock_token : NULL, pool));
1070 SVN_ERR(svn_fs_file_checksum(&checksum, svn_checksum_md5, b->t_root,
1071 t_path, TRUE, pool));
1072 hex_digest = svn_checksum_to_cstring(checksum, pool);
1073 return svn_error_trace(b->editor->close_file(new_baton, hex_digest,
1078 /* A helper macro for when we have to recurse into subdirectories. */
1079 #define DEPTH_BELOW_HERE(depth) ((depth) == svn_depth_immediates) ? \
1080 svn_depth_empty : (depth)
1082 /* Emit edits within directory DIR_BATON (with corresponding path
1083 E_PATH) with the changes from the directory S_REV/S_PATH to the
1084 directory B->t_rev/T_PATH. S_PATH may be NULL if the entry does
1085 not exist in the source.
1087 WC_DEPTH is this path's depth as reported by set_path/link_path.
1088 REQUESTED_DEPTH is derived from the depth set by
1089 svn_repos_begin_report().
1091 When iterating over this directory's entries, the following tables
1092 describe what happens for all possible combinations
1093 of WC_DEPTH/REQUESTED_DEPTH (rows represent WC_DEPTH, columns
1094 represent REQUESTED_DEPTH):
1097 X: ignore this entry (it's either below the requested depth, or
1098 if the requested depth is svn_depth_unknown, below the working
1100 o: handle this entry normally
1101 U: handle the entry as if it were a newly added repository path
1102 (the client is upgrading to a deeper wc and doesn't currently
1103 have this entry, but it should be there after the upgrade, so we
1104 need to send the whole thing, not just deltas)
1107 ______________________________________________________________
1108 | req. depth| unknown | empty | files | immediates | infinity |
1109 |wc. depth | | | | | |
1110 |___________|_________|_______|_______|____________|__________|
1111 |empty | X | X | U | U | U |
1112 |___________|_________|_______|_______|____________|__________|
1113 |files | o | X | o | o | o |
1114 |___________|_________|_______|_______|____________|__________|
1115 |immediates | o | X | o | o | o |
1116 |___________|_________|_______|_______|____________|__________|
1117 |infinity | o | X | o | o | o |
1118 |___________|_________|_______|_______|____________|__________|
1121 ______________________________________________________________
1122 | req. depth| unknown | empty | files | immediates | infinity |
1123 |wc. depth | | | | | |
1124 |___________|_________|_______|_______|____________|__________|
1125 |empty | X | X | X | U | U |
1126 |___________|_________|_______|_______|____________|__________|
1127 |files | X | X | X | U | U |
1128 |___________|_________|_______|_______|____________|__________|
1129 |immediates | o | X | X | o | o |
1130 |___________|_________|_______|_______|____________|__________|
1131 |infinity | o | X | X | o | o |
1132 |___________|_________|_______|_______|____________|__________|
1134 These rules are enforced by the is_depth_upgrade() function and by
1135 various other checks below.
1137 static svn_error_t *
1138 delta_dirs(report_baton_t *b, svn_revnum_t s_rev, const char *s_path,
1139 const char *t_path, void *dir_baton, const char *e_path,
1140 svn_boolean_t start_empty, svn_depth_t wc_depth,
1141 svn_depth_t requested_depth, apr_pool_t *pool)
1143 svn_fs_root_t *s_root;
1144 apr_hash_t *s_entries = NULL, *t_entries;
1145 apr_hash_index_t *hi;
1146 apr_pool_t *subpool;
1147 const char *name, *s_fullpath, *t_fullpath, *e_fullpath;
1150 /* Compare the property lists. If we're starting empty, pass a NULL
1151 source path so that we add all the properties.
1153 When we support directory locks, we must pass the lock token here. */
1154 SVN_ERR(delta_proplists(b, s_rev, start_empty ? NULL : s_path, t_path,
1155 NULL, change_dir_prop, dir_baton, pool));
1157 if (requested_depth > svn_depth_empty
1158 || requested_depth == svn_depth_unknown)
1160 /* Get the list of entries in each of source and target. */
1161 if (s_path && !start_empty)
1163 SVN_ERR(get_source_root(b, &s_root, s_rev));
1164 SVN_ERR(svn_fs_dir_entries(&s_entries, s_root, s_path, pool));
1166 SVN_ERR(svn_fs_dir_entries(&t_entries, b->t_root, t_path, pool));
1168 /* Iterate over the report information for this directory. */
1169 subpool = svn_pool_create(pool);
1173 const svn_fs_dirent_t *s_entry, *t_entry;
1175 svn_pool_clear(subpool);
1176 SVN_ERR(fetch_path_info(b, &name, &info, e_path, subpool));
1180 /* Invalid revnum means we should delete, unless this is
1181 just an excluded subpath. */
1183 && !SVN_IS_VALID_REVNUM(info->rev)
1184 && info->depth != svn_depth_exclude)
1186 /* We want to perform deletes before non-replacement adds,
1187 for graceful handling of case-only renames on
1188 case-insensitive client filesystems. So, if the report
1189 item is a delete, remove the entry from the source hash,
1190 but don't update the entry yet. */
1192 svn_hash_sets(s_entries, name, NULL);
1196 e_fullpath = svn_relpath_join(e_path, name, subpool);
1197 t_fullpath = svn_fspath__join(t_path, name, subpool);
1198 t_entry = svn_hash_gets(t_entries, name);
1199 s_fullpath = s_path ? svn_fspath__join(s_path, name, subpool) : NULL;
1200 s_entry = s_entries ?
1201 svn_hash_gets(s_entries, name) : NULL;
1203 /* The only special cases here are
1205 - When requested_depth is files but the reported path is
1206 a directory. This is technically a client error, but we
1207 handle it anyway, by skipping the entry.
1209 - When the reported depth is svn_depth_exclude.
1211 if ((! info || info->depth != svn_depth_exclude)
1212 && (requested_depth != svn_depth_files
1213 || ((! t_entry || t_entry->kind != svn_node_dir)
1214 && (! s_entry || s_entry->kind != svn_node_dir))))
1215 SVN_ERR(update_entry(b, s_rev, s_fullpath, s_entry, t_fullpath,
1216 t_entry, dir_baton, e_fullpath, info,
1218 : DEPTH_BELOW_HERE(wc_depth),
1219 DEPTH_BELOW_HERE(requested_depth), subpool));
1221 /* Don't revisit this name in the target or source entries. */
1222 svn_hash_sets(t_entries, name, NULL);
1224 /* Keep the entry for later process if it is reported as
1225 excluded and got deleted in repos. */
1226 && (! info || info->depth != svn_depth_exclude || t_entry))
1227 svn_hash_sets(s_entries, name, NULL);
1229 /* pathinfo entries live in their own subpools due to lookahead,
1230 so we need to clear each one out as we finish with it. */
1232 svn_pool_destroy(info->pool);
1235 /* Remove any deleted entries. Do this before processing the
1236 target, for graceful handling of case-only renames. */
1239 for (hi = apr_hash_first(pool, s_entries);
1241 hi = apr_hash_next(hi))
1243 const svn_fs_dirent_t *s_entry;
1245 svn_pool_clear(subpool);
1246 s_entry = svn__apr_hash_index_val(hi);
1248 if (svn_hash_gets(t_entries, s_entry->name) == NULL)
1250 svn_revnum_t deleted_rev;
1252 if (s_entry->kind == svn_node_file
1253 && wc_depth < svn_depth_files)
1256 if (s_entry->kind == svn_node_dir
1257 && (wc_depth < svn_depth_immediates
1258 || requested_depth == svn_depth_files))
1261 /* There is no corresponding target entry, so delete. */
1262 e_fullpath = svn_relpath_join(e_path, s_entry->name, subpool);
1263 SVN_ERR(svn_repos_deleted_rev(svn_fs_root_fs(b->t_root),
1264 svn_fspath__join(t_path,
1268 &deleted_rev, subpool));
1270 SVN_ERR(b->editor->delete_entry(e_fullpath,
1272 dir_baton, subpool));
1277 /* Loop over the dirents in the target. */
1278 for (hi = apr_hash_first(pool, t_entries); hi; hi = apr_hash_next(hi))
1280 const svn_fs_dirent_t *s_entry, *t_entry;
1282 svn_pool_clear(subpool);
1283 t_entry = svn__apr_hash_index_val(hi);
1285 if (is_depth_upgrade(wc_depth, requested_depth, t_entry->kind))
1287 /* We're making the working copy deeper, pretend the source
1294 if (t_entry->kind == svn_node_file
1295 && requested_depth == svn_depth_unknown
1296 && wc_depth < svn_depth_files)
1299 if (t_entry->kind == svn_node_dir
1300 && (wc_depth < svn_depth_immediates
1301 || requested_depth == svn_depth_files))
1304 /* Look for an entry with the same name
1305 in the source dirents. */
1306 s_entry = s_entries ?
1307 svn_hash_gets(s_entries, t_entry->name)
1309 s_fullpath = s_entry ?
1310 svn_fspath__join(s_path, t_entry->name, subpool) : NULL;
1313 /* Compose the report, editor, and target paths for this entry. */
1314 e_fullpath = svn_relpath_join(e_path, t_entry->name, subpool);
1315 t_fullpath = svn_fspath__join(t_path, t_entry->name, subpool);
1317 SVN_ERR(update_entry(b, s_rev, s_fullpath, s_entry, t_fullpath,
1318 t_entry, dir_baton, e_fullpath, NULL,
1319 DEPTH_BELOW_HERE(wc_depth),
1320 DEPTH_BELOW_HERE(requested_depth),
1325 /* Destroy iteration subpool. */
1326 svn_pool_destroy(subpool);
1328 return SVN_NO_ERROR;
1331 static svn_error_t *
1332 drive(report_baton_t *b, svn_revnum_t s_rev, path_info_t *info,
1335 const char *t_anchor, *s_fullpath;
1336 svn_boolean_t allowed, info_is_set_path;
1337 svn_fs_root_t *s_root;
1338 const svn_fs_dirent_t *s_entry, *t_entry;
1341 /* Compute the target path corresponding to the working copy anchor,
1342 and check its authorization. */
1343 t_anchor = *b->s_operand ? svn_fspath__dirname(b->t_path, pool) : b->t_path;
1344 SVN_ERR(check_auth(b, &allowed, t_anchor, pool));
1346 return svn_error_create
1347 (SVN_ERR_AUTHZ_ROOT_UNREADABLE, NULL,
1348 _("Not authorized to open root of edit operation"));
1350 /* Collect information about the source and target nodes. */
1351 s_fullpath = svn_fspath__join(b->fs_base, b->s_operand, pool);
1352 SVN_ERR(get_source_root(b, &s_root, s_rev));
1353 SVN_ERR(fake_dirent(&s_entry, s_root, s_fullpath, pool));
1354 SVN_ERR(fake_dirent(&t_entry, b->t_root, b->t_path, pool));
1356 /* If the operand is a locally added file or directory, it won't
1357 exist in the source, so accept that. */
1358 info_is_set_path = (SVN_IS_VALID_REVNUM(info->rev) && !info->link_path);
1359 if (info_is_set_path && !s_entry)
1362 /* Check if the target path exists first. */
1363 if (!*b->s_operand && !(t_entry))
1364 return svn_error_createf(SVN_ERR_FS_PATH_SYNTAX, NULL,
1365 _("Target path '%s' does not exist"),
1368 /* If the anchor is the operand, the source and target must be dirs.
1369 Check this before opening the root to avoid modifying the wc. */
1370 else if (!*b->s_operand && (!s_entry || s_entry->kind != svn_node_dir
1371 || t_entry->kind != svn_node_dir))
1372 return svn_error_create(SVN_ERR_FS_PATH_SYNTAX, NULL,
1373 _("Cannot replace a directory from within"));
1375 SVN_ERR(b->editor->set_target_revision(b->edit_baton, b->t_rev, pool));
1376 SVN_ERR(b->editor->open_root(b->edit_baton, s_rev, pool, &root_baton));
1378 /* If the anchor is the operand, diff the two directories; otherwise
1379 update the operand within the anchor directory. */
1381 SVN_ERR(delta_dirs(b, s_rev, s_fullpath, b->t_path, root_baton,
1382 "", info->start_empty, info->depth, b->requested_depth,
1385 SVN_ERR(update_entry(b, s_rev, s_fullpath, s_entry, b->t_path,
1386 t_entry, root_baton, b->s_operand, info,
1387 info->depth, b->requested_depth, pool));
1389 return svn_error_trace(b->editor->close_directory(root_baton, pool));
1392 /* Initialize the baton fields for editor-driving, and drive the editor. */
1393 static svn_error_t *
1394 finish_report(report_baton_t *b, apr_pool_t *pool)
1397 apr_pool_t *subpool;
1401 /* Save our pool to manage the lookahead and fs_root cache with. */
1404 /* Add the end marker. */
1405 SVN_ERR(svn_spillbuf__reader_write(b->reader, "-", 1, pool));
1407 /* Read the first pathinfo from the report and verify that it is a top-level
1409 SVN_ERR(read_path_info(&info, b->reader, pool));
1410 if (!info || strcmp(info->path, b->s_operand) != 0
1411 || info->link_path || !SVN_IS_VALID_REVNUM(info->rev))
1412 return svn_error_create(SVN_ERR_REPOS_BAD_REVISION_REPORT, NULL,
1413 _("Invalid report for top level of working copy"));
1416 /* Initialize the lookahead pathinfo. */
1417 subpool = svn_pool_create(pool);
1418 SVN_ERR(read_path_info(&b->lookahead, b->reader, subpool));
1420 if (b->lookahead && strcmp(b->lookahead->path, b->s_operand) == 0)
1422 /* If the operand of the wc operation is switched or deleted,
1423 then info above is just a place-holder, and the only thing we
1424 have to do is pass the revision it contains to open_root.
1425 The next pathinfo actually describes the target. */
1427 return svn_error_create(SVN_ERR_REPOS_BAD_REVISION_REPORT, NULL,
1428 _("Two top-level reports with no target"));
1429 /* If the client issued a set-path followed by a delete-path, we need
1430 to respect the depth set by the initial set-path. */
1431 if (! SVN_IS_VALID_REVNUM(b->lookahead->rev))
1433 b->lookahead->depth = info->depth;
1435 info = b->lookahead;
1436 SVN_ERR(read_path_info(&b->lookahead, b->reader, subpool));
1439 /* Open the target root and initialize the source root cache. */
1440 SVN_ERR(svn_fs_revision_root(&b->t_root, b->repos->fs, b->t_rev, pool));
1441 for (i = 0; i < NUM_CACHED_SOURCE_ROOTS; i++)
1442 b->s_roots[i] = NULL;
1445 svn_error_t *err = svn_error_trace(drive(b, s_rev, info, pool));
1447 if (err == SVN_NO_ERROR)
1448 return svn_error_trace(b->editor->close_edit(b->edit_baton, pool));
1450 return svn_error_trace(
1451 svn_error_compose_create(err,
1452 b->editor->abort_edit(b->edit_baton,
1457 /* --- COLLECTING THE REPORT INFORMATION --- */
1459 /* Record a report operation into the spill buffer. Return an error
1460 if DEPTH is svn_depth_unknown. */
1461 static svn_error_t *
1462 write_path_info(report_baton_t *b, const char *path, const char *lpath,
1463 svn_revnum_t rev, svn_depth_t depth,
1464 svn_boolean_t start_empty,
1465 const char *lock_token, apr_pool_t *pool)
1467 const char *lrep, *rrep, *drep, *ltrep, *rep;
1469 /* Munge the path to be anchor-relative, so that we can use edit paths
1471 path = svn_relpath_join(b->s_operand, path, pool);
1473 lrep = lpath ? apr_psprintf(pool, "+%" APR_SIZE_T_FMT ":%s",
1474 strlen(lpath), lpath) : "-";
1475 rrep = (SVN_IS_VALID_REVNUM(rev)) ?
1476 apr_psprintf(pool, "+%ld:", rev) : "-";
1478 if (depth == svn_depth_exclude)
1480 else if (depth == svn_depth_empty)
1482 else if (depth == svn_depth_files)
1484 else if (depth == svn_depth_immediates)
1486 else if (depth == svn_depth_infinity)
1489 return svn_error_createf(SVN_ERR_REPOS_BAD_ARGS, NULL,
1490 _("Unsupported report depth '%s'"),
1491 svn_depth_to_word(depth));
1493 ltrep = lock_token ? apr_psprintf(pool, "+%" APR_SIZE_T_FMT ":%s",
1494 strlen(lock_token), lock_token) : "-";
1495 rep = apr_psprintf(pool, "+%" APR_SIZE_T_FMT ":%s%s%s%s%c%s",
1496 strlen(path), path, lrep, rrep, drep,
1497 start_empty ? '+' : '-', ltrep);
1498 return svn_error_trace(
1499 svn_spillbuf__reader_write(b->reader, rep, strlen(rep), pool));
1503 svn_repos_set_path3(void *baton, const char *path, svn_revnum_t rev,
1504 svn_depth_t depth, svn_boolean_t start_empty,
1505 const char *lock_token, apr_pool_t *pool)
1507 return svn_error_trace(
1508 write_path_info(baton, path, NULL, rev, depth, start_empty,
1513 svn_repos_link_path3(void *baton, const char *path, const char *link_path,
1514 svn_revnum_t rev, svn_depth_t depth,
1515 svn_boolean_t start_empty,
1516 const char *lock_token, apr_pool_t *pool)
1518 if (depth == svn_depth_exclude)
1519 return svn_error_create(SVN_ERR_REPOS_BAD_ARGS, NULL,
1520 _("Depth 'exclude' not supported for link"));
1522 return svn_error_trace(
1523 write_path_info(baton, path, link_path, rev, depth,
1524 start_empty, lock_token, pool));
1528 svn_repos_delete_path(void *baton, const char *path, apr_pool_t *pool)
1530 /* We pass svn_depth_infinity because deletion of a path always
1531 deletes everything underneath it. */
1532 return svn_error_trace(
1533 write_path_info(baton, path, NULL, SVN_INVALID_REVNUM,
1534 svn_depth_infinity, FALSE, NULL, pool));
1538 svn_repos_finish_report(void *baton, apr_pool_t *pool)
1540 report_baton_t *b = baton;
1542 return svn_error_trace(finish_report(b, pool));
1546 svn_repos_abort_report(void *baton, apr_pool_t *pool)
1548 return SVN_NO_ERROR;
1551 /* --- BEGINNING THE REPORT --- */
1555 svn_repos_begin_report3(void **report_baton,
1556 svn_revnum_t revnum,
1558 const char *fs_base,
1559 const char *s_operand,
1560 const char *switch_path,
1561 svn_boolean_t text_deltas,
1563 svn_boolean_t ignore_ancestry,
1564 svn_boolean_t send_copyfrom_args,
1565 const svn_delta_editor_t *editor,
1567 svn_repos_authz_func_t authz_read_func,
1568 void *authz_read_baton,
1569 apr_size_t zero_copy_limit,
1575 if (depth == svn_depth_exclude)
1576 return svn_error_create(SVN_ERR_REPOS_BAD_ARGS, NULL,
1577 _("Request depth 'exclude' not supported"));
1579 SVN_ERR(svn_fs_get_uuid(repos->fs, &uuid, pool));
1581 /* Build a reporter baton. Copy strings in case the caller doesn't
1582 keep track of them. */
1583 b = apr_palloc(pool, sizeof(*b));
1585 b->fs_base = svn_fspath__canonicalize(fs_base, pool);
1586 b->s_operand = apr_pstrdup(pool, s_operand);
1588 b->t_path = switch_path ? svn_fspath__canonicalize(switch_path, pool)
1589 : svn_fspath__join(b->fs_base, s_operand, pool);
1590 b->text_deltas = text_deltas;
1591 b->zero_copy_limit = zero_copy_limit;
1592 b->requested_depth = depth;
1593 b->ignore_ancestry = ignore_ancestry;
1594 b->send_copyfrom_args = send_copyfrom_args;
1595 b->is_switch = (switch_path != NULL);
1597 b->edit_baton = edit_baton;
1598 b->authz_read_func = authz_read_func;
1599 b->authz_read_baton = authz_read_baton;
1600 b->revision_infos = apr_hash_make(pool);
1602 b->reader = svn_spillbuf__reader_create(1000 /* blocksize */,
1603 1000000 /* maxsize */,
1605 b->repos_uuid = svn_string_create(uuid, pool);
1607 /* Hand reporter back to client. */
1609 return SVN_NO_ERROR;