rev-list: let traversal die when --missing is not in use
[gitweb.git] / builtin / clean.c
index 057fc97fe4494338e6a85ac9f695563f1fcb9596..aaba4af3c26de2150ad655a0b162fc85a69a466d 100644 (file)
@@ -6,6 +6,7 @@
  * Based on git-clean.sh by Pavel Roskin
  */
 
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
@@ -16,6 +17,7 @@
 #include "column.h"
 #include "color.h"
 #include "pathspec.h"
+#include "help.h"
 
 static int force = -1; /* unset */
 static int interactive;
@@ -33,15 +35,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 +44,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 +93,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 +109,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)
@@ -144,6 +141,7 @@ static void clean_print_color(enum color_clean ix)
 static int exclude_cb(const struct option *opt, const char *arg, int unset)
 {
        struct string_list *exclude_list = opt->value;
+       BUG_ON_OPT_NEG(unset);
        string_list_append(exclude_list, arg);
        return 0;
 }
@@ -167,7 +165,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 +179,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 +248,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 +906,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")),
@@ -977,7 +978,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
                        continue;
 
                if (pathspec.nr)
-                       matches = dir_path_match(ent, &pathspec, 0, NULL);
+                       matches = dir_path_match(&the_index, ent, &pathspec, 0, NULL);
 
                if (pathspec.nr && !matches)
                        continue;