parse-options: let OPT__FORCE take optional flags argument

--force option is most likely hidden from command line completion for safety reasons. This is done by adding an extra flag PARSE_OPT_NOCOMPLETE. Update OPT__FORCE() to accept additional flags. Actual flag change comes later depending on individual commands. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Feb 9, 2018 at 18:01 UTC 1224781d6080b8b69a81526ee23b22a1587920ea
14 files changed +17 -15
builtin/add.c
+1 -1
@@ -294,7 +294,7 @@ static struct option builtin_add_options[] = {
294 OPT_BOOL('i', "interactive", &add_interactive, N_("interactive picking")),
295 OPT_BOOL('p', "patch", &patch_interactive, N_("select hunks interactively")),
296 OPT_BOOL('e', "edit", &edit_interactive, N_("edit current diff and apply")),
297 - OPT__FORCE(&ignored_too, N_("allow adding otherwise ignored files")),
297 + OPT__FORCE(&ignored_too, N_("allow adding otherwise ignored files"), 0),
298 OPT_BOOL('u', "update", &take_worktree_changes, N_("update tracked files")),
299 OPT_BOOL(0, "renormalize", &add_renormalize, N_("renormalize EOL of tracked files (implies -u)")),
300 OPT_BOOL('N', "intent-to-add", &intent_to_add, N_("record only the fact that the path will be added later")),
builtin/branch.c
+1 -1
@@ -615,7 +615,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
615 OPT_BOOL('l', "create-reflog", &reflog, N_("create the branch's reflog")),
616 OPT_BOOL(0, "edit-description", &edit_description,
617 N_("edit the description for the branch")),
618 - OPT__FORCE(&force, N_("force creation, move/rename, deletion")),
618 + OPT__FORCE(&force, N_("force creation, move/rename, deletion"), 0),
619 OPT_MERGED(&filter, N_("print only branches that are merged")),
620 OPT_NO_MERGED(&filter, N_("print only branches that are not merged")),
621 OPT_COLUMN(0, "column", &colopts, N_("list branches in columns")),
builtin/checkout-index.c
+1 -1
@@ -157,7 +157,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
157 struct option builtin_checkout_index_options[] = {
158 OPT_BOOL('a', "all", &all,
159 N_("check out all files in the index")),
160 - OPT__FORCE(&force, N_("force overwrite of existing files")),
160 + OPT__FORCE(&force, N_("force overwrite of existing files"), 0),
161 OPT__QUIET(&quiet,
162 N_("no warning for existing files and files not in index")),
163 OPT_BOOL('n', "no-create", &not_new,
builtin/checkout.c
+1 -1
@@ -1118,7 +1118,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1118 2),
1119 OPT_SET_INT('3', "theirs", &opts.writeout_stage, N_("checkout their version for unmerged files"),
1120 3),
1121 - OPT__FORCE(&opts.force, N_("force checkout (throw away local modifications)")),
1121 + OPT__FORCE(&opts.force, N_("force checkout (throw away local modifications)"), 0),
1122 OPT_BOOL('m', "merge", &opts.merge, N_("perform a 3-way merge with the new branch")),
1123 OPT_BOOL(0, "overwrite-ignore", &opts.overwrite_ignore, N_("update ignored files (default)")),
1124 OPT_STRING(0, "conflict", &conflict_style, N_("style"),
builtin/clean.c
+1 -1
@@ -909,7 +909,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
909 struct option options[] = {
910 OPT__QUIET(&quiet, N_("do not print names of files removed")),
911 OPT__DRY_RUN(&dry_run, N_("dry run")),
912 - OPT__FORCE(&force, N_("force")),
912 + OPT__FORCE(&force, N_("force"), 0),
913 OPT_BOOL('i', "interactive", &interactive, N_("interactive cleaning")),
914 OPT_BOOL('d', NULL, &remove_directories,
915 N_("remove whole directories")),
builtin/fetch.c
+1 -1
@@ -115,7 +115,7 @@ static struct option builtin_fetch_options[] = {
115 N_("append to .git/FETCH_HEAD instead of overwriting")),
116 OPT_STRING(0, "upload-pack", &upload_pack, N_("path"),
117 N_("path to upload pack on remote end")),
118 - OPT__FORCE(&force, N_("force overwrite of local branch")),
118 + OPT__FORCE(&force, N_("force overwrite of local branch"), 0),
119 OPT_BOOL('m', "multiple", &multiple,
120 N_("fetch from multiple remotes")),
121 OPT_SET_INT('t', "tags", &tags,
builtin/mv.c
+1 -1
@@ -122,7 +122,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
122 struct option builtin_mv_options[] = {
123 OPT__VERBOSE(&verbose, N_("be verbose")),
124 OPT__DRY_RUN(&show_only, N_("dry run")),
125 - OPT__FORCE(&force, N_("force move/rename even if target exists")),
125 + OPT__FORCE(&force, N_("force move/rename even if target exists"), 0),
126 OPT_BOOL('k', NULL, &ignore_errors, N_("skip move/rename errors")),
127 OPT_END(),
128 };
builtin/notes.c
+2 -2
@@ -413,7 +413,7 @@ static int add(int argc, const char **argv, const char *prefix)
413 parse_reuse_arg},
414 OPT_BOOL(0, "allow-empty", &allow_empty,
415 N_("allow storing empty note")),
416 - OPT__FORCE(&force, N_("replace existing notes")),
416 + OPT__FORCE(&force, N_("replace existing notes"), 0),
417 OPT_END()
418 };
419
@@ -484,7 +484,7 @@ static int copy(int argc, const char **argv, const char *prefix)
484 struct notes_tree *t;
485 const char *rewrite_cmd = NULL;
486 struct option options[] = {
487 - OPT__FORCE(&force, N_("replace existing notes")),
487 + OPT__FORCE(&force, N_("replace existing notes"), 0),
488 OPT_BOOL(0, "stdin", &from_stdin, N_("read objects from stdin")),
489 OPT_STRING(0, "for-rewrite", &rewrite_cmd, N_("command"),
490 N_("load rewriting config for <command> (implies "
builtin/pull.c
+1 -1
@@ -193,7 +193,7 @@ static struct option pull_options[] = {
193 OPT_PASSTHRU(0, "upload-pack", &opt_upload_pack, N_("path"),
194 N_("path to upload pack on remote end"),
195 0),
196 - OPT__FORCE(&opt_force, N_("force overwrite of local branch")),
196 + OPT__FORCE(&opt_force, N_("force overwrite of local branch"), 0),
197 OPT_PASSTHRU('t', "tags", &opt_tags, NULL,
198 N_("fetch all tags and associated objects"),
199 PARSE_OPT_NOARG),
builtin/rm.c
+1 -1
@@ -242,7 +242,7 @@ static struct option builtin_rm_options[] = {
242 OPT__DRY_RUN(&show_only, N_("dry run")),
243 OPT__QUIET(&quiet, N_("do not list removed files")),
244 OPT_BOOL( 0 , "cached", &index_only, N_("only remove from the index")),
245 - OPT__FORCE(&force, N_("override the up-to-date check")),
245 + OPT__FORCE(&force, N_("override the up-to-date check"), 0),
246 OPT_BOOL('r', NULL, &recursive, N_("allow recursive removal")),
247 OPT_BOOL( 0 , "ignore-unmatch", &ignore_unmatch,
248 N_("exit with a zero status even if nothing matched")),
builtin/tag.c
+1 -1
@@ -391,7 +391,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
391 N_("how to strip spaces and #comments from message")),
392 OPT_STRING('u', "local-user", &keyid, N_("key-id"),
393 N_("use another key to sign the tag")),
394 - OPT__FORCE(&force, N_("replace the tag if exists")),
394 + OPT__FORCE(&force, N_("replace the tag if exists"), 0),
395 OPT_BOOL(0, "create-reflog", &create_reflog, N_("create a reflog")),
396
397 OPT_GROUP(N_("Tag listing options")),
builtin/update-server-info.c
+1 -1
@@ -12,7 +12,7 @@ int cmd_update_server_info(int argc, const char **argv, const char *prefix)
12 {
13 int force = 0;
14 struct option options[] = {
15 - OPT__FORCE(&force, N_("update the info files from scratch")),
15 + OPT__FORCE(&force, N_("update the info files from scratch"), 0),
16 OPT_END()
17 };
18
builtin/worktree.c
+3 -1
@@ -365,7 +365,9 @@ static int add(int ac, const char **av, const char *prefix)
365 const char *branch;
366 const char *opt_track = NULL;
367 struct option options[] = {
368 - OPT__FORCE(&opts.force, N_("checkout <branch> even if already checked out in other worktree")),
368 + OPT__FORCE(&opts.force,
369 + N_("checkout <branch> even if already checked out in other worktree"),
370 + 0),
371 OPT_STRING('b', NULL, &opts.new_branch, N_("branch"),
372 N_("create a new branch")),
373 OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
parse-options.h
+1 -1
@@ -248,7 +248,7 @@ extern int parse_opt_passthru_argv(const struct option *, const char *, int);
248 { OPTION_CALLBACK, 'q', "quiet", (var), NULL, N_("be more quiet"), \
249 PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }
250 #define OPT__DRY_RUN(var, h) OPT_BOOL('n', "dry-run", (var), (h))
251 -#define OPT__FORCE(var, h) OPT_COUNTUP('f', "force", (var), (h))
251 +#define OPT__FORCE(var, h, f) OPT_COUNTUP_F('f', "force", (var), (h), (f))
252 #define OPT__ABBREV(var) \
253 { OPTION_CALLBACK, 0, "abbrev", (var), N_("n"), \
254 N_("use <n> digits to display SHA-1s"), \