@@ -69,7 +69,6 @@ static enum {
69
69
static const char * logfile , * force_author ;
70
70
static const char * template_file ;
71
71
static char * edit_message , * use_message ;
72
- static char * author_name , * author_email , * author_date ;
73
72
static int all , edit_flag , also , interactive , only , amend , signoff ;
74
73
static int quiet , verbose , no_verify , allow_empty , dry_run , renew_authorship ;
75
74
static int no_post_rewrite , allow_empty_message ;
@@ -459,7 +458,7 @@ static int is_a_merge(const unsigned char *sha1)
459
458
460
459
static const char sign_off_header [] = "Signed-off-by: " ;
461
460
462
- static void determine_author_info (void )
461
+ static void determine_author_info (struct strbuf * author_ident )
463
462
{
464
463
char * name , * email , * date ;
465
464
@@ -503,10 +502,8 @@ static void determine_author_info(void)
503
502
504
503
if (force_date )
505
504
date = force_date ;
506
-
507
- author_name = name ;
508
- author_email = email ;
509
- author_date = date ;
505
+ strbuf_addstr (author_ident , fmt_ident (name , email , date ,
506
+ IDENT_ERROR_ON_NO_NAME ));
510
507
}
511
508
512
509
static int ends_rfc2822_footer (struct strbuf * sb )
@@ -550,10 +547,21 @@ static int ends_rfc2822_footer(struct strbuf *sb)
550
547
return 1 ;
551
548
}
552
549
550
+ static char * cut_ident_timestamp_part (char * string )
551
+ {
552
+ char * ket = strrchr (string , '>' );
553
+ if (!ket || ket [1 ] != ' ' )
554
+ die ("Malformed ident string: '%s'" , string );
555
+ * ++ ket = '\0' ;
556
+ return ket ;
557
+ }
558
+
553
559
static int prepare_to_commit (const char * index_file , const char * prefix ,
554
- struct wt_status * s )
560
+ struct wt_status * s ,
561
+ struct strbuf * author_ident )
555
562
{
556
563
struct stat statbuf ;
564
+ struct strbuf committer_ident = STRBUF_INIT ;
557
565
int commitable , saved_color_setting ;
558
566
struct strbuf sb = STRBUF_INIT ;
559
567
char * buffer ;
@@ -637,14 +645,13 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
637
645
638
646
strbuf_release (& sb );
639
647
640
- determine_author_info ();
648
+ /* This checks and barfs if author is badly specified */
649
+ determine_author_info (author_ident );
641
650
642
651
/* This checks if committer ident is explicitly given */
643
- git_committer_info (0 );
652
+ strbuf_addstr ( & committer_ident , git_committer_info (0 ) );
644
653
if (use_editor && include_status ) {
645
- char * author_ident ;
646
- const char * committer_ident ;
647
-
654
+ char * ai_tmp , * ci_tmp ;
648
655
if (in_merge )
649
656
fprintf (fp ,
650
657
"#\n"
@@ -672,23 +679,21 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
672
679
if (only_include_assumed )
673
680
fprintf (fp , "# %s\n" , only_include_assumed );
674
681
675
- author_ident = xstrdup (fmt_name (author_name , author_email ));
676
- committer_ident = fmt_name (getenv ("GIT_COMMITTER_NAME" ),
677
- getenv ("GIT_COMMITTER_EMAIL" ));
678
- if (strcmp (author_ident , committer_ident ))
682
+ ai_tmp = cut_ident_timestamp_part (author_ident -> buf );
683
+ ci_tmp = cut_ident_timestamp_part (committer_ident .buf );
684
+ if (strcmp (author_ident -> buf , committer_ident .buf ))
679
685
fprintf (fp ,
680
686
"%s"
681
687
"# Author: %s\n" ,
682
688
ident_shown ++ ? "" : "#\n" ,
683
- author_ident );
684
- free (author_ident );
689
+ author_ident -> buf );
685
690
686
691
if (!user_ident_sufficiently_given ())
687
692
fprintf (fp ,
688
693
"%s"
689
694
"# Committer: %s\n" ,
690
695
ident_shown ++ ? "" : "#\n" ,
691
- committer_ident );
696
+ committer_ident . buf );
692
697
693
698
if (ident_shown )
694
699
fprintf (fp , "#\n" );
@@ -697,6 +702,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
697
702
s -> use_color = 0 ;
698
703
commitable = run_status (fp , index_file , prefix , 1 , s );
699
704
s -> use_color = saved_color_setting ;
705
+
706
+ * ai_tmp = ' ' ;
707
+ * ci_tmp = ' ' ;
700
708
} else {
701
709
unsigned char sha1 [20 ];
702
710
const char * parent = "HEAD" ;
@@ -712,6 +720,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
712
720
else
713
721
commitable = index_differs_from (parent , 0 );
714
722
}
723
+ strbuf_release (& committer_ident );
715
724
716
725
fclose (fp );
717
726
@@ -1246,6 +1255,7 @@ static int run_rewrite_hook(const unsigned char *oldsha1,
1246
1255
int cmd_commit (int argc , const char * * argv , const char * prefix )
1247
1256
{
1248
1257
struct strbuf sb = STRBUF_INIT ;
1258
+ struct strbuf author_ident = STRBUF_INIT ;
1249
1259
const char * index_file , * reflog_msg ;
1250
1260
char * nl , * p ;
1251
1261
unsigned char commit_sha1 [20 ];
@@ -1273,7 +1283,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1273
1283
1274
1284
/* Set up everything for writing the commit object. This includes
1275
1285
running hooks, writing the trees, and interacting with the user. */
1276
- if (!prepare_to_commit (index_file , prefix , & s )) {
1286
+ if (!prepare_to_commit (index_file , prefix , & s , & author_ident )) {
1277
1287
rollback_index_files ();
1278
1288
return 1 ;
1279
1289
}
@@ -1352,11 +1362,11 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1352
1362
}
1353
1363
1354
1364
if (commit_tree (sb .buf , active_cache_tree -> sha1 , parents , commit_sha1 ,
1355
- fmt_ident (author_name , author_email , author_date ,
1356
- IDENT_ERROR_ON_NO_NAME ))) {
1365
+ author_ident .buf )) {
1357
1366
rollback_index_files ();
1358
1367
die ("failed to write commit object" );
1359
1368
}
1369
+ strbuf_release (& author_ident );
1360
1370
1361
1371
ref_lock = lock_any_ref_for_update ("HEAD" ,
1362
1372
initial_commit ? NULL : head_sha1 ,
0 commit comments