@@ -526,10 +526,29 @@ static int sane_ident_split(struct ident_split *person)
526
526
return 1 ;
527
527
}
528
528
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
+
529
547
static void determine_author_info (struct strbuf * author_ident )
530
548
{
531
549
char * name , * email , * date ;
532
550
struct ident_split author ;
551
+ char date_buf [64 ];
533
552
534
553
name = getenv ("GIT_AUTHOR_NAME" );
535
554
email = getenv ("GIT_AUTHOR_EMAIL" );
@@ -574,8 +593,12 @@ static void determine_author_info(struct strbuf *author_ident)
574
593
email = xstrndup (lb + 2 , rb - (lb + 2 ));
575
594
}
576
595
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
+
579
602
strbuf_addstr (author_ident , fmt_ident (name , email , date , IDENT_STRICT ));
580
603
if (!split_ident_line (& author , author_ident -> buf , author_ident -> len ) &&
581
604
sane_ident_split (& author )) {
@@ -585,13 +608,16 @@ static void determine_author_info(struct strbuf *author_ident)
585
608
}
586
609
}
587
610
588
- static char * cut_ident_timestamp_part ( char * string )
611
+ static void split_ident_or_die ( struct ident_split * id , const struct strbuf * buf )
589
612
{
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 ;
595
621
}
596
622
597
623
static 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,
755
781
if (use_editor && include_status ) {
756
782
int ident_shown = 0 ;
757
783
int saved_color_setting ;
758
- char * ai_tmp , * ci_tmp ;
784
+ struct ident_split ci , ai ;
785
+
759
786
if (whence != FROM_COMMIT ) {
760
787
if (cleanup_mode == CLEANUP_SCISSORS )
761
788
wt_status_add_cut_line (s -> fp );
@@ -795,21 +822,31 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
795
822
status_printf_ln (s , GIT_COLOR_NORMAL ,
796
823
"%s" , only_include_assumed );
797
824
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 ))
801
829
status_printf_ln (s , GIT_COLOR_NORMAL ,
802
830
_ ("%s"
803
- "Author: %s " ),
831
+ "Author: %.*s <%.*s> " ),
804
832
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 ));
806
842
807
843
if (!committer_ident_sufficiently_given ())
808
844
status_printf_ln (s , GIT_COLOR_NORMAL ,
809
845
_ ("%s"
810
- "Committer: %s " ),
846
+ "Committer: %.*s <%.*s> " ),
811
847
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 );
813
850
814
851
if (ident_shown )
815
852
status_printf_ln (s , GIT_COLOR_NORMAL , "" );
@@ -818,9 +855,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
818
855
s -> use_color = 0 ;
819
856
commitable = run_status (s -> fp , index_file , prefix , 1 , s );
820
857
s -> use_color = saved_color_setting ;
821
-
822
- * ai_tmp = ' ' ;
823
- * ci_tmp = ' ' ;
824
858
} else {
825
859
unsigned char sha1 [20 ];
826
860
const char * parent = "HEAD" ;
@@ -1356,6 +1390,13 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
1356
1390
strbuf_addstr (& format , "\n Author: " );
1357
1391
strbuf_addbuf_percentquote (& format , & author_ident );
1358
1392
}
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
+ }
1359
1400
if (!committer_ident_sufficiently_given ()) {
1360
1401
strbuf_addstr (& format , "\n Committer: " );
1361
1402
strbuf_addbuf_percentquote (& format , & committer_ident );
0 commit comments