/* Normalize the encoding and line ending style of the values of properties * in REV_PROPS that "need translation" (according to * svn_prop_needs_translation(), which is currently all svn:* props) so that * they are encoded in UTF-8 and contain only LF (\n) line endings. * * The number of properties that needed line ending normalization is returned in * *NORMALIZED_COUNT. * * No re-encoding is performed if SOURCE_PROP_ENCODING is NULL. */ svn_error_t * svnsync_normalize_revprops(apr_hash_t *rev_props, int *normalized_count, const char *source_prop_encoding, apr_pool_t *pool) { apr_hash_index_t *hi; *normalized_count = 0; for (hi = apr_hash_first(pool, rev_props); hi; hi = apr_hash_next(hi)) { const char *propname = apr_hash_this_key(hi); const svn_string_t *propval = apr_hash_this_val(hi); if (svn_prop_needs_translation(propname)) { svn_boolean_t was_normalized; SVN_ERR(normalize_string(&propval, &was_normalized, source_prop_encoding, pool, pool)); /* Replace the existing prop value. */ svn_hash_sets(rev_props, propname, propval); if (was_normalized) (*normalized_count)++; /* Count it. */ } } return SVN_NO_ERROR; }
svn_error_t * svn_repos__validate_prop(const char *name, const svn_string_t *value, apr_pool_t *pool) { svn_prop_kind_t kind = svn_property_kind2(name); /* Allow deleting any property, even a property we don't allow to set. */ if (value == NULL) return SVN_NO_ERROR; /* Disallow setting non-regular properties. */ if (kind != svn_prop_regular_kind) return svn_error_createf (SVN_ERR_REPOS_BAD_ARGS, NULL, _("Storage of non-regular property '%s' is disallowed through the " "repository interface, and could indicate a bug in your client"), name); /* Validate "svn:" properties. */ if (svn_prop_is_svn_prop(name) && value != NULL) { /* Validate that translated props (e.g., svn:log) are UTF-8 with * LF line endings. */ if (svn_prop_needs_translation(name)) { if (!svn_utf__is_valid(value->data, value->len)) { return svn_error_createf (SVN_ERR_BAD_PROPERTY_VALUE, NULL, _("Cannot accept '%s' property because it is not encoded in " "UTF-8"), name); } /* Disallow inconsistent line ending style, by simply looking for * carriage return characters ('\r'). */ if (strchr(value->data, '\r') != NULL) { return svn_error_createf (SVN_ERR_BAD_PROPERTY_VALUE, NULL, _("Cannot accept non-LF line endings in '%s' property"), name); } } /* "svn:date" should be a valid date. */ if (strcmp(name, SVN_PROP_REVISION_DATE) == 0) { apr_time_t temp; svn_error_t *err; err = svn_time_from_cstring(&temp, value->data, pool); if (err) return svn_error_create(SVN_ERR_BAD_PROPERTY_VALUE, err, NULL); } } return SVN_NO_ERROR; }
static int l_revprop_list (lua_State *L) { const char *url = luaL_checkstring (L, 1); svn_opt_revision_t revision; if (lua_gettop (L) < 2 || lua_isnil (L, 2)) { revision.kind = get_revision_kind (url); } else { revision.kind = svn_opt_revision_number; revision.value.number = lua_tointeger (L, 2); } apr_pool_t *pool; svn_error_t *err; svn_client_ctx_t *ctx; init_function (&ctx, &pool, L); url = svn_path_canonicalize (url, pool); apr_hash_t *entries; apr_hash_index_t *hi; void *val; const void *key; svn_revnum_t rev; err = svn_client_revprop_list (&entries, url, &revision, &rev, ctx, pool); IF_ERROR_RETURN (err, pool, L); lua_newtable (L); for (hi = apr_hash_first (pool, entries); hi; hi = apr_hash_next (hi)) { const char *pname; svn_string_t *pval; apr_hash_this (hi, &key, NULL, &val); pname = key; pval = (svn_string_t *) val; if (svn_prop_needs_translation (pname)) { err = svn_subst_translate_string (&pval, pval, APR_LOCALE_CHARSET, pool); IF_ERROR_RETURN (err, pool, L); } err = svn_cmdline_cstring_from_utf8 (&pname, pname, pool); IF_ERROR_RETURN (err, pool, L); lua_pushstring (L, pval->data); lua_setfield (L, -2, pname); } svn_pool_destroy (pool); return 1; }
static svn_error_t * change_file_prop(void *file_baton, const char *name, const svn_string_t *value, apr_pool_t *pool) { node_baton_t *fb = file_baton; edit_baton_t *eb = fb->edit_baton; /* only regular properties can pass over libsvn_ra */ if (svn_property_kind2(name) != svn_prop_regular_kind) return SVN_NO_ERROR; /* Maybe drop svn:mergeinfo. */ if (eb->strip_mergeinfo && (strcmp(name, SVN_PROP_MERGEINFO) == 0)) { eb->mergeinfo_stripped = TRUE; return SVN_NO_ERROR; } /* Maybe drop (errantly set, as this is a file) svnmerge.py properties. */ if (eb->migrate_svnmerge && (strcmp(name, "svnmerge-integrated") == 0)) { eb->svnmerge_migrated = TRUE; return SVN_NO_ERROR; } /* Remember if we see any svnmerge-blocked properties. (They really shouldn't be here, as this is a file, but whatever...) */ if (eb->migrate_svnmerge && (strcmp(name, "svnmerge-blocked") == 0)) { eb->svnmerge_blocked = TRUE; } /* Normalize svn:* properties as necessary. */ if (svn_prop_needs_translation(name)) { svn_boolean_t was_normalized; svn_boolean_t mergeinfo_tweaked = FALSE; /* Normalize encoding to UTF-8, and EOL style to LF. */ SVN_ERR(normalize_string(&value, &was_normalized, eb->source_prop_encoding, pool, pool)); /* Correct malformed mergeinfo. */ if (value && strcmp(name, SVN_PROP_MERGEINFO) == 0) { SVN_ERR(remove_r0_mergeinfo(&value, &mergeinfo_tweaked, pool, pool)); if (mergeinfo_tweaked) eb->mergeinfo_tweaked = TRUE; } if (was_normalized) (*(eb->normalized_node_props_counter))++; } return eb->wrapped_editor->change_file_prop(fb->wrapped_node_baton, name, value, pool); }
static int l_revprop_set (lua_State *L) { apr_pool_t *pool; svn_error_t *err; svn_client_ctx_t *ctx; svn_opt_revision_t revision; svn_revnum_t rev; const char *url = luaL_checkstring (L, 1); const char *propname = luaL_checkstring (L, 2); const char *propval = lua_isnil (L, 3) ? NULL : luaL_checkstring (L, 3); const char *propname_utf8 = NULL; int itable = 5; svn_boolean_t force = FALSE; if (lua_gettop (L) < 4 || lua_isnil (L, 4)) { revision.kind = get_revision_kind (url); } else { revision.kind = svn_opt_revision_number; revision.value.number = lua_tointeger (L, 4); } if (lua_gettop (L) >= itable && lua_istable (L, itable)) { lua_getfield (L, itable, "force"); if (lua_isboolean (L, -1)) { force = lua_toboolean (L, -1); } } init_function (&ctx, &pool, L); url = svn_path_canonicalize (url, pool); err = svn_utf_cstring_to_utf8 (&propname_utf8, propname, pool); IF_ERROR_RETURN (err, pool, L); if (propval != NULL) { svn_string_t *sstring = svn_string_create (propval, pool); if (svn_prop_needs_translation (propname_utf8)) { err = svn_subst_translate_string (&sstring, sstring, APR_LOCALE_CHARSET, pool); IF_ERROR_RETURN (err, pool, L); } err = svn_client_revprop_set (propname_utf8, sstring, url, &revision, &rev, force, ctx, pool); } else { err = svn_client_revprop_set (propname_utf8, NULL, url, &revision, &rev, force, ctx, pool); } IF_ERROR_RETURN (err, pool, L); svn_pool_destroy (pool); return 0; }
static int l_revprop_get (lua_State *L) { const char *url = luaL_checkstring (L, 1); const char *propname = luaL_checkstring (L, 2); svn_opt_revision_t revision; if (lua_gettop (L) < 3 || lua_isnil (L, 3)) { revision.kind = get_revision_kind (url); } else { revision.kind = svn_opt_revision_number; revision.value.number = lua_tointeger (L, 3); } apr_pool_t *pool; svn_error_t *err; svn_client_ctx_t *ctx; init_function (&ctx, &pool, L); url = svn_path_canonicalize (url, pool); const char *propname_utf8; err = svn_utf_cstring_to_utf8 (&propname_utf8, propname, pool); IF_ERROR_RETURN (err, pool, L); svn_string_t *propval; svn_revnum_t rev; err = svn_client_revprop_get (propname_utf8, &propval, url, &revision, &rev, ctx, pool); IF_ERROR_RETURN (err, pool, L); svn_string_t *printable_val = propval; if (svn_prop_needs_translation (propname_utf8)) { err = svn_subst_detranslate_string (&printable_val, propval, TRUE, pool); IF_ERROR_RETURN (err, pool, L); } lua_pushstring (L, printable_val->data); svn_pool_destroy (pool); return 1; }
svn_error_t * svn_rdump__normalize_prop(const char *name, const svn_string_t **value, apr_pool_t *result_pool) { if (svn_prop_needs_translation(name)) { const char *cstring; SVN_ERR(svn_subst_translate_cstring2((*value)->data, &cstring, "\n", TRUE, NULL, FALSE, result_pool)); *value = svn_string_create(cstring, result_pool); } return SVN_NO_ERROR; }
/* This implements the `svn_opt_subcommand_t' interface. */ svn_error_t * svn_cl__propget(apr_getopt_t *os, void *baton, apr_pool_t *pool) { svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state; svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx; const char *pname, *pname_utf8; apr_array_header_t *args, *targets; svn_stream_t *out; if (opt_state->verbose && (opt_state->revprop || opt_state->strict || opt_state->xml)) return svn_error_create(SVN_ERR_CL_MUTUALLY_EXCLUSIVE_ARGS, NULL, _("--verbose cannot be used with --revprop or " "--strict or --xml")); /* PNAME is first argument (and PNAME_UTF8 will be a UTF-8 version thereof) */ SVN_ERR(svn_opt_parse_num_args(&args, os, 1, pool)); pname = APR_ARRAY_IDX(args, 0, const char *); SVN_ERR(svn_utf_cstring_to_utf8(&pname_utf8, pname, pool)); if (! svn_prop_name_is_valid(pname_utf8)) return svn_error_createf(SVN_ERR_CLIENT_PROPERTY_NAME, NULL, _("'%s' is not a valid Subversion property name"), pname_utf8); SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os, opt_state->targets, ctx, FALSE, pool)); /* Add "." if user passed 0 file arguments */ svn_opt_push_implicit_dot_target(targets, pool); /* Open a stream to stdout. */ SVN_ERR(svn_stream_for_stdout(&out, pool)); if (opt_state->revprop) /* operate on a revprop */ { svn_revnum_t rev; const char *URL; svn_string_t *propval; SVN_ERR(svn_cl__revprop_prepare(&opt_state->start_revision, targets, &URL, ctx, pool)); /* Let libsvn_client do the real work. */ SVN_ERR(svn_client_revprop_get(pname_utf8, &propval, URL, &(opt_state->start_revision), &rev, ctx, pool)); if (propval != NULL) { if (opt_state->xml) { svn_stringbuf_t *sb = NULL; char *revstr = apr_psprintf(pool, "%ld", rev); SVN_ERR(svn_cl__xml_print_header("properties", pool)); svn_xml_make_open_tag(&sb, pool, svn_xml_normal, "revprops", "rev", revstr, NULL); svn_cmdline__print_xml_prop(&sb, pname_utf8, propval, pool); svn_xml_make_close_tag(&sb, pool, "revprops"); SVN_ERR(svn_cl__error_checked_fputs(sb->data, stdout)); SVN_ERR(svn_cl__xml_print_footer("properties", pool)); } else { svn_string_t *printable_val = propval; /* If this is a special Subversion property, it is stored as UTF8 and LF, so convert to the native locale and eol-style. */ if (svn_prop_needs_translation(pname_utf8)) SVN_ERR(svn_subst_detranslate_string(&printable_val, propval, TRUE, pool)); SVN_ERR(stream_write(out, printable_val->data, printable_val->len)); if (! opt_state->strict) SVN_ERR(stream_write(out, APR_EOL_STR, strlen(APR_EOL_STR))); } } } else /* operate on a normal, versioned property (not a revprop) */ { apr_pool_t *subpool = svn_pool_create(pool); int i; if (opt_state->xml) SVN_ERR(svn_cl__xml_print_header("properties", subpool)); if (opt_state->depth == svn_depth_unknown) opt_state->depth = svn_depth_empty; /* Strict mode only makes sense for a single target. So make sure we have only a single target, and that we're not being asked to recurse on that target. */ if (opt_state->strict && ((targets->nelts > 1) || (opt_state->depth != svn_depth_empty))) return svn_error_create (SVN_ERR_CL_ARG_PARSING_ERROR, NULL, _("Strict output of property values only available for single-" "target, non-recursive propget operations")); for (i = 0; i < targets->nelts; i++) { const char *target = APR_ARRAY_IDX(targets, i, const char *); apr_hash_t *props; svn_boolean_t print_filenames; svn_boolean_t omit_newline; svn_boolean_t like_proplist; const char *truepath; svn_opt_revision_t peg_revision; svn_pool_clear(subpool); SVN_ERR(svn_cl__check_cancel(ctx->cancel_baton)); /* Check for a peg revision. */ SVN_ERR(svn_opt_parse_path(&peg_revision, &truepath, target, subpool)); if (!svn_path_is_url(truepath)) SVN_ERR(svn_dirent_get_absolute(&truepath, truepath, subpool)); SVN_ERR(svn_client_propget4(&props, pname_utf8, truepath, &peg_revision, &(opt_state->start_revision), NULL, opt_state->depth, opt_state->changelists, ctx, subpool, subpool)); /* Any time there is more than one thing to print, or where the path associated with a printed thing is not obvious, we'll print filenames. That is, unless we've been told not to do so with the --strict option. */ print_filenames = ((opt_state->depth > svn_depth_empty || targets->nelts > 1 || apr_hash_count(props) > 1 || opt_state->verbose) && (! opt_state->strict)); omit_newline = opt_state->strict; like_proplist = opt_state->verbose && !opt_state->strict; if (opt_state->xml) SVN_ERR(print_properties_xml(pname_utf8, props, subpool)); else SVN_ERR(print_properties(out, svn_path_is_url(target), pname_utf8, props, print_filenames, omit_newline, like_proplist, subpool)); } if (opt_state->xml) SVN_ERR(svn_cl__xml_print_footer("properties", subpool)); svn_pool_destroy(subpool); } return SVN_NO_ERROR; }
/* Print the properties in PROPS to the stream OUT. PROPS is a hash mapping * (const char *) path to (svn_string_t) property value. * If IS_URL is true, all paths are URLs, else all paths are local paths. * PNAME_UTF8 is the property name of all the properties. * If PRINT_FILENAMES is true, print the item's path before each property. * If OMIT_NEWLINE is true, don't add a newline at the end of each property. * If LIKE_PROPLIST is true, print everything in a more verbose format * like "svn proplist -v" does. * */ static svn_error_t * print_properties(svn_stream_t *out, svn_boolean_t is_url, const char *pname_utf8, apr_hash_t *props, svn_boolean_t print_filenames, svn_boolean_t omit_newline, svn_boolean_t like_proplist, apr_pool_t *pool) { apr_array_header_t *sorted_props; int i; apr_pool_t *iterpool = svn_pool_create(pool); const char *path_prefix; SVN_ERR(svn_dirent_get_absolute(&path_prefix, "", pool)); sorted_props = svn_sort__hash(props, svn_sort_compare_items_as_paths, pool); for (i = 0; i < sorted_props->nelts; i++) { svn_sort__item_t item = APR_ARRAY_IDX(sorted_props, i, svn_sort__item_t); const char *filename = item.key; svn_string_t *propval = item.value; svn_pool_clear(iterpool); if (print_filenames) { const char *header; /* Print the file name. */ if (! is_url) filename = svn_cl__local_style_skip_ancestor(path_prefix, filename, iterpool); /* In verbose mode, print exactly same as "proplist" does; * otherwise, print a brief header. */ header = apr_psprintf(iterpool, like_proplist ? _("Properties on '%s':\n") : "%s - ", filename); SVN_ERR(svn_cmdline_cstring_from_utf8(&header, header, iterpool)); SVN_ERR(svn_subst_translate_cstring2(header, &header, APR_EOL_STR, /* 'native' eol */ FALSE, /* no repair */ NULL, /* no keywords */ FALSE, /* no expansion */ iterpool)); SVN_ERR(stream_write(out, header, strlen(header))); } if (like_proplist) { /* Print the property name and value just as "proplist -v" does */ apr_hash_t *hash = apr_hash_make(iterpool); apr_hash_set(hash, pname_utf8, APR_HASH_KEY_STRING, propval); SVN_ERR(svn_cl__print_prop_hash(out, hash, FALSE, iterpool)); } else { /* If this is a special Subversion property, it is stored as UTF8, so convert to the native format. */ if (svn_prop_needs_translation(pname_utf8)) SVN_ERR(svn_subst_detranslate_string(&propval, propval, TRUE, iterpool)); SVN_ERR(stream_write(out, propval->data, propval->len)); if (! omit_newline) SVN_ERR(stream_write(out, APR_EOL_STR, strlen(APR_EOL_STR))); } } svn_pool_destroy(iterpool); return SVN_NO_ERROR; }
static svn_error_t * change_dir_prop(void *dir_baton, const char *name, const svn_string_t *value, apr_pool_t *pool) { node_baton_t *db = dir_baton; edit_baton_t *eb = db->edit_baton; /* Only regular properties can pass over libsvn_ra */ if (svn_property_kind2(name) != svn_prop_regular_kind) return SVN_NO_ERROR; /* Maybe drop svn:mergeinfo. */ if (eb->strip_mergeinfo && (strcmp(name, SVN_PROP_MERGEINFO) == 0)) { eb->mergeinfo_stripped = TRUE; return SVN_NO_ERROR; } /* Maybe convert svnmerge-integrated data into svn:mergeinfo. (We ignore svnmerge-blocked for now.) */ /* ### FIXME: Consult the mirror repository's HEAD prop values and ### merge svn:mergeinfo, svnmerge-integrated, and svnmerge-blocked. */ if (eb->migrate_svnmerge && (strcmp(name, "svnmerge-integrated") == 0)) { if (value) { /* svnmerge-integrated differs from svn:mergeinfo in a pair of ways. First, it can use tabs, newlines, or spaces to delimit source information. Secondly, the source paths are relative URLs, whereas svn:mergeinfo uses relative paths (not URI-encoded). */ svn_error_t *err; svn_stringbuf_t *mergeinfo_buf = svn_stringbuf_create_empty(pool); svn_mergeinfo_t mergeinfo; int i; apr_array_header_t *sources = svn_cstring_split(value->data, " \t\n", TRUE, pool); svn_string_t *new_value; for (i = 0; i < sources->nelts; i++) { const char *rel_path; apr_array_header_t *path_revs = svn_cstring_split(APR_ARRAY_IDX(sources, i, const char *), ":", TRUE, pool); /* ### TODO: Warn? */ if (path_revs->nelts != 2) continue; /* Append this source's mergeinfo data. */ rel_path = APR_ARRAY_IDX(path_revs, 0, const char *); rel_path = svn_path_uri_decode(rel_path, pool); svn_stringbuf_appendcstr(mergeinfo_buf, rel_path); svn_stringbuf_appendcstr(mergeinfo_buf, ":"); svn_stringbuf_appendcstr(mergeinfo_buf, APR_ARRAY_IDX(path_revs, 1, const char *)); svn_stringbuf_appendcstr(mergeinfo_buf, "\n"); } /* Try to parse the mergeinfo string we've created, just to check for bogosity. If all goes well, we'll unparse it again and use that as our property value. */ err = svn_mergeinfo_parse(&mergeinfo, mergeinfo_buf->data, pool); if (err) { svn_error_clear(err); return SVN_NO_ERROR; } SVN_ERR(svn_mergeinfo_to_string(&new_value, mergeinfo, pool)); value = new_value; } name = SVN_PROP_MERGEINFO; eb->svnmerge_migrated = TRUE; } /* Remember if we see any svnmerge-blocked properties. */ if (eb->migrate_svnmerge && (strcmp(name, "svnmerge-blocked") == 0)) { eb->svnmerge_blocked = TRUE; } /* Normalize svn:* properties as necessary. */ if (svn_prop_needs_translation(name)) { svn_boolean_t was_normalized; svn_boolean_t mergeinfo_tweaked = FALSE; /* Normalize encoding to UTF-8, and EOL style to LF. */ SVN_ERR(normalize_string(&value, &was_normalized, eb->source_prop_encoding, pool, pool)); /* Maybe adjust svn:mergeinfo. */ if (value && strcmp(name, SVN_PROP_MERGEINFO) == 0) { SVN_ERR(remove_r0_mergeinfo(&value, &mergeinfo_tweaked, pool, pool)); if (mergeinfo_tweaked) eb->mergeinfo_tweaked = TRUE; } if (was_normalized) (*(eb->normalized_node_props_counter))++; } return eb->wrapped_editor->change_dir_prop(db->wrapped_node_baton, name, value, pool); }
/* This implements the `svn_opt_subcommand_t' interface. */ svn_error_t * svn_cl__propset(apr_getopt_t *os, void *baton, apr_pool_t *scratch_pool) { svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state; svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx; const char *pname; svn_string_t *propval = NULL; svn_boolean_t propval_came_from_cmdline; apr_array_header_t *args, *targets; /* PNAME and PROPVAL expected as first 2 arguments if filedata was NULL, else PNAME alone will precede the targets. Get a UTF-8 version of the name, too. */ SVN_ERR(svn_opt_parse_num_args(&args, os, opt_state->filedata ? 1 : 2, scratch_pool)); pname = APR_ARRAY_IDX(args, 0, const char *); SVN_ERR(svn_utf_cstring_to_utf8(&pname, pname, scratch_pool)); if (! svn_prop_name_is_valid(pname)) return svn_error_createf(SVN_ERR_CLIENT_PROPERTY_NAME, NULL, _("'%s' is not a valid Subversion property name"), pname); if (!opt_state->force) SVN_ERR(svn_cl__check_svn_prop_name(pname, opt_state->revprop, svn_cl__prop_use_set, scratch_pool)); /* Get the PROPVAL from either an external file, or from the command line. */ if (opt_state->filedata) { propval = svn_string_create_from_buf(opt_state->filedata, scratch_pool); propval_came_from_cmdline = FALSE; } else { propval = svn_string_create(APR_ARRAY_IDX(args, 1, const char *), scratch_pool); propval_came_from_cmdline = TRUE; } /* We only want special Subversion property values to be in UTF-8 and LF line endings. All other propvals are taken literally. */ if (svn_prop_needs_translation(pname)) SVN_ERR(svn_subst_translate_string2(&propval, NULL, NULL, propval, opt_state->encoding, FALSE, scratch_pool, scratch_pool)); else if (opt_state->encoding) return svn_error_create (SVN_ERR_UNSUPPORTED_FEATURE, NULL, _("--encoding option applies only to textual" " Subversion-controlled properties")); /* Suck up all the remaining arguments into a targets array */ SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os, opt_state->targets, ctx, FALSE, scratch_pool)); /* Implicit "." is okay for revision properties; it just helps us find the right repository. */ if (opt_state->revprop) svn_opt_push_implicit_dot_target(targets, scratch_pool); SVN_ERR(svn_cl__eat_peg_revisions(&targets, targets, scratch_pool)); if (opt_state->revprop) /* operate on a revprop */ { svn_revnum_t rev; const char *URL; SVN_ERR(svn_cl__revprop_prepare(&opt_state->start_revision, targets, &URL, ctx, scratch_pool)); /* Let libsvn_client do the real work. */ SVN_ERR(svn_client_revprop_set2(pname, propval, NULL, URL, &(opt_state->start_revision), &rev, opt_state->force, ctx, scratch_pool)); } else if (opt_state->start_revision.kind != svn_opt_revision_unspecified) { return svn_error_createf (SVN_ERR_CL_ARG_PARSING_ERROR, NULL, _("Cannot specify revision for setting versioned property '%s'"), pname); } else /* operate on a normal, versioned property (not a revprop) */ { if (opt_state->depth == svn_depth_unknown) opt_state->depth = svn_depth_empty; /* The customary implicit dot rule has been prone to user error * here. People would do intuitive things like * * $ svn propset svn:executable script * * and then be surprised to get an error like: * * svn: Illegal target for the requested operation * svn: Cannot set svn:executable on a directory () * * So we don't do the implicit dot thing anymore. A * target * must always be explicitly provided when setting a versioned * property. See * * http://subversion.tigris.org/issues/show_bug.cgi?id=924 * * for more details. */ if (targets->nelts == 0) { if (propval_came_from_cmdline) { return svn_error_createf (SVN_ERR_CL_INSUFFICIENT_ARGS, NULL, _("Explicit target required ('%s' interpreted as prop value)"), propval->data); } else { return svn_error_create (SVN_ERR_CL_INSUFFICIENT_ARGS, NULL, _("Explicit target argument required")); } } SVN_ERR(svn_cl__propset_print_binary_mime_type_warning(targets, pname, propval, scratch_pool)); SVN_ERR(svn_client_propset_local(pname, propval, targets, opt_state->depth, opt_state->force, opt_state->changelists, ctx, scratch_pool)); if (! opt_state->quiet) svn_cl__check_boolean_prop_val(pname, propval->data, scratch_pool); } return SVN_NO_ERROR; }
/* This implements the `svn_opt_subcommand_t' interface. */ svn_error_t * svn_cl__propedit(apr_getopt_t *os, void *baton, apr_pool_t *pool) { svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state; svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx; const char *pname, *pname_utf8; apr_array_header_t *args, *targets; int i; /* Validate the input and get the property's name (and a UTF-8 version of that name). */ SVN_ERR(svn_opt_parse_num_args(&args, os, 1, pool)); pname = APR_ARRAY_IDX(args, 0, const char *); SVN_ERR(svn_utf_cstring_to_utf8(&pname_utf8, pname, pool)); if (! svn_prop_name_is_valid(pname_utf8)) return svn_error_createf(SVN_ERR_CLIENT_PROPERTY_NAME, NULL, _("'%s' is not a valid Subversion property name"), pname_utf8); if (opt_state->encoding && !svn_prop_needs_translation(pname_utf8)) return svn_error_create (SVN_ERR_UNSUPPORTED_FEATURE, NULL, _("--encoding option applies only to textual" " Subversion-controlled properties")); /* Suck up all the remaining arguments into a targets array */ SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os, opt_state->targets, ctx, pool)); if (opt_state->revprop) /* operate on a revprop */ { svn_revnum_t rev; const char *URL; svn_string_t *propval; svn_string_t original_propval; const char *temp_dir; /* Implicit "." is okay for revision properties; it just helps us find the right repository. */ svn_opt_push_implicit_dot_target(targets, pool); SVN_ERR(svn_cl__revprop_prepare(&opt_state->start_revision, targets, &URL, pool)); /* Fetch the current property. */ SVN_ERR(svn_client_revprop_get(pname_utf8, &propval, URL, &(opt_state->start_revision), &rev, ctx, pool)); if (! propval) { propval = svn_string_create("", pool); /* This is how we signify to svn_client_revprop_set2() that we want it to check that the original value hasn't changed, but that that original value was non-existent: */ original_propval.data = NULL; /* and .len is ignored */ } else { original_propval = *propval; } /* Run the editor on a temporary file which contains the original property value... */ SVN_ERR(svn_io_temp_dir(&temp_dir, pool)); SVN_ERR(svn_cl__edit_string_externally (&propval, NULL, opt_state->editor_cmd, temp_dir, propval, "svn-prop", ctx->config, svn_prop_needs_translation(pname_utf8), opt_state->encoding, pool)); /* ...and re-set the property's value accordingly. */ if (propval) { SVN_ERR(svn_client_revprop_set2(pname_utf8, propval, &original_propval, URL, &(opt_state->start_revision), &rev, opt_state->force, ctx, pool)); SVN_ERR (svn_cmdline_printf (pool, _("Set new value for property '%s' on revision %ld\n"), pname_utf8, rev)); } else { SVN_ERR(svn_cmdline_printf (pool, _("No changes to property '%s' on revision %ld\n"), pname_utf8, rev)); } } else if (opt_state->start_revision.kind != svn_opt_revision_unspecified) { return svn_error_createf (SVN_ERR_CL_ARG_PARSING_ERROR, NULL, _("Cannot specify revision for editing versioned property '%s'"), pname_utf8); } else /* operate on a normal, versioned property (not a revprop) */ { apr_pool_t *subpool = svn_pool_create(pool); /* The customary implicit dot rule has been prone to user error * here. For example, Jon Trowbridge <*****@*****.**> did * * $ svn propedit HACKING * * and then when he closed his editor, he was surprised to see * * Set new value for property 'HACKING' on '' * * ...meaning that the property named 'HACKING' had been set on * the current working directory, with the value taken from the * editor. So we don't do the implicit dot thing anymore; an * explicit target is always required when editing a versioned * property. */ if (targets->nelts == 0) { return svn_error_create (SVN_ERR_CL_INSUFFICIENT_ARGS, NULL, _("Explicit target argument required")); } SVN_ERR(svn_opt__eat_peg_revisions(&targets, targets, pool)); /* For each target, edit the property PNAME. */ for (i = 0; i < targets->nelts; i++) { apr_hash_t *props; const char *target = APR_ARRAY_IDX(targets, i, const char *); svn_string_t *propval, *edited_propval; const char *base_dir = target; const char *target_local; svn_wc_adm_access_t *adm_access; const svn_wc_entry_t *entry; svn_opt_revision_t peg_revision; svn_revnum_t base_rev = SVN_INVALID_REVNUM; svn_pool_clear(subpool); SVN_ERR(svn_cl__check_cancel(ctx->cancel_baton)); /* Propedits can only happen on HEAD or the working copy, so the peg revision can be as unspecified. */ peg_revision.kind = svn_opt_revision_unspecified; /* Fetch the current property. */ SVN_ERR(svn_client_propget3(&props, pname_utf8, target, &peg_revision, &(opt_state->start_revision), &base_rev, svn_depth_empty, NULL, ctx, subpool)); /* Get the property value. */ propval = apr_hash_get(props, target, APR_HASH_KEY_STRING); if (! propval) propval = svn_string_create("", subpool); if (svn_path_is_url(target)) { /* For URLs, put the temporary file in the current directory. */ base_dir = "."; } else { if (opt_state->message || opt_state->filedata || opt_state->revprop_table) { return svn_error_create (SVN_ERR_CL_UNNECESSARY_LOG_MESSAGE, NULL, _("Local, non-commit operations do not take a log message " "or revision properties")); } /* Split the path if it is a file path. */ SVN_ERR(svn_wc_adm_probe_open3(&adm_access, NULL, target, FALSE, 0, ctx->cancel_func, ctx->cancel_baton, subpool)); SVN_ERR(svn_wc_entry(&entry, target, adm_access, FALSE, subpool)); if (! entry) return svn_error_createf (SVN_ERR_ENTRY_NOT_FOUND, NULL, _("'%s' does not appear to be a working copy path"), target); if (entry->kind == svn_node_file) svn_path_split(target, &base_dir, NULL, subpool); } /* Run the editor on a temporary file which contains the original property value... */ SVN_ERR(svn_cl__edit_string_externally(&edited_propval, NULL, opt_state->editor_cmd, base_dir, propval, "svn-prop", ctx->config, svn_prop_needs_translation (pname_utf8), opt_state->encoding, subpool)); target_local = svn_path_is_url(target) ? target : svn_path_local_style(target, subpool); /* ...and re-set the property's value accordingly. */ if (edited_propval && !svn_string_compare(propval, edited_propval)) { svn_commit_info_t *commit_info = NULL; svn_error_t *err = SVN_NO_ERROR; svn_cl__check_boolean_prop_val(pname_utf8, edited_propval->data, subpool); if (ctx->log_msg_func3) SVN_ERR(svn_cl__make_log_msg_baton(&(ctx->log_msg_baton3), opt_state, NULL, ctx->config, subpool)); err = svn_client_propset3(&commit_info, pname_utf8, edited_propval, target, svn_depth_empty, opt_state->force, base_rev, NULL, opt_state->revprop_table, ctx, subpool); if (ctx->log_msg_func3) SVN_ERR(svn_cl__cleanup_log_msg(ctx->log_msg_baton3, err, pool)); else if (err) return err; /* Print a message if we successfully committed or if it was just a wc propset (but not if the user aborted an URL propedit). */ if (commit_info || ! svn_path_is_url(target)) SVN_ERR (svn_cmdline_printf (subpool, _("Set new value for property '%s' on '%s'\n"), pname_utf8, target_local)); if (commit_info && ! opt_state->quiet) SVN_ERR(svn_cl__print_commit_info(commit_info, subpool)); } else { SVN_ERR (svn_cmdline_printf (subpool, _("No changes to property '%s' on '%s'\n"), pname_utf8, target_local)); } } svn_pool_destroy(subpool); } return SVN_NO_ERROR; }