]> git.ipfire.org Git - thirdparty/git.git/commitdiff
add API: remove run_add_interactive() wrapper function
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 6 Feb 2023 22:58:57 +0000 (23:58 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 Feb 2023 23:03:34 +0000 (15:03 -0800)
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>
builtin/add.c
builtin/checkout.c
builtin/reset.c
builtin/stash.c
commit.h

index 9f5b6e26a02757a61e75af1b08099b672131e8fb..61dd386d109b3756e90756b91d9405c71d1b4145 100644 (file)
@@ -238,30 +238,6 @@ static int refresh(int verbose, const struct pathspec *pathspec)
        return ret;
 }
 
-int run_add_interactive(const char *revision, const char *patch_mode,
-                       const struct pathspec *pathspec)
-{
-       enum add_p_mode mode;
-
-       if (!patch_mode)
-               return !!run_add_i(the_repository, pathspec);
-
-       if (!strcmp(patch_mode, "--patch"))
-               mode = ADD_P_ADD;
-       else if (!strcmp(patch_mode, "--patch=stash"))
-               mode = ADD_P_STASH;
-       else if (!strcmp(patch_mode, "--patch=reset"))
-               mode = ADD_P_RESET;
-       else if (!strcmp(patch_mode, "--patch=checkout"))
-               mode = ADD_P_CHECKOUT;
-       else if (!strcmp(patch_mode, "--patch=worktree"))
-               mode = ADD_P_WORKTREE;
-       else
-               die("'%s' not supported", patch_mode);
-
-       return !!run_add_p(the_repository, mode, revision, pathspec);
-}
-
 int interactive_add(const char **argv, const char *prefix, int patch)
 {
        struct pathspec pathspec;
@@ -277,9 +253,10 @@ int interactive_add(const char **argv, const char *prefix, int patch)
                       PATHSPEC_PREFIX_ORIGIN,
                       prefix, argv);
 
-       return run_add_interactive(NULL,
-                                  patch ? "--patch" : NULL,
-                                  &pathspec);
+       if (patch)
+               return !!run_add_p(the_repository, ADD_P_ADD, NULL, &pathspec);
+       else
+               return !!run_add_i(the_repository, &pathspec);
 }
 
 static int edit_patch(int argc, const char **argv, const char *prefix)
index 5963e1b74b82f5bd1d572325aed01ff66c587d52..a5155cf55c1e5150fd954a5b59363ee899974361 100644 (file)
@@ -29,6 +29,7 @@
 #include "xdiff-interface.h"
 #include "entry.h"
 #include "parallel-checkout.h"
+#include "add-interactive.h"
 
 static const char * const checkout_usage[] = {
        N_("git checkout [<options>] <branch>"),
@@ -499,7 +500,7 @@ static int checkout_paths(const struct checkout_opts *opts,
                    "--merge", "--conflict", "--staged");
 
        if (opts->patch_mode) {
-               const char *patch_mode;
+               enum add_p_mode patch_mode;
                const char *rev = new_branch_info->name;
                char rev_oid[GIT_MAX_HEXSZ + 1];
 
@@ -517,15 +518,16 @@ static int checkout_paths(const struct checkout_opts *opts,
                        rev = oid_to_hex_r(rev_oid, &new_branch_info->commit->object.oid);
 
                if (opts->checkout_index && opts->checkout_worktree)
-                       patch_mode = "--patch=checkout";
+                       patch_mode = ADD_P_CHECKOUT;
                else if (opts->checkout_index && !opts->checkout_worktree)
-                       patch_mode = "--patch=reset";
+                       patch_mode = ADD_P_RESET;
                else if (!opts->checkout_index && opts->checkout_worktree)
-                       patch_mode = "--patch=worktree";
+                       patch_mode = ADD_P_WORKTREE;
                else
                        BUG("either flag must have been set, worktree=%d, index=%d",
                            opts->checkout_worktree, opts->checkout_index);
-               return run_add_interactive(rev, patch_mode, &opts->pathspec);
+               return !!run_add_p(the_repository, patch_mode, rev,
+                                  &opts->pathspec);
        }
 
        repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
index fea20a9ba0b99bc730f7c7fc7c1000fa57febf3e..4b59aa9aeae13dc13384635003d276e237668c0e 100644 (file)
@@ -26,6 +26,7 @@
 #include "submodule.h"
 #include "submodule-config.h"
 #include "dir.h"
+#include "add-interactive.h"
 
 #define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)
 
@@ -390,7 +391,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
                if (reset_type != NONE)
                        die(_("options '%s' and '%s' cannot be used together"), "--patch", "--{hard,mixed,soft}");
                trace2_cmd_mode("patch-interactive");
-               return run_add_interactive(rev, "--patch=reset", &pathspec);
+               return !!run_add_p(the_repository, ADD_P_RESET, rev,
+                                  &pathspec);
        }
 
        /* git reset tree [--] paths... can be used to
index 839569a98033f1cf2e8eb74b2eb6fc1770eba8fc..9fcd2e5d993425347935abe598e99ed8d90eead0 100644 (file)
@@ -18,6 +18,7 @@
 #include "diffcore.h"
 #include "exec-cmd.h"
 #include "reflog.h"
+#include "add-interactive.h"
 
 #define INCLUDE_ALL_FILES 2
 
@@ -1229,7 +1230,7 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps,
        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);
+       ret = !!run_add_p(the_repository, ADD_P_STASH, NULL, ps);
 
        the_repository->index_file = old_repo_index_file;
        if (old_index_env && *old_index_env)
index fa39202fa6b09837f2a08202bc1f758fa0eac4de..cc2c5da7bdb8344e9dbe69ae16092fcbf004d544 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -274,8 +274,6 @@ struct ref;
 int for_each_commit_graft(each_commit_graft_fn, void *);
 
 int interactive_add(const char **argv, const char *prefix, int patch);
-int run_add_interactive(const char *revision, const char *patch_mode,
-                       const struct pathspec *pathspec);
 
 struct commit_extra_header {
        struct commit_extra_header *next;