Skip to content

Commit a860476

Browse files
bk2204gitster
authored andcommitted
builtin/checkout: pass branch info down to checkout_worktree
In the future, we're going to want to use the branch info in checkout_worktree, so let's pass the whole struct branch_info down, not just the revision name. We hoist the definition of struct branch_info so it's in scope. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a56d361 commit a860476

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

builtin/checkout.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ struct checkout_opts {
8888
struct tree *source_tree;
8989
};
9090

91+
struct branch_info {
92+
const char *name; /* The short name used */
93+
const char *path; /* The full name of a real branch */
94+
struct commit *commit; /* The named commit */
95+
/*
96+
* if not null the branch is detached because it's already
97+
* checked out in this checkout
98+
*/
99+
char *checkout;
100+
};
101+
91102
static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit,
92103
int changed)
93104
{
@@ -337,7 +348,8 @@ static void mark_ce_for_checkout_no_overlay(struct cache_entry *ce,
337348
}
338349
}
339350

340-
static int checkout_worktree(const struct checkout_opts *opts)
351+
static int checkout_worktree(const struct checkout_opts *opts,
352+
const struct branch_info *info)
341353
{
342354
struct checkout state = CHECKOUT_INIT;
343355
int nr_checkouts = 0, nr_unmerged = 0;
@@ -396,7 +408,7 @@ static int checkout_worktree(const struct checkout_opts *opts)
396408
}
397409

398410
static int checkout_paths(const struct checkout_opts *opts,
399-
const char *revision)
411+
const struct branch_info *new_branch_info)
400412
{
401413
int pos;
402414
static char *ps_matched;
@@ -462,7 +474,7 @@ static int checkout_paths(const struct checkout_opts *opts,
462474
else
463475
BUG("either flag must have been set, worktree=%d, index=%d",
464476
opts->checkout_worktree, opts->checkout_index);
465-
return run_add_interactive(revision, patch_mode, &opts->pathspec);
477+
return run_add_interactive(new_branch_info->name, patch_mode, &opts->pathspec);
466478
}
467479

468480
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
@@ -523,7 +535,7 @@ static int checkout_paths(const struct checkout_opts *opts,
523535

524536
/* Now we are committed to check them out */
525537
if (opts->checkout_worktree)
526-
errs |= checkout_worktree(opts);
538+
errs |= checkout_worktree(opts, new_branch_info);
527539
else
528540
remove_marked_cache_entries(&the_index, 1);
529541

@@ -620,17 +632,6 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
620632
}
621633
}
622634

623-
struct branch_info {
624-
const char *name; /* The short name used */
625-
const char *path; /* The full name of a real branch */
626-
struct commit *commit; /* The named commit */
627-
/*
628-
* if not null the branch is detached because it's already
629-
* checked out in this checkout
630-
*/
631-
char *checkout;
632-
};
633-
634635
static void setup_branch_path(struct branch_info *branch)
635636
{
636637
struct strbuf buf = STRBUF_INIT;
@@ -1710,7 +1711,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
17101711

17111712
UNLEAK(opts);
17121713
if (opts->patch_mode || opts->pathspec.nr)
1713-
return checkout_paths(opts, new_branch_info.name);
1714+
return checkout_paths(opts, &new_branch_info);
17141715
else
17151716
return checkout_branch(opts, &new_branch_info);
17161717
}

0 commit comments

Comments
 (0)