Code

add OPT__FORCE
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>
Mon, 8 Nov 2010 18:01:54 +0000 (19:01 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Nov 2010 18:04:43 +0000 (10:04 -0800)
Add OPT__FORCE as a helper macro in the same spirit as OPT__VERBOSE
et.al. to simplify defining -f/--force options.

Signed-off-by: Rene Scharfe <rene.scharfe@lstfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
13 files changed:
Documentation/technical/api-parse-options.txt
builtin/add.c
builtin/branch.c
builtin/checkout-index.c
builtin/checkout.c
builtin/clean.c
builtin/fetch.c
builtin/mv.c
builtin/notes.c
builtin/rm.c
builtin/tag.c
builtin/update-server-info.c
parse-options.h

index 248a66dffb04a24b0c870ca60030b384ab72a862..f6a4a361bd56e1cc0f4645e09898e6852bfb8a8b 100644 (file)
@@ -121,6 +121,9 @@ There are some macros to easily define options:
 `OPT__DRY_RUN(&int_var, description)`::
        Add `-n, \--dry-run`.
 
+`OPT__FORCE(&int_var, description)`::
+       Add `-f, \--force`.
+
 `OPT__QUIET(&int_var, description)`::
        Add `-q, \--quiet`.
 
index 9625ceeb5bb6c6e7c8c37ea505ab7d8a9511ef9d..71f9b04fef829ad3725ca50902bd6935dc3cda36 100644 (file)
@@ -319,7 +319,7 @@ static struct option builtin_add_options[] = {
        OPT_BOOLEAN('i', "interactive", &add_interactive, "interactive picking"),
        OPT_BOOLEAN('p', "patch", &patch_interactive, "interactive patching"),
        OPT_BOOLEAN('e', "edit", &edit_interactive, "edit current diff and apply"),
-       OPT_BOOLEAN('f', "force", &ignored_too, "allow adding otherwise ignored files"),
+       OPT__FORCE(&ignored_too, "allow adding otherwise ignored files"),
        OPT_BOOLEAN('u', "update", &take_worktree_changes, "update tracked files"),
        OPT_BOOLEAN('N', "intent-to-add", &intent_to_add, "record only the fact that the path will be added later"),
        OPT_BOOLEAN('A', "all", &addremove, "add all, noticing removal of tracked files"),
index 10788fc1dd134aa9c9f6ef81fbc3b681b23718b0..e388edc413c1920557d51aa04c1dd1e9dbdfa2a5 100644 (file)
@@ -651,7 +651,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                OPT_BIT('m', NULL, &rename, "move/rename a branch and its reflog", 1),
                OPT_BIT('M', NULL, &rename, "move/rename a branch, even if target exists", 2),
                OPT_BOOLEAN('l', NULL, &reflog, "create the branch's reflog"),
-               OPT_BOOLEAN('f', "force", &force_create, "force creation (when already exists)"),
+               OPT__FORCE(&force_create, "force creation (when already exists)"),
                {
                        OPTION_CALLBACK, 0, "no-merged", &merge_filter_ref,
                        "commit", "print only not merged branches",
index 7ba09130cc2d1e9e3043ab867823b50e6227e2de..91fb9bfc624e3dc6556707e4a275c1d5543b5ce6 100644 (file)
@@ -217,8 +217,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
        struct option builtin_checkout_index_options[] = {
                OPT_BOOLEAN('a', "all", &all,
                        "checks out all files in the index"),
-               OPT_BOOLEAN('f', "force", &force,
-                       "forces overwrite of existing files"),
+               OPT__FORCE(&force, "forces overwrite of existing files"),
                OPT__QUIET(&quiet, "be quiet"),
                OPT_BOOLEAN('n', "no-create", &not_new,
                        "don't checkout new files"),
index a952477d19608a4324b5a141c7740d9ab5ed16c2..f275570cbda0fe6fee85037ed0ec0c2500eafa7c 100644 (file)
@@ -699,7 +699,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                            2),
                OPT_SET_INT('3', "theirs", &opts.writeout_stage, "checkout their version for unmerged files",
                            3),
-               OPT_BOOLEAN('f', "force", &opts.force, "force checkout (throw away local modifications)"),
+               OPT__FORCE(&opts.force, "force checkout (throw away local modifications)"),
                OPT_BOOLEAN('m', "merge", &opts.merge, "perform a 3-way merge with the new branch"),
                OPT_STRING(0, "conflict", &conflict_style, "style",
                           "conflict style (merge or diff3)"),
index 449d2a3237637f07258ca9a5ee5423790d587a82..9146bf3c1c70d306aab59812ea12f3a4d5fa7293 100644 (file)
@@ -50,7 +50,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
        struct option options[] = {
                OPT__QUIET(&quiet, "be quiet"),
                OPT__DRY_RUN(&show_only, "dry run"),
-               OPT_BOOLEAN('f', "force", &force, "force"),
+               OPT__FORCE(&force, "force"),
                OPT_BOOLEAN('d', NULL, &remove_directories,
                                "remove whole directories"),
                { OPTION_CALLBACK, 'e', "exclude", &exclude_list, "pattern",
index d35f000c034964ed600b1d8d45e2ef9260abcfb6..6aaf8e96b4b4415a909d244e200984fb586d574b 100644 (file)
@@ -43,8 +43,7 @@ static struct option builtin_fetch_options[] = {
                    "append to .git/FETCH_HEAD instead of overwriting"),
        OPT_STRING(0, "upload-pack", &upload_pack, "PATH",
                   "path to upload pack on remote end"),
-       OPT_BOOLEAN('f', "force", &force,
-                   "force overwrite of local branch"),
+       OPT__FORCE(&force, "force overwrite of local branch"),
        OPT_BOOLEAN('m', "multiple", &multiple,
                    "fetch from multiple remotes"),
        OPT_SET_INT('t', "tags", &tags,
index 8677bd2e40d98de1ce6cf727119176dc26357fed..93e8995d9e704faa041f97f92ba72dabe7839d81 100644 (file)
@@ -56,7 +56,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
        int verbose = 0, show_only = 0, force = 0, ignore_errors = 0;
        struct option builtin_mv_options[] = {
                OPT__DRY_RUN(&show_only, "dry run"),
-               OPT_BOOLEAN('f', "force", &force, "force move/rename even if target exists"),
+               OPT__FORCE(&force, "force move/rename even if target exists"),
                OPT_BOOLEAN('k', NULL, &ignore_errors, "skip move/rename errors"),
                OPT_END(),
        };
index 2ab070fa09dd1dfb253ae48d867d4c06699e40c3..c85cbf5a4758c8c08ef43dd65d9f85669c0063f2 100644 (file)
@@ -538,7 +538,7 @@ static int add(int argc, const char **argv, const char *prefix)
                { OPTION_CALLBACK, 'C', "reuse-message", &msg, "OBJECT",
                        "reuse specified note object", PARSE_OPT_NONEG,
                        parse_reuse_arg},
-               OPT_BOOLEAN('f', "force", &force, "replace existing notes"),
+               OPT__FORCE(&force, "replace existing notes"),
                OPT_END()
        };
 
@@ -594,7 +594,7 @@ static int copy(int argc, const char **argv, const char *prefix)
        struct notes_tree *t;
        const char *rewrite_cmd = NULL;
        struct option options[] = {
-               OPT_BOOLEAN('f', "force", &force, "replace existing notes"),
+               OPT__FORCE(&force, "replace existing notes"),
                OPT_BOOLEAN(0, "stdin", &from_stdin, "read objects from stdin"),
                OPT_STRING(0, "for-rewrite", &rewrite_cmd, "command",
                           "load rewriting config for <command> (implies "
index 49461b60c75d214a72cb1882c0d2f0c265e59ab5..9a5990513ab78a7c32cffdbe8b36b20c2509627e 100644 (file)
@@ -142,7 +142,7 @@ static struct option builtin_rm_options[] = {
        OPT__DRY_RUN(&show_only, "dry run"),
        OPT__QUIET(&quiet, "be quiet"),
        OPT_BOOLEAN( 0 , "cached",         &index_only, "only remove from the index"),
-       OPT_BOOLEAN('f', "force",          &force,      "override the up-to-date check"),
+       OPT__FORCE(&force, "override the up-to-date check"),
        OPT_BOOLEAN('r', NULL,             &recursive,  "allow recursive removal"),
        OPT_BOOLEAN( 0 , "ignore-unmatch", &ignore_unmatch,
                                "exit with a zero status even if nothing matched"),
index d311491e492787ae50aa172f51629abea53eec19..d1d7d8701db23dfa0db0fb3457f57826b7012d41 100644 (file)
@@ -390,7 +390,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
                OPT_BOOLEAN('s', NULL, &sign, "annotated and GPG-signed tag"),
                OPT_STRING('u', NULL, &keyid, "key-id",
                                        "use another key to sign the tag"),
-               OPT_BOOLEAN('f', "force", &force, "replace the tag if exists"),
+               OPT__FORCE(&force, "replace the tag if exists"),
 
                OPT_GROUP("Tag listing options"),
                {
index 2b3fddcc69087d856b6a9c9f4383c5577a759c77..b90dce6358153b274a1e26afde9cc89aad473d14 100644 (file)
@@ -11,8 +11,7 @@ int cmd_update_server_info(int argc, const char **argv, const char *prefix)
 {
        int force = 0;
        struct option options[] = {
-               OPT_BOOLEAN('f', "force", &force,
-                       "update the info files from scratch"),
+               OPT__FORCE(&force, "update the info files from scratch"),
                OPT_END()
        };
 
index 3dd3a94f22b23ffe9127aba3a90fe66c3ebc45f1..ae8647d8932512a49f5a7f9bc9decee34964976b 100644 (file)
@@ -206,6 +206,7 @@ extern int parse_opt_tertiary(const struct option *, const char *, int);
        { OPTION_CALLBACK, 'q', "quiet", (var), NULL, "be more quiet", \
          PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }
 #define OPT__DRY_RUN(var, h)  OPT_BOOLEAN('n', "dry-run", (var), (h))
+#define OPT__FORCE(var, h)    OPT_BOOLEAN('f', "force",   (var), (h))
 #define OPT__ABBREV(var)  \
        { OPTION_CALLBACK, 0, "abbrev", (var), "n", \
          "use <n> digits to display SHA-1s", \