@@ -526,10 +526,29 @@ static int sane_ident_split(struct ident_split *person)
526526 return 1 ;
527527}
528528
529+ static int parse_force_date (const char * in , char * out , int len )
530+ {
531+ if (len < 1 )
532+ return -1 ;
533+ * out ++ = '@' ;
534+ len -- ;
535+
536+ if (parse_date (in , out , len ) < 0 ) {
537+ int errors = 0 ;
538+ unsigned long t = approxidate_careful (in , & errors );
539+ if (errors )
540+ return -1 ;
541+ snprintf (out , len , "%lu" , t );
542+ }
543+
544+ return 0 ;
545+ }
546+
529547static void determine_author_info (struct strbuf * author_ident )
530548{
531549 char * name , * email , * date ;
532550 struct ident_split author ;
551+ char date_buf [64 ];
533552
534553 name = getenv ("GIT_AUTHOR_NAME" );
535554 email = getenv ("GIT_AUTHOR_EMAIL" );
@@ -574,8 +593,12 @@ static void determine_author_info(struct strbuf *author_ident)
574593 email = xstrndup (lb + 2 , rb - (lb + 2 ));
575594 }
576595
577- if (force_date )
578- date = force_date ;
596+ if (force_date ) {
597+ if (parse_force_date (force_date , date_buf , sizeof (date_buf )))
598+ die (_ ("invalid date format: %s" ), force_date );
599+ date = date_buf ;
600+ }
601+
579602 strbuf_addstr (author_ident , fmt_ident (name , email , date , IDENT_STRICT ));
580603 if (!split_ident_line (& author , author_ident -> buf , author_ident -> len ) &&
581604 sane_ident_split (& author )) {
@@ -585,13 +608,16 @@ static void determine_author_info(struct strbuf *author_ident)
585608 }
586609}
587610
588- static char * cut_ident_timestamp_part ( char * string )
611+ static void split_ident_or_die ( struct ident_split * id , const struct strbuf * buf )
589612{
590- char * ket = strrchr (string , '>' );
591- if (!ket || ket [1 ] != ' ' )
592- die (_ ("Malformed ident string: '%s'" ), string );
593- * ++ ket = '\0' ;
594- return ket ;
613+ if (split_ident_line (id , buf -> buf , buf -> len ) ||
614+ !sane_ident_split (id ))
615+ die (_ ("Malformed ident string: '%s'" ), buf -> buf );
616+ }
617+
618+ static int author_date_is_interesting (void )
619+ {
620+ return author_message || force_date ;
595621}
596622
597623static int prepare_to_commit (const char * index_file , const char * prefix ,
@@ -755,7 +781,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
755781 if (use_editor && include_status ) {
756782 int ident_shown = 0 ;
757783 int saved_color_setting ;
758- char * ai_tmp , * ci_tmp ;
784+ struct ident_split ci , ai ;
785+
759786 if (whence != FROM_COMMIT ) {
760787 if (cleanup_mode == CLEANUP_SCISSORS )
761788 wt_status_add_cut_line (s -> fp );
@@ -795,21 +822,31 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
795822 status_printf_ln (s , GIT_COLOR_NORMAL ,
796823 "%s" , only_include_assumed );
797824
798- ai_tmp = cut_ident_timestamp_part (author_ident -> buf );
799- ci_tmp = cut_ident_timestamp_part (committer_ident .buf );
800- if (strcmp (author_ident -> buf , committer_ident .buf ))
825+ split_ident_or_die (& ai , author_ident );
826+ split_ident_or_die (& ci , & committer_ident );
827+
828+ if (ident_cmp (& ai , & ci ))
801829 status_printf_ln (s , GIT_COLOR_NORMAL ,
802830 _ ("%s"
803- "Author: %s " ),
831+ "Author: %.*s <%.*s> " ),
804832 ident_shown ++ ? "" : "\n" ,
805- author_ident -> buf );
833+ (int )(ai .name_end - ai .name_begin ), ai .name_begin ,
834+ (int )(ai .mail_end - ai .mail_begin ), ai .mail_begin );
835+
836+ if (author_date_is_interesting ())
837+ status_printf_ln (s , GIT_COLOR_NORMAL ,
838+ _ ("%s"
839+ "Date: %s" ),
840+ ident_shown ++ ? "" : "\n" ,
841+ show_ident_date (& ai , DATE_NORMAL ));
806842
807843 if (!committer_ident_sufficiently_given ())
808844 status_printf_ln (s , GIT_COLOR_NORMAL ,
809845 _ ("%s"
810- "Committer: %s " ),
846+ "Committer: %.*s <%.*s> " ),
811847 ident_shown ++ ? "" : "\n" ,
812- committer_ident .buf );
848+ (int )(ci .name_end - ci .name_begin ), ci .name_begin ,
849+ (int )(ci .mail_end - ci .mail_begin ), ci .mail_begin );
813850
814851 if (ident_shown )
815852 status_printf_ln (s , GIT_COLOR_NORMAL , "" );
@@ -818,9 +855,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
818855 s -> use_color = 0 ;
819856 commitable = run_status (s -> fp , index_file , prefix , 1 , s );
820857 s -> use_color = saved_color_setting ;
821-
822- * ai_tmp = ' ' ;
823- * ci_tmp = ' ' ;
824858 } else {
825859 unsigned char sha1 [20 ];
826860 const char * parent = "HEAD" ;
@@ -1356,6 +1390,13 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
13561390 strbuf_addstr (& format , "\n Author: " );
13571391 strbuf_addbuf_percentquote (& format , & author_ident );
13581392 }
1393+ if (author_date_is_interesting ()) {
1394+ struct strbuf date = STRBUF_INIT ;
1395+ format_commit_message (commit , "%ad" , & date , & pctx );
1396+ strbuf_addstr (& format , "\n Date: " );
1397+ strbuf_addbuf_percentquote (& format , & date );
1398+ strbuf_release (& date );
1399+ }
13591400 if (!committer_ident_sufficiently_given ()) {
13601401 strbuf_addstr (& format , "\n Committer: " );
13611402 strbuf_addbuf_percentquote (& format , & committer_ident );
0 commit comments