svn_error_t * svn_client__wc_node_get_base(svn_client__pathrev_t **base_p, const char *wc_abspath, svn_wc_context_t *wc_ctx, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { const char *relpath; *base_p = apr_palloc(result_pool, sizeof(**base_p)); SVN_ERR(svn_wc__node_get_base(&(*base_p)->rev, &relpath, &(*base_p)->repos_root_url, &(*base_p)->repos_uuid, wc_ctx, wc_abspath, result_pool, scratch_pool)); if ((*base_p)->repos_root_url && relpath) { (*base_p)->url = svn_path_url_add_component2( (*base_p)->repos_root_url, relpath, result_pool); } else { *base_p = NULL; } return SVN_NO_ERROR; }
/* 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 char *url_from_externals_definition, 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_createf(SVN_ERR_WC_PATH_UNEXPECTED_STATUS, NULL, _("The external '%s' defined in %s at '%s' " "cannot be checked out because '%s' is " "already a versioned path."), url_from_externals_definition, SVN_PROP_EXTERNALS, svn_dirent_local_style(defining_abspath, pool), svn_dirent_local_style(local_abspath, pool)); } /* 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)); /* We just decided that this existing directory is an external, so update the external registry with this information, like when checking out an external */ 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)); 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; }
/* This is a helper for svn_client__update_internal(), which see for an explanation of most of these parameters. Some stuff that's unique is as follows: ANCHOR_ABSPATH is the local absolute path of the update anchor. This is typically either the same as LOCAL_ABSPATH, or the immediate parent of LOCAL_ABSPATH. If NOTIFY_SUMMARY is set (and there's a notification handler in CTX), transmit the final update summary upon successful completion of the update. Add the paths of any conflict victims to CONFLICTED_PATHS, if that is not null. */ static svn_error_t * update_internal(svn_revnum_t *result_rev, apr_hash_t *conflicted_paths, const char *local_abspath, const char *anchor_abspath, const svn_opt_revision_t *revision, svn_depth_t depth, svn_boolean_t depth_is_sticky, svn_boolean_t ignore_externals, svn_boolean_t allow_unver_obstructions, svn_boolean_t adds_as_modification, svn_boolean_t *timestamp_sleep, svn_boolean_t notify_summary, svn_client_ctx_t *ctx, apr_pool_t *pool) { const svn_delta_editor_t *update_editor; void *update_edit_baton; const svn_ra_reporter3_t *reporter; void *report_baton; const char *corrected_url; const char *target; const char *repos_root_url; const char *repos_relpath; const char *repos_uuid; const char *anchor_url; svn_revnum_t revnum; svn_boolean_t use_commit_times; svn_boolean_t clean_checkout = FALSE; const char *diff3_cmd; apr_hash_t *wcroot_iprops; svn_opt_revision_t opt_rev; svn_ra_session_t *ra_session; const char *preserved_exts_str; apr_array_header_t *preserved_exts; struct svn_client__dirent_fetcher_baton_t dfb; svn_boolean_t server_supports_depth; svn_boolean_t cropping_target; svn_boolean_t target_conflicted = FALSE; svn_config_t *cfg = ctx->config ? svn_hash_gets(ctx->config, SVN_CONFIG_CATEGORY_CONFIG) : NULL; if (result_rev) *result_rev = SVN_INVALID_REVNUM; /* An unknown depth can't be sticky. */ if (depth == svn_depth_unknown) depth_is_sticky = FALSE; if (strcmp(local_abspath, anchor_abspath)) target = svn_dirent_basename(local_abspath, pool); else target = ""; /* Check if our anchor exists in BASE. If it doesn't we can't update. */ SVN_ERR(svn_wc__node_get_base(NULL, NULL, &repos_relpath, &repos_root_url, &repos_uuid, NULL, ctx->wc_ctx, anchor_abspath, TRUE, FALSE, pool, pool)); /* It does not make sense to update conflict victims. */ if (repos_relpath) { svn_error_t *err; svn_boolean_t text_conflicted, prop_conflicted; anchor_url = svn_path_url_add_component2(repos_root_url, repos_relpath, pool); err = svn_wc_conflicted_p3(&text_conflicted, &prop_conflicted, NULL, ctx->wc_ctx, local_abspath, pool); if (err && err->apr_err != SVN_ERR_WC_PATH_NOT_FOUND) return svn_error_trace(err); svn_error_clear(err); /* tree-conflicts are handled by the update editor */ if (!err && (text_conflicted || prop_conflicted)) target_conflicted = TRUE; } else anchor_url = NULL; if (! anchor_url || target_conflicted) { if (ctx->notify_func2) { svn_wc_notify_t *nt; nt = svn_wc_create_notify(local_abspath, target_conflicted ? svn_wc_notify_skip_conflicted : svn_wc_notify_update_skip_working_only, pool); ctx->notify_func2(ctx->notify_baton2, nt, pool); } return SVN_NO_ERROR; } /* We may need to crop the tree if the depth is sticky */ cropping_target = (depth_is_sticky && depth < svn_depth_infinity); if (cropping_target) { svn_node_kind_t target_kind; if (depth == svn_depth_exclude) { SVN_ERR(svn_wc_exclude(ctx->wc_ctx, local_abspath, ctx->cancel_func, ctx->cancel_baton, ctx->notify_func2, ctx->notify_baton2, pool)); /* Target excluded, we are done now */ return SVN_NO_ERROR; } SVN_ERR(svn_wc_read_kind2(&target_kind, ctx->wc_ctx, local_abspath, TRUE, TRUE, pool)); if (target_kind == svn_node_dir) { SVN_ERR(svn_wc_crop_tree2(ctx->wc_ctx, local_abspath, depth, ctx->cancel_func, ctx->cancel_baton, ctx->notify_func2, ctx->notify_baton2, pool)); } } /* check whether the "clean c/o" optimization is applicable */ SVN_ERR(is_empty_wc(&clean_checkout, local_abspath, anchor_abspath, pool)); /* 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, pool)); /* 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)); /* 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, pool) : NULL; /* Let everyone know we're starting a real update (unless we're asked not to). */ if (ctx->notify_func2 && notify_summary) { svn_wc_notify_t *notify = svn_wc_create_notify(local_abspath, svn_wc_notify_update_started, 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; (*ctx->notify_func2)(ctx->notify_baton2, notify, pool); } /* Open an RA session for the URL */ SVN_ERR(svn_client__open_ra_session_internal(&ra_session, &corrected_url, anchor_url, anchor_abspath, NULL, TRUE, TRUE, ctx, pool, pool)); /* If we got a corrected URL from the RA subsystem, we'll need to relocate our working copy first. */ if (corrected_url) { const char *new_repos_root_url; /* To relocate everything inside our repository we need the old and new repos root. */ SVN_ERR(svn_ra_get_repos_root2(ra_session, &new_repos_root_url, pool)); /* svn_client_relocate2() will check the uuid */ SVN_ERR(svn_client_relocate2(anchor_abspath, repos_root_url, new_repos_root_url, ignore_externals, ctx, pool)); /* Store updated repository root for externals */ repos_root_url = new_repos_root_url; /* ### We should update anchor_loc->repos_uuid too, although currently * we don't use it. */ anchor_url = corrected_url; } /* Resolve unspecified REVISION now, because we need to retrieve the correct inherited props prior to the editor drive and we need to use the same value of HEAD for both. */ opt_rev.kind = revision->kind; opt_rev.value = revision->value; if (opt_rev.kind == svn_opt_revision_unspecified) opt_rev.kind = svn_opt_revision_head; /* ### todo: shouldn't svn_client__get_revision_number be able to take a URL as easily as a local path? */ SVN_ERR(svn_client__get_revision_number(&revnum, NULL, ctx->wc_ctx, local_abspath, ra_session, &opt_rev, pool)); SVN_ERR(svn_ra_has_capability(ra_session, &server_supports_depth, SVN_RA_CAPABILITY_DEPTH, pool)); dfb.ra_session = ra_session; dfb.target_revision = revnum; dfb.anchor_url = anchor_url; SVN_ERR(svn_client__get_inheritable_props(&wcroot_iprops, local_abspath, revnum, depth, ra_session, ctx, pool, pool)); /* Fetch the update editor. If REVISION is invalid, that's okay; the RA driver will call editor->set_target_revision later on. */ SVN_ERR(svn_wc__get_update_editor(&update_editor, &update_edit_baton, &revnum, ctx->wc_ctx, anchor_abspath, target, wcroot_iprops, use_commit_times, depth, depth_is_sticky, allow_unver_obstructions, adds_as_modification, server_supports_depth, clean_checkout, diff3_cmd, preserved_exts, svn_client__dirent_fetcher, &dfb, conflicted_paths ? record_conflict : NULL, conflicted_paths, NULL, NULL, ctx->cancel_func, ctx->cancel_baton, ctx->notify_func2, ctx->notify_baton2, pool, 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_update3(ra_session, &reporter, &report_baton, revnum, target, (!server_supports_depth || depth_is_sticky ? depth : svn_depth_unknown), FALSE /* send_copyfrom_args */, FALSE /* ignore_ancestry */, update_editor, update_edit_baton, pool, pool)); /* Past this point, we assume the WC is going to be modified so we will * need to sleep for timestamps. */ *timestamp_sleep = TRUE; /* Drive the reporter structure, describing the revisions within PATH. When we call reporter->finish_report, the update_editor will be driven by svn_repos_dir_delta2. */ SVN_ERR(svn_wc_crawl_revisions5(ctx->wc_ctx, local_abspath, reporter, report_baton, TRUE, depth, (! depth_is_sticky), (! server_supports_depth), use_commit_times, ctx->cancel_func, ctx->cancel_baton, ctx->notify_func2, ctx->notify_baton2, pool)); /* We handle externals after the update is complete, so that handling external items (and any errors therefrom) doesn't delay the primary operation. */ if ((SVN_DEPTH_IS_RECURSIVE(depth) || cropping_target) && (! ignore_externals)) { apr_hash_t *new_externals; apr_hash_t *new_depths; SVN_ERR(svn_wc__externals_gather_definitions(&new_externals, &new_depths, ctx->wc_ctx, local_abspath, depth, pool, pool)); SVN_ERR(svn_client__handle_externals(new_externals, new_depths, repos_root_url, local_abspath, depth, timestamp_sleep, ctx, pool)); } /* Let everyone know we're finished here (unless we're asked not to). */ if (ctx->notify_func2 && notify_summary) { svn_wc_notify_t *notify = svn_wc_create_notify(local_abspath, svn_wc_notify_update_completed, 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, pool); } /* If the caller wants the result revision, give it to them. */ if (result_rev) *result_rev = revnum; return SVN_NO_ERROR; }