Merge branch 'dt/clean-pathspec-filter-then-lstat' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 16 Jun 2015 21:33:46 +0000 (14:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 16 Jun 2015 21:33:46 +0000 (14:33 -0700)
"git clean pathspec..." tried to lstat(2) and complain even for
paths outside the given pathspec.

* dt/clean-pathspec-filter-then-lstat:
clean: only lstat files in pathspec

1  2 
builtin/clean.c
diff --combined builtin/clean.c
index 98c103fa8b4faa83c33a62e5d7871c1e9d888c38,3c1f4b0908c22d025cbb90b9a0d6ced9f0c9a6c4..ada0196c9e7be080847641973ddd5201534f6094
@@@ -67,7 -67,7 +67,7 @@@ struct menu_item 
        char hotkey;
        const char *title;
        int selected;
 -      int (*fn)();
 +      int (*fn)(void);
  };
  
  enum menu_stuff_type {
@@@ -100,8 -100,6 +100,8 @@@ static int parse_clean_color_slot(cons
  
  static int git_clean_config(const char *var, const char *value, void *cb)
  {
 +      const char *slot_name;
 +
        if (starts_with(var, "column."))
                return git_column_config(var, value, "clean", &colopts);
  
                clean_use_color = git_config_colorbool(var, value);
                return 0;
        }
 -      if (starts_with(var, "color.interactive.")) {
 -              int slot = parse_clean_color_slot(var +
 -                                                strlen("color.interactive."));
 +      if (skip_prefix(var, "color.interactive.", &slot_name)) {
 +              int slot = parse_clean_color_slot(slot_name);
                if (slot < 0)
                        return 0;
                if (!value)
                        return config_error_nonbool(var);
 -              color_parse(value, var, clean_colors[slot]);
 -              return 0;
 +              return color_parse(value, clean_colors[slot]);
        }
  
        if (!strcmp(var, "clean.requireforce")) {
@@@ -321,7 -321,7 +321,7 @@@ static void print_highlight_menu_stuff(
  
        switch (stuff->type) {
        default:
 -              die("Bad type of menu_staff when print menu");
 +              die("Bad type of menu_stuff when print menu");
        case MENU_STUFF_TYPE_MENU_ITEM:
                menu_item = (struct menu_item *)stuff->stuff;
                for (i = 0; i < stuff->nr; i++, menu_item++) {
@@@ -754,8 -754,7 +754,8 @@@ static int ask_each_cmd(void
                /* Ctrl-D should stop removing files */
                if (!eof) {
                        qname = quote_path_relative(item->string, NULL, &buf);
 -                      printf(_("remove %s? "), qname);
 +                      /* TRANSLATORS: Make sure to keep [y/N] as is */
 +                      printf(_("Remove %s [y/N]? "), qname);
                        if (strbuf_getline(&confirm, stdin, '\n') != EOF) {
                                strbuf_trim(&confirm);
                        } else {
@@@ -941,15 -940,15 +941,15 @@@ int cmd_clean(int argc, const char **ar
                if (!cache_name_is_other(ent->name, ent->len))
                        continue;
  
-               if (lstat(ent->name, &st))
-                       die_errno("Cannot lstat '%s'", ent->name);
                if (pathspec.nr)
                        matches = dir_path_match(ent, &pathspec, 0, NULL);
  
                if (pathspec.nr && !matches)
                        continue;
  
+               if (lstat(ent->name, &st))
+                       die_errno("Cannot lstat '%s'", ent->name);
                if (S_ISDIR(st.st_mode) && !remove_directories &&
                    matches != MATCHED_EXACTLY)
                        continue;