Skip to content

Commit 1942ee4

Browse files
dschogitster
authored andcommitted
built-in add -i: wire up the new C code for the patch command
The code in `git-add--interactive.perl` that takes care of the `patch` command can look quite intimidating. There are so many modes in which it can be called, for example. But for the `patch` command in `git add -i`, only one mode is relevant: the `stage` mode. And we just implemented the beginnings of that mode in C so far. So let's use it when `add.interactive.useBuiltin=true`. Now, while the code in `add-patch.c` is far from reaching feature parity with the code in `git-add--interactive.perl` (color is not implemented, the diff algorithm cannot be configured, the colored diff cannot be post-processed via `interactive.diffFilter`, many commands are unimplemented yet, etc), hooking it all up with the part of `git add -i` that is already converted to C makes it easier to test and develop it. Note: at this stage, both the `add.interactive.useBuiltin` config setting is still safely opt-in, and will probably be fore quite some time, to allow for thorough testing "in the wild" without adversely affecting existing users. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f6aa7ec commit 1942ee4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

add-interactive.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,15 +917,18 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
917917
count = list_and_choose(s, files, opts);
918918
if (count >= 0) {
919919
struct argv_array args = ARGV_ARRAY_INIT;
920+
struct pathspec ps_selected = { 0 };
920921

921-
argv_array_pushl(&args, "git", "add--interactive", "--patch",
922-
"--", NULL);
923922
for (i = 0; i < files->items.nr; i++)
924923
if (files->selected[i])
925924
argv_array_push(&args,
926925
files->items.items[i].string);
927-
res = run_command_v_opt(args.argv, 0);
926+
parse_pathspec(&ps_selected,
927+
PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
928+
PATHSPEC_LITERAL_PATH, "", args.argv);
929+
res = run_add_p(s->r, &ps_selected);
928930
argv_array_clear(&args);
931+
clear_pathspec(&ps_selected);
929932
}
930933

931934
return res;

0 commit comments

Comments
 (0)