There are two members of 'struct add_opts', which are only used inside
the 'add()' function, but being part of 'struct add_opts' they are
needlessly also passed to the 'add_worktree' function.

Make them local to the 'add()' function to make it clearer where they
are used.

Signed-off-by: Thomas Gummerer <t.gumme...@gmail.com>
---
 builtin/worktree.c | 32 +++++++++++++++-----------------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/builtin/worktree.c b/builtin/worktree.c
index 7cef5b120b..4d96a21a45 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -27,8 +27,6 @@ struct add_opts {
        int detach;
        int checkout;
        int keep_locked;
-       const char *new_branch;
-       int force_new_branch;
 };
 
 static int show_only;
@@ -363,10 +361,11 @@ static int add(int ac, const char **av, const char 
*prefix)
        const char *new_branch_force = NULL;
        char *path;
        const char *branch;
+       const char *new_branch = NULL;
        const char *opt_track = NULL;
        struct option options[] = {
                OPT__FORCE(&opts.force, N_("checkout <branch> even if already 
checked out in other worktree")),
-               OPT_STRING('b', NULL, &opts.new_branch, N_("branch"),
+               OPT_STRING('b', NULL, &new_branch, N_("branch"),
                           N_("create a new branch")),
                OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
                           N_("create or reset a branch")),
@@ -384,7 +383,7 @@ static int add(int ac, const char **av, const char *prefix)
        memset(&opts, 0, sizeof(opts));
        opts.checkout = 1;
        ac = parse_options(ac, av, prefix, options, worktree_usage, 0);
-       if (!!opts.detach + !!opts.new_branch + !!new_branch_force > 1)
+       if (!!opts.detach + !!new_branch + !!new_branch_force > 1)
                die(_("-b, -B, and --detach are mutually exclusive"));
        if (ac < 1 || ac > 2)
                usage_with_options(worktree_usage, options);
@@ -395,33 +394,32 @@ static int add(int ac, const char **av, const char 
*prefix)
        if (!strcmp(branch, "-"))
                branch = "@{-1}";
 
-       opts.force_new_branch = !!new_branch_force;
-       if (opts.force_new_branch) {
+       if (new_branch_force) {
                struct strbuf symref = STRBUF_INIT;
 
-               opts.new_branch = new_branch_force;
+               new_branch = new_branch_force;
 
                if (!opts.force &&
-                   !strbuf_check_branch_ref(&symref, opts.new_branch) &&
+                   !strbuf_check_branch_ref(&symref, new_branch) &&
                    ref_exists(symref.buf))
                        die_if_checked_out(symref.buf, 0);
                strbuf_release(&symref);
        }
 
-       if (ac < 2 && !opts.new_branch && !opts.detach) {
+       if (ac < 2 && !new_branch && !opts.detach) {
                int n;
                const char *s = worktree_basename(path, &n);
-               opts.new_branch = xstrndup(s, n);
+               new_branch = xstrndup(s, n);
                if (guess_remote) {
                        struct object_id oid;
                        const char *remote =
-                               unique_tracking_name(opts.new_branch, &oid);
+                               unique_tracking_name(new_branch, &oid);
                        if (remote)
                                branch = remote;
                }
        }
 
-       if (ac == 2 && !opts.new_branch && !opts.detach) {
+       if (ac == 2 && !new_branch && !opts.detach) {
                struct object_id oid;
                struct commit *commit;
                const char *remote;
@@ -430,25 +428,25 @@ static int add(int ac, const char **av, const char 
*prefix)
                if (!commit) {
                        remote = unique_tracking_name(branch, &oid);
                        if (remote) {
-                               opts.new_branch = branch;
+                               new_branch = branch;
                                branch = remote;
                        }
                }
        }
 
-       if (opts.new_branch) {
+       if (new_branch) {
                struct child_process cp = CHILD_PROCESS_INIT;
                cp.git_cmd = 1;
                argv_array_push(&cp.args, "branch");
-               if (opts.force_new_branch)
+               if (new_branch_force)
                        argv_array_push(&cp.args, "--force");
-               argv_array_push(&cp.args, opts.new_branch);
+               argv_array_push(&cp.args, new_branch);
                argv_array_push(&cp.args, branch);
                if (opt_track)
                        argv_array_push(&cp.args, opt_track);
                if (run_command(&cp))
                        return -1;
-               branch = opts.new_branch;
+               branch = new_branch;
        } else if (opt_track) {
                die(_("--[no-]track can only be used if a new branch is 
created"));
        }
-- 
2.17.0.252.gfe0a9eaf31

Reply via email to