Skip to content

Commit

Permalink
Merge branch 'ob/rebase-cleanup' into next
Browse files Browse the repository at this point in the history
Code clean-up.

* ob/rebase-cleanup:
  rebase: move parse_opt_keep_empty() down
  rebase: handle --strategy via imply_merge() as well
  rebase: simplify code related to imply_merge()
  • Loading branch information
gitster committed Oct 22, 2023
2 parents 0e47873 + 96db173 commit 05e14ca
Showing 1 changed file with 14 additions and 30 deletions.
44 changes: 14 additions & 30 deletions builtin/rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,20 +376,6 @@ static int run_sequencer_rebase(struct rebase_options *opts)
return ret;
}

static void imply_merge(struct rebase_options *opts, const char *option);
static int parse_opt_keep_empty(const struct option *opt, const char *arg,
int unset)
{
struct rebase_options *opts = opt->value;

BUG_ON_OPT_ARG(arg);

imply_merge(opts, unset ? "--no-keep-empty" : "--keep-empty");
opts->keep_empty = !unset;
opts->type = REBASE_MERGE;
return 0;
}

static int is_merge(struct rebase_options *opts)
{
return opts->type == REBASE_MERGE;
Expand Down Expand Up @@ -983,6 +969,18 @@ static enum empty_type parse_empty_value(const char *value)
die(_("unrecognized empty type '%s'; valid values are \"drop\", \"keep\", and \"ask\"."), value);
}

static int parse_opt_keep_empty(const struct option *opt, const char *arg,
int unset)
{
struct rebase_options *opts = opt->value;

BUG_ON_OPT_ARG(arg);

imply_merge(opts, unset ? "--no-keep-empty" : "--keep-empty");
opts->keep_empty = !unset;
return 0;
}

static int parse_opt_empty(const struct option *opt, const char *arg, int unset)
{
struct rebase_options *options = opt->value;
Expand Down Expand Up @@ -1491,23 +1489,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)

if (options.strategy) {
options.strategy = xstrdup(options.strategy);
switch (options.type) {
case REBASE_APPLY:
die(_("--strategy requires --merge or --interactive"));
case REBASE_MERGE:
/* compatible */
break;
case REBASE_UNSPECIFIED:
options.type = REBASE_MERGE;
break;
default:
BUG("unhandled rebase type (%d)", options.type);
}
imply_merge(&options, "--strategy");
}

if (options.type == REBASE_MERGE)
imply_merge(&options, "--merge");

if (options.root && !options.onto_name)
imply_merge(&options, "--root without --onto");

Expand Down Expand Up @@ -1552,7 +1536,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)

if (options.type == REBASE_UNSPECIFIED) {
if (!strcmp(options.default_backend, "merge"))
imply_merge(&options, "--merge");
options.type = REBASE_MERGE;
else if (!strcmp(options.default_backend, "apply"))
options.type = REBASE_APPLY;
else
Expand Down

0 comments on commit 05e14ca

Please sign in to comment.