t1000-t1999: fix broken &&-chains
[gitweb.git] / builtin / clean.c
index 057fc97fe4494338e6a85ac9f695563f1fcb9596..ab402c204cbcaea6190608753311605d37ca83d2 100644 (file)
@@ -16,6 +16,7 @@
 #include "column.h"
 #include "color.h"
 #include "pathspec.h"
+#include "help.h"
 
 static int force = -1; /* unset */
 static int interactive;
@@ -33,15 +34,6 @@ static const char *msg_skip_git_dir = N_("Skipping repository %s\n");
 static const char *msg_would_skip_git_dir = N_("Would skip repository %s\n");
 static const char *msg_warn_remove_failed = N_("failed to remove %s");
 
-static int clean_use_color = -1;
-static char clean_colors[][COLOR_MAXLEN] = {
-       GIT_COLOR_RESET,
-       GIT_COLOR_NORMAL,       /* PLAIN */
-       GIT_COLOR_BOLD_BLUE,    /* PROMPT */
-       GIT_COLOR_BOLD,         /* HEADER */
-       GIT_COLOR_BOLD_RED,     /* HELP */
-       GIT_COLOR_BOLD_RED,     /* ERROR */
-};
 enum color_clean {
        CLEAN_COLOR_RESET = 0,
        CLEAN_COLOR_PLAIN = 1,
@@ -51,6 +43,25 @@ enum color_clean {
        CLEAN_COLOR_ERROR = 5
 };
 
+static const char *color_interactive_slots[] = {
+       [CLEAN_COLOR_ERROR]  = "error",
+       [CLEAN_COLOR_HEADER] = "header",
+       [CLEAN_COLOR_HELP]   = "help",
+       [CLEAN_COLOR_PLAIN]  = "plain",
+       [CLEAN_COLOR_PROMPT] = "prompt",
+       [CLEAN_COLOR_RESET]  = "reset",
+};
+
+static int clean_use_color = -1;
+static char clean_colors[][COLOR_MAXLEN] = {
+       [CLEAN_COLOR_ERROR] = GIT_COLOR_BOLD_RED,
+       [CLEAN_COLOR_HEADER] = GIT_COLOR_BOLD,
+       [CLEAN_COLOR_HELP] = GIT_COLOR_BOLD_RED,
+       [CLEAN_COLOR_PLAIN] = GIT_COLOR_NORMAL,
+       [CLEAN_COLOR_PROMPT] = GIT_COLOR_BOLD_BLUE,
+       [CLEAN_COLOR_RESET] = GIT_COLOR_RESET,
+};
+
 #define MENU_OPTS_SINGLETON            01
 #define MENU_OPTS_IMMEDIATE            02
 #define MENU_OPTS_LIST_ONLY            04
@@ -81,22 +92,7 @@ struct menu_stuff {
        void *stuff;
 };
 
-static int parse_clean_color_slot(const char *var)
-{
-       if (!strcasecmp(var, "reset"))
-               return CLEAN_COLOR_RESET;
-       if (!strcasecmp(var, "plain"))
-               return CLEAN_COLOR_PLAIN;
-       if (!strcasecmp(var, "prompt"))
-               return CLEAN_COLOR_PROMPT;
-       if (!strcasecmp(var, "header"))
-               return CLEAN_COLOR_HEADER;
-       if (!strcasecmp(var, "help"))
-               return CLEAN_COLOR_HELP;
-       if (!strcasecmp(var, "error"))
-               return CLEAN_COLOR_ERROR;
-       return -1;
-}
+define_list_config_array(color_interactive_slots);
 
 static int git_clean_config(const char *var, const char *value, void *cb)
 {
@@ -112,7 +108,7 @@ static int git_clean_config(const char *var, const char *value, void *cb)
                return 0;
        }
        if (skip_prefix(var, "color.interactive.", &slot_name)) {
-               int slot = parse_clean_color_slot(slot_name);
+               int slot = LOOKUP_CONFIG(color_interactive_slots, slot_name);
                if (slot < 0)
                        return 0;
                if (!value)
@@ -167,7 +163,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
                }
 
                *dir_gone = 0;
-               return 0;
+               goto out;
        }
 
        dir = opendir(path->buf);
@@ -181,7 +177,8 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
                        warning_errno(_(msg_warn_remove_failed), quoted.buf);
                        *dir_gone = 0;
                }
-               return res;
+               ret = res;
+               goto out;
        }
 
        strbuf_complete(path, '/');
@@ -249,6 +246,8 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
                for (i = 0; i < dels.nr; i++)
                        printf(dry_run ?  _(msg_would_remove) : _(msg_remove), dels.items[i].string);
        }
+out:
+       strbuf_release(&quoted);
        string_list_clear(&dels, 0);
        return ret;
 }
@@ -905,7 +904,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
        struct option options[] = {
                OPT__QUIET(&quiet, N_("do not print names of files removed")),
                OPT__DRY_RUN(&dry_run, N_("dry run")),
-               OPT__FORCE(&force, N_("force")),
+               OPT__FORCE(&force, N_("force"), PARSE_OPT_NOCOMPLETE),
                OPT_BOOL('i', "interactive", &interactive, N_("interactive cleaning")),
                OPT_BOOL('d', NULL, &remove_directories,
                                N_("remove whole directories")),