Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Use more robust coding style in handling UTF-8 conversion of command-…
Browse files Browse the repository at this point in the history
…line

arguments.

Convert to UTF-8 as soon as possible, and name variables assuming UTF-8
encoding is the default rather than an exception, and minimize visibility of
non-UTF-8 values.

* subversion/svn/propdel-cmd.c,
  subversion/svn/propedit-cmd.c,
  subversion/svn/propget-cmd.c,
  subversion/svn/propset-cmd.c:
    Rename variables assuming UTF-8; minimize storing non-UTF-8 values.

* subversion/svn/svn.c,
  subversion/svnadmin/svnadmin.c,
  subversion/svnbench/svnbench.c,
  subversion/svndumpfilter/svndumpfilter.c,
  subversion/svnfsfs/svnfsfs.c,
  subversion/svnlook/svnlook.c,
  subversion/svnmucc/svnmucc.c,
  subversion/svnrdump/svnrdump.c,
  subversion/svnsync/svnsync.c
  tools/client-side/svnconflict/svnconflict.c
  tools/client-side/svn-mergeinfo-normalizer/svn-mergeinfo-normalizer.c
  tools/dev/svnmover/svnmover.c
  tools/server-side/svnauthz.c
  (sub_main): Convert to UTF-8 before matching the subcommand name; no
    observable change if environment's encoding is a superset of ASCII.
  (...): Rename variables assuming UTF-8; minimize storing non-UTF-8 values.


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1797362 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Julian Foad committed Jun 2, 2017
1 parent fcece47 commit c943018
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 161 deletions.
10 changes: 5 additions & 5 deletions subversion/svn/propdel-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ svn_cl__propdel(apr_getopt_t *os,
{
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;
const char *pname;
apr_array_header_t *args, *targets;

/* 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));
SVN_ERR(svn_utf_cstring_to_utf8(&pname, pname, pool));
/* No need to check svn_prop_name_is_valid for *deleting*
properties, and it may even be useful to allow, in case invalid
properties sneaked through somehow. */
Expand All @@ -78,23 +78,23 @@ svn_cl__propdel(apr_getopt_t *os,
&URL, ctx, pool));

/* Let libsvn_client do the real work. */
SVN_ERR(svn_client_revprop_set2(pname_utf8, NULL, NULL,
SVN_ERR(svn_client_revprop_set2(pname, NULL, NULL,
URL, &(opt_state->start_revision),
&rev, FALSE, ctx, pool));
}
else if (opt_state->start_revision.kind != svn_opt_revision_unspecified)
{
return svn_error_createf(SVN_ERR_CLIENT_PROPERTY_NAME, NULL,
_("Cannot specify revision for deleting versioned property '%s'"),
pname_utf8);
pname);
}
else /* operate on a normal, versioned property (not a revprop) */
{
if (opt_state->depth == svn_depth_unknown)
opt_state->depth = svn_depth_empty;

/* For each target, remove the property PNAME. */
SVN_ERR(svn_client_propset_local(pname_utf8, NULL, targets,
SVN_ERR(svn_client_propset_local(pname, NULL, targets,
opt_state->depth, FALSE,
opt_state->changelists, ctx, pool));
}
Expand Down
46 changes: 23 additions & 23 deletions subversion/svn/propedit-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
/*** Code. ***/
struct commit_info_baton
{
const char *pname_utf8;
const char *pname;
const char *target_local;
};

Expand All @@ -60,7 +60,7 @@ commit_info_handler(const svn_commit_info_t *commit_info,

SVN_ERR(svn_cmdline_printf(pool,
_("Set new value for property '%s' on '%s'\n"),
cib->pname_utf8, cib->target_local));
cib->pname, cib->target_local));
SVN_ERR(svn_cl__print_commit_info(commit_info, NULL, pool));

return SVN_NO_ERROR;
Expand All @@ -74,23 +74,23 @@ svn_cl__propedit(apr_getopt_t *os,
{
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;
const char *pname;
apr_array_header_t *args, *targets;

/* 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))
SVN_ERR(svn_utf_cstring_to_utf8(&pname, pname, 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_utf8);
pname);
if (!opt_state->force)
SVN_ERR(svn_cl__check_svn_prop_name(pname_utf8, opt_state->revprop,
SVN_ERR(svn_cl__check_svn_prop_name(pname, opt_state->revprop,
svn_cl__prop_use_edit, pool));

if (opt_state->encoding && !svn_prop_needs_translation(pname_utf8))
if (opt_state->encoding && !svn_prop_needs_translation(pname))
return svn_error_create
(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
_("--encoding option applies only to textual"
Expand Down Expand Up @@ -120,7 +120,7 @@ svn_cl__propedit(apr_getopt_t *os,
&URL, ctx, pool));

/* Fetch the current property. */
SVN_ERR(svn_client_revprop_get(pname_utf8, &propval,
SVN_ERR(svn_client_revprop_get(pname, &propval,
URL, &(opt_state->start_revision),
&rev, ctx, pool));

Expand All @@ -145,13 +145,13 @@ svn_cl__propedit(apr_getopt_t *os,
opt_state->editor_cmd, temp_dir,
propval, "svn-prop",
ctx->config,
svn_prop_needs_translation(pname_utf8),
svn_prop_needs_translation(pname),
opt_state->encoding, pool));

/* ...and re-set the property's value accordingly. */
if (propval)
{
SVN_ERR(svn_client_revprop_set2(pname_utf8,
SVN_ERR(svn_client_revprop_set2(pname,
propval, &original_propval,
URL, &(opt_state->start_revision),
&rev, opt_state->force, ctx, pool));
Expand All @@ -160,21 +160,21 @@ svn_cl__propedit(apr_getopt_t *os,
(svn_cmdline_printf
(pool,
_("Set new value for property '%s' on revision %ld\n"),
pname_utf8, rev));
pname, rev));
}
else
{
SVN_ERR(svn_cmdline_printf
(pool, _("No changes to property '%s' on revision %ld\n"),
pname_utf8, rev));
pname, 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);
pname);
}
else /* operate on a normal, versioned property (not a revprop) */
{
Expand Down Expand Up @@ -206,7 +206,7 @@ svn_cl__propedit(apr_getopt_t *os,

SVN_ERR(svn_cl__eat_peg_revisions(&targets, targets, pool));

cib.pname_utf8 = pname_utf8;
cib.pname = pname;

/* For each target, edit the property PNAME. */
for (i = 0; i < targets->nelts; i++)
Expand Down Expand Up @@ -234,7 +234,7 @@ svn_cl__propedit(apr_getopt_t *os,
peg_revision.kind = svn_opt_revision_unspecified;

/* Fetch the current property. */
SVN_ERR(svn_client_propget5(&props, NULL, pname_utf8, abspath_or_url,
SVN_ERR(svn_client_propget5(&props, NULL, pname, abspath_or_url,
&peg_revision,
&(opt_state->start_revision),
&base_rev, svn_depth_empty,
Expand Down Expand Up @@ -282,7 +282,7 @@ svn_cl__propedit(apr_getopt_t *os,
"svn-prop",
ctx->config,
svn_prop_needs_translation
(pname_utf8),
(pname),
opt_state->encoding,
subpool));

Expand All @@ -295,7 +295,7 @@ svn_cl__propedit(apr_getopt_t *os,
{
svn_error_t *err = SVN_NO_ERROR;

svn_cl__check_boolean_prop_val(pname_utf8, edited_propval->data,
svn_cl__check_boolean_prop_val(pname, edited_propval->data,
subpool);

if (ctx->log_msg_func3)
Expand All @@ -304,7 +304,7 @@ svn_cl__propedit(apr_getopt_t *os,
subpool));
if (svn_path_is_url(target))
{
err = svn_client_propset_remote(pname_utf8, edited_propval,
err = svn_client_propset_remote(pname, edited_propval,
target, opt_state->force,
base_rev,
opt_state->revprop_table,
Expand All @@ -319,9 +319,9 @@ svn_cl__propedit(apr_getopt_t *os,
APR_ARRAY_PUSH(targs, const char *) = target;

SVN_ERR(svn_cl__propset_print_binary_mime_type_warning(
targs, pname_utf8, propval, subpool));
targs, pname, propval, subpool));

err = svn_client_propset_local(pname_utf8, edited_propval,
err = svn_client_propset_local(pname, edited_propval,
targs, svn_depth_empty,
opt_state->force, NULL,
ctx, subpool);
Expand All @@ -339,14 +339,14 @@ svn_cl__propedit(apr_getopt_t *os,
if (!svn_path_is_url(target))
SVN_ERR(svn_cmdline_printf(
subpool, _("Set new value for property '%s' on '%s'\n"),
pname_utf8, target_local));
pname, target_local));
}
else
{
SVN_ERR
(svn_cmdline_printf
(subpool, _("No changes to property '%s' on '%s'\n"),
pname_utf8, target_local));
pname, target_local));
}
}
svn_pool_destroy(subpool);
Expand Down
43 changes: 21 additions & 22 deletions subversion/svn/propget-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ print_properties_xml(const char *pname,
return SVN_NO_ERROR;
}

/* Print the property PNAME_UTF with the value PROPVAL set on ABSPATH_OR_URL
/* Print the property PNAME with the value PROPVAL set on ABSPATH_OR_URL
to the stream OUT.
If INHERITED_PROPERTY is true then the property described is inherited,
Expand All @@ -153,7 +153,7 @@ print_single_prop(svn_string_t *propval,
const char *abspath_or_URL,
const char *wc_path_prefix,
svn_stream_t *out,
const char *pname_utf8,
const char *pname,
svn_boolean_t print_filenames,
svn_boolean_t omit_newline,
svn_boolean_t like_proplist,
Expand Down Expand Up @@ -211,14 +211,14 @@ print_single_prop(svn_string_t *propval,
/* Print the property name and value just as "proplist -v" does */
apr_hash_t *hash = apr_hash_make(scratch_pool);

svn_hash_sets(hash, pname_utf8, propval);
svn_hash_sets(hash, pname, propval);
SVN_ERR(svn_cmdline__print_prop_hash(out, hash, FALSE, scratch_pool));
}
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))
if (svn_prop_needs_translation(pname))
SVN_ERR(svn_subst_detranslate_string(&propval, propval,
TRUE, scratch_pool));

Expand All @@ -244,7 +244,7 @@ print_single_prop(svn_string_t *propval,
If IS_URL is true, all paths in PROPS are URLs, else all paths are local
paths.
PNAME_UTF8 is the property name of all the properties.
PNAME is the property name of all the properties.
If PRINT_FILENAMES is true, print the item's path before each property.
Expand All @@ -255,7 +255,7 @@ print_single_prop(svn_string_t *propval,
static svn_error_t *
print_properties(svn_stream_t *out,
const char *target_abspath_or_url,
const char *pname_utf8,
const char *pname,
apr_hash_t *props,
apr_array_header_t *inherited_props,
svn_boolean_t print_filenames,
Expand All @@ -282,7 +282,7 @@ print_properties(svn_stream_t *out,
iprop->prop_hash));
SVN_ERR(print_single_prop(propval, target_abspath_or_url,
iprop->path_or_url,
path_prefix, out, pname_utf8,
path_prefix, out, pname,
print_filenames, omit_newline,
like_proplist, TRUE, iterpool));
}
Expand All @@ -298,7 +298,7 @@ print_properties(svn_stream_t *out,
svn_pool_clear(iterpool);

SVN_ERR(print_single_prop(propval, target_abspath_or_url, filename,
path_prefix, out, pname_utf8, print_filenames,
path_prefix, out, pname, print_filenames,
omit_newline, like_proplist, FALSE,
iterpool));
}
Expand All @@ -317,7 +317,7 @@ svn_cl__propget(apr_getopt_t *os,
{
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;
const char *pname;
apr_array_header_t *args, *targets;
svn_stream_t *out;
svn_boolean_t warned = FALSE;
Expand All @@ -328,15 +328,14 @@ svn_cl__propget(apr_getopt_t *os,
_("--verbose cannot be used with --revprop or "
"--no-newline or --xml"));

/* PNAME is first argument (and PNAME_UTF8 will be a UTF-8 version
thereof) */
/* PNAME is first argument */
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))
SVN_ERR(svn_utf_cstring_to_utf8(&pname, pname, 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_utf8);
pname);

SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
opt_state->targets,
Expand All @@ -363,7 +362,7 @@ svn_cl__propget(apr_getopt_t *os,
&URL, ctx, pool));

/* Let libsvn_client do the real work. */
SVN_ERR(svn_client_revprop_get(pname_utf8, &propval,
SVN_ERR(svn_client_revprop_get(pname, &propval,
URL, &(opt_state->start_revision),
&rev, ctx, pool));

Expand All @@ -372,7 +371,7 @@ svn_cl__propget(apr_getopt_t *os,
return svn_error_createf(SVN_ERR_PROPERTY_NOT_FOUND, NULL,
_("Property '%s' not found on "
"revision %s"),
pname_utf8,
pname,
svn_opt__revision_to_string(
&opt_state->start_revision,
pool));
Expand All @@ -390,7 +389,7 @@ svn_cl__propget(apr_getopt_t *os,
"revprops",
"rev", revstr, SVN_VA_NULL);

svn_cmdline__print_xml_prop(&sb, pname_utf8, propval, FALSE,
svn_cmdline__print_xml_prop(&sb, pname, propval, FALSE,
pool);

svn_xml_make_close_tag(&sb, pool, "revprops");
Expand All @@ -405,7 +404,7 @@ svn_cl__propget(apr_getopt_t *os,
/* 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))
if (svn_prop_needs_translation(pname))
SVN_ERR(svn_subst_detranslate_string(&printable_val, propval,
TRUE, pool));

Expand Down Expand Up @@ -462,7 +461,7 @@ svn_cl__propget(apr_getopt_t *os,
SVN_ERR(svn_client_propget5(
&props,
opt_state->show_inherited_props ? &inherited_props : NULL,
pname_utf8, truepath,
pname, truepath,
&peg_revision,
&(opt_state->start_revision),
NULL, opt_state->depth,
Expand Down Expand Up @@ -491,20 +490,20 @@ svn_cl__propget(apr_getopt_t *os,
svn_error_t *err;
err = svn_error_createf(SVN_ERR_PROPERTY_NOT_FOUND, NULL,
_("Property '%s' not found on '%s'"),
pname_utf8, target);
pname, target);
svn_handle_warning2(stderr, err, "svn: ");
svn_error_clear(err);
warned = TRUE;
}

if (opt_state->xml)
SVN_ERR(print_properties_xml(
pname_utf8, props,
pname, props,
opt_state->show_inherited_props ? inherited_props : NULL,
subpool));
else
SVN_ERR(print_properties(
out, truepath, pname_utf8,
out, truepath, pname,
props,
opt_state->show_inherited_props ? inherited_props : NULL,
print_filenames,
Expand Down
Loading

0 comments on commit c943018

Please sign in to comment.