Skip to content

Commit 08187b4

Browse files
r1walzgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0185c68 commit 08187b4

File tree

5 files changed

+99
-11
lines changed

5 files changed

+99
-11
lines changed

Documentation/git-rebase.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ See also INCOMPATIBLE OPTIONS below.
391391
as the committer date. This implies --force-rebase.
392392

393393
--ignore-date::
394-
This flag is passed to 'git am' to change the author date
395-
of each rebased commit (see linkgit:git-am[1]).
394+
Instead of using the given author date, reset it to the
395+
current time. This implies --force-rebase.
396396
+
397397
See also INCOMPATIBLE OPTIONS below.
398398

@@ -529,7 +529,6 @@ INCOMPATIBLE OPTIONS
529529

530530
The following options:
531531

532-
* --ignore-date
533532
* --whitespace
534533
* -C
535534

@@ -555,6 +554,7 @@ In addition, the following pairs of options are incompatible:
555554
* --preserve-merges and --rebase-merges
556555
* --preserve-merges and --ignore-whitespace
557556
* --preserve-merges and --committer-date-is-author-date
557+
* --preserve-merges and --ignore-date
558558
* --rebase-merges and --strategy
559559
* --rebase-merges and --strategy-option
560560

builtin/rebase.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct rebase_options {
8383
char *gpg_sign_opt;
8484
int autostash;
8585
int committer_date_is_author_date;
86+
int ignore_date;
8687
char *cmd;
8788
int allow_empty_message;
8889
int rebase_merges, rebase_cousins;
@@ -117,6 +118,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
117118
replay.reschedule_failed_exec = opts->reschedule_failed_exec;
118119
replay.committer_date_is_author_date =
119120
opts->committer_date_is_author_date;
121+
replay.ignore_date = opts->ignore_date;
120122
replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
121123
replay.strategy = opts->strategy;
122124

@@ -981,6 +983,8 @@ static int run_am(struct rebase_options *opts)
981983
argv_array_push(&am.args, "--ignore-whitespace");
982984
if (opts->committer_date_is_author_date)
983985
argv_array_push(&opts->git_am_opts, "--committer-date-is-author-date");
986+
if (opts->ignore_date)
987+
argv_array_push(&opts->git_am_opts, "--ignore-date");
984988
if (opts->action && !strcmp("continue", opts->action)) {
985989
argv_array_push(&am.args, "--resolved");
986990
argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
@@ -1432,8 +1436,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
14321436
OPT_BOOL(0, "committer-date-is-author-date",
14331437
&options.committer_date_is_author_date,
14341438
N_("make committer date match author date")),
1435-
OPT_PASSTHRU_ARGV(0, "ignore-date", &options.git_am_opts, NULL,
1436-
N_("passed to 'git am'"), PARSE_OPT_NOARG),
1439+
OPT_BOOL(0, "ignore-date", &options.ignore_date,
1440+
"ignore author date and use current date"),
14371441
OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
14381442
N_("passed to 'git apply'"), 0),
14391443
OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace,
@@ -1706,13 +1710,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17061710
state_dir_base, cmd_live_rebase, buf.buf);
17071711
}
17081712

1709-
if (options.committer_date_is_author_date)
1713+
if (options.committer_date_is_author_date ||
1714+
options.ignore_date)
17101715
options.flags |= REBASE_FORCE;
17111716

17121717
for (i = 0; i < options.git_am_opts.argc; i++) {
17131718
const char *option = options.git_am_opts.argv[i], *p;
1714-
if (!strcmp(option, "--ignore-date") ||
1715-
!strcmp(option, "--whitespace=fix") ||
1719+
if (!strcmp(option, "--whitespace=fix") ||
17161720
!strcmp(option, "--whitespace=strip"))
17171721
options.flags |= REBASE_FORCE;
17181722
else if (skip_prefix(option, "-C", &p)) {

sequencer.c

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")
148148
*/
149149
static GIT_PATH_FUNC(rebase_path_gpg_sign_opt, "rebase-merge/gpg_sign_opt")
150150
static GIT_PATH_FUNC(rebase_path_cdate_is_adate, "rebase-merge/cdate_is_adate")
151+
static GIT_PATH_FUNC(rebase_path_ignore_date, "rebase-merge/ignore_date")
151152
static GIT_PATH_FUNC(rebase_path_orig_head, "rebase-merge/orig-head")
152153
static GIT_PATH_FUNC(rebase_path_verbose, "rebase-merge/verbose")
153154
static GIT_PATH_FUNC(rebase_path_quiet, "rebase-merge/quiet")
@@ -891,6 +892,36 @@ static char *read_author_date_or_null(void)
891892
return date;
892893
}
893894

895+
/* Construct a free()able author string with current time as the author date */
896+
static char *ignore_author_date(const char *author)
897+
{
898+
int len = strlen(author);
899+
struct ident_split ident;
900+
struct strbuf new_author = STRBUF_INIT;
901+
902+
if (split_ident_line(&ident, author, len) < 0) {
903+
error(_("malformed ident line"));
904+
return NULL;
905+
}
906+
len = ident.mail_end - ident.name_begin + 1;
907+
908+
strbuf_addf(&new_author, "%.*s ", len, ident.name_begin);
909+
datestamp(&new_author);
910+
return strbuf_detach(&new_author, NULL);
911+
}
912+
913+
static void push_dates(struct child_process *child, int change_committer_date)
914+
{
915+
time_t now = time(NULL);
916+
struct strbuf date = STRBUF_INIT;
917+
918+
strbuf_addf(&date, "@%"PRIuMAX, (uintmax_t)now);
919+
argv_array_pushf(&child->env_array, "GIT_AUTHOR_DATE=%s", date.buf);
920+
if (change_committer_date)
921+
argv_array_pushf(&child->env_array, "GIT_COMMITTER_DATE=%s", date.buf);
922+
strbuf_release(&date);
923+
}
924+
894925
static const char staged_changes_advice[] =
895926
N_("you have staged changes in your working tree\n"
896927
"If these changes are meant to be squashed into the previous commit, run:\n"
@@ -959,7 +990,8 @@ static int run_git_commit(struct repository *r,
959990
return -1;
960991

961992
strbuf_addf(&datebuf, "@%s", date);
962-
res = setenv("GIT_COMMITTER_DATE", datebuf.buf, 1);
993+
res = setenv("GIT_COMMITTER_DATE",
994+
opts->ignore_date ? "" : datebuf.buf, 1);
963995

964996
strbuf_release(&datebuf);
965997
free(date);
@@ -983,6 +1015,8 @@ static int run_git_commit(struct repository *r,
9831015
argv_array_push(&cmd.args, "--amend");
9841016
if (opts->gpg_sign)
9851017
argv_array_pushf(&cmd.args, "-S%s", opts->gpg_sign);
1018+
if (opts->ignore_date)
1019+
push_dates(&cmd, opts->committer_date_is_author_date);
9861020
if (defmsg)
9871021
argv_array_pushl(&cmd.args, "-F", defmsg, NULL);
9881022
else if (!(flags & EDIT_MSG))
@@ -1405,7 +1439,8 @@ static int try_to_commit(struct repository *r,
14051439
strbuf_addf(&date, "@%.*s %.*s",
14061440
(int)(ident.date_end - ident.date_begin), ident.date_begin,
14071441
(int)(ident.tz_end - ident.tz_begin), ident.tz_begin);
1408-
res = setenv("GIT_COMMITTER_DATE", date.buf, 1);
1442+
res = setenv("GIT_COMMITTER_DATE",
1443+
opts->ignore_date ? "" : date.buf, 1);
14091444
strbuf_release(&date);
14101445

14111446
if (res)
@@ -1455,6 +1490,15 @@ static int try_to_commit(struct repository *r,
14551490

14561491
reset_ident_date();
14571492

1493+
if (opts->ignore_date) {
1494+
author = ignore_author_date(author);
1495+
if (!author) {
1496+
res = -1;
1497+
goto out;
1498+
}
1499+
free(author_to_free);
1500+
author_to_free = (char *)author;
1501+
}
14581502
if (commit_tree_extended(msg->buf, msg->len, &tree, parents,
14591503
oid, author, opts->gpg_sign, extra)) {
14601504
res = error(_("failed to write commit object"));
@@ -2538,6 +2582,11 @@ static int read_populate_opts(struct replay_opts *opts)
25382582
opts->committer_date_is_author_date = 1;
25392583
}
25402584

2585+
if (file_exists(rebase_path_ignore_date())) {
2586+
opts->allow_ff = 0;
2587+
opts->ignore_date = 1;
2588+
}
2589+
25412590
if (file_exists(rebase_path_reschedule_failed_exec()))
25422591
opts->reschedule_failed_exec = 1;
25432592

@@ -2622,6 +2671,8 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
26222671
write_file(rebase_path_signoff(), "--signoff\n");
26232672
if (opts->committer_date_is_author_date)
26242673
write_file(rebase_path_cdate_is_adate(), "%s", "");
2674+
if (opts->ignore_date)
2675+
write_file(rebase_path_ignore_date(), "%s", "");
26252676
if (opts->reschedule_failed_exec)
26262677
write_file(rebase_path_reschedule_failed_exec(), "%s", "");
26272678

@@ -3439,6 +3490,8 @@ static int do_merge(struct repository *r,
34393490
argv_array_push(&cmd.args, git_path_merge_msg(r));
34403491
if (opts->gpg_sign)
34413492
argv_array_push(&cmd.args, opts->gpg_sign);
3493+
if (opts->ignore_date)
3494+
push_dates(&cmd, opts->committer_date_is_author_date);
34423495

34433496
/* Add the tips to be merged */
34443497
for (j = to_merge; j; j = j->next)
@@ -3711,7 +3764,8 @@ static int pick_commits(struct repository *r,
37113764
if (opts->allow_ff)
37123765
assert(!(opts->signoff || opts->no_commit ||
37133766
opts->record_origin || opts->edit ||
3714-
opts->committer_date_is_author_date));
3767+
opts->committer_date_is_author_date ||
3768+
opts->ignore_date));
37153769
if (read_and_refresh_cache(r, opts))
37163770
return -1;
37173771

sequencer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct replay_opts {
4444
int quiet;
4545
int reschedule_failed_exec;
4646
int committer_date_is_author_date;
47+
int ignore_date;
4748

4849
int mainline;
4950

t/t3433-rebase-options-compatibility.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,33 @@ test_expect_success '--committer-date-is-author-date works with rebase -r' '
9999
done <rev_list
100100
'
101101

102+
# Checking for +0000 in author time is enough since default
103+
# timezone is UTC, but the timezone used while committing
104+
# sets to +0530.
105+
test_expect_success '--ignore-date works with am backend' '
106+
git commit --amend --date="$GIT_AUTHOR_DATE" &&
107+
git rebase --ignore-date HEAD^ &&
108+
git show HEAD --pretty="format:%ai" >authortime &&
109+
grep "+0000" authortime
110+
'
111+
112+
test_expect_success '--ignore-date works with interactive backend' '
113+
git commit --amend --date="$GIT_AUTHOR_DATE" &&
114+
git rebase --ignore-date -i HEAD^ &&
115+
git show HEAD --pretty="format:%ai" >authortime &&
116+
grep "+0000" authortime
117+
'
118+
119+
test_expect_success '--ignore-date works with rebase -r' '
120+
git checkout side &&
121+
git merge --no-ff commit3 &&
122+
git rebase -r --root --ignore-date &&
123+
git rev-list HEAD >rev_list &&
124+
while read HASH
125+
do
126+
git show $HASH --pretty="format:%ai" >authortime
127+
grep "+0000" authortime
128+
done <rev_list
129+
'
130+
102131
test_done

0 commit comments

Comments
 (0)