@@ -140,6 +140,9 @@ static struct used_atom {
140
140
enum { O_FULL , O_LENGTH , O_SHORT } option ;
141
141
unsigned int length ;
142
142
} objectname ;
143
+ struct email_option {
144
+ enum { EO_RAW , EO_TRIM , EO_LOCALPART } option ;
145
+ } email_option ;
143
146
struct refname_atom refname ;
144
147
char * head ;
145
148
} u ;
@@ -377,6 +380,20 @@ static int objectname_atom_parser(const struct ref_format *format, struct used_a
377
380
return 0 ;
378
381
}
379
382
383
+ static int person_email_atom_parser (const struct ref_format * format , struct used_atom * atom ,
384
+ const char * arg , struct strbuf * err )
385
+ {
386
+ if (!arg )
387
+ atom -> u .email_option .option = EO_RAW ;
388
+ else if (!strcmp (arg , "trim" ))
389
+ atom -> u .email_option .option = EO_TRIM ;
390
+ else if (!strcmp (arg , "localpart" ))
391
+ atom -> u .email_option .option = EO_LOCALPART ;
392
+ else
393
+ return strbuf_addf_ret (err , -1 , _ ("unrecognized email option: %s" ), arg );
394
+ return 0 ;
395
+ }
396
+
380
397
static int refname_atom_parser (const struct ref_format * format , struct used_atom * atom ,
381
398
const char * arg , struct strbuf * err )
382
399
{
@@ -488,15 +505,15 @@ static struct {
488
505
{ "tag" , SOURCE_OBJ },
489
506
{ "author" , SOURCE_OBJ },
490
507
{ "authorname" , SOURCE_OBJ },
491
- { "authoremail" , SOURCE_OBJ },
508
+ { "authoremail" , SOURCE_OBJ , FIELD_STR , person_email_atom_parser },
492
509
{ "authordate" , SOURCE_OBJ , FIELD_TIME },
493
510
{ "committer" , SOURCE_OBJ },
494
511
{ "committername" , SOURCE_OBJ },
495
- { "committeremail" , SOURCE_OBJ },
512
+ { "committeremail" , SOURCE_OBJ , FIELD_STR , person_email_atom_parser },
496
513
{ "committerdate" , SOURCE_OBJ , FIELD_TIME },
497
514
{ "tagger" , SOURCE_OBJ },
498
515
{ "taggername" , SOURCE_OBJ },
499
- { "taggeremail" , SOURCE_OBJ },
516
+ { "taggeremail" , SOURCE_OBJ , FIELD_STR , person_email_atom_parser },
500
517
{ "taggerdate" , SOURCE_OBJ , FIELD_TIME },
501
518
{ "creator" , SOURCE_OBJ },
502
519
{ "creatordate" , SOURCE_OBJ , FIELD_TIME },
@@ -1037,16 +1054,35 @@ static const char *copy_name(const char *buf)
1037
1054
return xstrdup ("" );
1038
1055
}
1039
1056
1040
- static const char * copy_email (const char * buf )
1057
+ static const char * copy_email (const char * buf , struct used_atom * atom )
1041
1058
{
1042
1059
const char * email = strchr (buf , '<' );
1043
1060
const char * eoemail ;
1044
1061
if (!email )
1045
1062
return xstrdup ("" );
1046
- eoemail = strchr (email , '>' );
1063
+ switch (atom -> u .email_option .option ) {
1064
+ case EO_RAW :
1065
+ eoemail = strchr (email , '>' );
1066
+ if (eoemail )
1067
+ eoemail ++ ;
1068
+ break ;
1069
+ case EO_TRIM :
1070
+ email ++ ;
1071
+ eoemail = strchr (email , '>' );
1072
+ break ;
1073
+ case EO_LOCALPART :
1074
+ email ++ ;
1075
+ eoemail = strchr (email , '@' );
1076
+ if (!eoemail )
1077
+ eoemail = strchr (email , '>' );
1078
+ break ;
1079
+ default :
1080
+ BUG ("unknown email option" );
1081
+ }
1082
+
1047
1083
if (!eoemail )
1048
1084
return xstrdup ("" );
1049
- return xmemdupz (email , eoemail + 1 - email );
1085
+ return xmemdupz (email , eoemail - email );
1050
1086
}
1051
1087
1052
1088
static char * copy_subject (const char * buf , unsigned long len )
@@ -1116,7 +1152,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, void
1116
1152
continue ;
1117
1153
if (name [wholen ] != 0 &&
1118
1154
strcmp (name + wholen , "name" ) &&
1119
- strcmp (name + wholen , "email" ) &&
1155
+ ! starts_with (name + wholen , "email" ) &&
1120
1156
!starts_with (name + wholen , "date" ))
1121
1157
continue ;
1122
1158
if (!wholine )
@@ -1127,8 +1163,8 @@ static void grab_person(const char *who, struct atom_value *val, int deref, void
1127
1163
v -> s = copy_line (wholine );
1128
1164
else if (!strcmp (name + wholen , "name" ))
1129
1165
v -> s = copy_name (wholine );
1130
- else if (! strcmp (name + wholen , "email" ))
1131
- v -> s = copy_email (wholine );
1166
+ else if (starts_with (name + wholen , "email" ))
1167
+ v -> s = copy_email (wholine , & used_atom [ i ] );
1132
1168
else if (starts_with (name + wholen , "date" ))
1133
1169
grab_date (wholine , v , name );
1134
1170
}
0 commit comments