Skip to content
Permalink
Browse files

Merge branch 'ra/rebase-i-more-options' into pu

"git rebase -i" learned a few options that are known by "git
rebase" proper.

Looking good.

* ra/rebase-i-more-options:
  rebase: add --reset-author-date
  rebase -i: support --ignore-date
  sequencer: rename amend_author to author_to_rename
  rebase -i: support --committer-date-is-author-date
  sequencer: add NULL checks under read_author_script
  rebase -i: add --ignore-whitespace flag
  • Loading branch information...
gitster committed Aug 26, 2019
2 parents f0f5b74 + a46eec5 commit 966fc1252183b37a59f93f928bdb41ba8b2dc6bc
Showing with 251 additions and 28 deletions.
  1. +20 −6 Documentation/git-rebase.txt
  2. +44 −12 builtin/rebase.c
  3. +85 −8 sequencer.c
  4. +2 −0 sequencer.h
  5. +0 −2 t/t3422-rebase-incompatible-options.sh
  6. +100 −0 t/t3433-rebase-options-compatibility.sh
@@ -393,16 +393,29 @@ your branch contains commits which were dropped, this option can be used
with `--keep-base` in order to drop those commits from your branch.

--ignore-whitespace::
Behaves differently depending on which backend is selected.
+
'am' backend: When applying a patch, ignore changes in whitespace in
context lines if necessary.
+
'interactive' backend: Treat lines with only whitespace changes as
unchanged for the sake of a three-way merge.

--whitespace=<option>::
These flag are passed to the 'git apply' program
This flag is passed to the 'git apply' program
(see linkgit:git-apply[1]) that applies the patch.
+
See also INCOMPATIBLE OPTIONS below.

--committer-date-is-author-date::
Instead of recording the time the rebased commits are
created as the committer date, reuse the author date
as the committer date. This implies --force-rebase.

--ignore-date::
These flags are passed to 'git am' to easily change the dates
of the rebased commits (see linkgit:git-am[1]).
--reset-author-date::
Instead of using the given author date, reset it to the value
same as the current time. This implies --force-rebase.
+
See also INCOMPATIBLE OPTIONS below.

@@ -539,10 +552,7 @@ INCOMPATIBLE OPTIONS

The following options:

* --committer-date-is-author-date
* --ignore-date
* --whitespace
* --ignore-whitespace
* -C

are incompatible with the following options:
@@ -565,8 +575,12 @@ In addition, the following pairs of options are incompatible:
* --preserve-merges and --interactive
* --preserve-merges and --signoff
* --preserve-merges and --rebase-merges
* --preserve-merges and --ignore-whitespace
* --preserve-merges and --committer-date-is-author-date
* --preserve-merges and --ignore-date
* --keep-base and --onto
* --keep-base and --root
* --rebase-merges and --ignore-whitespace

BEHAVIORAL DIFFERENCES
-----------------------
@@ -79,8 +79,11 @@ struct rebase_options {
int allow_rerere_autoupdate;
int keep_empty;
int autosquash;
int ignore_whitespace;
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;
@@ -99,6 +102,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;
@@ -112,11 +116,20 @@ 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.ignore_date = opts->ignore_date;
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;
}

@@ -512,6 +525,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, 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;

@@ -965,6 +980,12 @@ 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->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,16 +1453,17 @@ 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),
OPT_PASSTHRU_ARGV(0, "ignore-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_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"),
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,
@@ -1713,11 +1735,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
state_dir_base, cmd_live_rebase, buf.buf);
}

if (options.ignore_date)
options.committer_date_is_author_date = 0;
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, "--committer-date-is-author-date") ||
!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)) {
@@ -1865,6 +1891,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
"'--reschedule-failed-exec'"));
}

if (options.rebase_merges) {
if (options.ignore_whitespace)
die(_("cannot combine '--rebase-merges' with "
"'--ignore-whitespace'"));
}

if (!options.root) {
if (argc < 1) {
struct branch *branch;
@@ -147,6 +147,8 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")
* command-line.
*/
static GIT_PATH_FUNC(rebase_path_gpg_sign_opt, "rebase-merge/gpg_sign_opt")
static GIT_PATH_FUNC(rebase_path_cdate_is_adate, "rebase-merge/cdate_is_adate")
static GIT_PATH_FUNC(rebase_path_ignore_date, "rebase-merge/ignore_date")
static GIT_PATH_FUNC(rebase_path_orig_head, "rebase-merge/orig-head")
static GIT_PATH_FUNC(rebase_path_verbose, "rebase-merge/verbose")
static GIT_PATH_FUNC(rebase_path_quiet, "rebase-merge/quiet")
@@ -823,9 +825,19 @@ int read_author_script(const char *path, char **name, char **email, char **date,
error(_("missing 'GIT_AUTHOR_DATE'"));
if (date_i < 0 || email_i < 0 || date_i < 0 || err)
goto finish;
*name = kv.items[name_i].util;
*email = kv.items[email_i].util;
*date = kv.items[date_i].util;

if (name)
*name = kv.items[name_i].util;
else
free(kv.items[name_i].util);
if (email)
*email = kv.items[email_i].util;
else
free(kv.items[email_i].util);
if (date)
*date = kv.items[date_i].util;
else
free(kv.items[date_i].util);
retval = 0;
finish:
string_list_clear(&kv, !!retval);
@@ -868,6 +880,32 @@ static char *get_author(const char *message)
return NULL;
}

/* Construct a free()able author string with current time as the author date */
static char *ignore_author_date(const char *author)
{
int len = strlen(author);
struct ident_split ident;
struct strbuf new_author = STRBUF_INIT;

split_ident_line(&ident, author, len);
len = ident.mail_end - ident.name_begin + 1;

strbuf_addf(&new_author, "%.*s ", len, author);
datestamp(&new_author);
return strbuf_detach(&new_author, NULL);
}

static void push_dates(struct child_process *child)
{
time_t now = time(NULL);
struct strbuf date = STRBUF_INIT;

strbuf_addf(&date, "@%"PRIuMAX, (uintmax_t)now);
argv_array_pushf(&child->args, "--date=%s", date.buf);
argv_array_pushf(&child->env_array, "GIT_COMMITTER_DATE=%s", date.buf);
strbuf_release(&date);
}

static const char staged_changes_advice[] =
N_("you have staged changes in your working tree\n"
"If these changes are meant to be squashed into the previous commit, run:\n"
@@ -942,6 +980,8 @@ static int run_git_commit(struct repository *r,
argv_array_push(&cmd.args, "--amend");
if (opts->gpg_sign)
argv_array_pushf(&cmd.args, "-S%s", opts->gpg_sign);
if (opts->ignore_date)
push_dates(&cmd);
if (defmsg)
argv_array_pushl(&cmd.args, "-F", defmsg, NULL);
else if (!(flags & EDIT_MSG))
@@ -1313,14 +1353,13 @@ static int try_to_commit(struct repository *r,
struct commit_extra_header *extra = NULL;
struct strbuf err = STRBUF_INIT;
struct strbuf commit_msg = STRBUF_INIT;
char *amend_author = NULL;
char *author_to_free = NULL;
const char *hook_commit = NULL;
enum commit_msg_cleanup_mode cleanup;
int res = 0;

if (parse_head(r, &current_head))
return -1;

if (flags & AMEND_MSG) {
const char *exclude_gpgsig[] = { "gpgsig", NULL };
const char *out_enc = get_commit_output_encoding();
@@ -1335,7 +1374,7 @@ static int try_to_commit(struct repository *r,
strbuf_addstr(msg, orig_message);
hook_commit = "HEAD";
}
author = amend_author = get_author(message);
author = author_to_free = get_author(message);
unuse_commit_buffer(current_head, message);
if (!author) {
res = error(_("unable to parse commit author"));
@@ -1348,6 +1387,21 @@ static int try_to_commit(struct repository *r,
commit_list_insert(current_head, &parents);
}

if (opts->committer_date_is_author_date) {
int len = strlen(author);
struct ident_split ident;
struct strbuf date = STRBUF_INIT;

split_ident_line(&ident, author, len);

if (!ident.date_begin)
return error(_("corrupted author without date information"));

strbuf_addf(&date, "@%s", ident.date_begin);
setenv("GIT_COMMITTER_DATE", date.buf, 1);
strbuf_release(&date);
}

if (write_index_as_tree(&tree, r->index, r->index_file, 0, NULL)) {
res = error(_("git write-tree failed to write a tree"));
goto out;
@@ -1391,6 +1445,11 @@ static int try_to_commit(struct repository *r,

reset_ident_date();

if (opts->ignore_date) {
author = ignore_author_date(author);
free(author_to_free);
author_to_free = (char *)author;
}
if (commit_tree_extended(msg->buf, msg->len, &tree, parents,
oid, author, opts->gpg_sign, extra)) {
res = error(_("failed to write commit object"));
@@ -1410,7 +1469,7 @@ static int try_to_commit(struct repository *r,
free_commit_extra_headers(extra);
strbuf_release(&err);
strbuf_release(&commit_msg);
free(amend_author);
free(author_to_free);

return res;
}
@@ -2470,6 +2529,16 @@ static int read_populate_opts(struct replay_opts *opts)
opts->signoff = 1;
}

if (file_exists(rebase_path_cdate_is_adate())) {
opts->allow_ff = 0;
opts->committer_date_is_author_date = 1;
}

if (file_exists(rebase_path_ignore_date())) {
opts->allow_ff = 0;
opts->ignore_date = 1;
}

if (file_exists(rebase_path_reschedule_failed_exec()))
opts->reschedule_failed_exec = 1;

@@ -2552,6 +2621,10 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
write_file(rebase_path_gpg_sign_opt(), "-S%s\n", opts->gpg_sign);
if (opts->signoff)
write_file(rebase_path_signoff(), "--signoff\n");
if (opts->committer_date_is_author_date)
write_file(rebase_path_cdate_is_adate(), "%s", "");
if (opts->ignore_date)
write_file(rebase_path_ignore_date(), "%s", "");
if (opts->reschedule_failed_exec)
write_file(rebase_path_reschedule_failed_exec(), "%s", "");

@@ -3487,6 +3560,8 @@ static int do_merge(struct repository *r,
argv_array_push(&cmd.args, git_path_merge_msg(r));
if (opts->gpg_sign)
argv_array_push(&cmd.args, opts->gpg_sign);
if (opts->ignore_date)
push_dates(&cmd);

/* Add the tips to be merged */
for (j = to_merge; j; j = j->next)
@@ -3759,7 +3834,9 @@ static int pick_commits(struct repository *r,
setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
if (opts->allow_ff)
assert(!(opts->signoff || opts->no_commit ||
opts->record_origin || opts->edit));
opts->record_origin || opts->edit ||
opts->committer_date_is_author_date ||
opts->ignore_date));
if (read_and_refresh_cache(r, opts))
return -1;

@@ -43,6 +43,8 @@ struct replay_opts {
int verbose;
int quiet;
int reschedule_failed_exec;
int committer_date_is_author_date;
int ignore_date;

int mainline;

@@ -61,8 +61,6 @@ test_rebase_am_only () {
}

test_rebase_am_only --whitespace=fix
test_rebase_am_only --ignore-whitespace
test_rebase_am_only --committer-date-is-author-date
test_rebase_am_only -C4

test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '

0 comments on commit 966fc12

Please sign in to comment.
You can’t perform that action at this time.