switch: better names for -b and -B

The shortcut of these options do not make much sense when used with switch. And their descriptions are also tied to checkout. Move -b/-B to cmd_checkout() and new -c/-C with the same functionality in cmd_switch_branch() Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Mar 29, 2019 at 17:39 UTC b7b5fce2701c12895f75f8e716c629b45f105b0c
1 file changed +21 -11
builtin/checkout.c
+21 -11
@@ -1368,14 +1368,10 @@ static struct option *add_common_options(struct checkout_opts *opts,
1368 return newopts;
1369 }
1370
1371 -static struct option *add_switch_branch_options(struct checkout_opts *opts,
1372 - struct option *prevopts)
1371 +static struct option *add_common_switch_branch_options(
1372 + struct checkout_opts *opts, struct option *prevopts)
1373 {
1374 struct option options[] = {
1375 - OPT_STRING('b', NULL, &opts->new_branch, N_("branch"),
1376 - N_("create and checkout a new branch")),
1377 - OPT_STRING('B', NULL, &opts->new_branch_force, N_("branch"),
1378 - N_("create/reset and checkout a branch")),
1375 OPT_BOOL('l', NULL, &opts->new_branch_log, N_("create reflog for new branch")),
1376 OPT_BOOL(0, "detach", &opts->force_detach, N_("detach HEAD at named commit")),
1377 OPT_SET_INT('t', "track", &opts->track, N_("set upstream info for new branch"),
@@ -1571,15 +1567,22 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1567 int cmd_checkout(int argc, const char **argv, const char *prefix)
1568 {
1569 struct checkout_opts opts;
1574 - struct option *options = NULL;
1570 + struct option *options;
1571 + struct option checkout_options[] = {
1572 + OPT_STRING('b', NULL, &opts.new_branch, N_("branch"),
1573 + N_("create and checkout a new branch")),
1574 + OPT_STRING('B', NULL, &opts.new_branch_force, N_("branch"),
1575 + N_("create/reset and checkout a branch")),
1576 + OPT_END()
1577 + };
1578 int ret;
1579
1580 memset(&opts, 0, sizeof(opts));
1581 opts.no_dwim_new_local_branch = 0;
1582
1580 - options = parse_options_dup(options);
1583 + options = parse_options_dup(checkout_options);
1584 options = add_common_options(&opts, options);
1582 - options = add_switch_branch_options(&opts, options);
1585 + options = add_common_switch_branch_options(&opts, options);
1586 options = add_checkout_path_options(&opts, options);
1587
1588 ret = checkout_main(argc, argv, prefix, &opts,
@@ -1592,14 +1595,21 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
1595 {
1596 struct checkout_opts opts;
1597 struct option *options = NULL;
1598 + struct option switch_options[] = {
1599 + OPT_STRING('c', "create", &opts.new_branch, N_("branch"),
1600 + N_("create and switch to a new branch")),
1601 + OPT_STRING('C', "force-create", &opts.new_branch_force, N_("branch"),
1602 + N_("create/reset and switch to a branch")),
1603 + OPT_END()
1604 + };
1605 int ret;
1606
1607 memset(&opts, 0, sizeof(opts));
1608 opts.no_dwim_new_local_branch = 0;
1609
1600 - options = parse_options_dup(options);
1610 + options = parse_options_dup(switch_options);
1611 options = add_common_options(&opts, options);
1602 - options = add_switch_branch_options(&opts, options);
1612 + options = add_common_switch_branch_options(&opts, options);
1613
1614 ret = checkout_main(argc, argv, prefix, &opts,
1615 options, switch_branch_usage);