@matheusbsbs / matheus-bagliano / commits / 2e697ced9d
Fork 0

built-in add -i: offer the `quit` command

We do not really want to `exit()` here, of course, as this is safely libified code. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Nov 29, 2019 at 21:11 UTC 2e697ced9d647d6998d70f010d582ba8019fe3af
1 file changed +11 -5
add-interactive.c
+11 -5
@@ -1071,6 +1071,7 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
1071 { "add untracked", run_add_untracked },
1072 { "patch", run_patch },
1073 { "diff", run_diff },
1074 + { "quit", NULL },
1075 { "help", run_help },
1076 };
1077 struct prefix_item_list commands = PREFIX_ITEM_LIST_INIT;
@@ -1122,17 +1123,22 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
1123 res = run_status(&s, ps, &files, &opts);
1124
1125 for (;;) {
1126 + struct command_item *util;
1127 +
1128 i = list_and_choose(&s, &commands, &main_loop_opts);
1126 - if (i == LIST_AND_CHOOSE_QUIT) {
1129 + if (i < 0 || i >= commands.items.nr)
1130 + util = NULL;
1131 + else
1132 + util = commands.items.items[i].util;
1133 +
1134 + if (i == LIST_AND_CHOOSE_QUIT || (util && !util->command)) {
1135 printf(_("Bye.\n"));
1136 res = 0;
1137 break;
1138 }
1131 - if (i != LIST_AND_CHOOSE_ERROR) {
1132 - struct command_item *util =
1133 - commands.items.items[i].util;
1139 +
1140 + if (util)
1141 res = util->command(&s, ps, &files, &opts);
1135 - }
1142 }
1143
1144 prefix_item_list_clear(&files);