/* Try to update a directory external at PATH to URL at REVISION. Use POOL for temporary allocations, and use the client context CTX. */ static svn_error_t * switch_dir_external(const char *local_abspath, const char *url, const svn_opt_revision_t *peg_revision, const svn_opt_revision_t *revision, const char *defining_abspath, svn_boolean_t *timestamp_sleep, svn_client_ctx_t *ctx, apr_pool_t *pool) { svn_node_kind_t kind; svn_error_t *err; svn_revnum_t external_peg_rev = SVN_INVALID_REVNUM; svn_revnum_t external_rev = SVN_INVALID_REVNUM; apr_pool_t *subpool = svn_pool_create(pool); const char *repos_root_url; const char *repos_uuid; SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath)); if (peg_revision->kind == svn_opt_revision_number) external_peg_rev = peg_revision->value.number; if (revision->kind == svn_opt_revision_number) external_rev = revision->value.number; /* * The code below assumes existing versioned paths are *not* part of * the external's defining working copy. * The working copy library does not support registering externals * on top of existing BASE nodes and will error out if we try. * So if the external target is part of the defining working copy's * BASE tree, don't attempt to create the external. Doing so would * leave behind a switched path instead of an external (since the * switch succeeds but registration of the external in the DB fails). * The working copy then cannot be updated until the path is switched back. * See issue #4085. */ SVN_ERR(svn_wc__node_get_base(&kind, NULL, NULL, &repos_root_url, &repos_uuid, NULL, ctx->wc_ctx, local_abspath, TRUE, /* ignore_enoent */ TRUE, /* show hidden */ pool, pool)); if (kind != svn_node_unknown) { const char *wcroot_abspath; const char *defining_wcroot_abspath; SVN_ERR(svn_wc__get_wcroot(&wcroot_abspath, ctx->wc_ctx, local_abspath, pool, pool)); SVN_ERR(svn_wc__get_wcroot(&defining_wcroot_abspath, ctx->wc_ctx, defining_abspath, pool, pool)); if (strcmp(wcroot_abspath, defining_wcroot_abspath) == 0) return svn_error_create(SVN_ERR_WC_PATH_UNEXPECTED_STATUS, NULL, NULL); } /* If path is a directory, try to update/switch to the correct URL and revision. */ SVN_ERR(svn_io_check_path(local_abspath, &kind, pool)); if (kind == svn_node_dir) { const char *node_url; /* Doubles as an "is versioned" check. */ err = svn_wc__node_get_url(&node_url, ctx->wc_ctx, local_abspath, pool, subpool); if (err && err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND) { svn_error_clear(err); err = SVN_NO_ERROR; goto relegate; } else if (err) return svn_error_trace(err); if (node_url) { /* If we have what appears to be a version controlled subdir, and its top-level URL matches that of our externals definition, perform an update. */ if (strcmp(node_url, url) == 0) { SVN_ERR(svn_client__update_internal(NULL, local_abspath, revision, svn_depth_unknown, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, timestamp_sleep, ctx, subpool)); svn_pool_destroy(subpool); goto cleanup; } /* We'd really prefer not to have to do a brute-force relegation -- blowing away the current external working copy and checking it out anew -- so we'll first see if we can get away with a generally cheaper relocation (if required) and switch-style update. To do so, we need to know the repository root URL of the external working copy as it currently sits. */ err = svn_wc__node_get_repos_info(NULL, NULL, &repos_root_url, &repos_uuid, ctx->wc_ctx, local_abspath, pool, subpool); if (err) { if (err->apr_err != SVN_ERR_WC_PATH_NOT_FOUND && err->apr_err != SVN_ERR_WC_NOT_WORKING_COPY) return svn_error_trace(err); svn_error_clear(err); repos_root_url = NULL; repos_uuid = NULL; } if (repos_root_url) { /* If the new external target URL is not obviously a child of the external working copy's current repository root URL... */ if (! svn_uri__is_ancestor(repos_root_url, url)) { const char *repos_root; /* ... then figure out precisely which repository root URL that target URL *is* a child of ... */ SVN_ERR(svn_client_get_repos_root(&repos_root, NULL, url, ctx, subpool, subpool)); /* ... and use that to try to relocate the external working copy to the target location. */ err = svn_client_relocate2(local_abspath, repos_root_url, repos_root, FALSE, ctx, subpool); /* If the relocation failed because the new URL points to a totally different repository, we've no choice but to relegate and check out a new WC. */ if (err && (err->apr_err == SVN_ERR_WC_INVALID_RELOCATION || (err->apr_err == SVN_ERR_CLIENT_INVALID_RELOCATION))) { svn_error_clear(err); goto relegate; } else if (err) return svn_error_trace(err); /* If the relocation went without a hitch, we should have a new repository root URL. */ repos_root_url = repos_root; } SVN_ERR(svn_client__switch_internal(NULL, local_abspath, url, peg_revision, revision, svn_depth_infinity, TRUE, FALSE, FALSE, TRUE /* ignore_ancestry */, timestamp_sleep, ctx, subpool)); SVN_ERR(svn_wc__external_register(ctx->wc_ctx, defining_abspath, local_abspath, svn_node_dir, repos_root_url, repos_uuid, svn_uri_skip_ancestor( repos_root_url, url, subpool), external_peg_rev, external_rev, subpool)); svn_pool_destroy(subpool); goto cleanup; } } } relegate: /* Fall back on removing the WC and checking out a new one. */ /* Ensure that we don't have any RA sessions or WC locks from failed operations above. */ svn_pool_destroy(subpool); if (kind == svn_node_dir) { /* Buh-bye, old and busted ... */ SVN_ERR(relegate_dir_external(ctx->wc_ctx, defining_abspath, local_abspath, ctx->cancel_func, ctx->cancel_baton, ctx->notify_func2, ctx->notify_baton2, pool)); } else { /* The target dir might have multiple components. Guarantee the path leading down to the last component. */ const char *parent = svn_dirent_dirname(local_abspath, pool); SVN_ERR(svn_io_make_dir_recursively(parent, pool)); } /* ... Hello, new hotness. */ SVN_ERR(svn_client__checkout_internal(NULL, url, local_abspath, peg_revision, revision, svn_depth_infinity, FALSE, FALSE, timestamp_sleep, ctx, pool)); SVN_ERR(svn_wc__node_get_repos_info(NULL, NULL, &repos_root_url, &repos_uuid, ctx->wc_ctx, local_abspath, pool, pool)); SVN_ERR(svn_wc__external_register(ctx->wc_ctx, defining_abspath, local_abspath, svn_node_dir, repos_root_url, repos_uuid, svn_uri_skip_ancestor(repos_root_url, url, pool), external_peg_rev, external_rev, pool)); cleanup: /* Issues #4123 and #4130: We don't need to keep the newly checked out external's DB open. */ SVN_ERR(svn_wc__close_db(local_abspath, ctx->wc_ctx, pool)); return SVN_NO_ERROR; }
/* Try to update a file external at LOCAL_ABSPATH to URL at REVISION using a access baton that has a write lock. Use SCRATCH_POOL for temporary allocations, and use the client context CTX. */ static svn_error_t * switch_file_external(const char *local_abspath, const char *url, const svn_opt_revision_t *peg_revision, const svn_opt_revision_t *revision, const char *def_dir_abspath, svn_ra_session_t *ra_session, svn_client_ctx_t *ctx, apr_pool_t *scratch_pool) { svn_config_t *cfg = ctx->config ? svn_hash_gets(ctx->config, SVN_CONFIG_CATEGORY_CONFIG) : NULL; svn_boolean_t use_commit_times; const char *diff3_cmd; const char *preserved_exts_str; const apr_array_header_t *preserved_exts; svn_node_kind_t kind, external_kind; SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath)); /* See if the user wants last-commit timestamps instead of current ones. */ SVN_ERR(svn_config_get_bool(cfg, &use_commit_times, SVN_CONFIG_SECTION_MISCELLANY, SVN_CONFIG_OPTION_USE_COMMIT_TIMES, FALSE)); /* Get the external diff3, if any. */ svn_config_get(cfg, &diff3_cmd, SVN_CONFIG_SECTION_HELPERS, SVN_CONFIG_OPTION_DIFF3_CMD, NULL); if (diff3_cmd != NULL) SVN_ERR(svn_path_cstring_to_utf8(&diff3_cmd, diff3_cmd, scratch_pool)); /* See which files the user wants to preserve the extension of when conflict files are made. */ svn_config_get(cfg, &preserved_exts_str, SVN_CONFIG_SECTION_MISCELLANY, SVN_CONFIG_OPTION_PRESERVED_CF_EXTS, ""); preserved_exts = *preserved_exts_str ? svn_cstring_split(preserved_exts_str, "\n\r\t\v ", FALSE, scratch_pool) : NULL; { const char *wcroot_abspath; SVN_ERR(svn_wc__get_wcroot(&wcroot_abspath, ctx->wc_ctx, local_abspath, scratch_pool, scratch_pool)); /* File externals can only be installed inside the current working copy. So verify if the working copy that contains/will contain the target is the defining abspath, or one of its ancestors */ if (!svn_dirent_is_ancestor(wcroot_abspath, def_dir_abspath)) return svn_error_createf( SVN_ERR_WC_BAD_PATH, NULL, _("Cannot insert a file external defined on '%s' " "into the working copy '%s'."), svn_dirent_local_style(def_dir_abspath, scratch_pool), svn_dirent_local_style(wcroot_abspath, scratch_pool)); } SVN_ERR(svn_wc_read_kind2(&kind, ctx->wc_ctx, local_abspath, TRUE, FALSE, scratch_pool)); SVN_ERR(svn_wc__read_external_info(&external_kind, NULL, NULL, NULL, NULL, ctx->wc_ctx, local_abspath, local_abspath, TRUE, scratch_pool, scratch_pool)); /* If there is a versioned item with this name, ensure it's a file external before working with it. If there is no entry in the working copy, then create an empty file and add it to the working copy. */ if (kind != svn_node_none && kind != svn_node_unknown) { if (external_kind != svn_node_file) { return svn_error_createf( SVN_ERR_CLIENT_FILE_EXTERNAL_OVERWRITE_VERSIONED, 0, _("The file external from '%s' cannot overwrite the existing " "versioned item at '%s'"), url, svn_dirent_local_style(local_abspath, scratch_pool)); } } else { svn_node_kind_t disk_kind; SVN_ERR(svn_io_check_path(local_abspath, &disk_kind, scratch_pool)); if (kind == svn_node_file || kind == svn_node_dir) return svn_error_createf(SVN_ERR_WC_PATH_FOUND, NULL, _("The file external '%s' can not be " "created because the node exists."), svn_dirent_local_style(local_abspath, scratch_pool)); } { const svn_ra_reporter3_t *reporter; void *report_baton; const svn_delta_editor_t *switch_editor; void *switch_baton; svn_client__pathrev_t *switch_loc; svn_revnum_t revnum; apr_array_header_t *inherited_props; const char *dir_abspath; const char *target; svn_dirent_split(&dir_abspath, &target, local_abspath, scratch_pool); /* ### Why do we open a new session? RA_SESSION is a valid ### session -- the caller used it to call svn_ra_check_path on ### this very URL, the caller also did the resolving and ### reparenting that is repeated here. */ SVN_ERR(svn_client__ra_session_from_path2(&ra_session, &switch_loc, url, dir_abspath, peg_revision, revision, ctx, scratch_pool)); /* Get the external file's iprops. */ SVN_ERR(svn_ra_get_inherited_props(ra_session, &inherited_props, "", switch_loc->rev, scratch_pool, scratch_pool)); SVN_ERR(svn_ra_reparent(ra_session, svn_uri_dirname(url, scratch_pool), scratch_pool)); SVN_ERR(svn_wc__get_file_external_editor(&switch_editor, &switch_baton, &revnum, ctx->wc_ctx, local_abspath, def_dir_abspath, switch_loc->url, switch_loc->repos_root_url, switch_loc->repos_uuid, inherited_props, use_commit_times, diff3_cmd, preserved_exts, def_dir_abspath, url, peg_revision, revision, ctx->conflict_func2, ctx->conflict_baton2, ctx->cancel_func, ctx->cancel_baton, ctx->notify_func2, ctx->notify_baton2, scratch_pool, scratch_pool)); /* Tell RA to do an update of URL+TARGET to REVISION; if we pass an invalid revnum, that means RA will use the latest revision. */ SVN_ERR(svn_ra_do_switch3(ra_session, &reporter, &report_baton, switch_loc->rev, target, svn_depth_unknown, switch_loc->url, FALSE /* send_copyfrom */, TRUE /* ignore_ancestry */, switch_editor, switch_baton, scratch_pool, scratch_pool)); SVN_ERR(svn_wc__crawl_file_external(ctx->wc_ctx, local_abspath, reporter, report_baton, TRUE, use_commit_times, ctx->cancel_func, ctx->cancel_baton, ctx->notify_func2, ctx->notify_baton2, scratch_pool)); if (ctx->notify_func2) { svn_wc_notify_t *notify = svn_wc_create_notify(local_abspath, svn_wc_notify_update_completed, scratch_pool); notify->kind = svn_node_none; notify->content_state = notify->prop_state = svn_wc_notify_state_inapplicable; notify->lock_state = svn_wc_notify_lock_state_inapplicable; notify->revision = revnum; (*ctx->notify_func2)(ctx->notify_baton2, notify, scratch_pool); } } return SVN_NO_ERROR; }
/* Given a list of committables described by their common base abspath BASE_ABSPATH and a list of relative dirents TARGET_RELPATHS determine which absolute paths must be locked to commit all these targets and return this as a const char * array in LOCK_TARGETS Allocate the result in RESULT_POOL and use SCRATCH_POOL for temporary storage */ static svn_error_t * determine_lock_targets(apr_array_header_t **lock_targets, svn_wc_context_t *wc_ctx, const char *base_abspath, const apr_array_header_t *target_relpaths, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { apr_pool_t *iterpool = svn_pool_create(scratch_pool); apr_hash_t *wc_items; /* const char *wcroot -> apr_array_header_t */ apr_hash_index_t *hi; int i; wc_items = apr_hash_make(scratch_pool); /* Create an array of targets for each working copy used */ for (i = 0; i < target_relpaths->nelts; i++) { const char *target_abspath; const char *wcroot_abspath; apr_array_header_t *wc_targets; svn_error_t *err; const char *target_relpath = APR_ARRAY_IDX(target_relpaths, i, const char *); svn_pool_clear(iterpool); target_abspath = svn_dirent_join(base_abspath, target_relpath, scratch_pool); err = svn_wc__get_wcroot(&wcroot_abspath, wc_ctx, target_abspath, iterpool, iterpool); if (err) { if (err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND) { svn_error_clear(err); continue; } return svn_error_trace(err); } wc_targets = svn_hash_gets(wc_items, wcroot_abspath); if (! wc_targets) { wc_targets = apr_array_make(scratch_pool, 4, sizeof(const char *)); svn_hash_sets(wc_items, apr_pstrdup(scratch_pool, wcroot_abspath), wc_targets); } APR_ARRAY_PUSH(wc_targets, const char *) = target_abspath; } *lock_targets = apr_array_make(result_pool, apr_hash_count(wc_items), sizeof(const char *)); /* For each working copy determine where to lock */ for (hi = apr_hash_first(scratch_pool, wc_items); hi; hi = apr_hash_next(hi)) { const char *common; const char *wcroot_abspath = apr_hash_this_key(hi); apr_array_header_t *wc_targets = apr_hash_this_val(hi); svn_pool_clear(iterpool); if (wc_targets->nelts == 1) { const char *target_abspath; target_abspath = APR_ARRAY_IDX(wc_targets, 0, const char *); if (! strcmp(wcroot_abspath, target_abspath)) { APR_ARRAY_PUSH(*lock_targets, const char *) = apr_pstrdup(result_pool, target_abspath); } else { /* Lock the parent to allow deleting the target */ APR_ARRAY_PUSH(*lock_targets, const char *) = svn_dirent_dirname(target_abspath, result_pool); } }