Merge branch 'jx/clean-interactive'
authorJunio C Hamano <gitster@pobox.com>
Thu, 1 Aug 2013 18:52:37 +0000 (11:52 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Aug 2013 18:52:37 +0000 (11:52 -0700)
* jx/clean-interactive:
git-clean: implement partial matching for selection
Documentation/git-clean: fix description for range

1  2 
builtin/clean.c
diff --combined builtin/clean.c
index dba8387747b0fa5129b9270ce5140ba847a7a139,203e9b7ea01bb203db23d20f50b7b1f6fb6a073c..3c85e152e140741855590f422c599407b6d6ae55
@@@ -365,6 -365,56 +365,56 @@@ static void print_highlight_menu_stuff(
        string_list_clear(&menu_list, 0);
  }
  
+ static int find_unique(const char *choice, struct menu_stuff *menu_stuff)
+ {
+       struct menu_item *menu_item;
+       struct string_list_item *string_list_item;
+       int i, len, found = 0;
+       len = strlen(choice);
+       switch (menu_stuff->type) {
+       default:
+               die("Bad type of menu_stuff when parse choice");
+       case MENU_STUFF_TYPE_MENU_ITEM:
+               menu_item = (struct menu_item *)menu_stuff->stuff;
+               for (i = 0; i < menu_stuff->nr; i++, menu_item++) {
+                       if (len == 1 && *choice == menu_item->hotkey) {
+                               found = i + 1;
+                               break;
+                       }
+                       if (!strncasecmp(choice, menu_item->title, len)) {
+                               if (found) {
+                                       if (len == 1) {
+                                               /* continue for hotkey matching */
+                                               found = -1;
+                                       } else {
+                                               found = 0;
+                                               break;
+                                       }
+                               } else {
+                                       found = i + 1;
+                               }
+                       }
+               }
+               break;
+       case MENU_STUFF_TYPE_STRING_LIST:
+               string_list_item = ((struct string_list *)menu_stuff->stuff)->items;
+               for (i = 0; i < menu_stuff->nr; i++, string_list_item++) {
+                       if (!strncasecmp(choice, string_list_item->string, len)) {
+                               if (found) {
+                                       found = 0;
+                                       break;
+                               }
+                               found = i + 1;
+                       }
+               }
+               break;
+       }
+       return found;
+ }
  /*
   * Parse user input, and return choice(s) for menu (menu_stuff).
   *
@@@ -392,8 -442,6 +442,6 @@@ static int parse_choice(struct menu_stu
                        int **chosen)
  {
        struct strbuf **choice_list, **ptr;
-       struct menu_item *menu_item;
-       struct string_list_item *string_list_item;
        int nr = 0;
        int i;
  
                        bottom = 1;
                        top = menu_stuff->nr;
                } else {
-                       switch (menu_stuff->type) {
-                       default:
-                               die("Bad type of menu_stuff when parse choice");
-                       case MENU_STUFF_TYPE_MENU_ITEM:
-                               menu_item = (struct menu_item *)menu_stuff->stuff;
-                               for (i = 0; i < menu_stuff->nr; i++, menu_item++) {
-                                       if (((*ptr)->len == 1 &&
-                                            *(*ptr)->buf == menu_item->hotkey) ||
-                                           !strcasecmp((*ptr)->buf, menu_item->title)) {
-                                               bottom = i + 1;
-                                               top = bottom;
-                                               break;
-                                       }
-                               }
-                               break;
-                       case MENU_STUFF_TYPE_STRING_LIST:
-                               string_list_item = ((struct string_list *)menu_stuff->stuff)->items;
-                               for (i = 0; i < menu_stuff->nr; i++, string_list_item++) {
-                                       if (!strcasecmp((*ptr)->buf, string_list_item->string)) {
-                                               bottom = i + 1;
-                                               top = bottom;
-                                               break;
-                                       }
-                               }
-                               break;
-                       }
+                       bottom = find_unique((*ptr)->buf, menu_stuff);
+                       top = bottom;
                }
  
                if (top <= 0 || bottom <= 0 || top > menu_stuff->nr || bottom > top ||
@@@ -912,7 -936,7 +936,7 @@@ int cmd_clean(int argc, const char **ar
                struct dir_entry *ent = dir.entries[i];
                int len, pos;
                int matches = 0;
 -              struct cache_entry *ce;
 +              const struct cache_entry *ce;
                struct stat st;
                const char *rel;