svn_error_t * svn_client__get_copy_source(const char **original_repos_relpath, svn_revnum_t *original_revision, const char *path_or_url, const svn_opt_revision_t *revision, svn_client_ctx_t *ctx, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { svn_error_t *err; copyfrom_info_t copyfrom_info = { 0 }; apr_pool_t *sesspool = svn_pool_create(scratch_pool); svn_ra_session_t *ra_session; svn_client__pathrev_t *at_loc; copyfrom_info.is_first = TRUE; copyfrom_info.path = NULL; copyfrom_info.rev = SVN_INVALID_REVNUM; copyfrom_info.pool = result_pool; SVN_ERR(svn_client__ra_session_from_path2(&ra_session, &at_loc, path_or_url, NULL, revision, revision, ctx, sesspool)); /* Find the copy source. Walk the location segments to find the revision at which this node was created (copied or added). */ err = svn_ra_get_location_segments(ra_session, "", at_loc->rev, at_loc->rev, SVN_INVALID_REVNUM, copyfrom_info_receiver, ©from_info, scratch_pool); svn_pool_destroy(sesspool); if (err) { if (err->apr_err == SVN_ERR_FS_NOT_FOUND || err->apr_err == SVN_ERR_RA_DAV_REQUEST_FAILED) { /* A locally-added but uncommitted versioned resource won't exist in the repository. */ svn_error_clear(err); err = SVN_NO_ERROR; *original_repos_relpath = NULL; *original_revision = SVN_INVALID_REVNUM; } return svn_error_trace(err); } *original_repos_relpath = copyfrom_info.path; *original_revision = copyfrom_info.rev; return SVN_NO_ERROR; }
svn_error_t * svn_client_info3(const char *abspath_or_url, const svn_opt_revision_t *peg_revision, const svn_opt_revision_t *revision, svn_depth_t depth, svn_boolean_t fetch_excluded, svn_boolean_t fetch_actual_only, const apr_array_header_t *changelists, svn_client_info_receiver2_t receiver, void *receiver_baton, svn_client_ctx_t *ctx, apr_pool_t *pool) { svn_ra_session_t *ra_session; svn_client__pathrev_t *pathrev; svn_lock_t *lock; svn_boolean_t related; const char *base_name; svn_dirent_t *the_ent; svn_client_info2_t *info; svn_error_t *err; if (depth == svn_depth_unknown) depth = svn_depth_empty; if ((revision == NULL || revision->kind == svn_opt_revision_unspecified) && (peg_revision == NULL || peg_revision->kind == svn_opt_revision_unspecified)) { /* Do all digging in the working copy. */ wc_info_receiver_baton_t b; b.client_receiver_func = receiver; b.client_receiver_baton = receiver_baton; return svn_error_trace( svn_wc__get_info(ctx->wc_ctx, abspath_or_url, depth, fetch_excluded, fetch_actual_only, changelists, wc_info_receiver, &b, ctx->cancel_func, ctx->cancel_baton, pool)); } /* Go repository digging instead. */ /* Trace rename history (starting at path_or_url@peg_revision) and return RA session to the possibly-renamed URL as it exists in REVISION. The ra_session returned will be anchored on this "final" URL. */ SVN_ERR(svn_client__ra_session_from_path2(&ra_session, &pathrev, abspath_or_url, NULL, peg_revision, revision, ctx, pool)); svn_uri_split(NULL, &base_name, pathrev->url, pool); /* Get the dirent for the URL itself. */ err = ra_stat_compatible(ra_session, pathrev->rev, &the_ent, DIRENT_FIELDS, ctx, pool); if (err && err->apr_err == SVN_ERR_RA_NOT_IMPLEMENTED) { svn_error_clear(err); /* If we're recursing, degrade gracefully: rather than throw an error, return no information about the repos root. */ if (depth > svn_depth_empty) goto pre_1_2_recurse; /* Otherwise, we really are stuck. Better tell the user what's going on. */ return svn_error_createf(SVN_ERR_UNSUPPORTED_FEATURE, NULL, _("Server does not support retrieving " "information about the repository root")); } else if (err) { return svn_error_trace(err); } if (! the_ent) return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL, _("URL '%s' non-existent in revision %ld"), pathrev->url, pathrev->rev); /* Check if the URL exists in HEAD and refers to the same resource. In this case, we check the repository for a lock on this URL. ### There is a possible race here, since HEAD might have changed since ### we checked it. A solution to this problem could be to do the below ### check in a loop which only terminates if the HEAD revision is the same ### before and after this check. That could, however, lead to a ### starvation situation instead. */ SVN_ERR(same_resource_in_head(&related, pathrev->url, pathrev->rev, ra_session, ctx, pool)); if (related) { err = svn_ra_get_lock(ra_session, &lock, "", pool); /* An old mod_dav_svn will always work; there's nothing wrong with doing a PROPFIND for a property named "DAV:supportedlock". But an old svnserve will error. */ if (err && err->apr_err == SVN_ERR_RA_NOT_IMPLEMENTED) { svn_error_clear(err); lock = NULL; } else if (err) return svn_error_trace(err); } else lock = NULL; /* Push the URL's dirent (and lock) at the callback.*/ SVN_ERR(build_info_from_dirent(&info, the_ent, lock, pathrev, pool)); SVN_ERR(receiver(receiver_baton, base_name, info, pool)); /* Possibly recurse, using the original RA session. */ if (depth > svn_depth_empty && (the_ent->kind == svn_node_dir)) { apr_hash_t *locks; pre_1_2_recurse: if (peg_revision->kind == svn_opt_revision_head) { err = svn_ra_get_locks2(ra_session, &locks, "", depth, pool); /* Catch specific errors thrown by old mod_dav_svn or svnserve. */ if (err && (err->apr_err == SVN_ERR_RA_NOT_IMPLEMENTED || err->apr_err == SVN_ERR_UNSUPPORTED_FEATURE)) { svn_error_clear(err); locks = apr_hash_make(pool); /* use an empty hash */ } else if (err) return svn_error_trace(err); } else locks = apr_hash_make(pool); /* use an empty hash */ SVN_ERR(push_dir_info(ra_session, pathrev, "", receiver, receiver_baton, depth, ctx, locks, pool)); } return SVN_NO_ERROR; }
static svn_error_t * bench_null_export(svn_revnum_t *result_rev, const char *from_path_or_url, svn_opt_revision_t *peg_revision, svn_opt_revision_t *revision, svn_depth_t depth, void *baton, svn_client_ctx_t *ctx, svn_boolean_t quiet, apr_pool_t *pool) { svn_revnum_t edit_revision = SVN_INVALID_REVNUM; svn_boolean_t from_is_url = svn_path_is_url(from_path_or_url); SVN_ERR_ASSERT(peg_revision != NULL); SVN_ERR_ASSERT(revision != NULL); if (peg_revision->kind == svn_opt_revision_unspecified) peg_revision->kind = svn_path_is_url(from_path_or_url) ? svn_opt_revision_head : svn_opt_revision_working; if (revision->kind == svn_opt_revision_unspecified) revision = peg_revision; if (from_is_url || ! SVN_CLIENT__REVKIND_IS_LOCAL_TO_WC(revision->kind)) { svn_client__pathrev_t *loc; svn_ra_session_t *ra_session; svn_node_kind_t kind; /* Get the RA connection. */ SVN_ERR(svn_client__ra_session_from_path2(&ra_session, &loc, from_path_or_url, NULL, peg_revision, revision, ctx, pool)); SVN_ERR(svn_ra_check_path(ra_session, "", loc->rev, &kind, pool)); if (kind == svn_node_file) { apr_hash_t *props; /* Since you cannot actually root an editor at a file, we * manually drive a few functions of our editor. */ /* Step outside the editor-likeness for a moment, to actually talk * to the repository. */ /* ### note: the stream will not be closed */ SVN_ERR(svn_ra_get_file(ra_session, "", loc->rev, svn_stream_empty(pool), NULL, &props, pool)); } else if (kind == svn_node_dir) { void *edit_baton = NULL; const svn_delta_editor_t *export_editor = NULL; const svn_ra_reporter3_t *reporter; void *report_baton; svn_delta_editor_t *editor = svn_delta_default_editor(pool); editor->set_target_revision = set_target_revision; editor->open_root = open_root; editor->add_directory = add_directory; editor->add_file = add_file; editor->apply_textdelta = apply_textdelta; editor->close_file = close_file; editor->change_file_prop = change_file_prop; editor->change_dir_prop = change_dir_prop; /* for ra_svn, we don't need an editior in quiet mode */ if (!quiet || strncmp(loc->repos_root_url, "svn:", 4)) SVN_ERR(svn_delta_get_cancellation_editor(ctx->cancel_func, ctx->cancel_baton, editor, baton, &export_editor, &edit_baton, pool)); /* Manufacture a basic 'report' to the update reporter. */ SVN_ERR(svn_ra_do_update3(ra_session, &reporter, &report_baton, loc->rev, "", /* no sub-target */ depth, FALSE, /* don't want copyfrom-args */ FALSE, /* don't want ignore_ancestry */ export_editor, edit_baton, pool, pool)); SVN_ERR(reporter->set_path(report_baton, "", loc->rev, /* Depth is irrelevant, as we're passing start_empty=TRUE anyway. */ svn_depth_infinity, TRUE, /* "help, my dir is empty!" */ NULL, pool)); SVN_ERR(reporter->finish_report(report_baton, pool)); } else if (kind == svn_node_none) { return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL, _("URL '%s' doesn't exist"), from_path_or_url); } /* kind == svn_node_unknown not handled */ } if (result_rev) *result_rev = edit_revision; return SVN_NO_ERROR; }
svn_error_t * svn_client__checkout_internal(svn_revnum_t *result_rev, const char *url, const char *local_abspath, const svn_opt_revision_t *peg_revision, const svn_opt_revision_t *revision, svn_depth_t depth, svn_boolean_t ignore_externals, svn_boolean_t allow_unver_obstructions, svn_boolean_t *timestamp_sleep, svn_client_ctx_t *ctx, apr_pool_t *pool) { svn_node_kind_t kind; apr_pool_t *session_pool = svn_pool_create(pool); svn_ra_session_t *ra_session; svn_client__pathrev_t *pathrev; /* Sanity check. Without these, the checkout is meaningless. */ SVN_ERR_ASSERT(local_abspath != NULL); SVN_ERR_ASSERT(svn_uri_is_canonical(url, pool)); SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath)); /* Fulfill the docstring promise of svn_client_checkout: */ if ((revision->kind != svn_opt_revision_number) && (revision->kind != svn_opt_revision_date) && (revision->kind != svn_opt_revision_head)) return svn_error_create(SVN_ERR_CLIENT_BAD_REVISION, NULL, NULL); /* Get the RA connection. */ SVN_ERR(svn_client__ra_session_from_path2(&ra_session, &pathrev, url, NULL, peg_revision, revision, ctx, session_pool)); pathrev = svn_client__pathrev_dup(pathrev, pool); SVN_ERR(svn_ra_check_path(ra_session, "", pathrev->rev, &kind, pool)); svn_pool_destroy(session_pool); if (kind == svn_node_none) return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL, _("URL '%s' doesn't exist"), pathrev->url); else if (kind == svn_node_file) return svn_error_createf (SVN_ERR_UNSUPPORTED_FEATURE , NULL, _("URL '%s' refers to a file, not a directory"), pathrev->url); SVN_ERR(svn_io_check_path(local_abspath, &kind, pool)); if (kind == svn_node_none) { /* Bootstrap: create an incomplete working-copy root dir. Its entries file should only have an entry for THIS_DIR with a URL, revnum, and an 'incomplete' flag. */ SVN_ERR(svn_io_make_dir_recursively(local_abspath, pool)); SVN_ERR(initialize_area(local_abspath, pathrev, depth, ctx, pool)); } else if (kind == svn_node_dir) { int wc_format; const char *entry_url; SVN_ERR(svn_wc_check_wc2(&wc_format, ctx->wc_ctx, local_abspath, pool)); if (! wc_format) { SVN_ERR(initialize_area(local_abspath, pathrev, depth, ctx, pool)); } else { /* Get PATH's URL. */ SVN_ERR(svn_wc__node_get_url(&entry_url, ctx->wc_ctx, local_abspath, pool, pool)); /* If PATH's existing URL matches the incoming one, then just update. This allows 'svn co' to restart an interrupted checkout. Otherwise bail out. */ if (strcmp(entry_url, pathrev->url) != 0) return svn_error_createf( SVN_ERR_WC_OBSTRUCTED_UPDATE, NULL, _("'%s' is already a working copy for a" " different URL"), svn_dirent_local_style(local_abspath, pool)); } } else { return svn_error_createf(SVN_ERR_WC_NODE_KIND_CHANGE, NULL, _("'%s' already exists and is not a directory"), svn_dirent_local_style(local_abspath, pool)); } /* Have update fix the incompleteness. */ SVN_ERR(svn_client__update_internal(result_rev, local_abspath, revision, depth, TRUE, ignore_externals, allow_unver_obstructions, TRUE /* adds_as_modification */, FALSE, FALSE, timestamp_sleep, ctx, pool)); return SVN_NO_ERROR; }
static svn_error_t * handle_external_item_change(svn_client_ctx_t *ctx, const char *repos_root_url, const char *parent_dir_abspath, const char *parent_dir_url, const char *local_abspath, const char *old_defining_abspath, const svn_wc_external_item2_t *new_item, svn_boolean_t *timestamp_sleep, apr_pool_t *scratch_pool) { svn_ra_session_t *ra_session; svn_client__pathrev_t *new_loc; const char *new_url; svn_node_kind_t ext_kind; SVN_ERR_ASSERT(repos_root_url && parent_dir_url); SVN_ERR_ASSERT(new_item != NULL); /* Don't bother to check status, since we'll get that for free by attempting to retrieve the hash values anyway. */ /* When creating the absolute URL, use the pool and not the iterpool, since the hash table values outlive the iterpool and any pointers they have should also outlive the iterpool. */ SVN_ERR(svn_wc__resolve_relative_external_url(&new_url, new_item, repos_root_url, parent_dir_url, scratch_pool, scratch_pool)); /* Determine if the external is a file or directory. */ /* Get the RA connection. */ SVN_ERR(svn_client__ra_session_from_path2(&ra_session, &new_loc, new_url, NULL, &(new_item->peg_revision), &(new_item->revision), ctx, scratch_pool)); SVN_ERR(svn_ra_check_path(ra_session, "", new_loc->rev, &ext_kind, scratch_pool)); if (svn_node_none == ext_kind) return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL, _("URL '%s' at revision %ld doesn't exist"), new_loc->url, new_loc->rev); if (svn_node_dir != ext_kind && svn_node_file != ext_kind) return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL, _("URL '%s' at revision %ld is not a file " "or a directory"), new_loc->url, new_loc->rev); /* Not protecting against recursive externals. Detecting them in the global case is hard, and it should be pretty obvious to a user when it happens. Worst case: your disk fills up :-). */ /* First notify that we're about to handle an external. */ if (ctx->notify_func2) { (*ctx->notify_func2)( ctx->notify_baton2, svn_wc_create_notify(local_abspath, svn_wc_notify_update_external, scratch_pool), scratch_pool); } if (! old_defining_abspath) { /* The target dir might have multiple components. Guarantee the path leading down to the last component. */ SVN_ERR(svn_io_make_dir_recursively(svn_dirent_dirname(local_abspath, scratch_pool), scratch_pool)); } switch (ext_kind) { case svn_node_dir: SVN_ERR(switch_dir_external(local_abspath, new_loc->url, new_item->url, &(new_item->peg_revision), &(new_item->revision), parent_dir_abspath, timestamp_sleep, ctx, scratch_pool)); break; case svn_node_file: if (strcmp(repos_root_url, new_loc->repos_root_url)) { const char *local_repos_root_url; const char *local_repos_uuid; const char *ext_repos_relpath; svn_error_t *err; /* * The working copy library currently requires that all files * in the working copy have the same repository root URL. * The URL from the file external's definition differs from the * one used by the working copy. As a workaround, replace the * root URL portion of the file external's URL, after making * sure both URLs point to the same repository. See issue #4087. */ err = svn_wc__node_get_repos_info(NULL, NULL, &local_repos_root_url, &local_repos_uuid, ctx->wc_ctx, parent_dir_abspath, scratch_pool, scratch_pool); 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); local_repos_root_url = NULL; local_repos_uuid = NULL; } ext_repos_relpath = svn_uri_skip_ancestor(new_loc->repos_root_url, new_url, scratch_pool); if (local_repos_uuid == NULL || local_repos_root_url == NULL || ext_repos_relpath == NULL || strcmp(local_repos_uuid, new_loc->repos_uuid) != 0) return svn_error_createf(SVN_ERR_UNSUPPORTED_FEATURE, NULL, _("Unsupported external: URL of file external '%s' " "is not in repository '%s'"), new_url, repos_root_url); new_url = svn_path_url_add_component2(local_repos_root_url, ext_repos_relpath, scratch_pool); SVN_ERR(svn_client__ra_session_from_path2(&ra_session, &new_loc, new_url, NULL, &(new_item->peg_revision), &(new_item->revision), ctx, scratch_pool)); } SVN_ERR(switch_file_external(local_abspath, new_url, &new_item->peg_revision, &new_item->revision, parent_dir_abspath, ra_session, ctx, scratch_pool)); break; default: SVN_ERR_MALFUNCTION(); break; } 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; }
/* ... Add the paths of any conflict victims to CONFLICTED_PATHS, if that is not null. */ static svn_error_t * switch_internal(svn_revnum_t *result_rev, apr_hash_t *conflicted_paths, const char *local_abspath, const char *anchor_abspath, const char *switch_url, const svn_opt_revision_t *peg_revision, 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 ignore_ancestry, svn_boolean_t *timestamp_sleep, svn_client_ctx_t *ctx, apr_pool_t *pool) { const svn_ra_reporter3_t *reporter; void *report_baton; const char *anchor_url, *target; svn_client__pathrev_t *switch_loc; svn_ra_session_t *ra_session; svn_revnum_t revnum; const char *diff3_cmd; apr_hash_t *wcroot_iprops; apr_array_header_t *inherited_props; svn_boolean_t use_commit_times; const svn_delta_editor_t *switch_editor; void *switch_edit_baton; const char *preserved_exts_str; apr_array_header_t *preserved_exts; svn_boolean_t server_supports_depth; struct svn_client__dirent_fetcher_baton_t dfb; svn_config_t *cfg = ctx->config ? svn_hash_gets(ctx->config, SVN_CONFIG_CATEGORY_CONFIG) : NULL; /* An unknown depth can't be sticky. */ if (depth == svn_depth_unknown) depth_is_sticky = FALSE; /* Do not support the situation of both exclude and switch a target. */ if (depth == svn_depth_exclude) return svn_error_createf(SVN_ERR_UNSUPPORTED_FEATURE, NULL, _("Cannot both exclude and switch a path")); /* 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)); { svn_boolean_t has_working; SVN_ERR(svn_wc__node_has_working(&has_working, ctx->wc_ctx, local_abspath, pool)); if (has_working) return svn_error_createf(SVN_ERR_UNSUPPORTED_FEATURE, NULL, _("Cannot switch '%s' because it is not in the " "repository yet"), svn_dirent_local_style(local_abspath, 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, pool) : NULL; /* Sanity check. Without these, the switch is meaningless. */ SVN_ERR_ASSERT(switch_url && (switch_url[0] != '\0')); if (strcmp(local_abspath, anchor_abspath)) target = svn_dirent_basename(local_abspath, pool); else target = ""; SVN_ERR(svn_wc__node_get_url(&anchor_url, ctx->wc_ctx, anchor_abspath, pool, pool)); if (! anchor_url) return svn_error_createf(SVN_ERR_ENTRY_MISSING_URL, NULL, _("Directory '%s' has no URL"), svn_dirent_local_style(anchor_abspath, pool)); /* We may need to crop the tree if the depth is sticky */ if (depth_is_sticky && depth < svn_depth_infinity) { 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)); } /* Open an RA session to 'source' URL */ SVN_ERR(svn_client__ra_session_from_path2(&ra_session, &switch_loc, switch_url, anchor_abspath, peg_revision, revision, ctx, pool)); /* Disallow a switch operation to change the repository root of the target. */ if (! svn_uri__is_ancestor(switch_loc->repos_root_url, anchor_url)) return svn_error_createf(SVN_ERR_WC_INVALID_SWITCH, NULL, _("'%s'\nis not the same repository as\n'%s'"), anchor_url, switch_loc->repos_root_url); /* If we're not ignoring ancestry, then error out if the switch source and target don't have a common ancestory. ### We're acting on the anchor here, not the target. Is that ### okay? */ if (! ignore_ancestry) { svn_client__pathrev_t *target_base_loc, *yca; SVN_ERR(svn_client__wc_node_get_base(&target_base_loc, local_abspath, ctx->wc_ctx, pool, pool)); if (!target_base_loc) yca = NULL; /* Not versioned */ else { SVN_ERR(svn_client__get_youngest_common_ancestor( &yca, switch_loc, target_base_loc, ra_session, ctx, pool, pool)); } if (! yca) return svn_error_createf(SVN_ERR_CLIENT_UNRELATED_RESOURCES, NULL, _("'%s' shares no common ancestry with '%s'"), switch_url, svn_dirent_local_style(local_abspath, pool)); } wcroot_iprops = apr_hash_make(pool); /* Will the base of LOCAL_ABSPATH require an iprop cache post-switch? If we are switching LOCAL_ABSPATH to the root of the repository then we don't need to cache inherited properties. In all other cases we *might* need to cache iprops. */ if (strcmp(switch_loc->repos_root_url, switch_loc->url) != 0) { svn_boolean_t wc_root; svn_boolean_t needs_iprop_cache = TRUE; SVN_ERR(svn_wc__is_wcroot(&wc_root, ctx->wc_ctx, local_abspath, pool)); /* Switching the WC root to anything but the repos root means we need an iprop cache. */ if (!wc_root) { /* We know we are switching a subtree to something other than the repos root, but if we are unswitching that subtree we don't need an iprops cache. */ const char *target_parent_url; const char *unswitched_url; /* Calculate the URL LOCAL_ABSPATH would have if it was unswitched relative to its parent. */ SVN_ERR(svn_wc__node_get_url(&target_parent_url, ctx->wc_ctx, svn_dirent_dirname(local_abspath, pool), pool, pool)); unswitched_url = svn_path_url_add_component2( target_parent_url, svn_dirent_basename(local_abspath, pool), pool); /* If LOCAL_ABSPATH will be unswitched relative to its parent, then it doesn't need an iprop cache. Note: It doesn't matter if LOCAL_ABSPATH is withing a switched subtree, only if it's the *root* of a switched subtree.*/ if (strcmp(unswitched_url, switch_loc->url) == 0) needs_iprop_cache = FALSE; } if (needs_iprop_cache) { SVN_ERR(svn_ra_get_inherited_props(ra_session, &inherited_props, "", switch_loc->rev, pool, pool)); svn_hash_sets(wcroot_iprops, local_abspath, inherited_props); } } SVN_ERR(svn_ra_reparent(ra_session, anchor_url, pool)); /* Fetch the switch (update) editor. If REVISION is invalid, that's okay; the RA driver will call editor->set_target_revision() later on. */ SVN_ERR(svn_ra_has_capability(ra_session, &server_supports_depth, SVN_RA_CAPABILITY_DEPTH, pool)); dfb.ra_session = ra_session; dfb.anchor_url = anchor_url; dfb.target_revision = switch_loc->rev; SVN_ERR(svn_wc__get_switch_editor(&switch_editor, &switch_edit_baton, &revnum, ctx->wc_ctx, anchor_abspath, target, switch_loc->url, wcroot_iprops, use_commit_times, depth, depth_is_sticky, allow_unver_obstructions, server_supports_depth, 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_switch3(ra_session, &reporter, &report_baton, switch_loc->rev, target, depth_is_sticky ? depth : svn_depth_unknown, switch_loc->url, FALSE /* send_copyfrom_args */, ignore_ancestry, switch_editor, switch_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 LOCAL_ABSPATH. When this calls reporter->finish_report, the reporter will drive the switch_editor. */ 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 switch is complete, so that handling external items (and any errors therefrom) doesn't delay the primary operation. */ if (SVN_DEPTH_IS_RECURSIVE(depth) && (! 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, switch_loc->repos_root_url, local_abspath, depth, timestamp_sleep, ctx, pool)); } /* Let everyone know we're finished here. */ if (ctx->notify_func2) { svn_wc_notify_t *notify = svn_wc_create_notify(anchor_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; }
svn_error_t * svn_client_blame5(const char *target, const svn_opt_revision_t *peg_revision, const svn_opt_revision_t *start, const svn_opt_revision_t *end, const svn_diff_file_options_t *diff_options, svn_boolean_t ignore_mime_type, svn_boolean_t include_merged_revisions, svn_client_blame_receiver3_t receiver, void *receiver_baton, svn_client_ctx_t *ctx, apr_pool_t *pool) { struct file_rev_baton frb; svn_ra_session_t *ra_session; svn_revnum_t start_revnum, end_revnum; svn_client__pathrev_t *end_loc; struct blame *walk, *walk_merged = NULL; apr_pool_t *iterpool; svn_stream_t *last_stream; svn_stream_t *stream; const char *target_abspath_or_url; if (start->kind == svn_opt_revision_unspecified || end->kind == svn_opt_revision_unspecified) return svn_error_create (SVN_ERR_CLIENT_BAD_REVISION, NULL, NULL); if (svn_path_is_url(target)) target_abspath_or_url = target; else SVN_ERR(svn_dirent_get_absolute(&target_abspath_or_url, target, pool)); /* Get an RA plugin for this filesystem object. */ SVN_ERR(svn_client__ra_session_from_path2(&ra_session, &end_loc, target, NULL, peg_revision, end, ctx, pool)); end_revnum = end_loc->rev; SVN_ERR(svn_client__get_revision_number(&start_revnum, NULL, ctx->wc_ctx, target_abspath_or_url, ra_session, start, pool)); if (end_revnum < start_revnum) return svn_error_create (SVN_ERR_CLIENT_BAD_REVISION, NULL, _("Start revision must precede end revision")); frb.start_rev = start_revnum; frb.end_rev = end_revnum; frb.target = target; frb.ctx = ctx; frb.diff_options = diff_options; frb.ignore_mime_type = ignore_mime_type; frb.include_merged_revisions = include_merged_revisions; frb.last_filename = NULL; frb.last_original_filename = NULL; frb.chain = apr_palloc(pool, sizeof(*frb.chain)); frb.chain->blame = NULL; frb.chain->avail = NULL; frb.chain->pool = pool; if (include_merged_revisions) { frb.merged_chain = apr_palloc(pool, sizeof(*frb.merged_chain)); frb.merged_chain->blame = NULL; frb.merged_chain->avail = NULL; frb.merged_chain->pool = pool; } SVN_ERR(svn_ra_get_repos_root2(ra_session, &frb.repos_root_url, pool)); frb.mainpool = pool; /* The callback will flip the following two pools, because it needs information from the previous call. Obviously, it can't rely on the lifetime of the pool provided by get_file_revs. */ frb.lastpool = svn_pool_create(pool); frb.currpool = svn_pool_create(pool); if (include_merged_revisions) { frb.filepool = svn_pool_create(pool); frb.prevfilepool = svn_pool_create(pool); } /* Collect all blame information. We need to ensure that we get one revision before the start_rev, if available so that we can know what was actually changed in the start revision. */ SVN_ERR(svn_ra_get_file_revs2(ra_session, "", start_revnum - (start_revnum > 0 ? 1 : 0), end_revnum, include_merged_revisions, file_rev_handler, &frb, pool)); if (end->kind == svn_opt_revision_working) { /* If the local file is modified we have to call the handler on the working copy file with keywords unexpanded */ svn_wc_status3_t *status; SVN_ERR(svn_wc_status3(&status, ctx->wc_ctx, target_abspath_or_url, pool, pool)); if (status->text_status != svn_wc_status_normal) { apr_hash_t *props; svn_stream_t *wcfile; svn_string_t *keywords; svn_stream_t *tempfile; const char *temppath; apr_hash_t *kw = NULL; SVN_ERR(svn_wc_prop_list2(&props, ctx->wc_ctx, target_abspath_or_url, pool, pool)); SVN_ERR(svn_stream_open_readonly(&wcfile, target, pool, pool)); keywords = apr_hash_get(props, SVN_PROP_KEYWORDS, APR_HASH_KEY_STRING); if (keywords) SVN_ERR(svn_subst_build_keywords2(&kw, keywords->data, NULL, NULL, 0, NULL, pool)); wcfile = svn_subst_stream_translated(wcfile, "\n", TRUE, kw, FALSE, pool); SVN_ERR(svn_stream_open_unique(&tempfile, &temppath, NULL, svn_io_file_del_on_pool_cleanup, pool, pool)); SVN_ERR(svn_stream_copy3(wcfile, tempfile, ctx->cancel_func, ctx->cancel_baton, pool)); SVN_ERR(add_file_blame(frb.last_filename, temppath, frb.chain, NULL, frb.diff_options, pool)); frb.last_filename = temppath; } } /* Report the blame to the caller. */ /* The callback has to have been called at least once. */ SVN_ERR_ASSERT(frb.last_filename != NULL); /* Create a pool for the iteration below. */ iterpool = svn_pool_create(pool); /* Open the last file and get a stream. */ SVN_ERR(svn_stream_open_readonly(&last_stream, frb.last_filename, pool, pool)); stream = svn_subst_stream_translated(last_stream, "\n", TRUE, NULL, FALSE, pool); /* Perform optional merged chain normalization. */ if (include_merged_revisions) { /* If we never created any blame for the original chain, create it now, with the most recent changed revision. This could occur if a file was created on a branch and them merged to another branch. This is semanticly a copy, and we want to use the revision on the branch as the most recently changed revision. ### Is this really what we want to do here? Do the sematics of copy change? */ if (!frb.chain->blame) frb.chain->blame = blame_create(frb.chain, frb.rev, 0); normalize_blames(frb.chain, frb.merged_chain, pool); walk_merged = frb.merged_chain->blame; } /* Process each blame item. */ for (walk = frb.chain->blame; walk; walk = walk->next) { apr_off_t line_no; svn_revnum_t merged_rev; const char *merged_path; apr_hash_t *merged_rev_props; if (walk_merged) { merged_rev = walk_merged->rev->revision; merged_rev_props = walk_merged->rev->rev_props; merged_path = walk_merged->rev->path; } else { merged_rev = SVN_INVALID_REVNUM; merged_rev_props = NULL; merged_path = NULL; } for (line_no = walk->start; !walk->next || line_no < walk->next->start; ++line_no) { svn_boolean_t eof; svn_stringbuf_t *sb; svn_pool_clear(iterpool); SVN_ERR(svn_stream_readline(stream, &sb, "\n", &eof, iterpool)); if (ctx->cancel_func) SVN_ERR(ctx->cancel_func(ctx->cancel_baton)); if (!eof || sb->len) { if (walk->rev) SVN_ERR(receiver(receiver_baton, start_revnum, end_revnum, line_no, walk->rev->revision, walk->rev->rev_props, merged_rev, merged_rev_props, merged_path, sb->data, FALSE, iterpool)); else SVN_ERR(receiver(receiver_baton, start_revnum, end_revnum, line_no, SVN_INVALID_REVNUM, NULL, SVN_INVALID_REVNUM, NULL, NULL, sb->data, TRUE, iterpool)); } if (eof) break; } if (walk_merged) walk_merged = walk_merged->next; } SVN_ERR(svn_stream_close(stream)); svn_pool_destroy(frb.lastpool); svn_pool_destroy(frb.currpool); if (include_merged_revisions) { svn_pool_destroy(frb.filepool); svn_pool_destroy(frb.prevfilepool); } svn_pool_destroy(iterpool); return SVN_NO_ERROR; }
svn_error_t * svn_client__copy_foreign(const char *url, const char *dst_abspath, svn_opt_revision_t *peg_revision, svn_opt_revision_t *revision, svn_depth_t depth, svn_boolean_t make_parents, svn_boolean_t already_locked, svn_client_ctx_t *ctx, apr_pool_t *scratch_pool) { svn_ra_session_t *ra_session; svn_client__pathrev_t *loc; svn_node_kind_t kind; svn_node_kind_t wc_kind; const char *dir_abspath; SVN_ERR_ASSERT(svn_path_is_url(url)); SVN_ERR_ASSERT(svn_dirent_is_absolute(dst_abspath)); /* Do we need to validate/update revisions? */ SVN_ERR(svn_client__ra_session_from_path2(&ra_session, &loc, url, NULL, peg_revision, revision, ctx, scratch_pool)); SVN_ERR(svn_ra_check_path(ra_session, "", loc->rev, &kind, scratch_pool)); if (kind != svn_node_file && kind != svn_node_dir) return svn_error_createf( SVN_ERR_ILLEGAL_TARGET, NULL, _("'%s' is not a valid location inside a repository"), url); SVN_ERR(svn_wc_read_kind2(&wc_kind, ctx->wc_ctx, dst_abspath, FALSE, TRUE, scratch_pool)); if (wc_kind != svn_node_none) { return svn_error_createf( SVN_ERR_ENTRY_EXISTS, NULL, _("'%s' is already under version control"), svn_dirent_local_style(dst_abspath, scratch_pool)); } dir_abspath = svn_dirent_dirname(dst_abspath, scratch_pool); SVN_ERR(svn_wc_read_kind2(&wc_kind, ctx->wc_ctx, dir_abspath, FALSE, FALSE, scratch_pool)); if (wc_kind == svn_node_none) { if (make_parents) SVN_ERR(svn_client__make_local_parents(dir_abspath, make_parents, ctx, scratch_pool)); SVN_ERR(svn_wc_read_kind2(&wc_kind, ctx->wc_ctx, dir_abspath, FALSE, FALSE, scratch_pool)); } if (wc_kind != svn_node_dir) return svn_error_createf( SVN_ERR_ENTRY_NOT_FOUND, NULL, _("Can't add '%s', because no parent directory is found"), svn_dirent_local_style(dst_abspath, scratch_pool)); if (kind == svn_node_file) { svn_stream_t *target; apr_hash_t *props; apr_hash_index_t *hi; SVN_ERR(svn_stream_open_writable(&target, dst_abspath, scratch_pool, scratch_pool)); SVN_ERR(svn_ra_get_file(ra_session, "", loc->rev, target, NULL, &props, scratch_pool)); if (props != NULL) for (hi = apr_hash_first(scratch_pool, props); hi; hi = apr_hash_next(hi)) { const char *name = apr_hash_this_key(hi); if (svn_property_kind2(name) != svn_prop_regular_kind || ! strcmp(name, SVN_PROP_MERGEINFO)) { /* We can't handle DAV, ENTRY and merge specific props here */ svn_hash_sets(props, name, NULL); } } if (!already_locked) SVN_WC__CALL_WITH_WRITE_LOCK( svn_wc_add_from_disk3(ctx->wc_ctx, dst_abspath, props, TRUE /* skip checks */, ctx->notify_func2, ctx->notify_baton2, scratch_pool), ctx->wc_ctx, dir_abspath, FALSE, scratch_pool); else SVN_ERR(svn_wc_add_from_disk3(ctx->wc_ctx, dst_abspath, props, TRUE /* skip checks */, ctx->notify_func2, ctx->notify_baton2, scratch_pool)); } else { if (!already_locked) SVN_WC__CALL_WITH_WRITE_LOCK( copy_foreign_dir(ra_session, loc, ctx->wc_ctx, dst_abspath, depth, ctx->notify_func2, ctx->notify_baton2, ctx->cancel_func, ctx->cancel_baton, scratch_pool), ctx->wc_ctx, dir_abspath, FALSE, scratch_pool); else SVN_ERR(copy_foreign_dir(ra_session, loc, ctx->wc_ctx, dst_abspath, depth, ctx->notify_func2, ctx->notify_baton2, ctx->cancel_func, ctx->cancel_baton, scratch_pool)); } return SVN_NO_ERROR; }
static svn_error_t * bench_null_blame(const char *target, const svn_opt_revision_t *peg_revision, const svn_opt_revision_t *start, const svn_opt_revision_t *end, svn_boolean_t include_merged_revisions, svn_boolean_t quiet, svn_client_ctx_t *ctx, apr_pool_t *pool) { struct file_rev_baton frb = { 0, 0, 0}; svn_ra_session_t *ra_session; svn_revnum_t start_revnum, end_revnum; svn_boolean_t backwards; const char *target_abspath_or_url; if (start->kind == svn_opt_revision_unspecified || end->kind == svn_opt_revision_unspecified) return svn_error_create (SVN_ERR_CLIENT_BAD_REVISION, NULL, NULL); if (svn_path_is_url(target)) target_abspath_or_url = target; else SVN_ERR(svn_dirent_get_absolute(&target_abspath_or_url, target, pool)); /* Get an RA plugin for this filesystem object. */ SVN_ERR(svn_client__ra_session_from_path2(&ra_session, NULL, target, NULL, peg_revision, peg_revision, ctx, pool)); SVN_ERR(svn_client__get_revision_number(&start_revnum, NULL, ctx->wc_ctx, target_abspath_or_url, ra_session, start, pool)); SVN_ERR(svn_client__get_revision_number(&end_revnum, NULL, ctx->wc_ctx, target_abspath_or_url, ra_session, end, pool)); { svn_client__pathrev_t *loc; svn_opt_revision_t younger_end; younger_end.kind = svn_opt_revision_number; younger_end.value.number = MAX(start_revnum, end_revnum); SVN_ERR(svn_client__resolve_rev_and_url(&loc, ra_session, target, peg_revision, &younger_end, ctx, pool)); /* Make the session point to the real URL. */ SVN_ERR(svn_ra_reparent(ra_session, loc->url, pool)); } backwards = (start_revnum > end_revnum); /* Collect all blame information. We need to ensure that we get one revision before the start_rev, if available so that we can know what was actually changed in the start revision. */ SVN_ERR(svn_ra_get_file_revs2(ra_session, "", backwards ? start_revnum : MAX(0, start_revnum-1), end_revnum, include_merged_revisions, file_rev_handler, &frb, pool)); if (!quiet) SVN_ERR(svn_cmdline_printf(pool, _("%15s revisions\n" "%15s deltas\n" "%15s bytes in deltas\n"), svn__ui64toa_sep(frb.rev_count, ',', pool), svn__ui64toa_sep(frb.delta_count, ',', pool), svn__ui64toa_sep(frb.byte_count, ',', pool))); return SVN_NO_ERROR; }