]> git.ipfire.org Git - thirdparty/git.git/commitdiff
parse-options: automatically infer PARSE_OPT_LITERAL_ARGHELP
authorRené Scharfe <l.s.r@web.de>
Thu, 2 Aug 2018 19:18:14 +0000 (21:18 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 3 Aug 2018 15:36:20 +0000 (08:36 -0700)
Parseopt wraps argument help strings in a pair of angular brackets by
default, to tell users that they need to replace it with an actual
value.  This is useful in most cases, because most option arguments
are indeed single values of a certain type.  The option
PARSE_OPT_LITERAL_ARGHELP needs to be used in option definitions with
arguments that have multiple parts or are literal strings.

Stop adding these angular brackets if special characters are present,
as they indicate that we don't deal with a simple placeholder.  This
simplifies the code a bit and makes defining special options slightly
easier.

Remove the flag PARSE_OPT_LITERAL_ARGHELP in the cases where the new
and more cautious handling suffices.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/add.c
builtin/pack-objects.c
builtin/read-tree.c
builtin/send-pack.c
builtin/shortlog.c
builtin/show-branch.c
builtin/update-index.c
builtin/write-tree.c
parse-options.c

index 110f2ae0dc68e2143eec6d14675735580ed0f408..8352bdf71f3838968a4e9e3ecaae80a702d01786 100644 (file)
@@ -306,9 +306,8 @@ static struct option builtin_add_options[] = {
        OPT_BOOL( 0 , "refresh", &refresh_only, N_("don't add, only refresh the index")),
        OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
        OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
-       { OPTION_STRING, 0, "chmod", &chmod_arg, "(+|-)x",
-         N_("override the executable bit of the listed files"),
-         PARSE_OPT_LITERAL_ARGHELP },
+       OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x",
+                  N_("override the executable bit of the listed files")),
        OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
                        N_("warn when adding an embedded repository")),
        OPT_END(),
index 5d7566a40b39c924c70b8614490f45e4db756ad2..1529a75e0392c6bd7183a0b3ee02b3b694ad4798 100644 (file)
@@ -2943,7 +2943,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
                         N_("similar to --all-progress when progress meter is shown")),
                { OPTION_CALLBACK, 0, "index-version", NULL, N_("<version>[,<offset>]"),
                  N_("write the pack index file in the specified idx format version"),
-                 PARSE_OPT_LITERAL_ARGHELP, option_parse_index_version },
+                 0, option_parse_index_version },
                OPT_MAGNITUDE(0, "max-pack-size", &pack_size_limit,
                              N_("maximum size of each output pack file")),
                OPT_BOOL(0, "local", &local,
index bf87a2710b31fa49b1802ed297c8ae52eede6354..3a7fd6394ea406a4091362a7a03281378e887cc6 100644 (file)
@@ -134,7 +134,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
                         N_("same as -m, but discard unmerged entries")),
                { OPTION_STRING, 0, "prefix", &opts.prefix, N_("<subdirectory>/"),
                  N_("read the tree into the index under <subdirectory>/"),
-                 PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP },
+                 PARSE_OPT_NONEG },
                OPT_BOOL('u', NULL, &opts.update,
                         N_("update working tree with merge result")),
                { OPTION_CALLBACK, 0, "exclude-per-directory", &opts,
index c8af374deeec5a4f631dd4e27a18eb3d4786b967..a4f7dea115a3cbf5be9895534d8e025fb3bdd168 100644 (file)
@@ -179,8 +179,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
                { OPTION_CALLBACK,
                  0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"),
                  N_("require old value of ref to be at this value"),
-                 PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP,
-                 parseopt_push_cas_option },
+                 PARSE_OPT_OPTARG, parseopt_push_cas_option },
                OPT_END()
        };
 
index 98508fc5561ec2b2290c8078cac49301dce5a347..581293ee7b2138daff127dfdafcaf5d927a1d5ba 100644 (file)
@@ -268,8 +268,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
                OPT_BOOL('e', "email", &log.email,
                         N_("Show the email address of each author")),
                { OPTION_CALLBACK, 'w', NULL, &log, N_("<w>[,<i1>[,<i2>]]"),
-                       N_("Linewrap output"),
-                       PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP,
+                       N_("Linewrap output"), PARSE_OPT_OPTARG,
                        &parse_wrap_args },
                OPT_END(),
        };
index e8a4aa40cb4b6cf8787af3dd35d833a92a85bba3..371b8c8b8482b077257c0429fb0cfbc043689129 100644 (file)
@@ -655,7 +655,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                { OPTION_CALLBACK, 'g', "reflog", &reflog_base, N_("<n>[,<base>]"),
                            N_("show <n> most recent ref-log entries starting at "
                               "base"),
-                           PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP,
+                           PARSE_OPT_OPTARG,
                            parse_reflog_param },
                OPT_END()
        };
index a2aee925a0e88b62873ce3ea2289578fbf2bbf55..6700a632beee7cd2702a737aaa7a8ea6fdfd97d1 100644 (file)
@@ -972,7 +972,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                        (parse_opt_cb *) cacheinfo_callback},
                {OPTION_CALLBACK, 0, "chmod", &set_executable_bit, "(+|-)x",
                        N_("override the executable bit of the listed files"),
-                       PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
+                       PARSE_OPT_NONEG,
                        chmod_callback},
                {OPTION_SET_INT, 0, "assume-unchanged", &mark_valid_only, NULL,
                        N_("mark files as \"not changing\""),
index bd0a78aa3c56b7e817c7ddf6fcaba703d6d5fecc..e636419122595c6607857f307e24862ae350ef8d 100644 (file)
@@ -24,9 +24,8 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
        struct option write_tree_options[] = {
                OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"),
                        WRITE_TREE_MISSING_OK),
-               { OPTION_STRING, 0, "prefix", &prefix, N_("<prefix>/"),
-                 N_("write tree object for a subdirectory <prefix>") ,
-                 PARSE_OPT_LITERAL_ARGHELP },
+               OPT_STRING(0, "prefix", &prefix, N_("<prefix>/"),
+                          N_("write tree object for a subdirectory <prefix>")),
                { OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
                  N_("only useful for debugging"),
                  PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,
index fca7159646c82cb9213e72afd94d8debc6bd4c51..2a2b97aec91e70577b7c81e83dd330a7a0681921 100644 (file)
@@ -562,7 +562,8 @@ int parse_options(int argc, const char **argv, const char *prefix,
 static int usage_argh(const struct option *opts, FILE *outfile)
 {
        const char *s;
-       int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opts->argh;
+       int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) ||
+               !opts->argh || !!strpbrk(opts->argh, "()<>[]|");
        if (opts->flags & PARSE_OPT_OPTARG)
                if (opts->long_name)
                        s = literal ? "[=%s]" : "[=<%s>]";