add API: remove run_add_interactive() wrapper function
Now that the Perl "git-add--interactive" has gone away in the preceding commit we don't need to pass along our desire for a mode as a string, and can instead directly use the "enum add_p_mode", see d2a233cb8b9 (built-in add -p: prepare for patch modes other than "stage", 2019-12-21) for its introduction. As a result of that the run_add_interactive() function would become a trivial wrapper which would only run run_add_i() if a 0 (or now, "NULL") "patch_mode" was provided. Let's instead remove it, and have the one callsite that wanted the "NULL" case (interactive_add()) handle it. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Feb 6, 2023 at 23:58 UTC
d21878f073043b9205f5049f1cd53560d67b9f3f
5 files changed
+16
-36
builtin/add.c
+4
-27
@@ -238,30 +238,6 @@ static int refresh(int verbose, const struct pathspec *pathspec)
238
return ret;
239
}
240
241
-int run_add_interactive(const char *revision, const char *patch_mode,
242
- const struct pathspec *pathspec)
243
-{
244
- enum add_p_mode mode;
245
-
246
- if (!patch_mode)
247
- return !!run_add_i(the_repository, pathspec);
248
-
249
- if (!strcmp(patch_mode, "--patch"))
250
- mode = ADD_P_ADD;
251
- else if (!strcmp(patch_mode, "--patch=stash"))
252
- mode = ADD_P_STASH;
253
- else if (!strcmp(patch_mode, "--patch=reset"))
254
- mode = ADD_P_RESET;
255
- else if (!strcmp(patch_mode, "--patch=checkout"))
256
- mode = ADD_P_CHECKOUT;
257
- else if (!strcmp(patch_mode, "--patch=worktree"))
258
- mode = ADD_P_WORKTREE;
259
- else
260
- die("'%s' not supported", patch_mode);
261
-
262
- return !!run_add_p(the_repository, mode, revision, pathspec);
263
-}
264
-
241
int interactive_add(const char **argv, const char *prefix, int patch)
242
{
243
struct pathspec pathspec;
@@ -277,9 +253,10 @@ int interactive_add(const char **argv, const char *prefix, int patch)
253
PATHSPEC_PREFIX_ORIGIN,
254
prefix, argv);
255
280
- return run_add_interactive(NULL,
281
- patch ? "--patch" : NULL,
282
- &pathspec);
256
+ if (patch)
257
+ return !!run_add_p(the_repository, ADD_P_ADD, NULL, &pathspec);
258
+ else
259
+ return !!run_add_i(the_repository, &pathspec);
260
}
261
262
static int edit_patch(int argc, const char **argv, const char *prefix)
builtin/checkout.c
+7
-5
@@ -29,6 +29,7 @@
29
#include "xdiff-interface.h"
30
#include "entry.h"
31
#include "parallel-checkout.h"
32
+#include "add-interactive.h"
33
34
static const char * const checkout_usage[] = {
35
N_("git checkout [<options>] <branch>"),
@@ -499,7 +500,7 @@ static int checkout_paths(const struct checkout_opts *opts,
500
"--merge", "--conflict", "--staged");
501
502
if (opts->patch_mode) {
502
- const char *patch_mode;
503
+ enum add_p_mode patch_mode;
504
const char *rev = new_branch_info->name;
505
char rev_oid[GIT_MAX_HEXSZ + 1];
506
@@ -517,15 +518,16 @@ static int checkout_paths(const struct checkout_opts *opts,
518
rev = oid_to_hex_r(rev_oid, &new_branch_info->commit->object.oid);
519
520
if (opts->checkout_index && opts->checkout_worktree)
520
- patch_mode = "--patch=checkout";
521
+ patch_mode = ADD_P_CHECKOUT;
522
else if (opts->checkout_index && !opts->checkout_worktree)
522
- patch_mode = "--patch=reset";
523
+ patch_mode = ADD_P_RESET;
524
else if (!opts->checkout_index && opts->checkout_worktree)
524
- patch_mode = "--patch=worktree";
525
+ patch_mode = ADD_P_WORKTREE;
526
else
527
BUG("either flag must have been set, worktree=%d, index=%d",
528
opts->checkout_worktree, opts->checkout_index);
528
- return run_add_interactive(rev, patch_mode, &opts->pathspec);
529
+ return !!run_add_p(the_repository, patch_mode, rev,
530
+ &opts->pathspec);
531
}
532
533
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
builtin/reset.c
+3
-1
@@ -26,6 +26,7 @@
26
#include "submodule.h"
27
#include "submodule-config.h"
28
#include "dir.h"
29
+#include "add-interactive.h"
30
31
#define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)
32
@@ -390,7 +391,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
391
if (reset_type != NONE)
392
die(_("options '%s' and '%s' cannot be used together"), "--patch", "--{hard,mixed,soft}");
393
trace2_cmd_mode("patch-interactive");
393
- return run_add_interactive(rev, "--patch=reset", &pathspec);
394
+ return !!run_add_p(the_repository, ADD_P_RESET, rev,
395
+ &pathspec);
396
}
397
398
/* git reset tree [--] paths... can be used to
builtin/stash.c
+2
-1
@@ -18,6 +18,7 @@
18
#include "diffcore.h"
19
#include "exec-cmd.h"
20
#include "reflog.h"
21
+#include "add-interactive.h"
22
23
#define INCLUDE_ALL_FILES 2
24
@@ -1229,7 +1230,7 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps,
1230
old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT));
1231
setenv(INDEX_ENVIRONMENT, the_repository->index_file, 1);
1232
1232
- ret = run_add_interactive(NULL, "--patch=stash", ps);
1233
+ ret = !!run_add_p(the_repository, ADD_P_STASH, NULL, ps);
1234
1235
the_repository->index_file = old_repo_index_file;
1236
if (old_index_env && *old_index_env)
commit.h
-2
@@ -274,8 +274,6 @@ struct ref;
274
int for_each_commit_graft(each_commit_graft_fn, void *);
275
276
int interactive_add(const char **argv, const char *prefix, int patch);
277
-int run_add_interactive(const char *revision, const char *patch_mode,
278
- const struct pathspec *pathspec);
277
278
struct commit_extra_header {
279
struct commit_extra_header *next;