summaryrefslogtreecommitdiff
path: root/builtin/add.c
diff options
context:
space:
mode:
authorLibravatar Johannes Schindelin <johannes.schindelin@gmx.de>2019-12-13 08:07:48 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2019-12-13 12:37:13 -0800
commitf6aa7ecc34373f32621b05659d5d2447d690be18 (patch)
treebb0a8d0fda00d7f5f5433ff7a9257dd12afb848e /builtin/add.c
parentapply --allow-overlap: fix a corner case (diff)
downloadtgif-f6aa7ecc34373f32621b05659d5d2447d690be18.tar.xz
built-in add -i: start implementing the `patch` functionality in C
In the previous steps, we re-implemented the main loop of `git add -i` in C, and most of the commands. Notably, we left out the actual functionality of `patch`, as the relevant code makes up more than half of `git-add--interactive.perl`, and is actually pretty independent of the rest of the commands. With this commit, we start to tackle that `patch` part. For better separation of concerns, we keep the code in a separate file, `add-patch.c`. The new code is still guarded behind the `add.interactive.useBuiltin` config setting, and for the moment, it can only be called via `git add -p`. The actual functionality follows the original implementation of 5cde71d64aff (git-add --interactive, 2006-12-10), but not too closely (for example, we use string offsets rather than copying strings around, and after seeing whether the `k` and `j` commands are applicable, in the C version we remember which previous/next hunk was undecided, and use it rather than looking again when the user asked to jump). As a further deviation from that commit, We also use a comma instead of a slash to separate the available commands in the prompt, as the current version of the Perl script does this, and we also add a line about the question mark ("print help") to the help text. While it is tempting to use this conversion of `git add -p` as an excuse to work on `apply_all_patches()` so that it does _not_ want to read a file from `stdin` or from a file, but accepts, say, an `strbuf` instead, we will refrain from this particular rabbit hole at this stage. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/add.c')
-rw-r--r--builtin/add.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/builtin/add.c b/builtin/add.c
index d4686d5218..1deb59a642 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -189,12 +189,17 @@ int run_add_interactive(const char *revision, const char *patch_mode,
int use_builtin_add_i =
git_env_bool("GIT_TEST_ADD_I_USE_BUILTIN", -1);
- if (!patch_mode) {
- if (use_builtin_add_i < 0)
- git_config_get_bool("add.interactive.usebuiltin",
- &use_builtin_add_i);
- if (use_builtin_add_i == 1)
+ if (use_builtin_add_i < 0)
+ git_config_get_bool("add.interactive.usebuiltin",
+ &use_builtin_add_i);
+
+ if (use_builtin_add_i == 1) {
+ if (!patch_mode)
return !!run_add_i(the_repository, pathspec);
+ if (strcmp(patch_mode, "--patch"))
+ die("'%s' not yet supported in the built-in add -p",
+ patch_mode);
+ return !!run_add_p(the_repository, pathspec);
}
argv_array_push(&argv, "add--interactive");