built-in add -p: prepare for patch modes other than "stage"

The Perl script backing `git add -p` is used not only for that command,
but also for `git stash -p`, `git reset -p` and `git checkout -p`.

In preparation for teaching the C version of `git add -p` to support
also the latter commands, let's abstract away what is "stage" specific
into a dedicated data structure describing the differences between the
patch modes.

Finally, please note that the Perl version tries to make sure that the
diffs are only generated for the modified files. This is not actually
necessary, as the calls to Git's diff machinery already perform that
work, and perform it well. This makes it unnecessary to port the
`FILTER` field of the `%patch_modes` struct, as well as the
`get_diff_reference()` function.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin
2019-12-21 21:57:10 +00:00
committed by Junio C Hamano
parent 2e4083198d
commit d2a233cb8b
4 changed files with 85 additions and 30 deletions

View File

@ -194,12 +194,18 @@ int run_add_interactive(const char *revision, const char *patch_mode,
&use_builtin_add_i);
if (use_builtin_add_i == 1) {
enum add_p_mode mode;
if (!patch_mode)
return !!run_add_i(the_repository, pathspec);
if (strcmp(patch_mode, "--patch"))
if (!strcmp(patch_mode, "--patch"))
mode = ADD_P_ADD;
else
die("'%s' not yet supported in the built-in add -p",
patch_mode);
return !!run_add_p(the_repository, pathspec);
return !!run_add_p(the_repository, mode, revision, pathspec);
}
argv_array_push(&argv, "add--interactive");