Merge branch 'jc/rev-parse-argh-dashed-multi-words'
authorJunio C Hamano <gitster@pobox.com>
Tue, 8 Apr 2014 18:59:27 +0000 (11:59 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Apr 2014 18:59:27 +0000 (11:59 -0700)
Make sure that the help text given to describe the "<param>" part
of the "git cmd --option=<param>" does not contain SP or _,
e.g. "--gpg-sign=<key-id>" option for "git commit" is not spelled
as "--gpg-sign=<key id>".

* jc/rev-parse-argh-dashed-multi-words:
parse-options: make sure argh string does not have SP or _
update-index: teach --cacheinfo a new syntax "mode,sha1,path"
parse-options: multi-word argh should use dash to separate words

17 files changed:
Documentation/git-cherry-pick.txt
Documentation/git-commit.txt
Documentation/git-merge.txt
Documentation/git-notes.txt
Documentation/git-rev-parse.txt
Documentation/git-revert.txt
Documentation/git-update-index.txt
builtin/checkout.c
builtin/commit.c
builtin/merge.c
builtin/notes.c
builtin/revert.c
builtin/tag.c
builtin/update-index.c
parse-options.c
parse-options.h
t/t2107-update-index-basic.sh
index f1e6b2fd6d15809f5180fe705c3d571bf247ff1d..1c03c792b0be98181d1e988d6bd19a4637ce6ec5 100644 (file)
@@ -9,7 +9,7 @@ SYNOPSIS
 --------
 [verse]
 'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff]
-                 [-S[<keyid>]] <commit>...
+                 [-S[<key-id>]] <commit>...
 'git cherry-pick' --continue
 'git cherry-pick' --quit
 'git cherry-pick' --abort
@@ -101,8 +101,8 @@ effect to your index in a row.
 --signoff::
        Add Signed-off-by line at the end of the commit message.
 
--S[<keyid>]::
---gpg-sign[=<keyid>]::
+-S[<key-id>]::
+--gpg-sign[=<key-id>]::
        GPG-sign commits.
 
 --ff::
index 429267abf640ef42b5bf9361ed8ab78f6509f77f..0bbc8f55f9bb558033abb877bf0bc6cd10335edd 100644 (file)
@@ -13,7 +13,7 @@ SYNOPSIS
           [-F <file> | -m <msg>] [--reset-author] [--allow-empty]
           [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
           [--date=<date>] [--cleanup=<mode>] [--[no-]status]
-          [-i | -o] [-S[<keyid>]] [--] [<file>...]
+          [-i | -o] [-S[<key-id>]] [--] [<file>...]
 
 DESCRIPTION
 -----------
index 439545926ecdcf609c299ca0e5ea44032969c1be..a3c1fa332abb8d65051f6f6d5df6a14708fba980 100644 (file)
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git merge' [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
-       [-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
+       [-s <strategy>] [-X <strategy-option>] [-S[<key-id>]]
        [--[no-]rerere-autoupdate] [-m <msg>] [<commit>...]
 'git merge' <msg> HEAD <commit>...
 'git merge' --abort
index 84bb0fecb0415ecbe7824e9f4d43b0aee742798b..310f0a5e8c1819f1f49e00b78aacface36ac21ad 100644 (file)
@@ -14,7 +14,7 @@ SYNOPSIS
 'git notes' append [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
 'git notes' edit [<object>]
 'git notes' show [<object>]
-'git notes' merge [-v | -q] [-s <strategy> ] <notes_ref>
+'git notes' merge [-v | -q] [-s <strategy> ] <notes-ref>
 'git notes' merge --commit [-v | -q]
 'git notes' merge --abort [-v | -q]
 'git notes' remove [--ignore-missing] [--stdin] [<object>...]
index e05e6b35939326caa5fa2658d875b0d099216d9f..c452f33a366fd1c85da8e4288fa6722263545a55 100644 (file)
@@ -290,14 +290,14 @@ The lines after the separator describe the options.
 Each line of options has this format:
 
 ------------
-<opt_spec><flags>*<arg_hint>? SP+ help LF
+<opt-spec><flags>*<arg-hint>? SP+ help LF
 ------------
 
-`<opt_spec>`::
+`<opt-spec>`::
        its format is the short option character, then the long option name
        separated by a comma. Both parts are not required, though at least one
        is necessary. `h,help`, `dry-run` and `f` are all three correct
-       `<opt_spec>`.
+       `<opt-spec>`.
 
 `<flags>`::
        `<flags>` are of `*`, `=`, `?` or `!`.
@@ -313,11 +313,11 @@ Each line of options has this format:
 
        * Use `!` to not make the corresponding negated long option available.
 
-`<arg_hint>`::
-       `<arg_hint>`, if specified, is used as a name of the argument in the
-       help output, for options that take arguments. `<arg_hint>` is
-       terminated by the first whitespace. When you need to use space in the
-       argument hint use dash instead.
+`<arg-hint>`::
+       `<arg-hint>`, if specified, is used as a name of the argument in the
+       help output, for options that take arguments. `<arg-hint>` is
+       terminated by the first whitespace.  It is customary to use a
+       dash to separate words in a multi-word argument hint.
 
 The remainder of the line, after stripping the spaces, is used
 as the help associated to the option.
index 9eb83f01a4513ae3503258067133cae99189d39e..cceb5f2f7fa0c41174215901a091158161d89bc3 100644 (file)
@@ -8,7 +8,7 @@ git-revert - Revert some existing commits
 SYNOPSIS
 --------
 [verse]
-'git revert' [--[no-]edit] [-n] [-m parent-number] [-s] [-S[<keyid>]] <commit>...
+'git revert' [--[no-]edit] [-n] [-m parent-number] [-s] [-S[<key-id>]] <commit>...
 'git revert' --continue
 'git revert' --quit
 'git revert' --abort
@@ -80,8 +80,8 @@ more details.
 This is useful when reverting more than one commits'
 effect to your index in a row.
 
--S[<keyid>]::
---gpg-sign[=<keyid>]::
+-S[<key-id>]::
+--gpg-sign[=<key-id>]::
        GPG-sign commits.
 
 -s::
index e0a87029cdfe9fadd9edd4cc493bedd6b5044ac3..d6de4a008ce74b9aa3f83035b4392e8d4505fae7 100644 (file)
@@ -12,7 +12,7 @@ SYNOPSIS
 'git update-index'
             [--add] [--remove | --force-remove] [--replace]
             [--refresh] [-q] [--unmerged] [--ignore-missing]
-            [(--cacheinfo <mode> <object> <file>)...]
+            [(--cacheinfo <mode>,<object>,<file>)...]
             [--chmod=(+|-)x]
             [--[no-]assume-unchanged]
             [--[no-]skip-worktree]
@@ -68,8 +68,12 @@ OPTIONS
 --ignore-missing::
        Ignores missing files during a --refresh
 
+--cacheinfo <mode>,<object>,<path>::
 --cacheinfo <mode> <object> <path>::
-       Directly insert the specified info into the index.
+       Directly insert the specified info into the index.  For
+       backward compatibility, you can also give these three
+       arguments as three separate parameters, but new users are
+       encouraged to use a single-parameter form.
 
 --index-info::
         Read index information from stdin.
index 1b86d9c868c35c7f0ad3f4b39f9d225c8365c77c..5b07757d4fca1950e293edf4a1183e5f79a72a2f 100644 (file)
@@ -1095,7 +1095,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                OPT_BOOL(0, "detach", &opts.force_detach, N_("detach the HEAD at named commit")),
                OPT_SET_INT('t', "track",  &opts.track, N_("set upstream info for new branch"),
                        BRANCH_TRACK_EXPLICIT),
-               OPT_STRING(0, "orphan", &opts.new_orphan_branch, N_("new branch"), N_("new unparented branch")),
+               OPT_STRING(0, "orphan", &opts.new_orphan_branch, N_("new-branch"), N_("new unparented branch")),
                OPT_SET_INT('2', "ours", &opts.writeout_stage, N_("checkout our version for unmerged files"),
                            2),
                OPT_SET_INT('3', "theirs", &opts.writeout_stage, N_("checkout their version for unmerged files"),
index d9550c54d02bbd1ba4df87734433dea4a7097e2e..215b5bec192777b36953c76fa8b15c5b14a8a643 100644 (file)
@@ -1501,7 +1501,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                OPT_BOOL('e', "edit", &edit_flag, N_("force edit of commit")),
                OPT_STRING(0, "cleanup", &cleanup_arg, N_("default"), N_("how to strip spaces and #comments from message")),
                OPT_BOOL(0, "status", &include_status, N_("include status in commit message template")),
-               { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key id"),
+               { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"),
                  N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
                /* end commit message options */
 
index e15d0e145a51d52687619673aec3ee80c0485375..66d8843301b22a6a89d9d765e9d3020942e6f672 100644 (file)
@@ -220,7 +220,7 @@ static struct option builtin_merge_options[] = {
        OPT_BOOL(0, "abort", &abort_current_merge,
                N_("abort the current in-progress merge")),
        OPT_SET_INT(0, "progress", &show_progress, N_("force progress reporting"), 1),
-       { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key id"),
+       { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"),
          N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
        OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")),
        OPT_END()
index bb89930373451eb0637bb92eedd0613513d959fb..39c8573cde00bc15e673ae549fcd0f22ea67d29f 100644 (file)
@@ -939,7 +939,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
        int result;
        const char *override_notes_ref = NULL;
        struct option options[] = {
-               OPT_STRING(0, "ref", &override_notes_ref, N_("notes_ref"),
+               OPT_STRING(0, "ref", &override_notes_ref, N_("notes-ref"),
                           N_("use notes from <notes_ref>")),
                OPT_END()
        };
index 065d88dd05ea65d6e53e617417555399920f8afd..f9ed5bd5d03675931609f533e92da3b0a82f0f46 100644 (file)
@@ -89,7 +89,7 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
                OPT_STRING(0, "strategy", &opts->strategy, N_("strategy"), N_("merge strategy")),
                OPT_CALLBACK('X', "strategy-option", &opts, N_("option"),
                        N_("option for merge strategy"), option_parse_x),
-               { OPTION_STRING, 'S', "gpg-sign", &opts->gpg_sign, N_("key id"),
+               { OPTION_STRING, 'S', "gpg-sign", &opts->gpg_sign, N_("key-id"),
                  N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
                OPT_END(),
                OPT_END(),
index 40356e3e41b44f87b565ebbed8ad0f7a5000b31d..6c7c6bde9de9cbc0ace94aa75df30b7b88b43aca 100644 (file)
@@ -513,7 +513,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
                OPT_BOOL('s', "sign", &opt.sign, N_("annotated and GPG-signed tag")),
                OPT_STRING(0, "cleanup", &cleanup_arg, N_("mode"),
                        N_("how to strip spaces and #comments from message")),
-               OPT_STRING('u', "local-user", &keyid, N_("key id"),
+               OPT_STRING('u', "local-user", &keyid, N_("key-id"),
                                        N_("use another key to sign the tag")),
                OPT__FORCE(&force, N_("replace the tag if exists")),
                OPT_COLUMN(0, "column", &colopts, N_("show tag list in columns")),
index d12ad95f3e210f780d95334d59a58e6b9d3b69ad..ba54e19cd559018fcca52b5251bffa78165e16a3 100644 (file)
@@ -629,14 +629,42 @@ static int resolve_undo_clear_callback(const struct option *opt,
        return 0;
 }
 
+static int parse_new_style_cacheinfo(const char *arg,
+                                    unsigned int *mode,
+                                    unsigned char sha1[],
+                                    const char **path)
+{
+       unsigned long ul;
+       char *endp;
+
+       errno = 0;
+       ul = strtoul(arg, &endp, 8);
+       if (errno || endp == arg || *endp != ',' || (unsigned int) ul != ul)
+               return -1; /* not a new-style cacheinfo */
+       *mode = ul;
+       endp++;
+       if (get_sha1_hex(endp, sha1) || endp[40] != ',')
+               return -1;
+       *path = endp + 41;
+       return 0;
+}
+
 static int cacheinfo_callback(struct parse_opt_ctx_t *ctx,
                                const struct option *opt, int unset)
 {
        unsigned char sha1[20];
        unsigned int mode;
+       const char *path;
 
+       if (!parse_new_style_cacheinfo(ctx->argv[1], &mode, sha1, &path)) {
+               if (add_cacheinfo(mode, sha1, path, 0))
+                       die("git update-index: --cacheinfo cannot add %s", path);
+               ctx->argv++;
+               ctx->argc--;
+               return 0;
+       }
        if (ctx->argc <= 3)
-               return error("option 'cacheinfo' expects three arguments");
+               return error("option 'cacheinfo' expects <mode>,<sha1>,<path>");
        if (strtoul_ui(*++ctx->argv, 8, &mode) ||
            get_sha1_hex(*++ctx->argv, sha1) ||
            add_cacheinfo(mode, sha1, *++ctx->argv, 0))
@@ -740,9 +768,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                        PARSE_OPT_NOARG | PARSE_OPT_NONEG,
                        really_refresh_callback},
                {OPTION_LOWLEVEL_CALLBACK, 0, "cacheinfo", NULL,
-                       N_("<mode> <object> <path>"),
+                       N_("<mode>,<object>,<path>"),
                        N_("add the specified entry to the index"),
-                       PARSE_OPT_NOARG |       /* disallow --cacheinfo=<mode> form */
+                       PARSE_OPT_NOARG | /* disallow --cacheinfo=<mode> form */
                        PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
                        (parse_opt_cb *) cacheinfo_callback},
                {OPTION_CALLBACK, 0, "chmod", &set_executable_bit, N_("(+/-)x"),
index a5fa0b8938cb2820635bbc620b1b26cc903a6c97..c81d3a06550a1015ab0f4f7284bb48dce0293ab2 100644 (file)
@@ -375,6 +375,9 @@ static void parse_options_check(const struct option *opts)
                default:
                        ; /* ok. (usually accepts an argument) */
                }
+               if (opts->argh &&
+                   strcspn(opts->argh, " _") != strlen(opts->argh))
+                       err |= optbug(opts, "multi-word argh should use dash to separate words");
        }
        if (err)
                exit(128);
index d670cb9669f213951b9b2cac332c7869be6ca2ee..8fa02dc9a947b9bc56f929b81a71f122f2457dc1 100644 (file)
@@ -143,7 +143,7 @@ struct option {
        { OPTION_CALLBACK, (s), (l), (v), N_("time"),(h), 0,    \
          parse_opt_approxidate_cb }
 #define OPT_EXPIRY_DATE(s, l, v, h) \
-       { OPTION_CALLBACK, (s), (l), (v), N_("expiry date"),(h), 0,     \
+       { OPTION_CALLBACK, (s), (l), (v), N_("expiry-date"),(h), 0,     \
          parse_opt_expiry_date_cb }
 #define OPT_CALLBACK(s, l, v, a, h, f) \
        { OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) }
index a6405d318d322b9e1f49e4762570a2c1f5371726..fe2fb17102cdc17168ae2d683d7d51a0b3e3f3bc 100755 (executable)
@@ -48,4 +48,17 @@ test_expect_success '--cacheinfo does not accept gitlink null sha1' '
        test_cmp expect actual
 '
 
+test_expect_success '--cacheinfo mode,sha1,path (new syntax)' '
+       echo content >file &&
+       git hash-object -w --stdin <file >expect &&
+
+       git update-index --add --cacheinfo 100644 "$(cat expect)" file &&
+       git rev-parse :file >actual &&
+       test_cmp expect actual &&
+
+       git update-index --add --cacheinfo "100644,$(cat expect),elif" &&
+       git rev-parse :elif >actual &&
+       test_cmp expect actual
+'
+
 test_done