5
5
#define DEBUG_MAILMAP 0
6
6
#if DEBUG_MAILMAP
7
7
#define debug_mm (...) fprintf(stderr, __VA_ARGS__)
8
+ #define debug_str (X ) ((X) ? (X) : "(none)")
8
9
#else
9
10
static inline void debug_mm (const char * format , ...) {}
11
+ static inline const char * debug_str (const char * s ) { return s ; }
10
12
#endif
11
13
12
14
const char * git_mailmap_file ;
@@ -29,16 +31,20 @@ struct mailmap_entry {
29
31
static void free_mailmap_info (void * p , const char * s )
30
32
{
31
33
struct mailmap_info * mi = (struct mailmap_info * )p ;
32
- debug_mm ("mailmap: -- complex: '%s' -> '%s' <%s>\n" , s , mi -> name , mi -> email );
34
+ debug_mm ("mailmap: -- complex: '%s' -> '%s' <%s>\n" ,
35
+ s , debug_str (mi -> name ), debug_str (mi -> email ));
33
36
free (mi -> name );
34
37
free (mi -> email );
35
38
}
36
39
37
40
static void free_mailmap_entry (void * p , const char * s )
38
41
{
39
42
struct mailmap_entry * me = (struct mailmap_entry * )p ;
40
- debug_mm ("mailmap: removing entries for <%s>, with %d sub-entries\n" , s , me -> namemap .nr );
41
- debug_mm ("mailmap: - simple: '%s' <%s>\n" , me -> name , me -> email );
43
+ debug_mm ("mailmap: removing entries for <%s>, with %d sub-entries\n" ,
44
+ s , me -> namemap .nr );
45
+ debug_mm ("mailmap: - simple: '%s' <%s>\n" ,
46
+ debug_str (me -> name ), debug_str (me -> email ));
47
+
42
48
free (me -> name );
43
49
free (me -> email );
44
50
@@ -47,18 +53,11 @@ static void free_mailmap_entry(void *p, const char *s)
47
53
}
48
54
49
55
static void add_mapping (struct string_list * map ,
50
- char * new_name , char * new_email , char * old_name , char * old_email )
56
+ char * new_name , char * new_email ,
57
+ char * old_name , char * old_email )
51
58
{
52
59
struct mailmap_entry * me ;
53
60
int index ;
54
- char * p ;
55
-
56
- if (old_email )
57
- for (p = old_email ; * p ; p ++ )
58
- * p = tolower (* p );
59
- if (new_email )
60
- for (p = new_email ; * p ; p ++ )
61
- * p = tolower (* p );
62
61
63
62
if (old_email == NULL ) {
64
63
old_email = new_email ;
@@ -68,16 +67,21 @@ static void add_mapping(struct string_list *map,
68
67
if ((index = string_list_find_insert_index (map , old_email , 1 )) < 0 ) {
69
68
/* mailmap entry exists, invert index value */
70
69
index = -1 - index ;
70
+ me = (struct mailmap_entry * )map -> items [index ].util ;
71
71
} else {
72
72
/* create mailmap entry */
73
- struct string_list_item * item = string_list_insert_at_index (map , index , old_email );
74
- item -> util = xcalloc (1 , sizeof (struct mailmap_entry ));
75
- ((struct mailmap_entry * )item -> util )-> namemap .strdup_strings = 1 ;
73
+ struct string_list_item * item ;
74
+
75
+ item = string_list_insert_at_index (map , index , old_email );
76
+ me = xcalloc (1 , sizeof (struct mailmap_entry ));
77
+ me -> namemap .strdup_strings = 1 ;
78
+ me -> namemap .cmp = strcasecmp ;
79
+ item -> util = me ;
76
80
}
77
- me = (struct mailmap_entry * )map -> items [index ].util ;
78
81
79
82
if (old_name == NULL ) {
80
- debug_mm ("mailmap: adding (simple) entry for %s at index %d\n" , old_email , index );
83
+ debug_mm ("mailmap: adding (simple) entry for %s at index %d\n" ,
84
+ old_email , index );
81
85
/* Replace current name and new email for simple entry */
82
86
if (new_name ) {
83
87
free (me -> name );
@@ -89,7 +93,8 @@ static void add_mapping(struct string_list *map,
89
93
}
90
94
} else {
91
95
struct mailmap_info * mi = xcalloc (1 , sizeof (struct mailmap_info ));
92
- debug_mm ("mailmap: adding (complex) entry for %s at index %d\n" , old_email , index );
96
+ debug_mm ("mailmap: adding (complex) entry for %s at index %d\n" ,
97
+ old_email , index );
93
98
if (new_name )
94
99
mi -> name = xstrdup (new_name );
95
100
if (new_email )
@@ -98,11 +103,12 @@ static void add_mapping(struct string_list *map,
98
103
}
99
104
100
105
debug_mm ("mailmap: '%s' <%s> -> '%s' <%s>\n" ,
101
- old_name , old_email , new_name , new_email );
106
+ debug_str (old_name ), old_email ,
107
+ debug_str (new_name ), debug_str (new_email ));
102
108
}
103
109
104
110
static char * parse_name_and_email (char * buffer , char * * name ,
105
- char * * email , int allow_empty_email )
111
+ char * * email , int allow_empty_email )
106
112
{
107
113
char * left , * right , * nstart , * nend ;
108
114
* name = * email = NULL ;
@@ -122,7 +128,7 @@ static char *parse_name_and_email(char *buffer, char **name,
122
128
while (nend > nstart && isspace (* nend ))
123
129
-- nend ;
124
130
125
- * name = (nstart < nend ? nstart : NULL );
131
+ * name = (nstart <= nend ? nstart : NULL );
126
132
* email = left + 1 ;
127
133
* (nend + 1 ) = '\0' ;
128
134
* right ++ = '\0' ;
@@ -306,21 +312,25 @@ static struct string_list_item *lookup_prefix(struct string_list *map,
306
312
}
307
313
308
314
int map_user (struct string_list * map ,
309
- const char * * email , size_t * emaillen ,
310
- const char * * name , size_t * namelen )
315
+ const char * * email , size_t * emaillen ,
316
+ const char * * name , size_t * namelen )
311
317
{
312
318
struct string_list_item * item ;
313
319
struct mailmap_entry * me ;
314
320
315
321
debug_mm ("map_user: map '%.*s' <%.*s>\n" ,
316
- * name , * namelen , * emaillen , * email );
322
+ (int )* namelen , debug_str (* name ),
323
+ (int )* emaillen , debug_str (* email ));
317
324
318
325
item = lookup_prefix (map , * email , * emaillen );
319
326
if (item != NULL ) {
320
327
me = (struct mailmap_entry * )item -> util ;
321
328
if (me -> namemap .nr ) {
322
- /* The item has multiple items, so we'll look up on name too */
323
- /* If the name is not found, we choose the simple entry */
329
+ /*
330
+ * The item has multiple items, so we'll look up on
331
+ * name too. If the name is not found, we choose the
332
+ * simple entry.
333
+ */
324
334
struct string_list_item * subitem ;
325
335
subitem = lookup_prefix (& me -> namemap , * name , * namelen );
326
336
if (subitem )
@@ -341,8 +351,9 @@ int map_user(struct string_list *map,
341
351
* name = mi -> name ;
342
352
* namelen = strlen (* name );
343
353
}
344
- debug_mm ("map_user: to '%.*s' <.*%s>\n" , * namelen , * name ,
345
- * emaillen , * email );
354
+ debug_mm ("map_user: to '%.*s' <%.*s>\n" ,
355
+ (int )* namelen , debug_str (* name ),
356
+ (int )* emaillen , debug_str (* email ));
346
357
return 1 ;
347
358
}
348
359
debug_mm ("map_user: --\n" );
0 commit comments