From ba51d2fb24b1a41b8cc15270a06f24c35c0fcf19 Mon Sep 17 00:00:00 2001 From: Rohit Ashiwal Date: Fri, 1 Nov 2019 19:29:58 +0530 Subject: rebase -i: add --ignore-whitespace flag There are two backends available for rebasing, viz, the am and the interactive. Naturally, there shall be some features that are implemented in one but not in the other. One such flag is --ignore-whitespace which indicates merge mechanism to treat lines with only whitespace changes as unchanged. Wire the interactive rebase to also understand the --ignore-whitespace flag by translating it to -Xignore-space-change. Signed-off-by: Rohit Ashiwal Signed-off-by: Junio C Hamano --- builtin/rebase.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'builtin') diff --git a/builtin/rebase.c b/builtin/rebase.c index 2748fa6f2e..fb2500c716 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -79,6 +79,7 @@ struct rebase_options { int allow_rerere_autoupdate; int keep_empty; int autosquash; + int ignore_whitespace; char *gpg_sign_opt; int autostash; char *cmd; @@ -99,6 +100,7 @@ struct rebase_options { static struct replay_opts get_replay_opts(const struct rebase_options *opts) { + struct strbuf strategy_buf = STRBUF_INIT; struct replay_opts replay = REPLAY_OPTS_INIT; replay.action = REPLAY_INTERACTIVE_REBASE; @@ -114,9 +116,15 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt); replay.strategy = opts->strategy; + if (opts->strategy_opts) - parse_strategy_opts(&replay, opts->strategy_opts); + strbuf_addstr(&strategy_buf, opts->strategy_opts); + if (opts->ignore_whitespace) + strbuf_addstr(&strategy_buf, " --ignore-space-change"); + if (strategy_buf.len) + parse_strategy_opts(&replay, strategy_buf.buf); + strbuf_release(&strategy_buf); return replay; } @@ -511,6 +519,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, NULL, options, builtin_rebase_interactive_usage, PARSE_OPT_KEEP_ARGV0); + opts.strategy_opts = xstrdup_or_null(opts.strategy_opts); + if (!is_null_oid(&squash_onto)) opts.squash_onto = &squash_onto; @@ -964,6 +974,8 @@ static int run_am(struct rebase_options *opts) am.git_cmd = 1; argv_array_push(&am.args, "am"); + if (opts->ignore_whitespace) + argv_array_push(&am.args, "--ignore-whitespace"); if (opts->action && !strcmp("continue", opts->action)) { argv_array_push(&am.args, "--resolved"); argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg); @@ -1412,9 +1424,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT }, OPT_BOOL(0, "signoff", &options.signoff, N_("add a Signed-off-by: line to each commit")), - OPT_PASSTHRU_ARGV(0, "ignore-whitespace", &options.git_am_opts, - NULL, N_("passed to 'git am'"), - PARSE_OPT_NOARG), OPT_PASSTHRU_ARGV(0, "committer-date-is-author-date", &options.git_am_opts, NULL, N_("passed to 'git am'"), PARSE_OPT_NOARG), @@ -1422,6 +1431,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) 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_BOOL(0, "ignore-whitespace", &options.ignore_whitespace, + N_("ignore changes in whitespace")), OPT_PASSTHRU_ARGV(0, "whitespace", &options.git_am_opts, N_("action"), N_("passed to 'git apply'"), 0), OPT_BIT('f', "force-rebase", &options.flags, -- cgit v1.2.3 From cbd8db17acb77ea646c739bf96c31fe7484bc491 Mon Sep 17 00:00:00 2001 From: Rohit Ashiwal Date: Fri, 1 Nov 2019 19:30:00 +0530 Subject: rebase -i: support --committer-date-is-author-date rebase am already has this flag to "lie" about the committer date by changing it to the author date. Let's add the same for interactive machinery. Signed-off-by: Rohit Ashiwal Signed-off-by: Junio C Hamano --- builtin/rebase.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'builtin') diff --git a/builtin/rebase.c b/builtin/rebase.c index fb2500c716..e6c6769752 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -82,6 +82,7 @@ struct rebase_options { int ignore_whitespace; char *gpg_sign_opt; int autostash; + int committer_date_is_author_date; char *cmd; int allow_empty_message; int rebase_merges, rebase_cousins; @@ -114,6 +115,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.allow_empty_message = opts->allow_empty_message; replay.verbose = opts->flags & REBASE_VERBOSE; replay.reschedule_failed_exec = opts->reschedule_failed_exec; + replay.committer_date_is_author_date = + opts->committer_date_is_author_date; replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt); replay.strategy = opts->strategy; @@ -976,6 +979,8 @@ static int run_am(struct rebase_options *opts) if (opts->ignore_whitespace) argv_array_push(&am.args, "--ignore-whitespace"); + if (opts->committer_date_is_author_date) + argv_array_push(&opts->git_am_opts, "--committer-date-is-author-date"); if (opts->action && !strcmp("continue", opts->action)) { argv_array_push(&am.args, "--resolved"); argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg); @@ -1424,9 +1429,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT }, OPT_BOOL(0, "signoff", &options.signoff, N_("add a Signed-off-by: line to each commit")), - OPT_PASSTHRU_ARGV(0, "committer-date-is-author-date", - &options.git_am_opts, NULL, - N_("passed to 'git am'"), PARSE_OPT_NOARG), + OPT_BOOL(0, "committer-date-is-author-date", + &options.committer_date_is_author_date, + N_("make committer date match author date")), 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"), @@ -1701,10 +1706,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) state_dir_base, cmd_live_rebase, buf.buf); } + if (options.committer_date_is_author_date) + options.flags |= REBASE_FORCE; + for (i = 0; i < options.git_am_opts.argc; i++) { const char *option = options.git_am_opts.argv[i], *p; - if (!strcmp(option, "--committer-date-is-author-date") || - !strcmp(option, "--ignore-date") || + if (!strcmp(option, "--ignore-date") || !strcmp(option, "--whitespace=fix") || !strcmp(option, "--whitespace=strip")) options.flags |= REBASE_FORCE; -- cgit v1.2.3 From 08187b4cbac2b2f870bb9c786d545b67f0262f74 Mon Sep 17 00:00:00 2001 From: Rohit Ashiwal Date: Fri, 1 Nov 2019 19:30:02 +0530 Subject: rebase -i: support --ignore-date rebase am already has this flag to "lie" about the author date by changing it to the committer (current) date. Let's add the same for interactive machinery. Signed-off-by: Rohit Ashiwal Signed-off-by: Junio C Hamano --- builtin/rebase.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'builtin') diff --git a/builtin/rebase.c b/builtin/rebase.c index e6c6769752..b7d3de1a0f 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -83,6 +83,7 @@ struct rebase_options { char *gpg_sign_opt; int autostash; int committer_date_is_author_date; + int ignore_date; char *cmd; int allow_empty_message; int rebase_merges, rebase_cousins; @@ -117,6 +118,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.reschedule_failed_exec = opts->reschedule_failed_exec; replay.committer_date_is_author_date = opts->committer_date_is_author_date; + replay.ignore_date = opts->ignore_date; replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt); replay.strategy = opts->strategy; @@ -981,6 +983,8 @@ static int run_am(struct rebase_options *opts) argv_array_push(&am.args, "--ignore-whitespace"); if (opts->committer_date_is_author_date) argv_array_push(&opts->git_am_opts, "--committer-date-is-author-date"); + if (opts->ignore_date) + argv_array_push(&opts->git_am_opts, "--ignore-date"); if (opts->action && !strcmp("continue", opts->action)) { argv_array_push(&am.args, "--resolved"); argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg); @@ -1432,8 +1436,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) OPT_BOOL(0, "committer-date-is-author-date", &options.committer_date_is_author_date, N_("make committer date match author date")), - OPT_PASSTHRU_ARGV(0, "ignore-date", &options.git_am_opts, NULL, - N_("passed to 'git am'"), PARSE_OPT_NOARG), + OPT_BOOL(0, "ignore-date", &options.ignore_date, + "ignore author date and use current date"), OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"), N_("passed to 'git apply'"), 0), OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace, @@ -1706,13 +1710,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) state_dir_base, cmd_live_rebase, buf.buf); } - if (options.committer_date_is_author_date) + if (options.committer_date_is_author_date || + options.ignore_date) options.flags |= REBASE_FORCE; for (i = 0; i < options.git_am_opts.argc; i++) { const char *option = options.git_am_opts.argv[i], *p; - if (!strcmp(option, "--ignore-date") || - !strcmp(option, "--whitespace=fix") || + if (!strcmp(option, "--whitespace=fix") || !strcmp(option, "--whitespace=strip")) options.flags |= REBASE_FORCE; else if (skip_prefix(option, "-C", &p)) { -- cgit v1.2.3 From fe28ad8520a0ecac5dfcbfa019727aa6d79c36dc Mon Sep 17 00:00:00 2001 From: Rohit Ashiwal Date: Fri, 1 Nov 2019 19:30:03 +0530 Subject: rebase: add --reset-author-date The previous commit introduced --ignore-date flag to interactive rebase, but the name is actually very vague in context of rebase -i since there are two dates we can work with. Add an alias to convey the precise purpose. Signed-off-by: Rohit Ashiwal Signed-off-by: Junio C Hamano --- builtin/rebase.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'builtin') diff --git a/builtin/rebase.c b/builtin/rebase.c index b7d3de1a0f..44768082b8 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1436,6 +1436,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) OPT_BOOL(0, "committer-date-is-author-date", &options.committer_date_is_author_date, N_("make committer date match author date")), + OPT_BOOL(0, "reset-author-date", &options.ignore_date, + "ignore author date and use current date"), OPT_BOOL(0, "ignore-date", &options.ignore_date, "ignore author date and use current date"), OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"), -- cgit v1.2.3 From d82dfa7f5b88d57cd4ddaf2c27a7218a39b9dd53 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 21 Nov 2019 15:14:28 +0900 Subject: rebase -i: finishing touches to --reset-author-date Clarify the way the `--reset-author-date` option is described, and mark its usage string translatable. Signed-off-by: Junio C Hamano --- builtin/rebase.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/rebase.c b/builtin/rebase.c index 44768082b8..0ddab0bcd2 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1437,9 +1437,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) &options.committer_date_is_author_date, N_("make committer date match author date")), OPT_BOOL(0, "reset-author-date", &options.ignore_date, - "ignore author date and use current date"), - OPT_BOOL(0, "ignore-date", &options.ignore_date, - "ignore author date and use current date"), + N_("ignore author date and use current date")), + OPT_HIDDEN_BOOL(0, "ignore-date", &options.ignore_date, + N_("synonym of --reset-author-date")), OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"), N_("passed to 'git apply'"), 0), OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace, -- cgit v1.2.3