locking_commands.c
来自「subversion-1.4.5.tar.gz 配置svn的源码」· C语言 代码 · 共 486 行 · 第 1/2 页
C
486 行
{ const svn_wc_entry_t *entry; const char *target = ((const char **) (rel_targets->elts))[i]; const char *abs_path; svn_pool_clear(subpool); abs_path = svn_path_join (svn_wc_adm_access_path(*parent_adm_access_p), target, subpool); SVN_ERR(svn_wc_entry(&entry, abs_path, *parent_adm_access_p, FALSE, subpool)); if (! entry) return svn_error_createf(SVN_ERR_UNVERSIONED_RESOURCE, NULL, _("'%s' is not under version control"), svn_path_local_style(target, pool)); if (! entry->url) return svn_error_createf(SVN_ERR_ENTRY_MISSING_URL, NULL, _("'%s' has no URL"), svn_path_local_style(target, pool)); (*((const char **)(apr_array_push(urls)))) = apr_pstrdup (pool, entry->url); } /* Condense our absolute urls and get the relative urls. */ SVN_ERR(svn_path_condense_targets(&common_url, &rel_urls, urls, FALSE, pool)); /* svn_path_condense_targets leaves paths empty if TARGETS only had 1 member, so we special case that (again). */ if (apr_is_empty_array(rel_urls)) { char *base_name = svn_path_basename(common_url, pool); common_url = svn_path_dirname(common_url, pool); APR_ARRAY_PUSH(rel_urls, char *) = base_name; } /* If we have no common URL parent, bail (cross-repos lock attempt) */ if (common_url == NULL || (common_url)[0] == '\0') return svn_error_create (SVN_ERR_UNSUPPORTED_FEATURE, NULL, _("Unable to lock/unlock across multiple repositories")); /* Now that we've got the relative URLs, gather our targets and store the mapping between relative repository path and WC path. */ for (i = 0; i < rel_targets->nelts; i++) { const svn_wc_entry_t *entry; const char *target = APR_ARRAY_IDX(rel_targets, i, const char *); const char *url = APR_ARRAY_IDX(rel_urls, i, const char *); const char *abs_path; const char *decoded_url = svn_path_uri_decode(url, pool); svn_pool_clear(subpool); apr_hash_set(urls_hash, decoded_url, APR_HASH_KEY_STRING, apr_pstrdup(pool, target)); abs_path = svn_path_join (svn_wc_adm_access_path(*parent_adm_access_p), target, subpool); SVN_ERR(svn_wc_entry(&entry, abs_path, *parent_adm_access_p, FALSE, subpool)); if (do_lock) /* Lock. */ { svn_revnum_t *revnum; revnum = apr_palloc(pool, sizeof(* revnum)); *revnum = entry->revision; apr_hash_set(rel_targets_ret, decoded_url, APR_HASH_KEY_STRING, revnum); } else /* Unlock. */ { /* If not force, get the lock token from the WC entry. */ if (! force) { if (! entry->lock_token) return svn_error_createf (SVN_ERR_CLIENT_MISSING_LOCK_TOKEN, NULL, _("'%s' is not locked in this working copy"), target); apr_hash_set(rel_targets_ret, decoded_url, APR_HASH_KEY_STRING, apr_pstrdup(pool, entry->lock_token)); } else { /* If breaking a lock, we shouldn't pass any lock token. */ apr_hash_set(rel_targets_ret, decoded_url, APR_HASH_KEY_STRING, ""); } } } *rel_fs_paths_p = urls_hash; *common_parent = common_url; } *rel_targets_p = rel_targets_ret; svn_pool_destroy(subpool); return SVN_NO_ERROR;}/* Fetch lock tokens from the repository for the paths in PATH_TOKENS, setting the values to the fetched tokens, allocated in pool. */static svn_error_t *fetch_tokens(svn_ra_session_t *ra_session, apr_hash_t *path_tokens, apr_pool_t *pool){ apr_hash_index_t *hi; apr_pool_t *iterpool = svn_pool_create(pool); for (hi = apr_hash_first(pool, path_tokens); hi; hi = apr_hash_next(hi)) { const void *key; const char *path; svn_lock_t *lock; svn_pool_clear(iterpool); apr_hash_this(hi, &key, NULL, NULL); path = key; SVN_ERR(svn_ra_get_lock(ra_session, &lock, path, iterpool)); if (! lock) return svn_error_createf (SVN_ERR_CLIENT_MISSING_LOCK_TOKEN, NULL, _("'%s' is not locked"), path); apr_hash_set(path_tokens, path, APR_HASH_KEY_STRING, apr_pstrdup(pool, lock->token)); } svn_pool_destroy(iterpool); return SVN_NO_ERROR;}svn_error_t *svn_client_lock(const apr_array_header_t *targets, const char *comment, svn_boolean_t steal_lock, svn_client_ctx_t *ctx, apr_pool_t *pool){ svn_wc_adm_access_t *adm_access; const char *common_parent; svn_ra_session_t *ra_session; apr_hash_t *path_revs, *urls_to_paths; struct lock_baton cb; if (apr_is_empty_array(targets)) return SVN_NO_ERROR; /* Enforce that the comment be xml-escapable. */ if (comment) { if (! svn_xml_is_xml_safe(comment, strlen(comment))) return svn_error_create (SVN_ERR_XML_UNESCAPABLE_DATA, NULL, _("Lock comment has illegal characters")); } SVN_ERR(organize_lock_targets(&common_parent, &adm_access, &path_revs, &urls_to_paths, targets, TRUE, steal_lock, ctx, pool)); /* Open an RA session to the common parent of TARGETS. */ SVN_ERR(svn_client__open_ra_session_internal (&ra_session, common_parent, adm_access ? svn_wc_adm_access_path(adm_access) : NULL, adm_access, NULL, FALSE, FALSE, ctx, pool)); cb.pool = pool; cb.adm_access = adm_access; cb.urls_to_paths = urls_to_paths; cb.ctx = ctx; /* Lock the paths. */ SVN_ERR(svn_ra_lock(ra_session, path_revs, comment, steal_lock, store_locks_callback, &cb, pool)); /* Unlock the wc. */ if (adm_access) SVN_ERR(svn_wc_adm_close(adm_access)); return SVN_NO_ERROR;}svn_error_t *svn_client_unlock(const apr_array_header_t *targets, svn_boolean_t break_lock, svn_client_ctx_t *ctx, apr_pool_t *pool){ svn_wc_adm_access_t *adm_access; const char *common_parent; svn_ra_session_t *ra_session; apr_hash_t *path_tokens, *urls_to_paths; struct lock_baton cb; if (apr_is_empty_array(targets)) return SVN_NO_ERROR; SVN_ERR(organize_lock_targets(&common_parent, &adm_access, &path_tokens, &urls_to_paths, targets, FALSE, break_lock, ctx, pool)); /* Open an RA session. */ SVN_ERR(svn_client__open_ra_session_internal (&ra_session, common_parent, adm_access ? svn_wc_adm_access_path(adm_access) : NULL, adm_access, NULL, FALSE, FALSE, ctx, pool)); /* If break_lock is not set, lock tokens are required by the server. If the targets were all URLs, ensure that we provide lock tokens, so the repository will only check that the user owns the locks. */ if (! adm_access && !break_lock) SVN_ERR(fetch_tokens(ra_session, path_tokens, pool)); cb.pool = pool; cb.adm_access = adm_access; cb.urls_to_paths = urls_to_paths; cb.ctx = ctx; /* Unlock the paths. */ SVN_ERR(svn_ra_unlock(ra_session, path_tokens, break_lock, store_locks_callback, &cb, pool)); /* Unlock the wc. */ if (adm_access) SVN_ERR(svn_wc_adm_close(adm_access)); return SVN_NO_ERROR;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?