@@ -147,6 +147,7 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")
147147 * command-line.
148148 */
149149static GIT_PATH_FUNC (rebase_path_gpg_sign_opt , "rebase-merge/gpg_sign_opt" )
150+ static GIT_PATH_FUNC (rebase_path_cdate_is_adate , "rebase-merge/cdate_is_adate" )
150151static GIT_PATH_FUNC (rebase_path_orig_head , "rebase-merge/orig-head" )
151152static GIT_PATH_FUNC (rebase_path_verbose , "rebase-merge/verbose" )
152153static GIT_PATH_FUNC (rebase_path_quiet , "rebase-merge/quiet" )
@@ -879,6 +880,17 @@ static char *get_author(const char *message)
879880 return NULL ;
880881}
881882
883+ /* Returns a "date" string that needs to be free()'d by the caller */
884+ static char * read_author_date_or_null (void )
885+ {
886+ char * date ;
887+
888+ if (read_author_script (rebase_path_author_script (),
889+ NULL , NULL , & date , 0 ))
890+ return NULL ;
891+ return date ;
892+ }
893+
882894static const char staged_changes_advice [] =
883895N_ ("you have staged changes in your working tree\n"
884896"If these changes are meant to be squashed into the previous commit, run:\n"
@@ -938,6 +950,24 @@ static int run_git_commit(struct repository *r,
938950
939951 cmd .git_cmd = 1 ;
940952
953+ if (opts -> committer_date_is_author_date ) {
954+ int res = -1 ;
955+ struct strbuf datebuf = STRBUF_INIT ;
956+ char * date = read_author_date_or_null ();
957+
958+ if (!date )
959+ return -1 ;
960+
961+ strbuf_addf (& datebuf , "@%s" , date );
962+ res = setenv ("GIT_COMMITTER_DATE" , datebuf .buf , 1 );
963+
964+ strbuf_release (& datebuf );
965+ free (date );
966+
967+ if (res )
968+ return -1 ;
969+ }
970+
941971 if (is_rebase_i (opts ) && read_env_script (& cmd .env_array )) {
942972 const char * gpg_opt = gpg_sign_opt_quoted (opts );
943973
@@ -1331,7 +1361,6 @@ static int try_to_commit(struct repository *r,
13311361
13321362 if (parse_head (r , & current_head ))
13331363 return -1 ;
1334-
13351364 if (flags & AMEND_MSG ) {
13361365 const char * exclude_gpgsig [] = { "gpgsig" , NULL };
13371366 const char * out_enc = get_commit_output_encoding ();
@@ -1359,6 +1388,30 @@ static int try_to_commit(struct repository *r,
13591388 commit_list_insert (current_head , & parents );
13601389 }
13611390
1391+ if (opts -> committer_date_is_author_date ) {
1392+ int len = strlen (author );
1393+ struct ident_split ident ;
1394+ struct strbuf date = STRBUF_INIT ;
1395+
1396+ if (split_ident_line (& ident , author , len ) < 0 ) {
1397+ res = error (_ ("malformed ident line" ));
1398+ goto out ;
1399+ }
1400+ if (!ident .date_begin ) {
1401+ res = error (_ ("corrupted author without date information" ));
1402+ goto out ;
1403+ }
1404+
1405+ strbuf_addf (& date , "@%.*s %.*s" ,
1406+ (int )(ident .date_end - ident .date_begin ), ident .date_begin ,
1407+ (int )(ident .tz_end - ident .tz_begin ), ident .tz_begin );
1408+ res = setenv ("GIT_COMMITTER_DATE" , date .buf , 1 );
1409+ strbuf_release (& date );
1410+
1411+ if (res )
1412+ goto out ;
1413+ }
1414+
13621415 if (write_index_as_tree (& tree , r -> index , r -> index_file , 0 , NULL )) {
13631416 res = error (_ ("git write-tree failed to write a tree" ));
13641417 goto out ;
@@ -2480,6 +2533,11 @@ static int read_populate_opts(struct replay_opts *opts)
24802533 opts -> signoff = 1 ;
24812534 }
24822535
2536+ if (file_exists (rebase_path_cdate_is_adate ())) {
2537+ opts -> allow_ff = 0 ;
2538+ opts -> committer_date_is_author_date = 1 ;
2539+ }
2540+
24832541 if (file_exists (rebase_path_reschedule_failed_exec ()))
24842542 opts -> reschedule_failed_exec = 1 ;
24852543
@@ -2562,6 +2620,8 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
25622620 write_file (rebase_path_gpg_sign_opt (), "-S%s\n" , opts -> gpg_sign );
25632621 if (opts -> signoff )
25642622 write_file (rebase_path_signoff (), "--signoff\n" );
2623+ if (opts -> committer_date_is_author_date )
2624+ write_file (rebase_path_cdate_is_adate (), "%s" , "" );
25652625 if (opts -> reschedule_failed_exec )
25662626 write_file (rebase_path_reschedule_failed_exec (), "%s" , "" );
25672627
@@ -3650,7 +3710,8 @@ static int pick_commits(struct repository *r,
36503710 setenv (GIT_REFLOG_ACTION , action_name (opts ), 0 );
36513711 if (opts -> allow_ff )
36523712 assert (!(opts -> signoff || opts -> no_commit ||
3653- opts -> record_origin || opts -> edit ));
3713+ opts -> record_origin || opts -> edit ||
3714+ opts -> committer_date_is_author_date ));
36543715 if (read_and_refresh_cache (r , opts ))
36553716 return -1 ;
36563717
0 commit comments