I feel change the order of patch 01/15 and patch 02/15 is better.
I.E. Add test cases for relative_path first, then refactor
relative_path and fix the test cases.
Also fix wrong indent in t/7301.
Differences with gitster/jx/clean-interactive:
diff --git a/Documentation/git-clean.txt b/Documentation/git-clean.txt
index 75fb54..5bf76 100644
--- a/Documentation/git-clean.txt
+++ b/Documentation/git-clean.txt
@@ -82,8 +82,8 @@ and type return, like this:
*** Commands ***
- 1: clean2: filter by pattern3: select by numbers
- 4: ask each 5: quit 6: help
+1: clean2: filter by pattern3: select by numbers
+4: ask each 5: quit 6: help
What now> 1
diff --git a/builtin/clean.c b/builtin/clean.c
index 73ba2..7d34b 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -64,7 +64,7 @@ struct menu_opts {
struct menu_item {
char hotkey;
- char *title;
+ const char *title;
int selected;
int (*fn)();
};
@@ -312,22 +312,26 @@ static void print_highlight_menu_stuff(struct menu_stuff
*stuff, int **chosen)
{
struct string_list menu_list = STRING_LIST_INIT_DUP;
struct strbuf menu = STRBUF_INIT;
+ struct strbuf buf = STRBUF_INIT;
+ struct menu_item *menu_item;
+ struct string_list_item *string_list_item;
int i;
- if (stuff->type == MENU_STUFF_TYPE_MENU_ITEM) {
- struct menu_item *item;
-
- item = (struct menu_item *)stuff->stuff;
- for (i = 0; i < stuff->nr; i++, item++) {
- char *p;
+ switch (stuff->type) {
+ default:
+ die("Bad type of menu_staff 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++) {
+ const char *p;
int highlighted = 0;
- p = item->title;
+ p = menu_item->title;
if ((*chosen)[i] < 0)
- (*chosen)[i] = item->selected ? 1 : 0;
+ (*chosen)[i] = menu_item->selected ? 1 : 0;
strbuf_addf(&menu, "%s%2d: ", (*chosen)[i] ? "*" : " ",
i+1);
for (; *p; p++) {
- if (!highlighted && *p == item->hotkey) {
+ if (!highlighted && *p == menu_item->hotkey) {
strbuf_addstr(&menu,
clean_get_color(CLEAN_COLOR_PROMPT));
strbuf_addch(&menu, *p);
strbuf_addstr(&menu,
clean_get_color(CLEAN_COLOR_RESET));
@@ -339,27 +343,25 @@ static void print_highlight_menu_stuff(struct menu_stuff
*stuff, int **chosen)
string_list_append(&menu_list, menu.buf);
strbuf_reset(&menu);
}
-
- } else if (stuff->type == MENU_STUFF_TYPE_STRING_LIST) {
- struct string_list_item *item;
- struct strbuf buf = STRBUF_INIT;
+ break;
+ case MENU_STUFF_TYPE_STRING_LIST:
i = 0;
-
- for_each_string_list_item(item, (struct string_list
*)stuff->stuff) {
+ for_each_string_list_item(string_list_item, (struct string_list
*)stuff->stuff) {
if ((*chosen)[i] < 0)
(*chosen)[i] = 0;
strbuf_addf(&menu, "%s%2d: %s",
- (*chosen)[i] ? "*" : " ", i + 1,
item->string);
+ (*chosen)[i] ? "*" : " ", i+1,
string_list_item->string);
string_list_append(&menu_list, menu.buf);
strbuf_reset(&menu);
i++;
}
- strbuf_release(&buf);
+ break;
}
pretty_print_menus(&menu_list);
strbuf_release(&menu);
+ strbuf_release(&buf);
string_list_clear(&menu_list, 0);
}
@@ -390,6 +392,8 @@ static int parse_choice(struct menu_stuff *menu_stuff,
int **chosen)
{
struct strbuf **choice_list, **ptr;
+ struct menu_item *menu_item;
+ struct string_list_item *string_list_item;
int nr = 0;
int i;
@@ -454,30 +458,31 @@ static int parse_choice(struct menu_stuff *menu_stuff,
bottom = 1;
top = menu_stuff->nr;
} else {
- if (MENU_STUFF_TYPE_MENU_ITEM == menu_stuff->type) {
- struct menu_item *item;
-
- item = (struct menu_item *)menu_stuff->stuff;
- for (i =