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 <bk2204@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Mar 10, 2020 at 18:20 UTC
a8604766de8136d78944053aadd74a8c1c87aea9
1 file changed
+17
-16
builtin/checkout.c
+17
-16
@@ -88,6 +88,17 @@ struct checkout_opts {
88
struct tree *source_tree;
89
};
90
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
+
102
static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit,
103
int changed)
104
{
@@ -337,7 +348,8 @@ static void mark_ce_for_checkout_no_overlay(struct cache_entry *ce,
348
}
349
}
350
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)
353
{
354
struct checkout state = CHECKOUT_INIT;
355
int nr_checkouts = 0, nr_unmerged = 0;
@@ -396,7 +408,7 @@ static int checkout_worktree(const struct checkout_opts *opts)
408
}
409
410
static int checkout_paths(const struct checkout_opts *opts,
399
- const char *revision)
411
+ const struct branch_info *new_branch_info)
412
{
413
int pos;
414
static char *ps_matched;
@@ -462,7 +474,7 @@ static int checkout_paths(const struct checkout_opts *opts,
474
else
475
BUG("either flag must have been set, worktree=%d, index=%d",
476
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);
478
}
479
480
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,
535
536
/* Now we are committed to check them out */
537
if (opts->checkout_worktree)
526
- errs |= checkout_worktree(opts);
538
+ errs |= checkout_worktree(opts, new_branch_info);
539
else
540
remove_marked_cache_entries(&the_index, 1);
541
@@ -620,17 +632,6 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
632
}
633
}
634
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
-
635
static void setup_branch_path(struct branch_info *branch)
636
{
637
struct strbuf buf = STRBUF_INIT;
@@ -1710,7 +1711,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1711
1712
UNLEAK(opts);
1713
if (opts->patch_mode || opts->pathspec.nr)
1713
- return checkout_paths(opts, new_branch_info.name);
1714
+ return checkout_paths(opts, &new_branch_info);
1715
else
1716
return checkout_branch(opts, &new_branch_info);
1717
}