worktree: remove extra members from struct add_opts

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.gummerer@gmail.com> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Gummerer committed Apr 24, 2018 at 22:56 UTC d861d34a6ed0d04cef99ad2bdf3fdd3b23cee63a
1 file changed +16 -17
builtin/worktree.c
+16 -17
@@ -27,8 +27,6 @@ struct add_opts {
27 int detach;
28 int checkout;
29 int keep_locked;
30 - const char *new_branch;
31 - int force_new_branch;
30 };
31
32 static int show_only;
@@ -363,10 +361,11 @@ static int add(int ac, const char **av, const char *prefix)
361 const char *new_branch_force = NULL;
362 char *path;
363 const char *branch;
364 + const char *new_branch = NULL;
365 const char *opt_track = NULL;
366 struct option options[] = {
367 OPT__FORCE(&opts.force, N_("checkout <branch> even if already checked out in other worktree")),
369 - OPT_STRING('b', NULL, &opts.new_branch, N_("branch"),
368 + OPT_STRING('b', NULL, &new_branch, N_("branch"),
369 N_("create a new branch")),
370 OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
371 N_("create or reset a branch")),
@@ -384,7 +383,7 @@ static int add(int ac, const char **av, const char *prefix)
383 memset(&opts, 0, sizeof(opts));
384 opts.checkout = 1;
385 ac = parse_options(ac, av, prefix, options, worktree_usage, 0);
387 - if (!!opts.detach + !!opts.new_branch + !!new_branch_force > 1)
386 + if (!!opts.detach + !!new_branch + !!new_branch_force > 1)
387 die(_("-b, -B, and --detach are mutually exclusive"));
388 if (ac < 1 || ac > 2)
389 usage_with_options(worktree_usage, options);
@@ -395,33 +394,33 @@ static int add(int ac, const char **av, const char *prefix)
394 if (!strcmp(branch, "-"))
395 branch = "@{-1}";
396
398 - opts.force_new_branch = !!new_branch_force;
399 - if (opts.force_new_branch) {
397 + if (new_branch_force) {
398 struct strbuf symref = STRBUF_INIT;
399
402 - opts.new_branch = new_branch_force;
400 + new_branch = new_branch_force;
401
402 if (!opts.force &&
405 - !strbuf_check_branch_ref(&symref, opts.new_branch) &&
403 + !strbuf_check_branch_ref(&symref, new_branch) &&
404 ref_exists(symref.buf))
405 die_if_checked_out(symref.buf, 0);
406 strbuf_release(&symref);
407 }
408
411 - if (ac < 2 && !opts.new_branch && !opts.detach) {
409 + if (ac < 2 && !new_branch && !opts.detach) {
410 int n;
411 const char *s = worktree_basename(path, &n);
414 - opts.new_branch = xstrndup(s, n);
412 + new_branch = xstrndup(s, n);
413 + UNLEAK(new_branch);
414 if (guess_remote) {
415 struct object_id oid;
416 const char *remote =
418 - unique_tracking_name(opts.new_branch, &oid);
417 + unique_tracking_name(new_branch, &oid);
418 if (remote)
419 branch = remote;
420 }
421 }
422
424 - if (ac == 2 && !opts.new_branch && !opts.detach) {
423 + if (ac == 2 && !new_branch && !opts.detach) {
424 struct object_id oid;
425 struct commit *commit;
426 const char *remote;
@@ -430,25 +429,25 @@ static int add(int ac, const char **av, const char *prefix)
429 if (!commit) {
430 remote = unique_tracking_name(branch, &oid);
431 if (remote) {
433 - opts.new_branch = branch;
432 + new_branch = branch;
433 branch = remote;
434 }
435 }
436 }
437
439 - if (opts.new_branch) {
438 + if (new_branch) {
439 struct child_process cp = CHILD_PROCESS_INIT;
440 cp.git_cmd = 1;
441 argv_array_push(&cp.args, "branch");
443 - if (opts.force_new_branch)
442 + if (new_branch_force)
443 argv_array_push(&cp.args, "--force");
445 - argv_array_push(&cp.args, opts.new_branch);
444 + argv_array_push(&cp.args, new_branch);
445 argv_array_push(&cp.args, branch);
446 if (opt_track)
447 argv_array_push(&cp.args, opt_track);
448 if (run_command(&cp))
449 return -1;
451 - branch = opts.new_branch;
450 + branch = new_branch;
451 } else if (opt_track) {
452 die(_("--[no-]track can only be used if a new branch is created"));
453 }