/* Attempt to find the repository root url for TARGET, possibly using CTX for * authentication. If one is found and *ROOT_URL is not NULL, then just check * that the root url for TARGET matches the value given in *ROOT_URL and * return an error if it does not. If one is found and *ROOT_URL is NULL then * set *ROOT_URL to the root url for TARGET, allocated from POOL. * If a root url is not found for TARGET because it does not exist in the * repository, then return with no error. * * TARGET is a UTF-8 encoded string that is fully canonicalized and escaped. */ static svn_error_t * check_root_url_of_target(const char **root_url, const char *target, svn_client_ctx_t *ctx, apr_pool_t *pool) { svn_error_t *err; const char *tmp_root_url; const char *truepath; svn_opt_revision_t opt_rev; SVN_ERR(svn_opt_parse_path(&opt_rev, &truepath, target, pool)); if (!svn_path_is_url(truepath)) SVN_ERR(svn_dirent_get_absolute(&truepath, truepath, pool)); err = svn_client__get_repos_root(&tmp_root_url, truepath, ctx, pool, pool); if (err) { /* It is OK if the given target does not exist, it just means * we will not be able to determine the root url from this particular * argument. * * If the target itself is a URL to a repository that does not exist, * that's fine, too. The callers will deal with this argument in an * appropriate manter if it does not make any sense. * * Also tolerate locally added targets ("bad revision" error). */ if ((err->apr_err == SVN_ERR_ENTRY_NOT_FOUND) || (err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND) || (err->apr_err == SVN_ERR_WC_NOT_WORKING_COPY) || (err->apr_err == SVN_ERR_RA_LOCAL_REPOS_OPEN_FAILED) || (err->apr_err == SVN_ERR_CLIENT_BAD_REVISION)) { svn_error_clear(err); return SVN_NO_ERROR; } else return svn_error_trace(err); } if (*root_url && tmp_root_url) { if (strcmp(*root_url, tmp_root_url) != 0) return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL, _("All non-relative targets must have " "the same root URL")); } else *root_url = tmp_root_url; return SVN_NO_ERROR; }
svn_error_t * svn_client_root_url_from_path(const char **url, const char *path_or_url, svn_client_ctx_t *ctx, apr_pool_t *pool) { svn_opt_revision_t peg_revision; peg_revision.kind = svn_path_is_url(path_or_url) ? svn_opt_revision_head : svn_opt_revision_base; return svn_client__get_repos_root(url, path_or_url, &peg_revision, NULL, ctx, pool); }