2 * adm_ops.c: routines for affecting working copy administrative
3 * information. NOTE: this code doesn't know where the adm
4 * info is actually stored. Instead, generic handles to
5 * adm data are requested via a reference to some PATH
6 * (PATH being a regular, non-administrative directory or
7 * file in the working copy).
9 * ====================================================================
10 * Licensed to the Apache Software Foundation (ASF) under one
11 * or more contributor license agreements. See the NOTICE file
12 * distributed with this work for additional information
13 * regarding copyright ownership. The ASF licenses this file
14 * to you under the Apache License, Version 2.0 (the
15 * "License"); you may not use this file except in compliance
16 * with the License. You may obtain a copy of the License at
18 * http://www.apache.org/licenses/LICENSE-2.0
20 * Unless required by applicable law or agreed to in writing,
21 * software distributed under the License is distributed on an
22 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23 * KIND, either express or implied. See the License for the
24 * specific language governing permissions and limitations
26 * ====================================================================
34 #include <apr_pools.h>
37 #include <apr_errno.h>
39 #include "svn_private_config.h"
40 #include "svn_types.h"
41 #include "svn_pools.h"
42 #include "svn_string.h"
43 #include "svn_error.h"
44 #include "svn_dirent_uri.h"
50 #include "svn_sorts.h"
53 #include "adm_files.h"
54 #include "conflicts.h"
55 #include "workqueue.h"
57 #include "private/svn_dep_compat.h"
58 #include "private/svn_sorts_private.h"
59 #include "private/svn_subr_private.h"
62 struct svn_wc_committed_queue_t
64 /* The pool in which ->queue is allocated. */
66 /* Mapping (const char *) wcroot_abspath to svn_wc__db_commit_queue_t * */
67 apr_hash_t *wc_queues;
70 typedef struct committed_queue_item_t
72 const char *local_abspath;
73 svn_boolean_t recurse; /* Use legacy recursion */
74 svn_boolean_t committed; /* Process the node as committed */
75 svn_boolean_t remove_lock; /* Remove existing lock on node */
76 svn_boolean_t remove_changelist; /* Remove changelist on node */
78 /* The pristine text checksum. NULL if the old value should be kept
79 and for directories */
80 const svn_checksum_t *new_sha1_checksum;
82 apr_hash_t *new_dav_cache; /* New DAV cache for the node */
83 } committed_queue_item_t;
87 svn_wc__get_committed_queue_pool(const struct svn_wc_committed_queue_t *queue)
93 svn_wc__prop_array_to_hash(const apr_array_header_t *props,
94 apr_pool_t *result_pool)
99 if (props == NULL || props->nelts == 0)
102 prophash = apr_hash_make(result_pool);
104 for (i = 0; i < props->nelts; i++)
106 const svn_prop_t *prop = APR_ARRAY_IDX(props, i, const svn_prop_t *);
107 if (prop->value != NULL)
108 svn_hash_sets(prophash, prop->name, prop->value);
115 svn_wc_committed_queue_t *
116 svn_wc_committed_queue_create(apr_pool_t *pool)
118 svn_wc_committed_queue_t *q;
120 q = apr_palloc(pool, sizeof(*q));
122 q->wc_queues = apr_hash_make(pool);
129 svn_wc_queue_committed4(svn_wc_committed_queue_t *queue,
130 svn_wc_context_t *wc_ctx,
131 const char *local_abspath,
132 svn_boolean_t recurse,
133 svn_boolean_t is_committed,
134 const apr_array_header_t *wcprop_changes,
135 svn_boolean_t remove_lock,
136 svn_boolean_t remove_changelist,
137 const svn_checksum_t *sha1_checksum,
138 apr_pool_t *scratch_pool)
140 const char *wcroot_abspath;
141 svn_wc__db_commit_queue_t *db_queue;
143 SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
145 /* Use the same pool as the one QUEUE was allocated in,
146 to prevent lifetime issues. Intermediate operations
147 should use SCRATCH_POOL. */
149 SVN_ERR(svn_wc__db_get_wcroot(&wcroot_abspath,
150 wc_ctx->db, local_abspath,
151 scratch_pool, scratch_pool));
153 db_queue = svn_hash_gets(queue->wc_queues, wcroot_abspath);
156 wcroot_abspath = apr_pstrdup(queue->pool, wcroot_abspath);
158 SVN_ERR(svn_wc__db_create_commit_queue(&db_queue,
159 wc_ctx->db, wcroot_abspath,
160 queue->pool, scratch_pool));
162 svn_hash_sets(queue->wc_queues, wcroot_abspath, db_queue);
165 return svn_error_trace(
166 svn_wc__db_commit_queue_add(db_queue, local_abspath, recurse,
167 is_committed, remove_lock,
168 remove_changelist, sha1_checksum,
169 svn_wc__prop_array_to_hash(wcprop_changes,
171 queue->pool, scratch_pool));
176 svn_wc_process_committed_queue2(svn_wc_committed_queue_t *queue,
177 svn_wc_context_t *wc_ctx,
178 svn_revnum_t new_revnum,
179 const char *rev_date,
180 const char *rev_author,
181 svn_cancel_func_t cancel_func,
183 apr_pool_t *scratch_pool)
185 apr_array_header_t *wcs;
187 apr_pool_t *iterpool = svn_pool_create(scratch_pool);
191 SVN_ERR(svn_time_from_cstring(&new_date, rev_date, iterpool));
195 /* Process the wc's in order of their paths. */
196 wcs = svn_sort__hash(queue->wc_queues, svn_sort_compare_items_as_paths,
198 for (i = 0; i < wcs->nelts; i++)
200 const svn_sort__item_t *sort_item
201 = &APR_ARRAY_IDX(wcs, i, svn_sort__item_t);
202 svn_wc__db_commit_queue_t *db_queue = sort_item->value;
204 svn_pool_clear(iterpool);
206 SVN_ERR(svn_wc__db_process_commit_queue(wc_ctx->db, db_queue,
207 new_revnum, new_date, rev_author,
211 /* Make sure nothing happens if this function is called again. */
212 apr_hash_clear(queue->wc_queues);
214 /* Ok; everything is committed now. Now we can start calling callbacks */
216 SVN_ERR(cancel_func(cancel_baton));
218 for (i = 0; i < wcs->nelts; i++)
220 const svn_sort__item_t *sort_item
221 = &APR_ARRAY_IDX(wcs, i, svn_sort__item_t);
222 const char *wcroot_abspath = sort_item->key;
224 svn_pool_clear(iterpool);
226 SVN_ERR(svn_wc__wq_run(wc_ctx->db, wcroot_abspath,
227 cancel_func, cancel_baton,
231 svn_pool_destroy(iterpool);
236 /* Schedule the single node at LOCAL_ABSPATH, of kind KIND, for addition in
237 * its parent directory in the WC. It will have the regular properties
238 * provided in PROPS, or none if that is NULL.
240 * If the node is a file, set its on-disk executable and read-only bits to
241 * match its properties and lock state,
242 * ### only if it has an svn:executable or svn:needs-lock property.
243 * ### This is to match the previous behaviour of setting its props
244 * afterwards by calling svn_wc_prop_set4(), but is not very clean.
246 * Sync the on-disk executable and read-only bits accordingly.
249 add_from_disk(svn_wc__db_t *db,
250 const char *local_abspath,
251 svn_node_kind_t kind,
252 const apr_hash_t *props,
253 apr_pool_t *scratch_pool)
255 if (kind == svn_node_file)
257 svn_skel_t *work_item = NULL;
259 if (props && (svn_prop_get_value(props, SVN_PROP_EXECUTABLE)
260 || svn_prop_get_value(props, SVN_PROP_NEEDS_LOCK)))
261 SVN_ERR(svn_wc__wq_build_sync_file_flags(&work_item, db, local_abspath,
262 scratch_pool, scratch_pool));
264 SVN_ERR(svn_wc__db_op_add_file(db, local_abspath, props, work_item,
267 SVN_ERR(svn_wc__wq_run(db, local_abspath, NULL, NULL, scratch_pool));
271 SVN_ERR(svn_wc__db_op_add_directory(db, local_abspath, props, NULL,
279 /* Set *REPOS_ROOT_URL and *REPOS_UUID to the repository of the parent of
280 LOCAL_ABSPATH. REPOS_ROOT_URL and/or REPOS_UUID may be NULL if not
281 wanted. Check that the parent of LOCAL_ABSPATH is a versioned directory
282 in a state in which a new child node can be scheduled for addition;
283 return an error if not. */
285 check_can_add_to_parent(const char **repos_root_url,
286 const char **repos_uuid,
288 const char *local_abspath,
289 apr_pool_t *result_pool,
290 apr_pool_t *scratch_pool)
292 const char *parent_abspath = svn_dirent_dirname(local_abspath, scratch_pool);
293 svn_wc__db_status_t parent_status;
294 svn_node_kind_t parent_kind;
297 SVN_ERR(svn_wc__write_check(db, parent_abspath, scratch_pool));
299 err = svn_wc__db_read_info(&parent_status, &parent_kind, NULL,
300 NULL, repos_root_url, repos_uuid, NULL, NULL,
301 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
302 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
304 db, parent_abspath, result_pool, scratch_pool);
307 || parent_status == svn_wc__db_status_not_present
308 || parent_status == svn_wc__db_status_excluded
309 || parent_status == svn_wc__db_status_server_excluded)
312 svn_error_createf(SVN_ERR_ENTRY_NOT_FOUND, err,
313 _("Can't find parent directory's node while"
314 " trying to add '%s'"),
315 svn_dirent_local_style(local_abspath,
318 else if (parent_status == svn_wc__db_status_deleted)
321 svn_error_createf(SVN_ERR_WC_SCHEDULE_CONFLICT, NULL,
322 _("Can't add '%s' to a parent directory"
323 " scheduled for deletion"),
324 svn_dirent_local_style(local_abspath,
327 else if (parent_kind != svn_node_dir)
328 return svn_error_createf(SVN_ERR_NODE_UNEXPECTED_KIND, NULL,
329 _("Can't schedule an addition of '%s'"
330 " below a not-directory node"),
331 svn_dirent_local_style(local_abspath,
334 /* If we haven't found the repository info yet, find it now. */
335 if ((repos_root_url && ! *repos_root_url)
336 || (repos_uuid && ! *repos_uuid))
338 if (parent_status == svn_wc__db_status_added)
339 SVN_ERR(svn_wc__db_scan_addition(NULL, NULL, NULL,
340 repos_root_url, repos_uuid, NULL,
343 result_pool, scratch_pool));
345 SVN_ERR(svn_wc__db_base_get_info(NULL, NULL, NULL, NULL,
346 repos_root_url, repos_uuid, NULL,
347 NULL, NULL, NULL, NULL, NULL, NULL,
350 result_pool, scratch_pool));
357 /* Check that the on-disk item at LOCAL_ABSPATH can be scheduled for
358 * addition to its WC parent directory.
360 * Set *KIND_P to the kind of node to be added, *DB_ROW_EXISTS_P to whether
361 * it is already a versioned path, and if so, *IS_WC_ROOT_P to whether it's
364 * ### The checks here, and the outputs, are geared towards svn_wc_add4().
367 check_can_add_node(svn_node_kind_t *kind_p,
368 svn_boolean_t *db_row_exists_p,
369 svn_boolean_t *is_wc_root_p,
371 const char *local_abspath,
372 const char *copyfrom_url,
373 svn_revnum_t copyfrom_rev,
374 apr_pool_t *scratch_pool)
376 const char *base_name = svn_dirent_basename(local_abspath, scratch_pool);
377 svn_boolean_t is_wc_root;
378 svn_node_kind_t kind;
379 svn_boolean_t is_special;
381 SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
382 SVN_ERR_ASSERT(!copyfrom_url || (svn_uri_is_canonical(copyfrom_url,
384 && SVN_IS_VALID_REVNUM(copyfrom_rev)));
386 /* Check that the proposed node has an acceptable name. */
387 if (svn_wc_is_adm_dir(base_name, scratch_pool))
388 return svn_error_createf
389 (SVN_ERR_ENTRY_FORBIDDEN, NULL,
390 _("Can't create an entry with a reserved name while trying to add '%s'"),
391 svn_dirent_local_style(local_abspath, scratch_pool));
393 SVN_ERR(svn_path_check_valid(local_abspath, scratch_pool));
395 /* Make sure something's there; set KIND and *KIND_P. */
396 SVN_ERR(svn_io_check_special_path(local_abspath, &kind, &is_special,
398 if (kind == svn_node_none)
399 return svn_error_createf(SVN_ERR_WC_PATH_NOT_FOUND, NULL,
401 svn_dirent_local_style(local_abspath,
403 if (kind == svn_node_unknown)
404 return svn_error_createf(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
405 _("Unsupported node kind for path '%s'"),
406 svn_dirent_local_style(local_abspath,
411 /* Determine whether a DB row for this node EXISTS, and whether it
412 IS_WC_ROOT. If it exists, check that it is in an acceptable state for
413 adding the new node; if not, return an error. */
415 svn_wc__db_status_t status;
416 svn_boolean_t conflicted;
417 svn_boolean_t exists;
419 = svn_wc__db_read_info(&status, NULL, NULL, NULL, NULL, NULL, NULL,
420 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
421 NULL, NULL, NULL, NULL, NULL, NULL,
423 NULL, NULL, NULL, NULL, NULL, NULL,
425 scratch_pool, scratch_pool);
429 if (err->apr_err != SVN_ERR_WC_PATH_NOT_FOUND)
430 return svn_error_trace(err);
432 svn_error_clear(err);
441 /* Note that the node may be in conflict even if it does not
442 * exist on disk (certain tree conflict scenarios). */
444 return svn_error_createf(SVN_ERR_WC_FOUND_CONFLICT, NULL,
445 _("'%s' is an existing item in conflict; "
446 "please mark the conflict as resolved "
447 "before adding a new item here"),
448 svn_dirent_local_style(local_abspath,
452 case svn_wc__db_status_not_present:
454 case svn_wc__db_status_deleted:
455 /* A working copy root should never have a WORKING_NODE */
456 SVN_ERR_ASSERT(!is_wc_root);
458 case svn_wc__db_status_normal:
459 SVN_ERR(svn_wc__db_is_wcroot(&is_wc_root, db, local_abspath,
462 if (is_wc_root && copyfrom_url)
464 /* Integrate a sub working copy in a parent working copy
468 else if (is_wc_root && is_special)
470 /* Adding a symlink to a working copy root.
471 (special_tests.py 23: externals as symlink targets) */
474 /* else: Fall through in default error */
477 return svn_error_createf(
478 SVN_ERR_ENTRY_EXISTS, NULL,
479 _("'%s' is already under version control"),
480 svn_dirent_local_style(local_abspath,
486 *db_row_exists_p = exists;
488 *is_wc_root_p = is_wc_root;
495 /* Convert the nested pristine working copy rooted at LOCAL_ABSPATH into
496 * a copied subtree in the outer working copy.
498 * LOCAL_ABSPATH must be the root of a nested working copy that has no
499 * local modifications. The parent directory of LOCAL_ABSPATH must be a
500 * versioned directory in the outer WC, and must belong to the same
501 * repository as the nested WC. The nested WC will be integrated into the
502 * parent's WC, and will no longer be a separate WC. */
504 integrate_nested_wc_as_copy(svn_wc_context_t *wc_ctx,
505 const char *local_abspath,
506 apr_pool_t *scratch_pool)
508 svn_wc__db_t *db = wc_ctx->db;
509 const char *moved_abspath;
511 /* Drop any references to the wc that is to be rewritten */
512 SVN_ERR(svn_wc__db_drop_root(db, local_abspath, scratch_pool));
514 /* Move the admin dir from the wc to a temporary location: MOVED_ABSPATH */
516 const char *tmpdir_abspath;
517 const char *moved_adm_abspath;
518 const char *adm_abspath;
520 SVN_ERR(svn_wc__db_temp_wcroot_tempdir(&tmpdir_abspath, db,
521 svn_dirent_dirname(local_abspath,
523 scratch_pool, scratch_pool));
524 SVN_ERR(svn_io_open_unique_file3(NULL, &moved_abspath, tmpdir_abspath,
525 svn_io_file_del_on_close,
526 scratch_pool, scratch_pool));
527 SVN_ERR(svn_io_dir_make(moved_abspath, APR_OS_DEFAULT, scratch_pool));
529 adm_abspath = svn_wc__adm_child(local_abspath, "", scratch_pool);
530 moved_adm_abspath = svn_wc__adm_child(moved_abspath, "", scratch_pool);
531 SVN_ERR(svn_io_file_move(adm_abspath, moved_adm_abspath, scratch_pool));
534 /* Copy entries from temporary location into the main db */
535 SVN_ERR(svn_wc_copy3(wc_ctx, moved_abspath, local_abspath,
536 TRUE /* metadata_only */,
537 NULL, NULL, NULL, NULL, scratch_pool));
539 /* Cleanup the temporary admin dir */
540 SVN_ERR(svn_wc__db_drop_root(db, moved_abspath, scratch_pool));
541 SVN_ERR(svn_io_remove_dir2(moved_abspath, FALSE, NULL, NULL,
544 /* The subdir is now part of our parent working copy. Our caller assumes
545 that we return the new node locked, so obtain a lock if we didn't
546 receive the lock via our depth infinity lock */
548 svn_boolean_t owns_lock;
550 SVN_ERR(svn_wc__db_wclock_owns_lock(&owns_lock, db, local_abspath,
551 FALSE, scratch_pool));
553 SVN_ERR(svn_wc__db_wclock_obtain(db, local_abspath, 0, FALSE,
562 svn_wc_add4(svn_wc_context_t *wc_ctx,
563 const char *local_abspath,
565 const char *copyfrom_url,
566 svn_revnum_t copyfrom_rev,
567 svn_cancel_func_t cancel_func,
569 svn_wc_notify_func2_t notify_func,
571 apr_pool_t *scratch_pool)
573 svn_wc__db_t *db = wc_ctx->db;
574 svn_node_kind_t kind;
575 svn_boolean_t db_row_exists;
576 svn_boolean_t is_wc_root;
577 const char *repos_root_url;
578 const char *repos_uuid;
580 SVN_ERR(check_can_add_node(&kind, &db_row_exists, &is_wc_root,
581 db, local_abspath, copyfrom_url, copyfrom_rev,
584 /* Get REPOS_ROOT_URL and REPOS_UUID. Check that the
585 parent is a versioned directory in an acceptable state. */
586 SVN_ERR(check_can_add_to_parent(&repos_root_url, &repos_uuid,
587 db, local_abspath, scratch_pool,
590 /* If we're performing a repos-to-WC copy, check that the copyfrom
591 repository is the same as the parent dir's repository. */
592 if (copyfrom_url && !svn_uri__is_ancestor(repos_root_url, copyfrom_url))
593 return svn_error_createf(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
594 _("The URL '%s' has a different repository "
595 "root than its parent"), copyfrom_url);
597 /* Verify that we can actually integrate the inner working copy */
600 const char *repos_relpath, *inner_repos_root_url, *inner_repos_uuid;
601 const char *inner_url;
603 SVN_ERR(svn_wc__db_base_get_info(NULL, NULL, NULL, &repos_relpath,
604 &inner_repos_root_url,
605 &inner_repos_uuid, NULL, NULL, NULL,
606 NULL, NULL, NULL, NULL, NULL, NULL,
609 scratch_pool, scratch_pool));
611 if (strcmp(inner_repos_uuid, repos_uuid)
612 || strcmp(repos_root_url, inner_repos_root_url))
613 return svn_error_createf(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
614 _("Can't schedule the working copy at '%s' "
615 "from repository '%s' with uuid '%s' "
616 "for addition under a working copy from "
617 "repository '%s' with uuid '%s'."),
618 svn_dirent_local_style(local_abspath,
620 inner_repos_root_url, inner_repos_uuid,
621 repos_root_url, repos_uuid);
623 inner_url = svn_path_url_add_component2(repos_root_url, repos_relpath,
626 if (strcmp(copyfrom_url, inner_url))
627 return svn_error_createf(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
628 _("Can't add '%s' with URL '%s', but with "
629 "the data from '%s'"),
630 svn_dirent_local_style(local_abspath,
632 copyfrom_url, inner_url);
635 if (!copyfrom_url) /* Case 2a: It's a simple add */
637 SVN_ERR(add_from_disk(db, local_abspath, kind, NULL,
639 if (kind == svn_node_dir && !db_row_exists)
641 /* If using the legacy 1.6 interface the parent lock may not
642 be recursive and add is expected to lock the new dir.
644 ### Perhaps the lock should be created in the same
645 transaction that adds the node? */
646 svn_boolean_t owns_lock;
648 SVN_ERR(svn_wc__db_wclock_owns_lock(&owns_lock, db, local_abspath,
649 FALSE, scratch_pool));
651 SVN_ERR(svn_wc__db_wclock_obtain(db, local_abspath, 0, FALSE,
655 else if (!is_wc_root) /* Case 2b: It's a copy from the repository */
657 if (kind == svn_node_file)
659 /* This code should never be used, as it doesn't install proper
660 pristine and/or properties. But it was not an error in the old
661 version of this function.
663 ===> Use svn_wc_add_repos_file4() directly! */
664 svn_stream_t *content = svn_stream_empty(scratch_pool);
666 SVN_ERR(svn_wc_add_repos_file4(wc_ctx, local_abspath,
667 content, NULL, NULL, NULL,
668 copyfrom_url, copyfrom_rev,
669 cancel_func, cancel_baton,
674 const char *repos_relpath =
675 svn_uri_skip_ancestor(repos_root_url, copyfrom_url, scratch_pool);
677 SVN_ERR(svn_wc__db_op_copy_dir(db, local_abspath,
678 apr_hash_make(scratch_pool),
679 copyfrom_rev, 0, NULL,
681 repos_root_url, repos_uuid,
683 NULL /* children */, depth,
685 NULL /* conflicts */,
686 NULL /* work items */,
690 else /* Case 1: Integrating a separate WC into this one, in place */
692 SVN_ERR(integrate_nested_wc_as_copy(wc_ctx, local_abspath,
696 /* Report the addition to the caller. */
697 if (notify_func != NULL)
699 svn_wc_notify_t *notify = svn_wc_create_notify(local_abspath,
703 (*notify_func)(notify_baton, notify, scratch_pool);
711 svn_wc_add_from_disk3(svn_wc_context_t *wc_ctx,
712 const char *local_abspath,
713 const apr_hash_t *props,
714 svn_boolean_t skip_checks,
715 svn_wc_notify_func2_t notify_func,
717 apr_pool_t *scratch_pool)
719 svn_node_kind_t kind;
721 SVN_ERR(check_can_add_node(&kind, NULL, NULL, wc_ctx->db, local_abspath,
722 NULL, SVN_INVALID_REVNUM, scratch_pool));
723 SVN_ERR(check_can_add_to_parent(NULL, NULL, wc_ctx->db, local_abspath,
724 scratch_pool, scratch_pool));
726 /* Canonicalize and check the props */
729 apr_hash_t *new_props;
731 SVN_ERR(svn_wc__canonicalize_props(
733 local_abspath, kind, props, skip_checks,
734 scratch_pool, scratch_pool));
738 /* Add to the DB and maybe update on-disk executable read-only bits */
739 SVN_ERR(add_from_disk(wc_ctx->db, local_abspath, kind, props,
742 /* Report the addition to the caller. */
743 if (notify_func != NULL)
745 svn_wc_notify_t *notify = svn_wc_create_notify(local_abspath,
749 notify->mime_type = svn_prop_get_value(props, SVN_PROP_MIME_TYPE);
750 (*notify_func)(notify_baton, notify, scratch_pool);
756 /* Return a path where nothing exists on disk, within the admin directory
757 belonging to the WCROOT_ABSPATH directory. */
759 nonexistent_path(const char *wcroot_abspath, apr_pool_t *scratch_pool)
761 return svn_wc__adm_child(wcroot_abspath, SVN_WC__ADM_NONEXISTENT_PATH,
767 svn_wc_get_pristine_copy_path(const char *path,
768 const char **pristine_path,
772 const char *local_abspath;
775 SVN_ERR(svn_dirent_get_absolute(&local_abspath, path, pool));
777 SVN_ERR(svn_wc__db_open(&db, NULL, FALSE, TRUE, pool, pool));
778 /* DB is now open. This is seemingly a "light" function that a caller
779 may use repeatedly despite error return values. The rest of this
780 function should aggressively close DB, even in the error case. */
782 err = svn_wc__text_base_path_to_read(pristine_path, db, local_abspath,
784 if (err && err->apr_err == SVN_ERR_WC_PATH_UNEXPECTED_STATUS)
786 /* The node doesn't exist, so return a non-existent path located
788 const char *wcroot_abspath;
790 svn_error_clear(err);
792 err = svn_wc__db_get_wcroot(&wcroot_abspath, db, local_abspath,
795 *pristine_path = nonexistent_path(wcroot_abspath, pool);
798 return svn_error_compose_create(err, svn_wc__db_close(db));
803 svn_wc_get_pristine_contents2(svn_stream_t **contents,
804 svn_wc_context_t *wc_ctx,
805 const char *local_abspath,
806 apr_pool_t *result_pool,
807 apr_pool_t *scratch_pool)
809 return svn_error_trace(svn_wc__get_pristine_contents(contents, NULL,
817 typedef struct get_pristine_lazyopen_baton_t
819 svn_wc_context_t *wc_ctx;
820 const char *wri_abspath;
821 const svn_checksum_t *checksum;
823 } get_pristine_lazyopen_baton_t;
826 /* Implements svn_stream_lazyopen_func_t */
828 get_pristine_lazyopen_func(svn_stream_t **stream,
830 apr_pool_t *result_pool,
831 apr_pool_t *scratch_pool)
833 get_pristine_lazyopen_baton_t *b = baton;
834 const svn_checksum_t *sha1_checksum;
836 /* svn_wc__db_pristine_read() wants a SHA1, so if we have an MD5,
837 we'll use it to lookup the SHA1. */
838 if (b->checksum->kind == svn_checksum_sha1)
839 sha1_checksum = b->checksum;
841 SVN_ERR(svn_wc__db_pristine_get_sha1(&sha1_checksum, b->wc_ctx->db,
842 b->wri_abspath, b->checksum,
843 scratch_pool, scratch_pool));
845 SVN_ERR(svn_wc__db_pristine_read(stream, NULL, b->wc_ctx->db,
846 b->wri_abspath, sha1_checksum,
847 result_pool, scratch_pool));
852 svn_wc__get_pristine_contents_by_checksum(svn_stream_t **contents,
853 svn_wc_context_t *wc_ctx,
854 const char *wri_abspath,
855 const svn_checksum_t *checksum,
856 apr_pool_t *result_pool,
857 apr_pool_t *scratch_pool)
859 svn_boolean_t present;
863 SVN_ERR(svn_wc__db_pristine_check(&present, wc_ctx->db, wri_abspath,
864 checksum, scratch_pool));
868 get_pristine_lazyopen_baton_t *gpl_baton;
870 gpl_baton = apr_pcalloc(result_pool, sizeof(*gpl_baton));
871 gpl_baton->wc_ctx = wc_ctx;
872 gpl_baton->wri_abspath = wri_abspath;
873 gpl_baton->checksum = checksum;
875 *contents = svn_stream_lazyopen_create(get_pristine_lazyopen_func,
876 gpl_baton, FALSE, result_pool);
885 svn_wc_add_lock2(svn_wc_context_t *wc_ctx,
886 const char *local_abspath,
887 const svn_lock_t *lock,
888 apr_pool_t *scratch_pool)
890 svn_wc__db_lock_t db_lock;
892 const svn_string_t *needs_lock;
894 SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
896 SVN_ERR(svn_wc__write_check(wc_ctx->db,
897 svn_dirent_dirname(local_abspath, scratch_pool),
900 db_lock.token = lock->token;
901 db_lock.owner = lock->owner;
902 db_lock.comment = lock->comment;
903 db_lock.date = lock->creation_date;
904 err = svn_wc__db_lock_add(wc_ctx->db, local_abspath, &db_lock, scratch_pool);
907 if (err->apr_err != SVN_ERR_WC_PATH_NOT_FOUND)
908 return svn_error_trace(err);
910 /* Remap the error. */
911 svn_error_clear(err);
912 return svn_error_createf(SVN_ERR_ENTRY_NOT_FOUND, NULL,
913 _("'%s' is not under version control"),
914 svn_dirent_local_style(local_abspath,
918 /* if svn:needs-lock is present, then make the file read-write. */
919 err = svn_wc__internal_propget(&needs_lock, wc_ctx->db, local_abspath,
920 SVN_PROP_NEEDS_LOCK, scratch_pool,
923 if (err && err->apr_err == SVN_ERR_WC_PATH_UNEXPECTED_STATUS)
925 /* The node has non wc representation (e.g. deleted), so
926 we don't want to touch the in-wc file */
927 svn_error_clear(err);
933 SVN_ERR(svn_io_set_file_read_write(local_abspath, FALSE, scratch_pool));
940 svn_wc_remove_lock2(svn_wc_context_t *wc_ctx,
941 const char *local_abspath,
942 apr_pool_t *scratch_pool)
945 svn_skel_t *work_item;
947 SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
949 SVN_ERR(svn_wc__write_check(wc_ctx->db,
950 svn_dirent_dirname(local_abspath, scratch_pool),
953 SVN_ERR(svn_wc__wq_build_sync_file_flags(&work_item,
954 wc_ctx->db, local_abspath,
955 scratch_pool, scratch_pool));
957 err = svn_wc__db_lock_remove(wc_ctx->db, local_abspath, work_item,
961 if (err->apr_err != SVN_ERR_WC_PATH_NOT_FOUND)
962 return svn_error_trace(err);
964 /* Remap the error. */
965 svn_error_clear(err);
966 return svn_error_createf(SVN_ERR_ENTRY_NOT_FOUND, NULL,
967 _("'%s' is not under version control"),
968 svn_dirent_local_style(local_abspath,
972 return svn_error_trace(svn_wc__wq_run(wc_ctx->db, local_abspath,
973 NULL, NULL /* cancel*/,
979 svn_wc_set_changelist2(svn_wc_context_t *wc_ctx,
980 const char *local_abspath,
981 const char *new_changelist,
983 const apr_array_header_t *changelist_filter,
984 svn_cancel_func_t cancel_func,
986 svn_wc_notify_func2_t notify_func,
988 apr_pool_t *scratch_pool)
990 /* Assert that we aren't being asked to set an empty changelist. */
991 SVN_ERR_ASSERT(! (new_changelist && new_changelist[0] == '\0'));
993 SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
995 SVN_ERR(svn_wc__db_op_set_changelist(wc_ctx->db, local_abspath,
996 new_changelist, changelist_filter,
997 depth, notify_func, notify_baton,
998 cancel_func, cancel_baton,
1001 return SVN_NO_ERROR;
1004 struct get_cl_fn_baton
1008 svn_changelist_receiver_t callback_func;
1009 void *callback_baton;
1013 static svn_error_t *
1014 get_node_changelist(const char *local_abspath,
1015 svn_node_kind_t kind,
1017 apr_pool_t *scratch_pool)
1019 struct get_cl_fn_baton *b = baton;
1020 const char *changelist;
1022 SVN_ERR(svn_wc__db_read_info(NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1023 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1024 NULL, NULL, NULL, NULL, NULL, &changelist,
1025 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1026 b->db, local_abspath,
1027 scratch_pool, scratch_pool));
1029 || (changelist && svn_hash_gets(b->clhash, changelist) != NULL))
1030 SVN_ERR(b->callback_func(b->callback_baton, local_abspath,
1031 changelist, scratch_pool));
1033 return SVN_NO_ERROR;
1038 svn_wc_get_changelists(svn_wc_context_t *wc_ctx,
1039 const char *local_abspath,
1041 const apr_array_header_t *changelist_filter,
1042 svn_changelist_receiver_t callback_func,
1043 void *callback_baton,
1044 svn_cancel_func_t cancel_func,
1046 apr_pool_t *scratch_pool)
1048 struct get_cl_fn_baton gnb;
1050 gnb.db = wc_ctx->db;
1052 gnb.callback_func = callback_func;
1053 gnb.callback_baton = callback_baton;
1055 if (changelist_filter)
1056 SVN_ERR(svn_hash_from_cstring_keys(&gnb.clhash, changelist_filter,
1059 return svn_error_trace(
1060 svn_wc__internal_walk_children(wc_ctx->db, local_abspath, FALSE,
1061 changelist_filter, get_node_changelist,
1063 cancel_func, cancel_baton,
1070 svn_wc__internal_changelist_match(svn_wc__db_t *db,
1071 const char *local_abspath,
1072 const apr_hash_t *clhash,
1073 apr_pool_t *scratch_pool)
1076 const char *changelist;
1081 err = svn_wc__db_read_info(NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1082 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1083 NULL, NULL, NULL, NULL, NULL, &changelist,
1084 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1085 db, local_abspath, scratch_pool, scratch_pool);
1088 svn_error_clear(err);
1093 && svn_hash_gets((apr_hash_t *)clhash, changelist) != NULL);
1098 svn_wc__changelist_match(svn_wc_context_t *wc_ctx,
1099 const char *local_abspath,
1100 const apr_hash_t *clhash,
1101 apr_pool_t *scratch_pool)
1103 return svn_wc__internal_changelist_match(wc_ctx->db, local_abspath, clhash,