📄 prop_commands.c
字号:
return SVN_NO_ERROR;}/* A baton for propget_walk_cb. */struct propget_walk_baton{ const char *propname; /* The name of the property to get. */ svn_boolean_t pristine; /* Select base rather than working props. */ svn_wc_adm_access_t *base_access; /* Access for the tree being walked. */ apr_hash_t *props; /* Out: mapping of (path:propval). */};/* An entries-walk callback for svn_client_propget. * * For the path given by PATH and ENTRY, * populate wb->PROPS with the values of property wb->PROPNAME, * where "wb" is the WALK_BATON of type "struct propget_walk_baton *". * If wb->PRISTINE is true, use the base value, else use the working value. * * The keys of wb->PROPS will be 'const char *' paths, rooted at the * path svn_wc_adm_access_path(ADM_ACCESS), and the values are * 'const svn_string_t *' property values. */static svn_error_t *propget_walk_cb(const char *path, const svn_wc_entry_t *entry, void *walk_baton, apr_pool_t *pool){ struct propget_walk_baton *wb = walk_baton; const svn_string_t *propval; /* We're going to receive dirents twice; we want to ignore the first one (where it's a child of a parent dir), and only use the second one (where we're looking at THIS_DIR). */ if ((entry->kind == svn_node_dir) && (strcmp(entry->name, SVN_WC_ENTRY_THIS_DIR) != 0)) return SVN_NO_ERROR; /* Ignore the entry if it does not exist at the time of interest. */ if (entry->schedule == (wb->pristine ? svn_wc_schedule_add : svn_wc_schedule_delete)) return SVN_NO_ERROR; SVN_ERR(pristine_or_working_propval(&propval, wb->propname, path, wb->base_access, wb->pristine, apr_hash_pool_get(wb->props))); if (propval) { path = apr_pstrdup(apr_hash_pool_get(wb->props), path); apr_hash_set(wb->props, path, APR_HASH_KEY_STRING, propval); } return SVN_NO_ERROR;}/* If REVISION represents a revision not present in the working copy, * then set *NEW_TARGET to the url for TARGET, allocated in POOL; else * set *NEW_TARGET to TARGET (just assign, do not copy), whether or * not TARGET is a url. * * TARGET and *NEW_TARGET may be the same, though most callers * probably don't want them to be. */static svn_error_t *maybe_convert_to_url(const char **new_target, const char *target, const svn_opt_revision_t *revision, apr_pool_t *pool){ /* If we don't already have a url, and the revision kind is such that we need a url, then get one. */ if ((revision->kind != svn_opt_revision_unspecified) && (revision->kind != svn_opt_revision_base) && (revision->kind != svn_opt_revision_working) && (revision->kind != svn_opt_revision_committed) && (! svn_path_is_url(target))) { svn_wc_adm_access_t *adm_access; svn_node_kind_t kind; const char *pdir; const svn_wc_entry_t *entry; SVN_ERR(svn_io_check_path(target, &kind, pool)); if (kind == svn_node_file) svn_path_split(target, &pdir, NULL, pool); else pdir = target; SVN_ERR(svn_wc_adm_open3(&adm_access, NULL, pdir, FALSE, 0, NULL, NULL, pool)); SVN_ERR(svn_wc_entry(&entry, target, adm_access, FALSE, pool)); if (! entry) return svn_error_createf(SVN_ERR_UNVERSIONED_RESOURCE, NULL, _("'%s' is not under version control"), svn_path_local_style(target, pool)); *new_target = entry->url; } else *new_target = target; return SVN_NO_ERROR;}/* Helper for the remote case of svn_client_propget. * * Get the value of property PROPNAME in REVNUM, using RA_LIB and * SESSION. Store the value ('svn_string_t *') in PROPS, under the * path key "TARGET_PREFIX/TARGET_RELATIVE" ('const char *'). * * If RECURSE is true and KIND is svn_node_dir, then recurse. * * KIND is the kind of the node at "TARGET_PREFIX/TARGET_RELATIVE". * Yes, caller passes this; it makes the recursion more efficient :-). * * Allocate the keys and values in POOL. */static svn_error_t *remote_propget(apr_hash_t *props, const char *propname, const char *target_prefix, const char *target_relative, svn_node_kind_t kind, svn_revnum_t revnum, svn_ra_session_t *ra_session, svn_boolean_t recurse, apr_pool_t *pool){ apr_hash_t *dirents; apr_hash_t *prop_hash; if (kind == svn_node_dir) { SVN_ERR(svn_ra_get_dir2(ra_session, (recurse ? &dirents : NULL), NULL, &prop_hash, target_relative, revnum, SVN_DIRENT_KIND, pool)); } else if (kind == svn_node_file) { SVN_ERR(svn_ra_get_file(ra_session, target_relative, revnum, NULL, NULL, &prop_hash, pool)); } else if (kind == svn_node_none) { return svn_error_createf (SVN_ERR_ENTRY_NOT_FOUND, NULL, _("'%s' does not exist in revision '%ld'"), svn_path_join(target_prefix, target_relative, pool), revnum); } else { return svn_error_createf (SVN_ERR_NODE_UNKNOWN_KIND, NULL, _("Unknown node kind for '%s'"), svn_path_join(target_prefix, target_relative, pool)); } apr_hash_set(props, svn_path_join(target_prefix, target_relative, pool), APR_HASH_KEY_STRING, apr_hash_get(prop_hash, propname, APR_HASH_KEY_STRING)); if (recurse && (kind == svn_node_dir) && (apr_hash_count(dirents) > 0)) { apr_hash_index_t *hi; for (hi = apr_hash_first(pool, dirents); hi; hi = apr_hash_next(hi)) { const void *key; void *val; const char *this_name; svn_dirent_t *this_ent; const char *new_target_relative; apr_hash_this(hi, &key, NULL, &val); this_name = key; this_ent = val; new_target_relative = svn_path_join(target_relative, this_name, pool); SVN_ERR(remote_propget(props, propname, target_prefix, new_target_relative, this_ent->kind, revnum, ra_session, recurse, pool)); } } return SVN_NO_ERROR;}/* Note: this implementation is very similar to svn_client_proplist. */svn_error_t *svn_client_propget2(apr_hash_t **props, const char *propname, const char *target, const svn_opt_revision_t *peg_revision, const svn_opt_revision_t *revision, svn_boolean_t recurse, svn_client_ctx_t *ctx, apr_pool_t *pool){ svn_wc_adm_access_t *adm_access; const svn_wc_entry_t *node; const char *utarget; /* target, or the url for target */ const char *url; svn_revnum_t revnum; SVN_ERR(error_if_wcprop_name(propname)); *props = apr_hash_make(pool); SVN_ERR(maybe_convert_to_url(&utarget, target, revision, pool)); /* Iff utarget is a url, that means we must use it, that is, the requested property information is not available locally. */ if (svn_path_is_url(utarget)) { svn_ra_session_t *ra_session; svn_node_kind_t kind; /* Get an RA plugin for this filesystem object. */ SVN_ERR(svn_client__ra_session_from_path(&ra_session, &revnum, &url, target, peg_revision, revision, ctx, pool)); SVN_ERR(svn_ra_check_path(ra_session, "", revnum, &kind, pool)); SVN_ERR(remote_propget(*props, propname, url, "", kind, revnum, ra_session, recurse, pool)); } else /* working copy path */ { svn_boolean_t pristine; struct propget_walk_baton wb; static const svn_wc_entry_callbacks_t walk_callbacks = { propget_walk_cb }; SVN_ERR(svn_wc_adm_probe_open3(&adm_access, NULL, target, FALSE, recurse ? -1 : 0, ctx->cancel_func, ctx->cancel_baton, pool)); SVN_ERR(svn_wc_entry(&node, target, adm_access, FALSE, pool)); if (! node) return svn_error_createf (SVN_ERR_UNVERSIONED_RESOURCE, NULL, _("'%s' is not under version control"), svn_path_local_style(target, pool)); SVN_ERR(svn_client__get_revision_number (&revnum, NULL, revision, target, pool)); if ((revision->kind == svn_opt_revision_committed) || (revision->kind == svn_opt_revision_base)) { pristine = TRUE; } else /* must be the working revision */ { pristine = FALSE; } wb.base_access = adm_access; wb.props = *props; wb.propname = propname; wb.pristine = pristine; /* Fetch, recursively or not. */ if (recurse && (node->kind == svn_node_dir)) { SVN_ERR(svn_wc_walk_entries2(target, adm_access, &walk_callbacks, &wb, FALSE, ctx->cancel_func, ctx->cancel_baton, pool)); } else { const svn_wc_entry_t *entry; SVN_ERR(svn_wc_entry(&entry, target, adm_access, FALSE, pool)); SVN_ERR(walk_callbacks.found_entry(target, entry, &wb, pool)); } SVN_ERR(svn_wc_adm_close(adm_access)); } return SVN_NO_ERROR;}svn_error_t *svn_client_propget(apr_hash_t **props, const char *propname, const char *target, const svn_opt_revision_t *revision, svn_boolean_t recurse, svn_client_ctx_t *ctx, apr_pool_t *pool){ return svn_client_propget2(props, propname, target, revision, revision, recurse, ctx, pool);} svn_error_t *svn_client_revprop_get(const char *propname, svn_string_t **propval, const char *URL, const svn_opt_revision_t *revision, svn_revnum_t *set_rev, svn_client_ctx_t *ctx, apr_pool_t *pool){ svn_ra_session_t *ra_session; /* Open an RA session for the URL. Note that we don't have a local directory, nor a place to put temp files. */ SVN_ERR(svn_client__open_ra_session_internal(&ra_session, URL, NULL, NULL, NULL, FALSE, TRUE, ctx, pool)); /* Resolve the revision into something real, and return that to the caller as well. */ SVN_ERR(svn_client__get_revision_number (set_rev, ra_session, revision, NULL, pool)); /* The actual RA call. */ SVN_ERR(svn_ra_rev_prop(ra_session, *set_rev, propname, propval, pool)); return SVN_NO_ERROR;}/* Push a new 'svn_client_proplist_item_t *' item onto LIST.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -