diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2019-12-21 21:57:13 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-12-21 16:06:21 -0800 |
commit | 6610e4628ac12396efc20201fe85d67591bed247 (patch) | |
tree | 7a583cc35cf15dac16f1294ec0f21916549d1baf /builtin/stash.c | |
parent | legacy stash -p: respect the add.interactive.usebuiltin setting (diff) | |
download | tgif-6610e4628ac12396efc20201fe85d67591bed247.tar.xz |
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>
Diffstat (limited to 'builtin/stash.c')
-rw-r--r-- | builtin/stash.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/builtin/stash.c b/builtin/stash.c index 4e806176b0..2dafd97766 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -999,9 +999,9 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps, { int ret = 0; struct child_process cp_read_tree = CHILD_PROCESS_INIT; - struct child_process cp_add_i = CHILD_PROCESS_INIT; struct child_process cp_diff_tree = CHILD_PROCESS_INIT; struct index_state istate = { NULL }; + char *old_index_env = NULL, *old_repo_index_file; remove_path(stash_index_path.buf); @@ -1015,16 +1015,19 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps, } /* Find out what the user wants. */ - cp_add_i.git_cmd = 1; - argv_array_pushl(&cp_add_i.args, "add--interactive", "--patch=stash", - "--", NULL); - add_pathspecs(&cp_add_i.args, ps); - argv_array_pushf(&cp_add_i.env_array, "GIT_INDEX_FILE=%s", - stash_index_path.buf); - if (run_command(&cp_add_i)) { - ret = -1; - goto done; - } + old_repo_index_file = the_repository->index_file; + the_repository->index_file = stash_index_path.buf; + old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT)); + setenv(INDEX_ENVIRONMENT, the_repository->index_file, 1); + + ret = run_add_interactive(NULL, "--patch=stash", ps); + + the_repository->index_file = old_repo_index_file; + if (old_index_env && *old_index_env) + setenv(INDEX_ENVIRONMENT, old_index_env, 1); + else + unsetenv(INDEX_ENVIRONMENT); + FREE_AND_NULL(old_index_env); /* State of the working tree. */ if (write_index_as_tree(&info->w_tree, &istate, stash_index_path.buf, 0, |