Skip to content

Commit b6610d7

Browse files
committed
squash! built-in add -i: implement the main loop
built-in add -i: implement the main loop The reason why we did not start with the main loop to begin with is that it is the first user of `list_and_choose()`, which uses the `list()` function that we conveniently introduced for use by the `status` command. In contrast to the Perl version, in the built-in interactive `add`, we will keep the `list()` function (which only displays items) and the `list_and_choose()` function (which uses `list()` to display the items, and only takes care of the "and choose" part) separate. The `list_and_choose()` function, as implemented in `git-add--interactive.perl` knows a few more tricks than the function we introduce in this patch: - There is a flag to let the user select multiple items. - In multi-select mode, the list of items is prefixed with a marker indicating what items have been selected. - Initially, for each item a unique prefix is determined (if there exists any within the given parameters), and shown in the list, and accepted as a shortcut for the selection. These features will be implemented in the C version later. This patch does not add any new main loop command, of course, the built-in `git add -i` still only supports the `status` command. The remaining commands to follow over the course of the next commits. To accommodate for listing the commands in columns, preparing for the commands that will be implemented over the course of the next patches/patch series, we teach the `list()` function to do precisely that. Note that we only have a prompt ending in a single ">" at this stage; later commits will add commands that display a double ">>" to indicate that the user is in a different loop than the main one. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 4b20fcf commit b6610d7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

add-interactive.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static ssize_t list_and_choose(struct add_i_state *s,
279279
find_unique_prefixes(items);
280280

281281
for (;;) {
282-
char *p, *endp;
282+
char *p;
283283

284284
strbuf_reset(&input);
285285

@@ -330,6 +330,7 @@ static ssize_t list_and_choose(struct add_i_state *s,
330330
from = 0;
331331
to = items->items.nr;
332332
} else if (isdigit(*p)) {
333+
char *endp;
333334
/* A range can be specified like 5-7 or 5-. */
334335
from = strtoul(p, &endp, 10) - 1;
335336
if (endp == p + sep)

0 commit comments

Comments
 (0)