2 * util.c: general routines defying categorization; eventually I
3 * suspect they'll end up in libsvn_subr, but don't want to
4 * pollute that right now. Note that nothing in here is
5 * specific to working copies.
7 * ====================================================================
8 * Licensed to the Apache Software Foundation (ASF) under one
9 * or more contributor license agreements. See the NOTICE file
10 * distributed with this work for additional information
11 * regarding copyright ownership. The ASF licenses this file
12 * to you under the Apache License, Version 2.0 (the
13 * "License"); you may not use this file except in compliance
14 * with the License. You may obtain a copy of the License at
16 * http://www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing,
19 * software distributed under the License is distributed on an
20 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 * KIND, either express or implied. See the License for the
22 * specific language governing permissions and limitations
24 * ====================================================================
27 #include <apr_pools.h>
28 #include <apr_file_io.h>
31 #include "svn_types.h"
32 #include "svn_error.h"
33 #include "svn_dirent_uri.h"
35 #include "svn_props.h"
36 #include "svn_version.h"
38 #include "wc.h" /* just for prototypes of things in this .c file */
40 #include "private/svn_wc_private.h"
42 #include "svn_private_config.h"
46 svn_wc__ensure_directory(const char *path,
51 SVN_ERR(svn_io_check_path(path, &kind, pool));
53 if (kind != svn_node_none && kind != svn_node_dir)
55 /* If got an error other than dir non-existence, then we can't
56 ensure this directory's existence, so just return the error.
57 Might happen if there's a file in the way, for example. */
58 return svn_error_createf(APR_ENOTDIR, NULL,
59 _("'%s' is not a directory"),
60 svn_dirent_local_style(path, pool));
62 else if (kind == svn_node_none)
64 /* The dir doesn't exist, and it's our job to change that. */
65 SVN_ERR(svn_io_make_dir_recursively(path, pool));
67 else /* No problem, the dir already existed, so just leave. */
68 SVN_ERR_ASSERT(kind == svn_node_dir);
73 /* Return the library version number. */
81 svn_wc_create_notify(const char *path,
82 svn_wc_notify_action_t action,
85 svn_wc_notify_t *ret = apr_pcalloc(pool, sizeof(*ret));
88 ret->kind = svn_node_unknown;
89 ret->content_state = ret->prop_state = svn_wc_notify_state_unknown;
90 ret->lock_state = svn_wc_notify_lock_state_unknown;
91 ret->revision = SVN_INVALID_REVNUM;
92 ret->old_revision = SVN_INVALID_REVNUM;
98 svn_wc_create_notify_url(const char *url,
99 svn_wc_notify_action_t action,
102 svn_wc_notify_t *ret = svn_wc_create_notify(".", action, pool);
108 /* Pool cleanup function to clear an svn_error_t *. */
109 static apr_status_t err_cleanup(void *data)
111 svn_error_clear(data);
117 svn_wc_dup_notify(const svn_wc_notify_t *notify,
120 svn_wc_notify_t *ret = apr_palloc(pool, sizeof(*ret));
125 ret->path = apr_pstrdup(pool, ret->path);
127 ret->mime_type = apr_pstrdup(pool, ret->mime_type);
129 ret->lock = svn_lock_dup(ret->lock, pool);
132 ret->err = svn_error_dup(ret->err);
133 apr_pool_cleanup_register(pool, ret->err, err_cleanup,
134 apr_pool_cleanup_null);
136 if (ret->changelist_name)
137 ret->changelist_name = apr_pstrdup(pool, ret->changelist_name);
138 if (ret->merge_range)
139 ret->merge_range = svn_merge_range_dup(ret->merge_range, pool);
141 ret->url = apr_pstrdup(pool, ret->url);
142 if (ret->path_prefix)
143 ret->path_prefix = apr_pstrdup(pool, ret->path_prefix);
145 ret->prop_name = apr_pstrdup(pool, ret->prop_name);
147 ret->rev_props = svn_prop_hash_dup(ret->rev_props, pool);
153 svn_wc_external_item2_create(svn_wc_external_item2_t **item,
156 *item = apr_pcalloc(pool, sizeof(svn_wc_external_item2_t));
161 svn_wc_external_item2_t *
162 svn_wc_external_item2_dup(const svn_wc_external_item2_t *item,
165 svn_wc_external_item2_t *new_item = apr_palloc(pool, sizeof(*new_item));
169 if (new_item->target_dir)
170 new_item->target_dir = apr_pstrdup(pool, new_item->target_dir);
173 new_item->url = apr_pstrdup(pool, new_item->url);
180 svn_wc_match_ignore_list(const char *str, const apr_array_header_t *list,
183 /* For now, we simply forward to svn_cstring_match_glob_list. In the
184 future, if we support more complex ignore patterns, we would iterate
185 over 'list' ourselves, and decide for each pattern how to handle
188 return svn_cstring_match_glob_list(str, list);
191 svn_wc_conflict_description2_t *
192 svn_wc_conflict_description_create_text2(const char *local_abspath,
193 apr_pool_t *result_pool)
195 svn_wc_conflict_description2_t *conflict;
197 SVN_ERR_ASSERT_NO_RETURN(svn_dirent_is_absolute(local_abspath));
199 conflict = apr_pcalloc(result_pool, sizeof(*conflict));
200 conflict->local_abspath = apr_pstrdup(result_pool, local_abspath);
201 conflict->node_kind = svn_node_file;
202 conflict->kind = svn_wc_conflict_kind_text;
203 conflict->action = svn_wc_conflict_action_edit;
204 conflict->reason = svn_wc_conflict_reason_edited;
208 svn_wc_conflict_description2_t *
209 svn_wc_conflict_description_create_prop2(const char *local_abspath,
210 svn_node_kind_t node_kind,
211 const char *property_name,
212 apr_pool_t *result_pool)
214 svn_wc_conflict_description2_t *conflict;
216 SVN_ERR_ASSERT_NO_RETURN(svn_dirent_is_absolute(local_abspath));
218 conflict = apr_pcalloc(result_pool, sizeof(*conflict));
219 conflict->local_abspath = apr_pstrdup(result_pool, local_abspath);
220 conflict->node_kind = node_kind;
221 conflict->kind = svn_wc_conflict_kind_property;
222 conflict->property_name = apr_pstrdup(result_pool, property_name);
226 svn_wc_conflict_description2_t *
227 svn_wc_conflict_description_create_tree2(
228 const char *local_abspath,
229 svn_node_kind_t node_kind,
230 svn_wc_operation_t operation,
231 const svn_wc_conflict_version_t *src_left_version,
232 const svn_wc_conflict_version_t *src_right_version,
233 apr_pool_t *result_pool)
235 svn_wc_conflict_description2_t *conflict;
237 SVN_ERR_ASSERT_NO_RETURN(svn_dirent_is_absolute(local_abspath));
239 conflict = apr_pcalloc(result_pool, sizeof(*conflict));
240 conflict->local_abspath = apr_pstrdup(result_pool, local_abspath);
241 conflict->node_kind = node_kind;
242 conflict->kind = svn_wc_conflict_kind_tree;
243 conflict->operation = operation;
244 conflict->src_left_version = svn_wc_conflict_version_dup(src_left_version,
246 conflict->src_right_version = svn_wc_conflict_version_dup(src_right_version,
251 svn_wc_conflict_version_t *
252 svn_wc_conflict_version_create2(const char *repos_url,
253 const char *repos_uuid,
254 const char *repos_relpath,
255 svn_revnum_t revision,
256 svn_node_kind_t kind,
257 apr_pool_t *result_pool)
259 svn_wc_conflict_version_t *version;
261 version = apr_pcalloc(result_pool, sizeof(*version));
263 SVN_ERR_ASSERT_NO_RETURN(svn_uri_is_canonical(repos_url, result_pool)
264 && svn_relpath_is_canonical(repos_relpath)
265 && SVN_IS_VALID_REVNUM(revision)
266 /* ### repos_uuid can be NULL :( */);
268 version->repos_url = repos_url;
269 version->peg_rev = revision;
270 version->path_in_repos = repos_relpath;
271 version->node_kind = kind;
272 version->repos_uuid = repos_uuid;
277 svn_wc_conflict_description2_t *
278 svn_wc_conflict_description2_dup(const svn_wc_conflict_description2_t *conflict,
281 svn_wc_conflict_description2_t *new_conflict;
283 new_conflict = apr_pcalloc(pool, sizeof(*new_conflict));
285 /* Shallow copy all members. */
286 *new_conflict = *conflict;
288 if (conflict->local_abspath)
289 new_conflict->local_abspath = apr_pstrdup(pool, conflict->local_abspath);
290 if (conflict->property_name)
291 new_conflict->property_name = apr_pstrdup(pool, conflict->property_name);
292 if (conflict->mime_type)
293 new_conflict->mime_type = apr_pstrdup(pool, conflict->mime_type);
294 if (conflict->base_abspath)
295 new_conflict->base_abspath = apr_pstrdup(pool, conflict->base_abspath);
296 if (conflict->their_abspath)
297 new_conflict->their_abspath = apr_pstrdup(pool, conflict->their_abspath);
298 if (conflict->my_abspath)
299 new_conflict->my_abspath = apr_pstrdup(pool, conflict->my_abspath);
300 if (conflict->merged_file)
301 new_conflict->merged_file = apr_pstrdup(pool, conflict->merged_file);
302 if (conflict->src_left_version)
303 new_conflict->src_left_version =
304 svn_wc_conflict_version_dup(conflict->src_left_version, pool);
305 if (conflict->src_right_version)
306 new_conflict->src_right_version =
307 svn_wc_conflict_version_dup(conflict->src_right_version, pool);
309 /* ### For property conflicts, cd2 stores prop_reject_abspath in
310 * ### their_abspath, and stores theirs_abspath in merged_file. */
311 if (conflict->prop_reject_abspath)
312 new_conflict->prop_reject_abspath = new_conflict->their_abspath;
314 if (conflict->prop_value_base)
315 new_conflict->prop_value_base =
316 svn_string_dup(conflict->prop_value_base, pool);
317 if (conflict->prop_value_working)
318 new_conflict->prop_value_working =
319 svn_string_dup(conflict->prop_value_working, pool);
320 if (conflict->prop_value_incoming_old)
321 new_conflict->prop_value_incoming_old =
322 svn_string_dup(conflict->prop_value_incoming_old, pool);
323 if (conflict->prop_value_incoming_new)
324 new_conflict->prop_value_incoming_new =
325 svn_string_dup(conflict->prop_value_incoming_new, pool);
330 svn_wc_conflict_version_t *
331 svn_wc_conflict_version_dup(const svn_wc_conflict_version_t *version,
332 apr_pool_t *result_pool)
335 svn_wc_conflict_version_t *new_version;
340 new_version = apr_pcalloc(result_pool, sizeof(*new_version));
342 /* Shallow copy all members. */
343 *new_version = *version;
345 if (version->repos_url)
346 new_version->repos_url = apr_pstrdup(result_pool, version->repos_url);
348 if (version->path_in_repos)
349 new_version->path_in_repos = apr_pstrdup(result_pool,
350 version->path_in_repos);
352 if (version->repos_uuid)
353 new_version->repos_uuid = apr_pstrdup(result_pool, version->repos_uuid);
358 svn_wc_conflict_description_t *
359 svn_wc__cd2_to_cd(const svn_wc_conflict_description2_t *conflict,
360 apr_pool_t *result_pool)
362 svn_wc_conflict_description_t *new_conflict;
364 if (conflict == NULL)
367 new_conflict = apr_pcalloc(result_pool, sizeof(*new_conflict));
369 new_conflict->path = apr_pstrdup(result_pool, conflict->local_abspath);
370 new_conflict->node_kind = conflict->node_kind;
371 new_conflict->kind = conflict->kind;
372 new_conflict->action = conflict->action;
373 new_conflict->reason = conflict->reason;
374 if (conflict->src_left_version)
375 new_conflict->src_left_version =
376 svn_wc_conflict_version_dup(conflict->src_left_version, result_pool);
377 if (conflict->src_right_version)
378 new_conflict->src_right_version =
379 svn_wc_conflict_version_dup(conflict->src_right_version, result_pool);
381 switch (conflict->kind)
384 case svn_wc_conflict_kind_property:
385 new_conflict->property_name = apr_pstrdup(result_pool,
386 conflict->property_name);
387 /* Falling through. */
389 case svn_wc_conflict_kind_text:
390 new_conflict->is_binary = conflict->is_binary;
391 if (conflict->mime_type)
392 new_conflict->mime_type = apr_pstrdup(result_pool,
393 conflict->mime_type);
394 if (conflict->base_abspath)
395 new_conflict->base_file = apr_pstrdup(result_pool,
396 conflict->base_abspath);
397 if (conflict->their_abspath)
398 new_conflict->their_file = apr_pstrdup(result_pool,
399 conflict->their_abspath);
400 if (conflict->my_abspath)
401 new_conflict->my_file = apr_pstrdup(result_pool,
402 conflict->my_abspath);
403 if (conflict->merged_file)
404 new_conflict->merged_file = apr_pstrdup(result_pool,
405 conflict->merged_file);
408 case svn_wc_conflict_kind_tree:
409 new_conflict->operation = conflict->operation;
413 /* A NULL access baton is allowable by the API. */
414 new_conflict->access = NULL;
421 svn_wc__fetch_kind_func(svn_node_kind_t *kind,
424 svn_revnum_t base_revision,
425 apr_pool_t *scratch_pool)
427 struct svn_wc__shim_fetch_baton_t *sfb = baton;
428 const char *local_abspath = svn_dirent_join(sfb->base_abspath, path,
431 SVN_ERR(svn_wc__db_read_kind(kind, sfb->db, local_abspath,
432 FALSE /* allow_missing */,
433 TRUE /* show_deleted */,
434 FALSE /* show_hidden */,
442 svn_wc__fetch_props_func(apr_hash_t **props,
445 svn_revnum_t base_revision,
446 apr_pool_t *result_pool,
447 apr_pool_t *scratch_pool)
449 struct svn_wc__shim_fetch_baton_t *sfb = baton;
450 const char *local_abspath = svn_dirent_join(sfb->base_abspath, path,
455 err = svn_wc__db_base_get_props(props, sfb->db, local_abspath, result_pool,
458 err = svn_wc__db_read_props(props, sfb->db, local_abspath,
459 result_pool, scratch_pool);
461 /* If the path doesn't exist, just return an empty set of props. */
462 if (err && err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND)
464 svn_error_clear(err);
465 *props = apr_hash_make(result_pool);
468 return svn_error_trace(err);
475 svn_wc__fetch_base_func(const char **filename,
478 svn_revnum_t base_revision,
479 apr_pool_t *result_pool,
480 apr_pool_t *scratch_pool)
482 struct svn_wc__shim_fetch_baton_t *sfb = baton;
483 const svn_checksum_t *checksum;
485 const char *local_abspath = svn_dirent_join(sfb->base_abspath, path,
488 err = svn_wc__db_base_get_info(NULL, NULL, NULL, NULL, NULL, NULL,
489 NULL, NULL, NULL, NULL, &checksum,
490 NULL, NULL, NULL, NULL, NULL,
491 sfb->db, local_abspath,
492 scratch_pool, scratch_pool);
493 if (err && err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND)
495 svn_error_clear(err);
500 return svn_error_trace(err);
502 if (checksum == NULL)
508 SVN_ERR(svn_wc__db_pristine_get_path(filename, sfb->db, local_abspath,
509 checksum, scratch_pool, scratch_pool));