rebase: really just passthru the git am
options
Currently, we parse the options intended for `git am` as if we wanted to handle them in `git rebase`, and then reconstruct them painstakingly to define the `git_am_opt` variable. However, there is a much better way (that I was unaware of, at the time when I mentored Pratik to implement these options): OPT_PASSTHRU_ARGV. It is intended for exactly this use case, where command-line options want to be parsed into a separate `argv_array`. Let's use this feature. Incidentally, this also allows us to address a bug discovered by Phillip Wood, where the built-in rebase failed to understand that the `-C` option takes an optional argument. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
d166e6afe5
commit
f57696802c
100
builtin/rebase.c
100
builtin/rebase.c
@ -87,7 +87,7 @@ struct rebase_options {
|
|||||||
REBASE_FORCE = 1<<3,
|
REBASE_FORCE = 1<<3,
|
||||||
REBASE_INTERACTIVE_EXPLICIT = 1<<4,
|
REBASE_INTERACTIVE_EXPLICIT = 1<<4,
|
||||||
} flags;
|
} flags;
|
||||||
struct strbuf git_am_opt;
|
struct argv_array git_am_opts;
|
||||||
const char *action;
|
const char *action;
|
||||||
int signoff;
|
int signoff;
|
||||||
int allow_rerere_autoupdate;
|
int allow_rerere_autoupdate;
|
||||||
@ -339,7 +339,7 @@ N_("Resolve all conflicts manually, mark them as resolved with\n"
|
|||||||
static int run_specific_rebase(struct rebase_options *opts)
|
static int run_specific_rebase(struct rebase_options *opts)
|
||||||
{
|
{
|
||||||
const char *argv[] = { NULL, NULL };
|
const char *argv[] = { NULL, NULL };
|
||||||
struct strbuf script_snippet = STRBUF_INIT;
|
struct strbuf script_snippet = STRBUF_INIT, buf = STRBUF_INIT;
|
||||||
int status;
|
int status;
|
||||||
const char *backend, *backend_func;
|
const char *backend, *backend_func;
|
||||||
|
|
||||||
@ -433,7 +433,9 @@ static int run_specific_rebase(struct rebase_options *opts)
|
|||||||
oid_to_hex(&opts->restrict_revision->object.oid) : NULL);
|
oid_to_hex(&opts->restrict_revision->object.oid) : NULL);
|
||||||
add_var(&script_snippet, "GIT_QUIET",
|
add_var(&script_snippet, "GIT_QUIET",
|
||||||
opts->flags & REBASE_NO_QUIET ? "" : "t");
|
opts->flags & REBASE_NO_QUIET ? "" : "t");
|
||||||
add_var(&script_snippet, "git_am_opt", opts->git_am_opt.buf);
|
sq_quote_argv_pretty(&buf, opts->git_am_opts.argv);
|
||||||
|
add_var(&script_snippet, "git_am_opt", buf.buf);
|
||||||
|
strbuf_release(&buf);
|
||||||
add_var(&script_snippet, "verbose",
|
add_var(&script_snippet, "verbose",
|
||||||
opts->flags & REBASE_VERBOSE ? "t" : "");
|
opts->flags & REBASE_VERBOSE ? "t" : "");
|
||||||
add_var(&script_snippet, "diffstat",
|
add_var(&script_snippet, "diffstat",
|
||||||
@ -756,7 +758,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
struct rebase_options options = {
|
struct rebase_options options = {
|
||||||
.type = REBASE_UNSPECIFIED,
|
.type = REBASE_UNSPECIFIED,
|
||||||
.flags = REBASE_NO_QUIET,
|
.flags = REBASE_NO_QUIET,
|
||||||
.git_am_opt = STRBUF_INIT,
|
.git_am_opts = ARGV_ARRAY_INIT,
|
||||||
.allow_rerere_autoupdate = -1,
|
.allow_rerere_autoupdate = -1,
|
||||||
.allow_empty_message = 1,
|
.allow_empty_message = 1,
|
||||||
.git_format_patch_opt = STRBUF_INIT,
|
.git_format_patch_opt = STRBUF_INIT,
|
||||||
@ -777,12 +779,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
ACTION_EDIT_TODO,
|
ACTION_EDIT_TODO,
|
||||||
ACTION_SHOW_CURRENT_PATCH,
|
ACTION_SHOW_CURRENT_PATCH,
|
||||||
} action = NO_ACTION;
|
} action = NO_ACTION;
|
||||||
int committer_date_is_author_date = 0;
|
|
||||||
int ignore_date = 0;
|
|
||||||
int ignore_whitespace = 0;
|
|
||||||
const char *gpg_sign = NULL;
|
const char *gpg_sign = NULL;
|
||||||
int opt_c = -1;
|
|
||||||
struct string_list whitespace = STRING_LIST_INIT_NODUP;
|
|
||||||
struct string_list exec = STRING_LIST_INIT_NODUP;
|
struct string_list exec = STRING_LIST_INIT_NODUP;
|
||||||
const char *rebase_merges = NULL;
|
const char *rebase_merges = NULL;
|
||||||
int fork_point = -1;
|
int fork_point = -1;
|
||||||
@ -804,15 +801,20 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
{OPTION_NEGBIT, 'n', "no-stat", &options.flags, NULL,
|
{OPTION_NEGBIT, 'n', "no-stat", &options.flags, NULL,
|
||||||
N_("do not show diffstat of what changed upstream"),
|
N_("do not show diffstat of what changed upstream"),
|
||||||
PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },
|
PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },
|
||||||
OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
|
|
||||||
N_("passed to 'git apply'")),
|
|
||||||
OPT_BOOL(0, "signoff", &options.signoff,
|
OPT_BOOL(0, "signoff", &options.signoff,
|
||||||
N_("add a Signed-off-by: line to each commit")),
|
N_("add a Signed-off-by: line to each commit")),
|
||||||
OPT_BOOL(0, "committer-date-is-author-date",
|
OPT_PASSTHRU_ARGV(0, "ignore-whitespace", &options.git_am_opts,
|
||||||
&committer_date_is_author_date,
|
NULL, N_("passed to 'git am'"),
|
||||||
N_("passed to 'git am'")),
|
PARSE_OPT_NOARG),
|
||||||
OPT_BOOL(0, "ignore-date", &ignore_date,
|
OPT_PASSTHRU_ARGV(0, "committer-date-is-author-date",
|
||||||
N_("passed to 'git am'")),
|
&options.git_am_opts, NULL,
|
||||||
|
N_("passed to 'git am'"), PARSE_OPT_NOARG),
|
||||||
|
OPT_PASSTHRU_ARGV(0, "ignore-date", &options.git_am_opts, NULL,
|
||||||
|
N_("passed to 'git am'"), PARSE_OPT_NOARG),
|
||||||
|
OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
|
||||||
|
N_("passed to 'git apply'"), 0),
|
||||||
|
OPT_PASSTHRU_ARGV(0, "whitespace", &options.git_am_opts,
|
||||||
|
N_("action"), N_("passed to 'git apply'"), 0),
|
||||||
OPT_BIT('f', "force-rebase", &options.flags,
|
OPT_BIT('f', "force-rebase", &options.flags,
|
||||||
N_("cherry-pick all commits, even if unchanged"),
|
N_("cherry-pick all commits, even if unchanged"),
|
||||||
REBASE_FORCE),
|
REBASE_FORCE),
|
||||||
@ -856,10 +858,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
{ OPTION_STRING, 'S', "gpg-sign", &gpg_sign, N_("key-id"),
|
{ OPTION_STRING, 'S', "gpg-sign", &gpg_sign, N_("key-id"),
|
||||||
N_("GPG-sign commits"),
|
N_("GPG-sign commits"),
|
||||||
PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
|
PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
|
||||||
OPT_STRING_LIST(0, "whitespace", &whitespace,
|
|
||||||
N_("whitespace"), N_("passed to 'git apply'")),
|
|
||||||
OPT_SET_INT('C', NULL, &opt_c, N_("passed to 'git apply'"),
|
|
||||||
REBASE_AM),
|
|
||||||
OPT_BOOL(0, "autostash", &options.autostash,
|
OPT_BOOL(0, "autostash", &options.autostash,
|
||||||
N_("automatically stash/stash pop before and after")),
|
N_("automatically stash/stash pop before and after")),
|
||||||
OPT_STRING_LIST('x', "exec", &exec, N_("exec"),
|
OPT_STRING_LIST('x', "exec", &exec, N_("exec"),
|
||||||
@ -884,6 +882,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
N_("rebase all reachable commits up to the root(s)")),
|
N_("rebase all reachable commits up to the root(s)")),
|
||||||
OPT_END(),
|
OPT_END(),
|
||||||
};
|
};
|
||||||
|
int i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NEEDSWORK: Once the builtin rebase has been tested enough
|
* NEEDSWORK: Once the builtin rebase has been tested enough
|
||||||
@ -1064,22 +1063,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
state_dir_base, cmd_live_rebase, buf.buf);
|
state_dir_base, cmd_live_rebase, buf.buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < options.git_am_opts.argc; i++) {
|
||||||
|
const char *option = options.git_am_opts.argv[i];
|
||||||
|
if (!strcmp(option, "--committer-date-is-author-date") ||
|
||||||
|
!strcmp(option, "--ignore-date") ||
|
||||||
|
!strcmp(option, "--whitespace=fix") ||
|
||||||
|
!strcmp(option, "--whitespace=strip"))
|
||||||
|
options.flags |= REBASE_FORCE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(options.flags & REBASE_NO_QUIET))
|
if (!(options.flags & REBASE_NO_QUIET))
|
||||||
strbuf_addstr(&options.git_am_opt, " -q");
|
argv_array_push(&options.git_am_opts, "-q");
|
||||||
|
|
||||||
if (committer_date_is_author_date) {
|
|
||||||
strbuf_addstr(&options.git_am_opt,
|
|
||||||
" --committer-date-is-author-date");
|
|
||||||
options.flags |= REBASE_FORCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ignore_whitespace)
|
|
||||||
strbuf_addstr(&options.git_am_opt, " --ignore-whitespace");
|
|
||||||
|
|
||||||
if (ignore_date) {
|
|
||||||
strbuf_addstr(&options.git_am_opt, " --ignore-date");
|
|
||||||
options.flags |= REBASE_FORCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.keep_empty)
|
if (options.keep_empty)
|
||||||
imply_interactive(&options, "--keep-empty");
|
imply_interactive(&options, "--keep-empty");
|
||||||
@ -1089,23 +1083,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
options.gpg_sign_opt = xstrfmt("-S%s", gpg_sign);
|
options.gpg_sign_opt = xstrfmt("-S%s", gpg_sign);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt_c >= 0)
|
|
||||||
strbuf_addf(&options.git_am_opt, " -C%d", opt_c);
|
|
||||||
|
|
||||||
if (whitespace.nr) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < whitespace.nr; i++) {
|
|
||||||
const char *item = whitespace.items[i].string;
|
|
||||||
|
|
||||||
strbuf_addf(&options.git_am_opt, " --whitespace=%s",
|
|
||||||
item);
|
|
||||||
|
|
||||||
if ((!strcmp(item, "fix")) || (!strcmp(item, "strip")))
|
|
||||||
options.flags |= REBASE_FORCE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exec.nr) {
|
if (exec.nr) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -1181,23 +1158,18 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.git_am_opt.len) {
|
if (options.git_am_opts.argc) {
|
||||||
const char *p;
|
|
||||||
|
|
||||||
/* all am options except -q are compatible only with --am */
|
/* all am options except -q are compatible only with --am */
|
||||||
strbuf_reset(&buf);
|
for (i = options.git_am_opts.argc - 1; i >= 0; i--)
|
||||||
strbuf_addbuf(&buf, &options.git_am_opt);
|
if (strcmp(options.git_am_opts.argv[i], "-q"))
|
||||||
strbuf_addch(&buf, ' ');
|
break;
|
||||||
while ((p = strstr(buf.buf, " -q ")))
|
|
||||||
strbuf_splice(&buf, p - buf.buf, 4, " ", 1);
|
|
||||||
strbuf_trim(&buf);
|
|
||||||
|
|
||||||
if (is_interactive(&options) && buf.len)
|
if (is_interactive(&options) && i >= 0)
|
||||||
die(_("error: cannot combine interactive options "
|
die(_("error: cannot combine interactive options "
|
||||||
"(--interactive, --exec, --rebase-merges, "
|
"(--interactive, --exec, --rebase-merges, "
|
||||||
"--preserve-merges, --keep-empty, --root + "
|
"--preserve-merges, --keep-empty, --root + "
|
||||||
"--onto) with am options (%s)"), buf.buf);
|
"--onto) with am options (%s)"), buf.buf);
|
||||||
if (options.type == REBASE_MERGE && buf.len)
|
if (options.type == REBASE_MERGE && i >= 0)
|
||||||
die(_("error: cannot combine merge options (--merge, "
|
die(_("error: cannot combine merge options (--merge, "
|
||||||
"--strategy, --strategy-option) with am options "
|
"--strategy, --strategy-option) with am options "
|
||||||
"(%s)"), buf.buf);
|
"(%s)"), buf.buf);
|
||||||
@ -1207,7 +1179,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
if (options.type == REBASE_PRESERVE_MERGES)
|
if (options.type == REBASE_PRESERVE_MERGES)
|
||||||
die("cannot combine '--signoff' with "
|
die("cannot combine '--signoff' with "
|
||||||
"'--preserve-merges'");
|
"'--preserve-merges'");
|
||||||
strbuf_addstr(&options.git_am_opt, " --signoff");
|
argv_array_push(&options.git_am_opts, "--signoff");
|
||||||
options.flags |= REBASE_FORCE;
|
options.flags |= REBASE_FORCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user