@matheusbsbs / matheus-bagliano / commits / f83dff60a7
Fork 0

Start to implement a built-in version of `git add --interactive`

Unlike previous conversions to C, where we started with a built-in helper, we start this conversion by adding an interception in the `run_add_interactive()` function when the new opt-in `add.interactive.useBuiltin` config knob is turned on (or the corresponding environment variable `GIT_TEST_ADD_I_USE_BUILTIN`), and calling the new internal API function `run_add_i()` that is implemented directly in libgit.a. At this point, the built-in version of `git add -i` only states that it cannot do anything yet. In subsequent patches/patch series, the `run_add_i()` function will gain more and more functionality, until it is feature complete. The whole arc of the conversion can be found in the PRs #170-175 at https://github.com/gitgitgadget/git. The "--helper approach" can unfortunately not be used here: on Windows we face the very specific problem that a `system()` call in Perl seems to close `stdin` in the parent process when the spawned process consumes even one character from `stdin`. Which prevents us from implementing the main loop in C and still trying to hand off to the Perl script. The very real downside of the approach we have to take here is that the test suite won't pass with `GIT_TEST_ADD_I_USE_BUILTIN=true` until the conversion is complete (the `--helper` approach would have let it pass, even at each of the incremental conversion steps). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Nov 13, 2019 at 12:40 UTC f83dff60a7880f1abfc3dc3c6b8e2972c4889da5
6 files changed +37
Documentation/config/add.txt
+5
@@ -5,3 +5,8 @@ add.ignore-errors (deprecated)::
5 option of linkgit:git-add[1]. `add.ignore-errors` is deprecated,
6 as it does not follow the usual naming convention for configuration
7 variables.
8 +
9 +add.interactive.useBuiltin::
10 + [EXPERIMENTAL] Set to `true` to use the experimental built-in
11 + implementation of the interactive version of linkgit:git-add[1]
12 + instead of the Perl script version. Is `false` by default.
Makefile
+1
@@ -823,6 +823,7 @@ LIB_H := $(sort $(patsubst ./%,%,$(shell git ls-files '*.h' ':!t/' ':!Documentat
823 -name '*.h' -print)))
824
825 LIB_OBJS += abspath.o
826 +LIB_OBJS += add-interactive.o
827 LIB_OBJS += advice.o
828 LIB_OBJS += alias.o
829 LIB_OBJS += alloc.o
add-interactive.c new
+7
@@ -0,0 +1,7 @@
1 +#include "cache.h"
2 +#include "add-interactive.h"
3 +
4 +int run_add_i(struct repository *r, const struct pathspec *ps)
5 +{
6 + die(_("No commands are available in the built-in `git add -i` yet!"));
7 +}
add-interactive.h new
+8
@@ -0,0 +1,8 @@
1 +#ifndef ADD_INTERACTIVE_H
2 +#define ADD_INTERACTIVE_H
3 +
4 +struct repository;
5 +struct pathspec;
6 +int run_add_i(struct repository *r, const struct pathspec *ps);
7 +
8 +#endif
builtin/add.c
+12
@@ -20,6 +20,7 @@
20 #include "bulk-checkin.h"
21 #include "argv-array.h"
22 #include "submodule.h"
23 +#include "add-interactive.h"
24
25 static const char * const builtin_add_usage[] = {
26 N_("git add [<options>] [--] <pathspec>..."),
@@ -185,6 +186,16 @@ int run_add_interactive(const char *revision, const char *patch_mode,
186 {
187 int status, i;
188 struct argv_array argv = ARGV_ARRAY_INIT;
189 + int use_builtin_add_i =
190 + git_env_bool("GIT_TEST_ADD_I_USE_BUILTIN", -1);
191 +
192 + if (!patch_mode) {
193 + if (use_builtin_add_i < 0)
194 + git_config_get_bool("add.interactive.usebuiltin",
195 + &use_builtin_add_i);
196 + if (use_builtin_add_i == 1)
197 + return !!run_add_i(the_repository, pathspec);
198 + }
199
200 argv_array_push(&argv, "add--interactive");
201 if (patch_mode)
@@ -319,6 +330,7 @@ static int add_config(const char *var, const char *value, void *cb)
330 ignore_add_errors = git_config_bool(var, value);
331 return 0;
332 }
333 +
334 return git_default_config(var, value, cb);
335 }
336
t/README
+4
@@ -397,6 +397,10 @@ GIT_TEST_STASH_USE_BUILTIN=<boolean>, when false, disables the
397 built-in version of git-stash. See 'stash.useBuiltin' in
398 git-config(1).
399
400 +GIT_TEST_ADD_I_USE_BUILTIN=<boolean>, when true, enables the
401 +built-in version of git add -i. See 'add.interactive.useBuiltin' in
402 +git-config(1).
403 +
404 GIT_TEST_INDEX_THREADS=<n> enables exercising the multi-threaded loading
405 of the index for the whole test suite by bypassing the default number of
406 cache entries and thread minimums. Setting this to 1 will make the