1111static struct strbuf git_default_name = STRBUF_INIT ;
1212static struct strbuf git_default_email = STRBUF_INIT ;
1313static struct strbuf git_default_date = STRBUF_INIT ;
14+ static struct strbuf git_author_name = STRBUF_INIT ;
15+ static struct strbuf git_author_email = STRBUF_INIT ;
16+ static struct strbuf git_committer_name = STRBUF_INIT ;
17+ static struct strbuf git_committer_email = STRBUF_INIT ;
1418static int default_email_is_bogus ;
1519static int default_name_is_bogus ;
1620
@@ -355,13 +359,19 @@ N_("\n"
355359 "\n" );
356360
357361const char * fmt_ident (const char * name , const char * email ,
358- const char * date_str , int flag )
362+ enum want_ident whose_ident , const char * date_str , int flag )
359363{
360364 static struct strbuf ident = STRBUF_INIT ;
361365 int strict = (flag & IDENT_STRICT );
362366 int want_date = !(flag & IDENT_NO_DATE );
363367 int want_name = !(flag & IDENT_NO_NAME );
364368
369+ if (!email ) {
370+ if (whose_ident == WANT_AUTHOR_IDENT && git_author_email .len )
371+ email = git_author_email .buf ;
372+ else if (whose_ident == WANT_COMMITTER_IDENT && git_committer_email .len )
373+ email = git_committer_email .buf ;
374+ }
365375 if (!email ) {
366376 if (strict && ident_use_config_only
367377 && !(ident_config_given & IDENT_MAIL_GIVEN )) {
@@ -377,6 +387,13 @@ const char *fmt_ident(const char *name, const char *email,
377387
378388 if (want_name ) {
379389 int using_default = 0 ;
390+ if (!name ) {
391+ if (whose_ident == WANT_AUTHOR_IDENT && git_author_name .len )
392+ name = git_author_name .buf ;
393+ else if (whose_ident == WANT_COMMITTER_IDENT &&
394+ git_committer_name .len )
395+ name = git_committer_name .buf ;
396+ }
380397 if (!name ) {
381398 if (strict && ident_use_config_only
382399 && !(ident_config_given & IDENT_NAME_GIVEN )) {
@@ -425,9 +442,25 @@ const char *fmt_ident(const char *name, const char *email,
425442 return ident .buf ;
426443}
427444
428- const char * fmt_name (const char * name , const char * email )
445+ const char * fmt_name (enum want_ident whose_ident )
429446{
430- return fmt_ident (name , email , NULL , IDENT_STRICT | IDENT_NO_DATE );
447+ char * name = NULL ;
448+ char * email = NULL ;
449+
450+ switch (whose_ident ) {
451+ case WANT_BLANK_IDENT :
452+ break ;
453+ case WANT_AUTHOR_IDENT :
454+ name = getenv ("GIT_AUTHOR_NAME" );
455+ email = getenv ("GIT_AUTHOR_EMAIL" );
456+ break ;
457+ case WANT_COMMITTER_IDENT :
458+ name = getenv ("GIT_COMMITTER_NAME" );
459+ email = getenv ("GIT_COMMITTER_EMAIL" );
460+ break ;
461+ }
462+ return fmt_ident (name , email , whose_ident , NULL ,
463+ IDENT_STRICT | IDENT_NO_DATE );
431464}
432465
433466const char * git_author_info (int flag )
@@ -438,6 +471,7 @@ const char *git_author_info(int flag)
438471 author_ident_explicitly_given |= IDENT_MAIL_GIVEN ;
439472 return fmt_ident (getenv ("GIT_AUTHOR_NAME" ),
440473 getenv ("GIT_AUTHOR_EMAIL" ),
474+ WANT_AUTHOR_IDENT ,
441475 getenv ("GIT_AUTHOR_DATE" ),
442476 flag );
443477}
@@ -450,6 +484,7 @@ const char *git_committer_info(int flag)
450484 committer_ident_explicitly_given |= IDENT_MAIL_GIVEN ;
451485 return fmt_ident (getenv ("GIT_COMMITTER_NAME" ),
452486 getenv ("GIT_COMMITTER_EMAIL" ),
487+ WANT_COMMITTER_IDENT ,
453488 getenv ("GIT_COMMITTER_DATE" ),
454489 flag );
455490}
@@ -473,10 +508,45 @@ int author_ident_sufficiently_given(void)
473508 return ident_is_sufficient (author_ident_explicitly_given );
474509}
475510
476- int git_ident_config (const char * var , const char * value , void * data )
511+ static int set_ident (const char * var , const char * value )
477512{
478- if (!strcmp (var , "user.useconfigonly" )) {
479- ident_use_config_only = git_config_bool (var , value );
513+ if (!strcmp (var , "author.name" )) {
514+ if (!value )
515+ return config_error_nonbool (var );
516+ strbuf_reset (& git_author_name );
517+ strbuf_addstr (& git_author_name , value );
518+ author_ident_explicitly_given |= IDENT_NAME_GIVEN ;
519+ ident_config_given |= IDENT_NAME_GIVEN ;
520+ return 0 ;
521+ }
522+
523+ if (!strcmp (var , "author.email" )) {
524+ if (!value )
525+ return config_error_nonbool (var );
526+ strbuf_reset (& git_author_email );
527+ strbuf_addstr (& git_author_email , value );
528+ author_ident_explicitly_given |= IDENT_MAIL_GIVEN ;
529+ ident_config_given |= IDENT_MAIL_GIVEN ;
530+ return 0 ;
531+ }
532+
533+ if (!strcmp (var , "committer.name" )) {
534+ if (!value )
535+ return config_error_nonbool (var );
536+ strbuf_reset (& git_committer_name );
537+ strbuf_addstr (& git_committer_name , value );
538+ committer_ident_explicitly_given |= IDENT_NAME_GIVEN ;
539+ ident_config_given |= IDENT_NAME_GIVEN ;
540+ return 0 ;
541+ }
542+
543+ if (!strcmp (var , "committer.email" )) {
544+ if (!value )
545+ return config_error_nonbool (var );
546+ strbuf_reset (& git_committer_email );
547+ strbuf_addstr (& git_committer_email , value );
548+ committer_ident_explicitly_given |= IDENT_MAIL_GIVEN ;
549+ ident_config_given |= IDENT_MAIL_GIVEN ;
480550 return 0 ;
481551 }
482552
@@ -505,6 +575,16 @@ int git_ident_config(const char *var, const char *value, void *data)
505575 return 0 ;
506576}
507577
578+ int git_ident_config (const char * var , const char * value , void * data )
579+ {
580+ if (!strcmp (var , "user.useconfigonly" )) {
581+ ident_use_config_only = git_config_bool (var , value );
582+ return 0 ;
583+ }
584+
585+ return set_ident (var , value );
586+ }
587+
508588static int buf_cmp (const char * a_begin , const char * a_end ,
509589 const char * b_begin , const char * b_end )
510590{
0 commit comments