Skip to content

Commit d21878f

Browse files
avargitster
authored andcommitted
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 d2a233c (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 20b813d commit d21878f

File tree

5 files changed

+16
-36
lines changed

5 files changed

+16
-36
lines changed

builtin/add.c

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -238,30 +238,6 @@ static int refresh(int verbose, const struct pathspec *pathspec)
238238
return ret;
239239
}
240240

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-
265241
int interactive_add(const char **argv, const char *prefix, int patch)
266242
{
267243
struct pathspec pathspec;
@@ -277,9 +253,10 @@ int interactive_add(const char **argv, const char *prefix, int patch)
277253
PATHSPEC_PREFIX_ORIGIN,
278254
prefix, argv);
279255

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);
283260
}
284261

285262
static int edit_patch(int argc, const char **argv, const char *prefix)

builtin/checkout.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "xdiff-interface.h"
3030
#include "entry.h"
3131
#include "parallel-checkout.h"
32+
#include "add-interactive.h"
3233

3334
static const char * const checkout_usage[] = {
3435
N_("git checkout [<options>] <branch>"),
@@ -499,7 +500,7 @@ static int checkout_paths(const struct checkout_opts *opts,
499500
"--merge", "--conflict", "--staged");
500501

501502
if (opts->patch_mode) {
502-
const char *patch_mode;
503+
enum add_p_mode patch_mode;
503504
const char *rev = new_branch_info->name;
504505
char rev_oid[GIT_MAX_HEXSZ + 1];
505506

@@ -517,15 +518,16 @@ static int checkout_paths(const struct checkout_opts *opts,
517518
rev = oid_to_hex_r(rev_oid, &new_branch_info->commit->object.oid);
518519

519520
if (opts->checkout_index && opts->checkout_worktree)
520-
patch_mode = "--patch=checkout";
521+
patch_mode = ADD_P_CHECKOUT;
521522
else if (opts->checkout_index && !opts->checkout_worktree)
522-
patch_mode = "--patch=reset";
523+
patch_mode = ADD_P_RESET;
523524
else if (!opts->checkout_index && opts->checkout_worktree)
524-
patch_mode = "--patch=worktree";
525+
patch_mode = ADD_P_WORKTREE;
525526
else
526527
BUG("either flag must have been set, worktree=%d, index=%d",
527528
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);
529531
}
530532

531533
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);

builtin/reset.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "submodule.h"
2727
#include "submodule-config.h"
2828
#include "dir.h"
29+
#include "add-interactive.h"
2930

3031
#define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)
3132

@@ -390,7 +391,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
390391
if (reset_type != NONE)
391392
die(_("options '%s' and '%s' cannot be used together"), "--patch", "--{hard,mixed,soft}");
392393
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);
394396
}
395397

396398
/* git reset tree [--] paths... can be used to

builtin/stash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "diffcore.h"
1919
#include "exec-cmd.h"
2020
#include "reflog.h"
21+
#include "add-interactive.h"
2122

2223
#define INCLUDE_ALL_FILES 2
2324

@@ -1229,7 +1230,7 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps,
12291230
old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT));
12301231
setenv(INDEX_ENVIRONMENT, the_repository->index_file, 1);
12311232

1232-
ret = run_add_interactive(NULL, "--patch=stash", ps);
1233+
ret = !!run_add_p(the_repository, ADD_P_STASH, NULL, ps);
12331234

12341235
the_repository->index_file = old_repo_index_file;
12351236
if (old_index_env && *old_index_env)

commit.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ struct ref;
274274
int for_each_commit_graft(each_commit_graft_fn, void *);
275275

276276
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);
279277

280278
struct commit_extra_header {
281279
struct commit_extra_header *next;

0 commit comments

Comments
 (0)