You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ju...@apache.org on 2010/10/25 13:54:59 UTC
svn commit: r1027079 - in /subversion/trunk/subversion: include/svn_opt.h
libsvn_subr/opt.c svn/main.c
Author: julianfoad
Date: Mon Oct 25 11:54:58 2010
New Revision: 1027079
URL: http://svn.apache.org/viewvc?rev=1027079&view=rev
Log:
Print the aliases for command-line long options automatically instead of
manually.
This adds new optional behaviour to svn_opt_subcommand_help3(). I think
this is backward compatible, but if that is disputed we can rev the API.
* subversion/libsvn_subr/opt.c
(get_option_from_code): New function.
(format_option): New function, extracted from svn_opt_format_option(),
enhanced to print a long option alias as well.
(svn_opt_format_option): Rewrite as a wrapper around format_option().
(print_command_info2): Use get_option_from_code() and format_option() so
as to print the long option aliases if defined in the options table.
* subversion/svn/main.c
(svn_cl__options): Remove the hand-written mentions of long option aliases.
* subversion/include/svn_opt.h
(svn_opt_subcommand_help3): Mention this in the doc string.
Modified:
subversion/trunk/subversion/include/svn_opt.h
subversion/trunk/subversion/libsvn_subr/opt.c
subversion/trunk/subversion/svn/main.c
Modified: subversion/trunk/subversion/include/svn_opt.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_opt.h?rev=1027079&r1=1027078&r2=1027079&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_opt.h (original)
+++ subversion/trunk/subversion/include/svn_opt.h Mon Oct 25 11:54:58 2010
@@ -292,6 +292,11 @@ svn_opt_format_option(const char **strin
* command name or an alias. ### @todo Why does this only print to
* @c stdout, whereas svn_opt_print_generic_help() gives us a choice?
*
+ * When printing the description of an option, if the same option code
+ * appears a second time in @a options_table with a different name, then
+ * use that second name as an alias for the first name. This additional
+ * behaviour is new in 1.7.
+ *
* @since New in 1.5.
*/
void
Modified: subversion/trunk/subversion/libsvn_subr/opt.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/opt.c?rev=1027079&r1=1027078&r2=1027079&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/opt.c (original)
+++ subversion/trunk/subversion/libsvn_subr/opt.c Mon Oct 25 11:54:58 2010
@@ -124,11 +124,47 @@ svn_opt_get_option_from_code(int code,
}
-void
-svn_opt_format_option(const char **string,
- const apr_getopt_option_t *opt,
- svn_boolean_t doc,
- apr_pool_t *pool)
+/* Like svn_opt_get_option_from_code2(), but also, if CODE appears a second
+ * time in OPTION_TABLE with a different name, then set *LONG_ALIAS to that
+ * second name, else set it to NULL. */
+static const apr_getopt_option_t *
+get_option_from_code(const char **long_alias,
+ int code,
+ const apr_getopt_option_t *option_table,
+ const svn_opt_subcommand_desc2_t *command,
+ apr_pool_t *pool)
+{
+ const apr_getopt_option_t *i;
+ const apr_getopt_option_t *opt
+ = svn_opt_get_option_from_code2(code, option_table, command, pool);
+
+ /* Find a long alias in the table, if there is one. */
+ *long_alias = NULL;
+ for (i = option_table; i->optch; i++)
+ {
+ if (i->optch == code && i->name != opt->name)
+ {
+ *long_alias = i->name;
+ break;
+ }
+ }
+
+ return opt;
+}
+
+
+/* Print an option OPT nicely into a STRING allocated in POOL.
+ * If OPT has a single-character short form, then print OPT->name (if not
+ * NULL) as an alias, else print LONG_ALIAS (if not NULL) as an alias.
+ * If DOC is set, include the generic documentation string of OPT,
+ * localized to the current locale if a translation is available.
+ */
+static void
+format_option(const char **string,
+ const apr_getopt_option_t *opt,
+ const char *long_alias,
+ svn_boolean_t doc,
+ apr_pool_t *pool)
{
char *opts;
@@ -149,11 +185,26 @@ svn_opt_format_option(const char **strin
opts = apr_pstrcat(pool, opts, _(" ARG"), (char *)NULL);
if (doc)
- opts = apr_psprintf(pool, "%-24s : %s", opts, _(opt->description));
+ {
+ opts = apr_psprintf(pool, "%-24s : %s", opts, _(opt->description));
+ if (long_alias)
+ opts = apr_pstrcat(pool, opts,
+ "\n [alias: --",
+ long_alias, "]", (char *)NULL);
+ }
*string = opts;
}
+void
+svn_opt_format_option(const char **string,
+ const apr_getopt_option_t *opt,
+ svn_boolean_t doc,
+ apr_pool_t *pool)
+{
+ format_option(string, opt, NULL, doc, pool);
+}
+
svn_boolean_t
svn_opt_subcommand_takes_option3(const svn_opt_subcommand_desc2_t *command,
@@ -238,6 +289,7 @@ print_command_info2(const svn_opt_subcom
if (help)
{
const apr_getopt_option_t *option;
+ const char *long_alias;
svn_boolean_t have_options = FALSE;
SVN_ERR(svn_cmdline_fprintf(stream, pool, ": %s", _(cmd->help)));
@@ -255,16 +307,14 @@ print_command_info2(const svn_opt_subcom
}
/* convert each option code into an option */
- option =
- svn_opt_get_option_from_code2(cmd->valid_options[i],
- options_table,
- cmd, pool);
+ option = get_option_from_code(&long_alias, cmd->valid_options[i],
+ options_table, cmd, pool);
/* print the option's docstring */
if (option && option->description)
{
const char *optstr;
- svn_opt_format_option(&optstr, option, TRUE, pool);
+ format_option(&optstr, option, long_alias, TRUE, pool);
SVN_ERR(svn_cmdline_fprintf(stream, pool, " %s\n",
optstr));
}
@@ -281,16 +331,14 @@ print_command_info2(const svn_opt_subcom
{
/* convert each option code into an option */
- option =
- svn_opt_get_option_from_code2(global_options[i],
- options_table,
- cmd, pool);
+ option = get_option_from_code(&long_alias, global_options[i],
+ options_table, cmd, pool);
/* print the option's docstring */
if (option && option->description)
{
const char *optstr;
- svn_opt_format_option(&optstr, option, TRUE, pool);
+ format_option(&optstr, option, long_alias, TRUE, pool);
SVN_ERR(svn_cmdline_fprintf(stream, pool, " %s\n",
optstr));
}
Modified: subversion/trunk/subversion/svn/main.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/main.c?rev=1027079&r1=1027078&r2=1027079&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/main.c (original)
+++ subversion/trunk/subversion/svn/main.c Mon Oct 25 11:54:58 2010
@@ -166,9 +166,7 @@ const apr_getopt_option_t svn_cl__option
{"incremental", opt_incremental, 0,
N_("give output suitable for concatenation")},
{"encoding", opt_encoding, 1,
- N_("treat value as being in charset encoding ARG\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --enc]")},
+ N_("treat value as being in charset encoding ARG")},
{"version", opt_version, 0, N_("show program version information")},
{"verbose", 'v', 0, N_("print extra information")},
{"show-updates", 'u', 0, N_("display update information")},
@@ -215,21 +213,15 @@ const apr_getopt_option_t svn_cl__option
{"set-depth", opt_set_depth, 1,
N_("set new working copy depth to ARG ('exclude',\n"
SVN_CL__OPTION_CONTINUATION_INDENT
- "'empty', 'files', 'immediates', or 'infinity')\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --sd]")},
+ "'empty', 'files', 'immediates', or 'infinity')")},
{"xml", opt_xml, 0, N_("output in XML")},
{"strict", opt_strict, 0, N_("use strict semantics")},
{"stop-on-copy", opt_stop_on_copy, 0,
- N_("do not cross copies while traversing history\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --soc]")},
+ N_("do not cross copies while traversing history")},
{"no-ignore", opt_no_ignore, 0,
N_("disregard default and svn:ignore property ignores")},
{"no-auth-cache", opt_no_auth_cache, 0,
- N_("do not cache authentication tokens\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --nac]")},
+ N_("do not cache authentication tokens")},
{"trust-server-cert", opt_trust_server_cert, 0,
N_("accept unknown SSL server certificates without\n"
SVN_CL__OPTION_CONTINUATION_INDENT
@@ -237,41 +229,27 @@ const apr_getopt_option_t svn_cl__option
{"non-interactive", opt_non_interactive, 0,
N_("do no interactive prompting")},
{"dry-run", opt_dry_run, 0,
- N_("try operation but make no changes\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --dry]")},
+ N_("try operation but make no changes")},
{"no-diff-deleted", opt_no_diff_deleted, 0,
- N_("do not print differences for deleted files\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --ndd]")},
+ N_("do not print differences for deleted files")},
{"notice-ancestry", opt_notice_ancestry, 0,
- N_("notice ancestry when calculating differences\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --na]")},
+ N_("notice ancestry when calculating differences")},
{"ignore-ancestry", opt_ignore_ancestry, 0,
- N_("ignore ancestry when calculating merges\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --ia]")},
+ N_("ignore ancestry when calculating merges")},
{"ignore-externals", opt_ignore_externals, 0,
- N_("ignore externals definitions\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --ie]")},
+ N_("ignore externals definitions")},
{"diff-cmd", opt_diff_cmd, 1, N_("use ARG as diff command")},
{"diff3-cmd", opt_merge_cmd, 1, N_("use ARG as merge command")},
{"editor-cmd", opt_editor_cmd, 1, N_("use ARG as external editor")},
{"record-only", opt_record_only, 0,
- N_("merge only mergeinfo differences\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --ro]")},
+ N_("merge only mergeinfo differences")},
{"old", opt_old_cmd, 1, N_("use ARG as the older target")},
{"new", opt_new_cmd, 1, N_("use ARG as the newer target")},
{"revprop", opt_revprop, 0,
N_("operate on a revision property (use with -r)")},
{"relocate", opt_relocate, 0, N_("relocate via URL-rewriting")},
{"config-dir", opt_config_dir, 1,
- N_("read user configuration files from directory ARG\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --cd]")},
+ N_("read user configuration files from directory ARG")},
{"config-option", opt_config_options, 1,
N_("set user configuration option in the format:\n"
SVN_CL__OPTION_CONTINUATION_INDENT
@@ -291,20 +269,14 @@ const apr_getopt_option_t svn_cl__option
SVN_CL__OPTION_CONTINUATION_INDENT
"ARG may be one of 'LF', 'CR', 'CRLF'")},
{"limit", 'l', 1, N_("maximum number of log entries")},
- {"no-unlock", opt_no_unlock, 0, N_("don't unlock the targets\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --keep-lock]")},
+ {"no-unlock", opt_no_unlock, 0, N_("don't unlock the targets")},
{"summarize", opt_summarize, 0, N_("show a summary of the results")},
{"remove", opt_remove, 0, N_("remove changelist association")},
{"changelist", opt_changelist, 1,
- N_("operate only on members of changelist ARG\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --cl]")},
+ N_("operate only on members of changelist ARG")},
{"keep-changelists", opt_keep_changelists, 0,
N_("don't delete changelists after commit")},
- {"keep-local", opt_keep_local, 0, N_("keep path in working copy\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --kl]")},
+ {"keep-local", opt_keep_local, 0, N_("keep path in working copy")},
{"with-all-revprops", opt_with_all_revprops, 0,
N_("retrieve all revision properties")},
{"with-no-revprops", opt_with_no_revprops, 0,
@@ -329,13 +301,9 @@ const apr_getopt_option_t svn_cl__option
{"show-revs", opt_show_revs, 1,
N_("specify which collection of revisions to display\n"
SVN_CL__OPTION_CONTINUATION_INDENT
- "('merged', 'eligible')\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --sr]")},
+ "('merged', 'eligible')")},
{"reintegrate", opt_reintegrate, 0,
- N_("lump-merge all of source URL's unmerged changes\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --ri]")},
+ N_("lump-merge all of source URL's unmerged changes")},
{"strip-count", opt_strip_count, 1,
N_("number of leading path components to strip from\n"
SVN_CL__OPTION_CONTINUATION_INDENT
@@ -351,37 +319,23 @@ const apr_getopt_option_t svn_cl__option
SVN_CL__OPTION_CONTINUATION_INDENT
"The expected component separator is '/' on all\n"
SVN_CL__OPTION_CONTINUATION_INDENT
- "platforms. A leading '/' counts as one component.\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --strip]")},
+ "platforms. A leading '/' counts as one component.")},
{"show-copies-as-adds", opt_show_copies_as_adds, 0,
- N_("don't diff copied or moved files with their source\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --sca]")},
+ N_("don't diff copied or moved files with their source")},
{"ignore-keywords", opt_ignore_keywords, 0,
- N_("don't expand keywords\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --ik]")},
+ N_("don't expand keywords")},
{"reverse-diff", opt_reverse_diff, 0,
N_("apply the unidiff in reverse\n"
SVN_CL__OPTION_CONTINUATION_INDENT
"This option also reverses patch target names; the\n"
SVN_CL__OPTION_CONTINUATION_INDENT
- "--old-patch-target-names option will prevent this.\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --rd]")},
+ "--old-patch-target-names option will prevent this.")},
{"ignore-whitespace", opt_ignore_whitespace, 0,
- N_("ignore whitespace during pattern matching\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --iw]")},
+ N_("ignore whitespace during pattern matching")},
{"show-diff", opt_show_diff, 0,
- N_("produce diff output\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --diff]")},
+ N_("produce diff output")},
{"internal-diff", opt_internal_diff, 0,
- N_("override diff-cmd specified in config file\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --idiff]")},
+ N_("override diff-cmd specified in config file")},
{"git", opt_use_git_diff_format, 0,
N_("use git's extended diff format")},
{"old-patch-target-names", opt_old_patch_target_names, 0,
@@ -393,9 +347,7 @@ const apr_getopt_option_t svn_cl__option
SVN_CL__OPTION_CONTINUATION_INDENT
" +++ foo.c.new\n"
SVN_CL__OPTION_CONTINUATION_INDENT
- "this option will cause the name \"foo.c\" to be used\n"
- SVN_CL__OPTION_CONTINUATION_INDENT
- "[alias: --optn]")},
+ "this option will cause the name \"foo.c\" to be used")},
/* Long-opt Aliases
*