mailmap: use higher level string list functions
PATCH v2 2/3 mailmap: use higher level string list functions
In reply to a message not in the archiveNo functional changes intended. This commit makes user of higher level and better documented functions of the string list API, so the code is more understandable.
Note that also the required computational amount should not change in principal as we need to look up the item no matter if it is already part of the list or not. Once looked up, insertion comes for free.
---
Changes since Version 1:
* Remove declaration-after-statement.
mailmap.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
mailmap.c +4 -8
@@ -71,6 +71,7 @@ static void add_mapping(struct string_list *map, char *old_name, char *old_email) { struct mailmap_entry *me; +struct string_list_item *item;int index;if (old_email ==NULL ) {
@@ -78,15 +79,10 @@ static void add_mapping(struct string_list *map, new_email =NULL ; } -if ((index =string_list_find_insert_index (map, old_email,1 )) <0 ) { -/* mailmap entry exists, invert index value */ - index =-1 - index; - me = (struct mailmap_entry *)map->items[index].util; + item =string_list_insert (map, old_email); +if (item->util) { + me = (struct mailmap_entry *)item->util; }else { -/* create mailmap entry */ -struct string_list_item *item; - - item =string_list_insert_at_index (map, index, old_email); me =xcalloc (1 ,sizeof (struct mailmap_entry )); me->namemap.strdup_strings =1 ; me->namemap.cmp = namemap_cmp;
Signature · 1 line
2.2.0.rc3
Quoted 1 line · Stefan Beller
No functional changes intended. This commit makes user of higher level
s/user/use/
Quoted 8 lines
and better documented functions of the string list API, so the code is more understandable.
Note that also the required computational amount should not change in principal as we need to look up the item no matter if it is already part of the list or not. Once looked up, insertion comes for free.
Signed-off-by Stefan Beller <[email protected]>
PATCH v3 2/3 mailmap: use higher level string list functions
No functional changes intended. This commit makes use of higher level and better documented functions of the string list API, so the code is more understandable.
Note that also the required computational amount should not change in principal as we need to look up the item no matter if it is already part of the list or not. Once looked up, insertion comes for free.
---
Changes since Version 1:
* Remove declaration-after-statement.
Changes Version 1 to Version 2:
* typo in commit message
mailmap.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
mailmap.c +4 -8
@@ -71,6 +71,7 @@ static void add_mapping(struct string_list *map, char *old_name, char *old_email) { struct mailmap_entry *me; +struct string_list_item *item;int index;if (old_email ==NULL ) {
@@ -78,15 +79,10 @@ static void add_mapping(struct string_list *map, new_email =NULL ; } -if ((index =string_list_find_insert_index (map, old_email,1 )) <0 ) { -/* mailmap entry exists, invert index value */ - index =-1 - index; - me = (struct mailmap_entry *)map->items[index].util; + item =string_list_insert (map, old_email); +if (item->util) { + me = (struct mailmap_entry *)item->util; }else { -/* create mailmap entry */ -struct string_list_item *item; - - item =string_list_insert_at_index (map, index, old_email); me =xcalloc (1 ,sizeof (struct mailmap_entry )); me->namemap.strdup_strings =1 ; me->namemap.cmp = namemap_cmp;
Signature · 1 line
2.2.0.rc3
Quoted 3 lines · Michael Blume
The variable index seems to be unused/uninitialized now -- it's still printed in debug messages, but if I'm reading correctly, its contents are going to be nonsense.
Nice catch.
(Aside: Please don't top-post on this list [1].)
[1]: https://lkml.org/lkml/2005/1/11/111
Quoted 55 lines · Stefan Beller
Quoted 54 lines
No functional changes intended. This commit makes use of higher level and better documented functions of the string list API, so the code is more understandable.
Note that also the required computational amount should not change in principal as we need to look up the item no matter if it is already part of the list or not. Once looked up, insertion comes for free.
Signed-off-by Stefan Beller <[email protected]>---
Changes since Version 1:
* Remove declaration-after-statement.Changes Version 1 to Version 2:
* typo in commit messagemailmap.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)mailmap.c +4
-8@@ -71,6 +71,7 @@ static void add_mapping(struct string_list *map, char *old_name, char *old_email) { struct mailmap_entry *me; +struct string_list_item *item;int index;if (old_email ==NULL ) {@@ -78,15 +79,10 @@ static void add_mapping(struct string_list *map, new_email =NULL ; } -if ((index =string_list_find_insert_index (map, old_email,1 )) < 0) { -/* mailmap entry exists, invert index value */ - index =-1 - index; - me = (struct mailmap_entry *)map->items[index].util; + item =string_list_insert (map, old_email); +if (item->util) { + me = (struct mailmap_entry *)item->util; }else { -/* create mailmap entry */ -struct string_list_item *item; - - item =string_list_insert_at_index (map, index, old_email); me =xcalloc (1 ,sizeof (struct mailmap_entry )); me->namemap.strdup_strings =1 ;me->namemap.cmp = namemap_cmp;--
2.2.0.rc3
Quoted 6 lines · Eric Sunshine
Quoted 3 lines · Michael Blume
The variable index seems to be unused/uninitialized now -- it's still printed in debug messages, but if I'm reading correctly, its contents are going to be nonsense.
Nice catch.
Let's do something like this squashed in, then.
mailmap.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
mailmap.c +3 -4
@@ -90,8 +90,8 @@ static void add_mapping(struct string_list *map, }if (old_name ==NULL ) { -debug_mm ("mailmap: adding (simple) entry for %s at index %d\n" , - old_email, index); +debug_mm ("mailmap: adding (simple) entry for '%s'\n" , old_email); +/* Replace current name and new email for simple entry */ if (new_name) {free (me->name);
@@ -103,8 +103,7 @@ static void add_mapping(struct string_list *map, } }else {struct mailmap_info *mi =xcalloc (1 ,sizeof (struct mailmap_info )); -debug_mm ("mailmap: adding (complex) entry for %s at index %d\n" , - old_email, index); +debug_mm ("mailmap: adding (complex) entry for '%s'\n" , old_email);if (new_name) mi->name =xstrdup (new_name);if (new_email)
Quoted 10 lines · Junio C Hamano
Quoted 6 lines · Eric Sunshine
Quoted 3 lines · Michael Blume
The variable index seems to be unused/uninitialized now -- it's still printed in debug messages, but if I'm reading correctly, its contents are going to be nonsense.
Nice catch.
Let's do something like this squashed in, then.
Michael, thanks for catching that!
Junio, the squash-in looks fine with me.
Quoted 34 lines
mailmap.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)mailmap.c +3
-5@@ -90,8 +90,8 @@ static void add_mapping(struct string_list *map, }if (old_name ==NULL ) { -debug_mm ("mailmap: adding (simple) entry for %s at index %d\n" , - old_email, index); +debug_mm ("mailmap: adding (simple) entry for '%s'\n" , old_email); +/* Replace current name and new email for simple entry */ if (new_name) {free (me->name);@@ -103,8 +103,7 @@ static void add_mapping(struct string_list *map, } }else {struct mailmap_info *mi =xcalloc (1 ,sizeof (struct mailmap_info )); -debug_mm ("mailmap: adding (complex) entry for %s at index %d\n" , - old_email, index); +debug_mm ("mailmap: adding (complex) entry for '%s'\n" , old_email);if (new_name) mi->name =xstrdup (new_name);if (new_email) --To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html