2 * repos_diff.c -- The diff editor for comparing two repository versions
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 /* This code uses an editor driven by a tree delta between two
25 * repository revisions (REV1 and REV2). For each file encountered in
26 * the delta the editor constructs two temporary files, one for each
27 * revision. This necessitates a separate request for the REV1 version
28 * of the file when the delta shows the file being modified or
29 * deleted. Files that are added by the delta do not require a
30 * separate request, the REV1 version is empty and the delta is
31 * sufficient to construct the REV2 version. When both versions of
32 * each file have been created the diff callback is invoked to display
33 * the difference between the two files. */
39 #include "svn_checksum.h"
42 #include "svn_pools.h"
43 #include "svn_dirent_uri.h"
46 #include "svn_props.h"
47 #include "svn_private_config.h"
51 #include "private/svn_subr_private.h"
52 #include "private/svn_wc_private.h"
53 #include "private/svn_editor.h"
55 /* Overall crawler editor baton. */
57 /* The passed depth */
60 /* The result processor */
61 const svn_diff_tree_processor_t *processor;
63 /* RA_SESSION is the open session for making requests to the RA layer */
64 svn_ra_session_t *ra_session;
66 /* The rev1 from the '-r Rev1:Rev2' command line option */
67 svn_revnum_t revision;
69 /* The rev2 from the '-r Rev1:Rev2' option, specifically set by
70 set_target_revision(). */
71 svn_revnum_t target_revision;
73 /* The path to a temporary empty file used for add/delete
74 differences. The path is cached here so that it can be reused,
75 since all empty files are the same. */
76 const char *empty_file;
78 /* Empty hash used for adds. */
79 apr_hash_t *empty_hash;
81 /* Whether to report text deltas */
82 svn_boolean_t text_deltas;
84 /* A callback used to see if the client wishes to cancel the running
86 svn_cancel_func_t cancel_func;
88 /* A baton to pass to the cancellation callback. */
94 typedef struct deleted_path_notify_t
97 svn_wc_notify_action_t action;
98 svn_wc_notify_state_t state;
99 svn_boolean_t tree_conflicted;
100 } deleted_path_notify_t;
102 /* Directory level baton.
105 /* Gets set if the directory is added rather than replaced/unchanged. */
108 /* Gets set if this operation caused a tree-conflict on this directory
109 * (does not show tree-conflicts persisting from before this operation). */
110 svn_boolean_t tree_conflicted;
112 /* If TRUE, this node is skipped entirely.
113 * This is used to skip all children of a tree-conflicted
114 * directory without setting TREE_CONFLICTED to TRUE everywhere. */
117 /* If TRUE, all children of this directory are skipped. */
118 svn_boolean_t skip_children;
120 /* The path of the directory within the repository */
123 /* The baton for the parent directory, or null if this is the root of the
124 hierarchy to be compared. */
125 struct dir_baton *parent_baton;
127 /* The overall crawler editor baton. */
128 struct edit_baton *edit_baton;
130 /* A cache of any property changes (svn_prop_t) received for this dir. */
131 apr_array_header_t *propchanges;
133 /* Boolean indicating whether a node property was changed */
134 svn_boolean_t has_propchange;
136 /* Baton for svn_diff_tree_processor_t */
138 svn_diff_source_t *left_source;
139 svn_diff_source_t *right_source;
141 /* The pool passed in by add_dir, open_dir, or open_root.
142 Also, the pool this dir baton is allocated in. */
145 /* Base revision of directory. */
146 svn_revnum_t base_revision;
148 /* Number of users of baton. Its pool will be destroyed 0 */
155 /* Reference to parent baton */
156 struct dir_baton *parent_baton;
158 /* Gets set if the file is added rather than replaced. */
161 /* Gets set if this operation caused a tree-conflict on this file
162 * (does not show tree-conflicts persisting from before this operation). */
163 svn_boolean_t tree_conflicted;
165 /* If TRUE, this node is skipped entirely.
166 * This is currently used to skip all children of a tree-conflicted
170 /* The path of the file within the repository */
173 /* The path and APR file handle to the temporary file that contains the
174 first repository version. Also, the pristine-property list of
176 const char *path_start_revision;
177 apr_hash_t *pristine_props;
178 svn_revnum_t base_revision;
180 /* The path and APR file handle to the temporary file that contains the
181 second repository version. These fields are set when processing
182 textdelta and file deletion, and will be NULL if there's no
183 textual difference between the two revisions. */
184 const char *path_end_revision;
186 /* APPLY_HANDLER/APPLY_BATON represent the delta application baton. */
187 svn_txdelta_window_handler_t apply_handler;
190 /* The overall crawler editor baton. */
191 struct edit_baton *edit_baton;
193 /* Holds the checksum of the start revision file */
194 svn_checksum_t *start_md5_checksum;
196 /* Holds the resulting md5 digest of a textdelta transform */
197 unsigned char result_digest[APR_MD5_DIGESTSIZE];
198 svn_checksum_t *result_md5_checksum;
200 /* A cache of any property changes (svn_prop_t) received for this file. */
201 apr_array_header_t *propchanges;
203 /* Boolean indicating whether a node property was changed */
204 svn_boolean_t has_propchange;
206 /* Baton for svn_diff_tree_processor_t */
208 svn_diff_source_t *left_source;
209 svn_diff_source_t *right_source;
211 /* The pool passed in by add_file or open_file.
212 Also, the pool this file_baton is allocated in. */
216 /* Create a new directory baton for PATH in POOL. ADDED is set if
217 * this directory is being added rather than replaced. PARENT_BATON is
218 * the baton of the parent directory (or NULL if this is the root of
219 * the comparison hierarchy). The directory and its parent may or may
220 * not exist in the working copy. EDIT_BATON is the overall crawler
223 static struct dir_baton *
224 make_dir_baton(const char *path,
225 struct dir_baton *parent_baton,
226 struct edit_baton *edit_baton,
228 svn_revnum_t base_revision,
229 apr_pool_t *result_pool)
231 apr_pool_t *dir_pool = svn_pool_create(result_pool);
232 struct dir_baton *dir_baton = apr_pcalloc(dir_pool, sizeof(*dir_baton));
234 dir_baton->parent_baton = parent_baton;
235 dir_baton->edit_baton = edit_baton;
236 dir_baton->added = added;
237 dir_baton->tree_conflicted = FALSE;
238 dir_baton->skip = FALSE;
239 dir_baton->skip_children = FALSE;
240 dir_baton->pool = dir_pool;
241 dir_baton->path = apr_pstrdup(dir_pool, path);
242 dir_baton->propchanges = apr_array_make(dir_pool, 8, sizeof(svn_prop_t));
243 dir_baton->base_revision = base_revision;
247 parent_baton->users++;
252 /* New function. Called by everyone who has a reference when done */
254 release_dir(struct dir_baton *db)
256 assert(db->users > 0);
263 struct dir_baton *pb = db->parent_baton;
265 svn_pool_destroy(db->pool);
268 SVN_ERR(release_dir(pb));
274 /* Create a new file baton for PATH in POOL, which is a child of
275 * directory PARENT_PATH. ADDED is set if this file is being added
276 * rather than replaced. EDIT_BATON is a pointer to the global edit
279 static struct file_baton *
280 make_file_baton(const char *path,
281 struct dir_baton *parent_baton,
283 apr_pool_t *result_pool)
285 apr_pool_t *file_pool = svn_pool_create(result_pool);
286 struct file_baton *file_baton = apr_pcalloc(file_pool, sizeof(*file_baton));
288 file_baton->parent_baton = parent_baton;
289 file_baton->edit_baton = parent_baton->edit_baton;
290 file_baton->added = added;
291 file_baton->tree_conflicted = FALSE;
292 file_baton->skip = FALSE;
293 file_baton->pool = file_pool;
294 file_baton->path = apr_pstrdup(file_pool, path);
295 file_baton->propchanges = apr_array_make(file_pool, 8, sizeof(svn_prop_t));
296 file_baton->base_revision = parent_baton->edit_baton->revision;
298 parent_baton->users++;
303 /* Get revision FB->base_revision of the file described by FB from the
304 * repository, through FB->edit_baton->ra_session.
306 * Unless PROPS_ONLY is true:
307 * Set FB->path_start_revision to the path of a new temporary file containing
309 * Set FB->start_md5_checksum to that file's MD-5 checksum.
310 * Install a pool cleanup handler on FB->pool to delete the file.
313 * Set FB->pristine_props to a new hash containing the file's properties.
315 * Allocate all results in FB->pool.
318 get_file_from_ra(struct file_baton *fb,
319 svn_boolean_t props_only,
320 apr_pool_t *scratch_pool)
324 svn_stream_t *fstream;
326 SVN_ERR(svn_stream_open_unique(&fstream, &(fb->path_start_revision),
327 NULL, svn_io_file_del_on_pool_cleanup,
328 fb->pool, scratch_pool));
330 fstream = svn_stream_checksummed2(fstream, NULL, &fb->start_md5_checksum,
331 svn_checksum_md5, TRUE, fb->pool);
333 /* Retrieve the file and its properties */
334 SVN_ERR(svn_ra_get_file(fb->edit_baton->ra_session,
338 &(fb->pristine_props),
340 SVN_ERR(svn_stream_close(fstream));
344 SVN_ERR(svn_ra_get_file(fb->edit_baton->ra_session,
348 &(fb->pristine_props),
355 /* Remove every no-op property change from CHANGES: that is, remove every
356 entry in which the target value is the same as the value of the
357 corresponding property in PRISTINE_PROPS.
359 Issue #3657 'dav update report handler in skelta mode can cause
360 spurious conflicts'. When communicating with the repository via ra_serf,
361 the change_dir_prop and change_file_prop svn_delta_editor_t
362 callbacks are called (obviously) when a directory or file property has
363 changed between the start and end of the edit. Less obvious however,
364 is that these callbacks may be made describing *all* of the properties
365 on FILE_BATON->PATH when using the DAV providers, not just the change(s).
366 (Specifically ra_serf does it for diff/merge/update/switch).
368 This means that the change_[file|dir]_prop svn_delta_editor_t callbacks
369 may be made where there are no property changes (i.e. a noop change of
370 NAME from VALUE to VALUE). Normally this is harmless, but during a
371 merge it can result in spurious conflicts if the WC's pristine property
372 NAME has a value other than VALUE. In an ideal world the mod_dav_svn
373 update report handler, when in 'skelta' mode and describing changes to
374 a path on which a property has changed, wouldn't ask the client to later
375 fetch all properties and figure out what has changed itself. The server
376 already knows which properties have changed!
378 Regardless, such a change is not yet implemented, and even when it is,
379 the client should DTRT with regard to older servers which behave this
380 way. Hence this little hack: We populate FILE_BATON->PROPCHANGES only
381 with *actual* property changes.
383 See http://subversion.tigris.org/issues/show_bug.cgi?id=3657#desc9 and
384 http://svn.haxx.se/dev/archive-2010-08/0351.shtml for more details.
387 remove_non_prop_changes(apr_hash_t *pristine_props,
388 apr_array_header_t *changes)
392 /* For added nodes, there is nothing to filter. */
393 if (apr_hash_count(pristine_props) == 0)
396 for (i = 0; i < changes->nelts; i++)
398 svn_prop_t *change = &APR_ARRAY_IDX(changes, i, svn_prop_t);
402 const svn_string_t *old_val = svn_hash_gets(pristine_props,
405 if (old_val && svn_string_compare(old_val, change->value))
409 /* Remove the matching change by shifting the rest */
410 for (j = i; j < changes->nelts - 1; j++)
412 APR_ARRAY_IDX(changes, j, svn_prop_t)
413 = APR_ARRAY_IDX(changes, j+1, svn_prop_t);
421 /* Get the empty file associated with the edit baton. This is cached so
422 * that it can be reused, all empty files are the same.
425 get_empty_file(struct edit_baton *eb,
426 const char **empty_file_path)
428 /* Create the file if it does not exist */
429 /* Note that we tried to use /dev/null in r857294, but
430 that won't work on Windows: it's impossible to stat NUL */
432 SVN_ERR(svn_io_open_unique_file3(NULL, &(eb->empty_file), NULL,
433 svn_io_file_del_on_pool_cleanup,
434 eb->pool, eb->pool));
436 *empty_file_path = eb->empty_file;
441 /* An svn_delta_editor_t function. */
443 set_target_revision(void *edit_baton,
444 svn_revnum_t target_revision,
447 struct edit_baton *eb = edit_baton;
449 eb->target_revision = target_revision;
453 /* An svn_delta_editor_t function. The root of the comparison hierarchy */
455 open_root(void *edit_baton,
456 svn_revnum_t base_revision,
460 struct edit_baton *eb = edit_baton;
461 struct dir_baton *db = make_dir_baton("", NULL, eb, FALSE, base_revision,
464 db->left_source = svn_diff__source_create(eb->revision, db->pool);
465 db->right_source = svn_diff__source_create(eb->target_revision, db->pool);
467 SVN_ERR(eb->processor->dir_opened(&db->pdb,
477 db->pool /* scratch_pool */));
483 /* Compare a file being deleted against an empty file.
486 diff_deleted_file(const char *path,
487 struct dir_baton *db,
488 apr_pool_t *scratch_pool)
490 struct edit_baton *eb = db->edit_baton;
491 struct file_baton *fb = make_file_baton(path, db, FALSE, scratch_pool);
492 svn_boolean_t skip = FALSE;
493 svn_diff_source_t *left_source = svn_diff__source_create(eb->revision,
497 SVN_ERR(eb->cancel_func(eb->cancel_baton));
499 SVN_ERR(eb->processor->file_opened(&fb->pfb, &skip, path,
501 NULL /* right_source */,
502 NULL /* copyfrom_source */,
505 scratch_pool, scratch_pool));
508 SVN_ERR(eb->cancel_func(eb->cancel_baton));
513 SVN_ERR(get_file_from_ra(fb, ! eb->text_deltas, scratch_pool));
515 SVN_ERR(eb->processor->file_deleted(fb->path,
517 fb->path_start_revision,
526 /* Recursively walk tree rooted at DIR (at EB->revision) in the repository,
527 * reporting all children as deleted. Part of a workaround for issue 2333.
529 * DIR is a repository path relative to the URL in EB->ra_session. EB is
530 * the overall crawler editor baton. EB->revision must be a valid revision
531 * number, not SVN_INVALID_REVNUM. Use EB->cancel_func (if not null) with
532 * EB->cancel_baton for cancellation.
534 /* ### TODO: Handle depth. */
536 diff_deleted_dir(const char *path,
537 struct dir_baton *pb,
538 apr_pool_t *scratch_pool)
540 struct edit_baton *eb = pb->edit_baton;
541 struct dir_baton *db;
542 apr_pool_t *iterpool = svn_pool_create(scratch_pool);
543 svn_boolean_t skip = FALSE;
544 svn_boolean_t skip_children = FALSE;
545 apr_hash_t *dirents = NULL;
546 apr_hash_t *left_props = NULL;
547 svn_diff_source_t *left_source = svn_diff__source_create(eb->revision,
549 db = make_dir_baton(path, pb, pb->edit_baton, FALSE, SVN_INVALID_REVNUM,
552 SVN_ERR_ASSERT(SVN_IS_VALID_REVNUM(eb->revision));
555 SVN_ERR(eb->cancel_func(eb->cancel_baton));
557 SVN_ERR(eb->processor->dir_opened(&db->pdb, &skip, &skip_children,
560 NULL /* right_source */,
561 NULL /* copyfrom_source */,
564 scratch_pool, iterpool));
566 if (!skip || !skip_children)
567 SVN_ERR(svn_ra_get_dir2(eb->ra_session,
568 skip_children ? NULL : &dirents,
570 skip ? NULL : &left_props,
576 /* The "old" dir will be skipped by the repository report. If required,
577 * crawl it recursively, diffing each file against the empty file. This
578 * is a workaround for issue 2333 "'svn diff URL1 URL2' not reverse of
579 * 'svn diff URL2 URL1'". */
582 apr_hash_index_t *hi;
584 for (hi = apr_hash_first(scratch_pool, dirents); hi;
585 hi = apr_hash_next(hi))
587 const char *child_path;
588 const char *name = apr_hash_this_key(hi);
589 svn_dirent_t *dirent = apr_hash_this_val(hi);
591 svn_pool_clear(iterpool);
593 child_path = svn_relpath_join(path, name, iterpool);
595 if (dirent->kind == svn_node_file)
597 SVN_ERR(diff_deleted_file(child_path, db, iterpool));
599 else if (dirent->kind == svn_node_dir)
601 SVN_ERR(diff_deleted_dir(child_path, db, iterpool));
608 SVN_ERR(eb->processor->dir_deleted(path,
616 SVN_ERR(release_dir(db));
618 svn_pool_destroy(iterpool);
622 /* An svn_delta_editor_t function. */
624 delete_entry(const char *path,
625 svn_revnum_t base_revision,
629 struct dir_baton *pb = parent_baton;
630 struct edit_baton *eb = pb->edit_baton;
631 svn_node_kind_t kind;
632 apr_pool_t *scratch_pool;
635 if (pb->skip_children)
638 scratch_pool = svn_pool_create(eb->pool);
640 /* We need to know if this is a directory or a file */
641 SVN_ERR(svn_ra_check_path(eb->ra_session, path, eb->revision, &kind,
648 SVN_ERR(diff_deleted_file(path, pb, scratch_pool));
653 SVN_ERR(diff_deleted_dir(path, pb, scratch_pool));
660 svn_pool_destroy(scratch_pool);
665 /* An svn_delta_editor_t function. */
667 add_directory(const char *path,
669 const char *copyfrom_path,
670 svn_revnum_t copyfrom_revision,
674 struct dir_baton *pb = parent_baton;
675 struct edit_baton *eb = pb->edit_baton;
676 struct dir_baton *db;
678 /* ### TODO: support copyfrom? */
680 db = make_dir_baton(path, pb, eb, TRUE, SVN_INVALID_REVNUM, pb->pool);
683 /* Skip *everything* within a newly tree-conflicted directory,
684 * and directories the children of which should be skipped. */
685 if (pb->skip_children)
688 db->skip_children = TRUE;
692 db->right_source = svn_diff__source_create(eb->target_revision,
695 SVN_ERR(eb->processor->dir_opened(&db->pdb,
701 NULL /* copyfrom_source */,
704 db->pool, db->pool));
709 /* An svn_delta_editor_t function. */
711 open_directory(const char *path,
713 svn_revnum_t base_revision,
717 struct dir_baton *pb = parent_baton;
718 struct edit_baton *eb = pb->edit_baton;
719 struct dir_baton *db;
721 db = make_dir_baton(path, pb, eb, FALSE, base_revision, pb->pool);
726 if (pb->skip_children)
729 db->skip_children = TRUE;
733 db->left_source = svn_diff__source_create(eb->revision, db->pool);
734 db->right_source = svn_diff__source_create(eb->target_revision, db->pool);
736 SVN_ERR(eb->processor->dir_opened(&db->pdb,
737 &db->skip, &db->skip_children,
744 db->pool, db->pool));
750 /* An svn_delta_editor_t function. */
752 add_file(const char *path,
754 const char *copyfrom_path,
755 svn_revnum_t copyfrom_revision,
759 struct dir_baton *pb = parent_baton;
760 struct edit_baton *eb = pb->edit_baton;
761 struct file_baton *fb;
763 /* ### TODO: support copyfrom? */
765 fb = make_file_baton(path, pb, TRUE, pb->pool);
769 if (pb->skip_children)
775 fb->pristine_props = pb->edit_baton->empty_hash;
777 fb->right_source = svn_diff__source_create(eb->target_revision, fb->pool);
779 SVN_ERR(eb->processor->file_opened(&fb->pfb,
784 NULL /* copy source */,
787 fb->pool, fb->pool));
792 /* An svn_delta_editor_t function. */
794 open_file(const char *path,
796 svn_revnum_t base_revision,
800 struct dir_baton *pb = parent_baton;
801 struct file_baton *fb;
802 struct edit_baton *eb = pb->edit_baton;
803 fb = make_file_baton(path, pb, FALSE, pb->pool);
807 if (pb->skip_children)
813 fb->base_revision = base_revision;
815 fb->left_source = svn_diff__source_create(eb->revision, fb->pool);
816 fb->right_source = svn_diff__source_create(eb->target_revision, fb->pool);
818 SVN_ERR(eb->processor->file_opened(&fb->pfb,
823 NULL /* copy source */,
826 fb->pool, fb->pool));
831 /* Do the work of applying the text delta. */
833 window_handler(svn_txdelta_window_t *window,
836 struct file_baton *fb = window_baton;
838 SVN_ERR(fb->apply_handler(window, fb->apply_baton));
842 fb->result_md5_checksum = svn_checksum__from_digest_md5(
850 /* Implements svn_stream_lazyopen_func_t. */
852 lazy_open_source(svn_stream_t **stream,
854 apr_pool_t *result_pool,
855 apr_pool_t *scratch_pool)
857 struct file_baton *fb = baton;
859 SVN_ERR(svn_stream_open_readonly(stream, fb->path_start_revision,
860 result_pool, scratch_pool));
865 /* Implements svn_stream_lazyopen_func_t. */
867 lazy_open_result(svn_stream_t **stream,
869 apr_pool_t *result_pool,
870 apr_pool_t *scratch_pool)
872 struct file_baton *fb = baton;
874 SVN_ERR(svn_stream_open_unique(stream, &fb->path_end_revision, NULL,
875 svn_io_file_del_on_pool_cleanup,
876 result_pool, scratch_pool));
881 /* An svn_delta_editor_t function. */
883 apply_textdelta(void *file_baton,
884 const char *base_md5_digest,
886 svn_txdelta_window_handler_t *handler,
887 void **handler_baton)
889 struct file_baton *fb = file_baton;
890 svn_stream_t *src_stream;
891 svn_stream_t *result_stream;
892 apr_pool_t *scratch_pool = fb->pool;
894 /* Skip *everything* within a newly tree-conflicted directory. */
897 *handler = svn_delta_noop_window_handler;
898 *handler_baton = NULL;
902 /* If we're not sending file text, then ignore any that we receive. */
903 if (! fb->edit_baton->text_deltas)
905 /* Supply valid paths to indicate there is a text change. */
906 SVN_ERR(get_empty_file(fb->edit_baton, &fb->path_start_revision));
907 SVN_ERR(get_empty_file(fb->edit_baton, &fb->path_end_revision));
909 *handler = svn_delta_noop_window_handler;
910 *handler_baton = NULL;
915 /* We need the expected pristine file, so go get it */
917 SVN_ERR(get_file_from_ra(fb, FALSE, scratch_pool));
919 SVN_ERR(get_empty_file(fb->edit_baton, &(fb->path_start_revision)));
921 SVN_ERR_ASSERT(fb->path_start_revision != NULL);
923 if (base_md5_digest != NULL)
925 svn_checksum_t *base_md5_checksum;
927 SVN_ERR(svn_checksum_parse_hex(&base_md5_checksum, svn_checksum_md5,
928 base_md5_digest, scratch_pool));
930 if (!svn_checksum_match(base_md5_checksum, fb->start_md5_checksum))
931 return svn_error_trace(svn_checksum_mismatch_err(
933 fb->start_md5_checksum,
935 _("Base checksum mismatch for '%s'"),
939 /* Open the file to be used as the base for second revision */
940 src_stream = svn_stream_lazyopen_create(lazy_open_source, fb, TRUE,
943 /* Open the file that will become the second revision after applying the
944 text delta, it starts empty */
945 result_stream = svn_stream_lazyopen_create(lazy_open_result, fb, TRUE,
948 svn_txdelta_apply(src_stream,
952 &(fb->apply_handler), &(fb->apply_baton));
954 *handler = window_handler;
955 *handler_baton = file_baton;
960 /* An svn_delta_editor_t function. When the file is closed we have a temporary
961 * file containing a pristine version of the repository file. This can
962 * be compared against the working copy.
964 * ### Ignore TEXT_CHECKSUM for now. Someday we can use it to verify
965 * ### the integrity of the file being diffed. Done efficiently, this
966 * ### would probably involve calculating the checksum as the data is
967 * ### received, storing the final checksum in the file_baton, and
968 * ### comparing against it here.
971 close_file(void *file_baton,
972 const char *expected_md5_digest,
975 struct file_baton *fb = file_baton;
976 struct dir_baton *pb = fb->parent_baton;
977 struct edit_baton *eb = fb->edit_baton;
978 apr_pool_t *scratch_pool;
980 /* Skip *everything* within a newly tree-conflicted directory. */
983 svn_pool_destroy(fb->pool);
984 SVN_ERR(release_dir(pb));
988 scratch_pool = fb->pool;
990 if (expected_md5_digest && eb->text_deltas)
992 svn_checksum_t *expected_md5_checksum;
994 SVN_ERR(svn_checksum_parse_hex(&expected_md5_checksum, svn_checksum_md5,
995 expected_md5_digest, scratch_pool));
997 if (!svn_checksum_match(expected_md5_checksum, fb->result_md5_checksum))
998 return svn_error_trace(svn_checksum_mismatch_err(
999 expected_md5_checksum,
1000 fb->result_md5_checksum,
1002 _("Checksum mismatch for '%s'"),
1006 if (fb->added || fb->path_end_revision || fb->has_propchange)
1008 apr_hash_t *right_props;
1010 if (!fb->added && !fb->pristine_props)
1012 /* We didn't receive a text change, so we have no pristine props.
1013 Retrieve just the props now. */
1014 SVN_ERR(get_file_from_ra(fb, TRUE, scratch_pool));
1017 if (fb->pristine_props)
1018 remove_non_prop_changes(fb->pristine_props, fb->propchanges);
1020 right_props = svn_prop__patch(fb->pristine_props, fb->propchanges,
1024 SVN_ERR(eb->processor->file_added(fb->path,
1025 NULL /* copyfrom_src */,
1027 NULL /* copyfrom_file */,
1028 fb->path_end_revision,
1029 NULL /* copyfrom_props */,
1035 SVN_ERR(eb->processor->file_changed(fb->path,
1038 fb->path_end_revision
1039 ? fb->path_start_revision
1041 fb->path_end_revision,
1044 (fb->path_end_revision != NULL),
1051 svn_pool_destroy(fb->pool); /* Destroy file and scratch pool */
1053 SVN_ERR(release_dir(pb));
1055 return SVN_NO_ERROR;
1058 /* Report any accumulated prop changes via the 'dir_props_changed' callback,
1059 * and then call the 'dir_closed' callback. Notify about any deleted paths
1060 * within this directory that have not already been notified, and then about
1061 * this directory itself (unless it was added, in which case the notification
1062 * was done at that time).
1064 * An svn_delta_editor_t function. */
1065 static svn_error_t *
1066 close_directory(void *dir_baton,
1069 struct dir_baton *db = dir_baton;
1070 struct edit_baton *eb = db->edit_baton;
1071 apr_pool_t *scratch_pool;
1072 apr_hash_t *pristine_props;
1073 svn_boolean_t send_changed = FALSE;
1075 scratch_pool = db->pool;
1077 if ((db->has_propchange || db->added) && !db->skip)
1081 pristine_props = eb->empty_hash;
1085 SVN_ERR(svn_ra_get_dir2(eb->ra_session, NULL, NULL, &pristine_props,
1086 db->path, db->base_revision, 0, scratch_pool));
1089 if (db->propchanges->nelts > 0)
1091 remove_non_prop_changes(pristine_props, db->propchanges);
1094 if (db->propchanges->nelts > 0 || db->added)
1096 apr_hash_t *right_props;
1098 right_props = svn_prop__patch(pristine_props, db->propchanges,
1103 SVN_ERR(eb->processor->dir_added(db->path,
1104 NULL /* copyfrom */,
1106 NULL /* copyfrom props */,
1114 SVN_ERR(eb->processor->dir_changed(db->path,
1125 send_changed = TRUE; /* Skip dir_closed */
1129 if (! db->skip && !send_changed)
1131 SVN_ERR(eb->processor->dir_closed(db->path,
1138 SVN_ERR(release_dir(db));
1140 return SVN_NO_ERROR;
1144 /* Record a prop change, which we will report later in close_file().
1146 * An svn_delta_editor_t function. */
1147 static svn_error_t *
1148 change_file_prop(void *file_baton,
1150 const svn_string_t *value,
1153 struct file_baton *fb = file_baton;
1154 svn_prop_t *propchange;
1155 svn_prop_kind_t propkind;
1157 /* Skip *everything* within a newly tree-conflicted directory. */
1159 return SVN_NO_ERROR;
1161 propkind = svn_property_kind2(name);
1162 if (propkind == svn_prop_wc_kind)
1163 return SVN_NO_ERROR;
1164 else if (propkind == svn_prop_regular_kind)
1165 fb->has_propchange = TRUE;
1167 propchange = apr_array_push(fb->propchanges);
1168 propchange->name = apr_pstrdup(fb->pool, name);
1169 propchange->value = svn_string_dup(value, fb->pool);
1171 return SVN_NO_ERROR;
1174 /* Make a note of this prop change, to be reported when the dir is closed.
1176 * An svn_delta_editor_t function. */
1177 static svn_error_t *
1178 change_dir_prop(void *dir_baton,
1180 const svn_string_t *value,
1183 struct dir_baton *db = dir_baton;
1184 svn_prop_t *propchange;
1185 svn_prop_kind_t propkind;
1187 /* Skip *everything* within a newly tree-conflicted directory. */
1189 return SVN_NO_ERROR;
1191 propkind = svn_property_kind2(name);
1192 if (propkind == svn_prop_wc_kind)
1193 return SVN_NO_ERROR;
1194 else if (propkind == svn_prop_regular_kind)
1195 db->has_propchange = TRUE;
1197 propchange = apr_array_push(db->propchanges);
1198 propchange->name = apr_pstrdup(db->pool, name);
1199 propchange->value = svn_string_dup(value, db->pool);
1201 return SVN_NO_ERROR;
1205 /* An svn_delta_editor_t function. */
1206 static svn_error_t *
1207 close_edit(void *edit_baton,
1210 struct edit_baton *eb = edit_baton;
1212 svn_pool_destroy(eb->pool);
1214 return SVN_NO_ERROR;
1217 /* Notify that the node at PATH is 'missing'.
1218 * An svn_delta_editor_t function. */
1219 static svn_error_t *
1220 absent_directory(const char *path,
1224 struct dir_baton *pb = parent_baton;
1225 struct edit_baton *eb = pb->edit_baton;
1227 SVN_ERR(eb->processor->node_absent(path, pb->pdb, eb->processor, pool));
1229 return SVN_NO_ERROR;
1233 /* Notify that the node at PATH is 'missing'.
1234 * An svn_delta_editor_t function. */
1235 static svn_error_t *
1236 absent_file(const char *path,
1240 struct dir_baton *pb = parent_baton;
1241 struct edit_baton *eb = pb->edit_baton;
1243 SVN_ERR(eb->processor->node_absent(path, pb->pdb, eb->processor, pool));
1245 return SVN_NO_ERROR;
1248 static svn_error_t *
1249 fetch_kind_func(svn_node_kind_t *kind,
1252 svn_revnum_t base_revision,
1253 apr_pool_t *scratch_pool)
1255 struct edit_baton *eb = baton;
1257 if (!SVN_IS_VALID_REVNUM(base_revision))
1258 base_revision = eb->revision;
1260 SVN_ERR(svn_ra_check_path(eb->ra_session, path, base_revision, kind,
1263 return SVN_NO_ERROR;
1266 static svn_error_t *
1267 fetch_props_func(apr_hash_t **props,
1270 svn_revnum_t base_revision,
1271 apr_pool_t *result_pool,
1272 apr_pool_t *scratch_pool)
1274 struct edit_baton *eb = baton;
1275 svn_node_kind_t node_kind;
1277 if (!SVN_IS_VALID_REVNUM(base_revision))
1278 base_revision = eb->revision;
1280 SVN_ERR(svn_ra_check_path(eb->ra_session, path, base_revision, &node_kind,
1283 if (node_kind == svn_node_file)
1285 SVN_ERR(svn_ra_get_file(eb->ra_session, path, base_revision,
1286 NULL, NULL, props, result_pool));
1288 else if (node_kind == svn_node_dir)
1290 apr_array_header_t *tmp_props;
1292 SVN_ERR(svn_ra_get_dir2(eb->ra_session, NULL, NULL, props, path,
1293 base_revision, 0 /* Dirent fields */,
1295 tmp_props = svn_prop_hash_to_array(*props, result_pool);
1296 SVN_ERR(svn_categorize_props(tmp_props, NULL, NULL, &tmp_props,
1298 *props = svn_prop_array_to_hash(tmp_props, result_pool);
1302 *props = apr_hash_make(result_pool);
1305 return SVN_NO_ERROR;
1308 static svn_error_t *
1309 fetch_base_func(const char **filename,
1312 svn_revnum_t base_revision,
1313 apr_pool_t *result_pool,
1314 apr_pool_t *scratch_pool)
1316 struct edit_baton *eb = baton;
1317 svn_stream_t *fstream;
1320 if (!SVN_IS_VALID_REVNUM(base_revision))
1321 base_revision = eb->revision;
1323 SVN_ERR(svn_stream_open_unique(&fstream, filename, NULL,
1324 svn_io_file_del_on_pool_cleanup,
1325 result_pool, scratch_pool));
1327 err = svn_ra_get_file(eb->ra_session, path, base_revision,
1328 fstream, NULL, NULL, scratch_pool);
1329 if (err && err->apr_err == SVN_ERR_FS_NOT_FOUND)
1331 svn_error_clear(err);
1332 SVN_ERR(svn_stream_close(fstream));
1335 return SVN_NO_ERROR;
1338 return svn_error_trace(err);
1340 SVN_ERR(svn_stream_close(fstream));
1342 return SVN_NO_ERROR;
1345 /* Create a repository diff editor and baton. */
1347 svn_client__get_diff_editor2(const svn_delta_editor_t **editor,
1349 svn_ra_session_t *ra_session,
1351 svn_revnum_t revision,
1352 svn_boolean_t text_deltas,
1353 const svn_diff_tree_processor_t *processor,
1354 svn_cancel_func_t cancel_func,
1356 apr_pool_t *result_pool)
1358 apr_pool_t *editor_pool = svn_pool_create(result_pool);
1359 svn_delta_editor_t *tree_editor = svn_delta_default_editor(editor_pool);
1360 struct edit_baton *eb = apr_pcalloc(editor_pool, sizeof(*eb));
1361 svn_delta_shim_callbacks_t *shim_callbacks =
1362 svn_delta_shim_callbacks_default(editor_pool);
1364 eb->pool = editor_pool;
1367 eb->processor = processor;
1369 eb->ra_session = ra_session;
1371 eb->revision = revision;
1372 eb->target_revision = SVN_INVALID_REVNUM;
1373 eb->empty_file = NULL;
1374 eb->empty_hash = apr_hash_make(eb->pool);
1375 eb->text_deltas = text_deltas;
1376 eb->cancel_func = cancel_func;
1377 eb->cancel_baton = cancel_baton;
1379 tree_editor->set_target_revision = set_target_revision;
1380 tree_editor->open_root = open_root;
1381 tree_editor->delete_entry = delete_entry;
1382 tree_editor->add_directory = add_directory;
1383 tree_editor->open_directory = open_directory;
1384 tree_editor->add_file = add_file;
1385 tree_editor->open_file = open_file;
1386 tree_editor->apply_textdelta = apply_textdelta;
1387 tree_editor->close_file = close_file;
1388 tree_editor->close_directory = close_directory;
1389 tree_editor->change_file_prop = change_file_prop;
1390 tree_editor->change_dir_prop = change_dir_prop;
1391 tree_editor->close_edit = close_edit;
1392 tree_editor->absent_directory = absent_directory;
1393 tree_editor->absent_file = absent_file;
1395 SVN_ERR(svn_delta_get_cancellation_editor(cancel_func, cancel_baton,
1400 shim_callbacks->fetch_kind_func = fetch_kind_func;
1401 shim_callbacks->fetch_props_func = fetch_props_func;
1402 shim_callbacks->fetch_base_func = fetch_base_func;
1403 shim_callbacks->fetch_baton = eb;
1405 SVN_ERR(svn_editor__insert_shims(editor, edit_baton, *editor, *edit_baton,
1406 NULL, NULL, shim_callbacks,
1407 result_pool, result_pool));
1409 return SVN_NO_ERROR;