@@ -148,6 +148,7 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")
148148 */
149149static GIT_PATH_FUNC (rebase_path_gpg_sign_opt , "rebase-merge/gpg_sign_opt" )
150150static 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" )
151152static GIT_PATH_FUNC (rebase_path_orig_head , "rebase-merge/orig-head" )
152153static GIT_PATH_FUNC (rebase_path_verbose , "rebase-merge/verbose" )
153154static 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+
894925static const char staged_changes_advice [] =
895926N_ ("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
0 commit comments