Skip to content

Commit d861d34

Browse files
tgummerergitster
authored andcommitted
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 <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5be1f00 commit d861d34

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

builtin/worktree.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ struct add_opts {
2727
int detach;
2828
int checkout;
2929
int keep_locked;
30-
const char *new_branch;
31-
int force_new_branch;
3230
};
3331

3432
static int show_only;
@@ -363,10 +361,11 @@ static int add(int ac, const char **av, const char *prefix)
363361
const char *new_branch_force = NULL;
364362
char *path;
365363
const char *branch;
364+
const char *new_branch = NULL;
366365
const char *opt_track = NULL;
367366
struct option options[] = {
368367
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"),
370369
N_("create a new branch")),
371370
OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
372371
N_("create or reset a branch")),
@@ -384,7 +383,7 @@ static int add(int ac, const char **av, const char *prefix)
384383
memset(&opts, 0, sizeof(opts));
385384
opts.checkout = 1;
386385
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)
388387
die(_("-b, -B, and --detach are mutually exclusive"));
389388
if (ac < 1 || ac > 2)
390389
usage_with_options(worktree_usage, options);
@@ -395,33 +394,33 @@ static int add(int ac, const char **av, const char *prefix)
395394
if (!strcmp(branch, "-"))
396395
branch = "@{-1}";
397396

398-
opts.force_new_branch = !!new_branch_force;
399-
if (opts.force_new_branch) {
397+
if (new_branch_force) {
400398
struct strbuf symref = STRBUF_INIT;
401399

402-
opts.new_branch = new_branch_force;
400+
new_branch = new_branch_force;
403401

404402
if (!opts.force &&
405-
!strbuf_check_branch_ref(&symref, opts.new_branch) &&
403+
!strbuf_check_branch_ref(&symref, new_branch) &&
406404
ref_exists(symref.buf))
407405
die_if_checked_out(symref.buf, 0);
408406
strbuf_release(&symref);
409407
}
410408

411-
if (ac < 2 && !opts.new_branch && !opts.detach) {
409+
if (ac < 2 && !new_branch && !opts.detach) {
412410
int n;
413411
const char *s = worktree_basename(path, &n);
414-
opts.new_branch = xstrndup(s, n);
412+
new_branch = xstrndup(s, n);
413+
UNLEAK(new_branch);
415414
if (guess_remote) {
416415
struct object_id oid;
417416
const char *remote =
418-
unique_tracking_name(opts.new_branch, &oid);
417+
unique_tracking_name(new_branch, &oid);
419418
if (remote)
420419
branch = remote;
421420
}
422421
}
423422

424-
if (ac == 2 && !opts.new_branch && !opts.detach) {
423+
if (ac == 2 && !new_branch && !opts.detach) {
425424
struct object_id oid;
426425
struct commit *commit;
427426
const char *remote;
@@ -430,25 +429,25 @@ static int add(int ac, const char **av, const char *prefix)
430429
if (!commit) {
431430
remote = unique_tracking_name(branch, &oid);
432431
if (remote) {
433-
opts.new_branch = branch;
432+
new_branch = branch;
434433
branch = remote;
435434
}
436435
}
437436
}
438437

439-
if (opts.new_branch) {
438+
if (new_branch) {
440439
struct child_process cp = CHILD_PROCESS_INIT;
441440
cp.git_cmd = 1;
442441
argv_array_push(&cp.args, "branch");
443-
if (opts.force_new_branch)
442+
if (new_branch_force)
444443
argv_array_push(&cp.args, "--force");
445-
argv_array_push(&cp.args, opts.new_branch);
444+
argv_array_push(&cp.args, new_branch);
446445
argv_array_push(&cp.args, branch);
447446
if (opt_track)
448447
argv_array_push(&cp.args, opt_track);
449448
if (run_command(&cp))
450449
return -1;
451-
branch = opts.new_branch;
450+
branch = new_branch;
452451
} else if (opt_track) {
453452
die(_("--[no-]track can only be used if a new branch is created"));
454453
}

0 commit comments

Comments
 (0)