built-in stash: use the built-in `git add -p` if so configured
The scripted version of `git stash` called directly into the Perl script `git-add--interactive.perl`, and this was faithfully converted to C. However, we have a much better way to do this now: call the internal API directly, which will now incidentally also respect the `add.interactive.useBuiltin` setting. Let's just do this. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Dec 21, 2019 at 21:57 UTC
6610e4628ac12396efc20201fe85d67591bed247
1 file changed
+14
-11
builtin/stash.c
+14
-11
@@ -999,9 +999,9 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps,
999
{
1000
int ret = 0;
1001
struct child_process cp_read_tree = CHILD_PROCESS_INIT;
1002
- struct child_process cp_add_i = CHILD_PROCESS_INIT;
1002
struct child_process cp_diff_tree = CHILD_PROCESS_INIT;
1003
struct index_state istate = { NULL };
1004
+ char *old_index_env = NULL, *old_repo_index_file;
1005
1006
remove_path(stash_index_path.buf);
1007
@@ -1015,16 +1015,19 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps,
1015
}
1016
1017
/* Find out what the user wants. */
1018
- cp_add_i.git_cmd = 1;
1019
- argv_array_pushl(&cp_add_i.args, "add--interactive", "--patch=stash",
1020
- "--", NULL);
1021
- add_pathspecs(&cp_add_i.args, ps);
1022
- argv_array_pushf(&cp_add_i.env_array, "GIT_INDEX_FILE=%s",
1023
- stash_index_path.buf);
1024
- if (run_command(&cp_add_i)) {
1025
- ret = -1;
1026
- goto done;
1027
- }
1018
+ old_repo_index_file = the_repository->index_file;
1019
+ the_repository->index_file = stash_index_path.buf;
1020
+ old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT));
1021
+ setenv(INDEX_ENVIRONMENT, the_repository->index_file, 1);
1022
+
1023
+ ret = run_add_interactive(NULL, "--patch=stash", ps);
1024
+
1025
+ the_repository->index_file = old_repo_index_file;
1026
+ if (old_index_env && *old_index_env)
1027
+ setenv(INDEX_ENVIRONMENT, old_index_env, 1);
1028
+ else
1029
+ unsetenv(INDEX_ENVIRONMENT);
1030
+ FREE_AND_NULL(old_index_env);
1031
1032
/* State of the working tree. */
1033
if (write_index_as_tree(&info->w_tree, &istate, stash_index_path.buf, 0,