@@ -149,6 +149,7 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")
149149 * command-line.
150150 */
151151static GIT_PATH_FUNC (rebase_path_gpg_sign_opt , "rebase-merge/gpg_sign_opt" )
152+ static GIT_PATH_FUNC (rebase_path_cdate_is_adate , "rebase-merge/cdate_is_adate" )
152153static GIT_PATH_FUNC (rebase_path_orig_head , "rebase-merge/orig-head" )
153154static GIT_PATH_FUNC (rebase_path_verbose , "rebase-merge/verbose" )
154155static GIT_PATH_FUNC (rebase_path_quiet , "rebase-merge/quiet" )
@@ -302,6 +303,8 @@ int sequencer_remove_state(struct replay_opts *opts)
302303 }
303304 }
304305
306+ free (opts -> committer_name );
307+ free (opts -> committer_email );
305308 free (opts -> gpg_sign );
306309 free (opts -> strategy );
307310 for (i = 0 ; i < opts -> xopts_nr ; i ++ )
@@ -872,6 +875,22 @@ static char *get_author(const char *message)
872875 return NULL ;
873876}
874877
878+ static const char * author_date_from_env_array (const struct argv_array * env )
879+ {
880+ int i ;
881+ const char * date ;
882+
883+ for (i = 0 ; i < env -> argc ; i ++ )
884+ if (skip_prefix (env -> argv [i ],
885+ "GIT_AUTHOR_DATE=" , & date ))
886+ return date ;
887+ /*
888+ * If GIT_AUTHOR_DATE is missing we should have already errored out when
889+ * reading the script
890+ */
891+ BUG ("GIT_AUTHOR_DATE missing from author script" );
892+ }
893+
875894static const char staged_changes_advice [] =
876895N_ ("you have staged changes in your working tree\n"
877896"If these changes are meant to be squashed into the previous commit, run:\n"
@@ -938,6 +957,10 @@ static int run_git_commit(struct repository *r,
938957 gpg_opt , gpg_opt );
939958 }
940959
960+ if (opts -> committer_date_is_author_date )
961+ argv_array_pushf (& cmd .env_array , "GIT_COMMITTER_DATE=%s" ,
962+ author_date_from_env_array (& cmd .env_array ));
963+
941964 argv_array_push (& cmd .args , "commit" );
942965
943966 if (!(flags & VERIFY_MSG ))
@@ -1315,6 +1338,7 @@ static int try_to_commit(struct repository *r,
13151338 struct strbuf err = STRBUF_INIT ;
13161339 struct strbuf commit_msg = STRBUF_INIT ;
13171340 char * amend_author = NULL ;
1341+ const char * committer = NULL ;
13181342 const char * hook_commit = NULL ;
13191343 enum commit_msg_cleanup_mode cleanup ;
13201344 int res = 0 ;
@@ -1406,10 +1430,32 @@ static int try_to_commit(struct repository *r,
14061430 goto out ;
14071431 }
14081432
1409- reset_ident_date ();
1433+ if (opts -> committer_date_is_author_date ) {
1434+ struct ident_split id ;
1435+ struct strbuf date = STRBUF_INIT ;
1436+
1437+ if (split_ident_line (& id , author , (int )strlen (author )) < 0 ) {
1438+ res = error (_ ("invalid author identity '%s'" ), author );
1439+ goto out ;
1440+ }
1441+ if (!id .date_begin ) {
1442+ res = error (_ ("corrupt author: missing date information" ));
1443+ goto out ;
1444+ }
1445+ strbuf_addf (& date , "@%.*s %.*s" ,
1446+ (int )(id .date_end - id .date_begin ), id .date_begin ,
1447+ (int )(id .tz_end - id .tz_begin ), id .tz_begin );
1448+ committer = fmt_ident (opts -> committer_name ,
1449+ opts -> committer_email ,
1450+ WANT_COMMITTER_IDENT , date .buf ,
1451+ IDENT_STRICT );
1452+ strbuf_release (& date );
1453+ } else {
1454+ reset_ident_date ();
1455+ }
14101456
14111457 if (commit_tree_extended (msg -> buf , msg -> len , & tree , parents , oid ,
1412- author , NULL , opts -> gpg_sign , extra )) {
1458+ author , committer , opts -> gpg_sign , extra )) {
14131459 res = error (_ ("failed to write commit object" ));
14141460 goto out ;
14151461 }
@@ -2532,6 +2578,11 @@ static int read_populate_opts(struct replay_opts *opts)
25322578 opts -> signoff = 1 ;
25332579 }
25342580
2581+ if (file_exists (rebase_path_cdate_is_adate ())) {
2582+ opts -> allow_ff = 0 ;
2583+ opts -> committer_date_is_author_date = 1 ;
2584+ }
2585+
25352586 if (file_exists (rebase_path_reschedule_failed_exec ()))
25362587 opts -> reschedule_failed_exec = 1 ;
25372588
@@ -2622,6 +2673,8 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
26222673 write_file (rebase_path_drop_redundant_commits (), "%s" , "" );
26232674 if (opts -> keep_redundant_commits )
26242675 write_file (rebase_path_keep_redundant_commits (), "%s" , "" );
2676+ if (opts -> committer_date_is_author_date )
2677+ write_file (rebase_path_cdate_is_adate (), "%s" , "" );
26252678 if (opts -> reschedule_failed_exec )
26262679 write_file (rebase_path_reschedule_failed_exec (), "%s" , "" );
26272680
@@ -3542,6 +3595,10 @@ static int do_merge(struct repository *r,
35423595 goto leave_merge ;
35433596 }
35443597
3598+ if (opts -> committer_date_is_author_date )
3599+ argv_array_pushf (& cmd .env_array , "GIT_COMMITTER_DATE=%s" ,
3600+ author_date_from_env_array (& cmd .env_array ));
3601+
35453602 cmd .git_cmd = 1 ;
35463603 argv_array_push (& cmd .args , "merge" );
35473604 argv_array_push (& cmd .args , "-s" );
@@ -3819,7 +3876,8 @@ static int pick_commits(struct repository *r,
38193876 setenv (GIT_REFLOG_ACTION , action_name (opts ), 0 );
38203877 if (opts -> allow_ff )
38213878 assert (!(opts -> signoff || opts -> no_commit ||
3822- opts -> record_origin || opts -> edit ));
3879+ opts -> record_origin || opts -> edit ||
3880+ opts -> committer_date_is_author_date ));
38233881 if (read_and_refresh_cache (r , opts ))
38243882 return -1 ;
38253883
@@ -4258,6 +4316,22 @@ static int commit_staged_changes(struct repository *r,
42584316 return 0 ;
42594317}
42604318
4319+ static int init_committer (struct replay_opts * opts )
4320+ {
4321+ struct ident_split id ;
4322+ const char * committer ;
4323+
4324+ committer = git_committer_info (IDENT_STRICT );
4325+ if (split_ident_line (& id , committer , strlen (committer )) < 0 )
4326+ return error (_ ("invalid committer '%s'" ), committer );
4327+ opts -> committer_name =
4328+ xmemdupz (id .name_begin , id .name_end - id .name_begin );
4329+ opts -> committer_email =
4330+ xmemdupz (id .mail_begin , id .mail_end - id .mail_end );
4331+
4332+ return 0 ;
4333+ }
4334+
42614335int sequencer_continue (struct repository * r , struct replay_opts * opts )
42624336{
42634337 struct todo_list todo_list = TODO_LIST_INIT ;
@@ -4269,6 +4343,9 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
42694343 if (read_populate_opts (opts ))
42704344 return -1 ;
42714345 if (is_rebase_i (opts )) {
4346+ if (opts -> committer_date_is_author_date && init_committer (opts ))
4347+ return -1 ;
4348+
42724349 if ((res = read_populate_todo (r , & todo_list , opts )))
42734350 goto release_todo_list ;
42744351
@@ -5145,6 +5222,9 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
51455222
51465223 res = -1 ;
51475224
5225+ if (opts -> committer_date_is_author_date && init_committer (opts ))
5226+ goto cleanup ;
5227+
51485228 if (checkout_onto (r , opts , onto_name , & oid , orig_head ))
51495229 goto cleanup ;
51505230
0 commit comments