git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/3 v2] mailmap: use higher level string list functions
       [not found] <xmqq3898w9v4.fsf@gitster.dls.corp.google.com>
@ 2014-11-24 21:52 ` Stefan Beller
  2014-11-25  2:36   ` Eric Sunshine
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Beller @ 2014-11-24 21:52 UTC (permalink / raw)
  To: marius, gitster, julian, git; +Cc: Stefan Beller

No 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.

Signed-off-by: Stefan Beller <sbeller@google.com>
---

Changes since Version 1:
* Remove declaration-after-statement.

 mailmap.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/mailmap.c b/mailmap.c
index 81890a6..3b00a65 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3 v2] mailmap: use higher level string list functions
  2014-11-24 21:52 ` [PATCH 2/3 v2] mailmap: use higher level string list functions Stefan Beller
@ 2014-11-25  2:36   ` Eric Sunshine
  2014-11-25  3:44     ` [PATCHv3 2/3] " Stefan Beller
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Sunshine @ 2014-11-25  2:36 UTC (permalink / raw)
  To: Stefan Beller; +Cc: Marius Storm-Olsen, Junio C Hamano, julian, Git List

On Mon, Nov 24, 2014 at 4:52 PM, Stefan Beller <sbeller@google.com> wrote:
> No functional changes intended. This commit makes user of higher level

s/user/use/

> 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 <sbeller@google.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCHv3 2/3] mailmap: use higher level string list functions
  2014-11-25  2:36   ` Eric Sunshine
@ 2014-11-25  3:44     ` Stefan Beller
       [not found]       ` <CAO2U3QjNua2HvJKLnq80mPFEp931yLzHKENKo-LHm4CFZWRhBA@mail.gmail.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Beller @ 2014-11-25  3:44 UTC (permalink / raw)
  To: marius, gitster, julian, sunshine, git; +Cc: Stefan Beller

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 <sbeller@google.com>
---
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(-)

diff --git a/mailmap.c b/mailmap.c
index 81890a6..3b00a65 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCHv3 2/3] mailmap: use higher level string list functions
       [not found]       ` <CAO2U3QjNua2HvJKLnq80mPFEp931yLzHKENKo-LHm4CFZWRhBA@mail.gmail.com>
@ 2014-11-27 19:57         ` Eric Sunshine
  2014-12-01  0:47           ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Sunshine @ 2014-11-27 19:57 UTC (permalink / raw)
  To: Michael Blume
  Cc: Stefan Beller, Marius Storm-Olsen, Junio C Hamano,
	Julian Phillips, Git List

On Thu, Nov 27, 2014 at 1:44 PM, Michael Blume <blume.mike@gmail.com> wrote:
> 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


> On Mon Nov 24 2014 at 7:48:27 PM Stefan Beller <sbeller@google.com> wrote:
>>
>> 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 <sbeller@google.com>
>> ---
>> 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(-)
>>
>> diff --git a/mailmap.c b/mailmap.c
>> index 81890a6..3b00a65 100644
>> --- a/mailmap.c
>> +++ b/mailmap.c
>> @@ -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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCHv3 2/3] mailmap: use higher level string list functions
  2014-11-27 19:57         ` Eric Sunshine
@ 2014-12-01  0:47           ` Junio C Hamano
  2014-12-01  2:33             ` Stefan Beller
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2014-12-01  0:47 UTC (permalink / raw)
  To: Eric Sunshine
  Cc: Michael Blume, Stefan Beller, Marius Storm-Olsen, Julian Phillips,
	Git List

Eric Sunshine <sunshine@sunshineco.com> writes:

> On Thu, Nov 27, 2014 at 1:44 PM, Michael Blume <blume.mike@gmail.com> wrote:
>> 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(-)

diff --git a/mailmap.c b/mailmap.c
index 3b00a65..cb26af0 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -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)

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCHv3 2/3] mailmap: use higher level string list functions
  2014-12-01  0:47           ` Junio C Hamano
@ 2014-12-01  2:33             ` Stefan Beller
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Beller @ 2014-12-01  2:33 UTC (permalink / raw)
  To: Junio C Hamano, Eric Sunshine
  Cc: Michael Blume, Stefan Beller, Marius Storm-Olsen, Julian Phillips,
	Git List

On 30.11.2014 16:47, Junio C Hamano wrote:
> Eric Sunshine <sunshine@sunshineco.com> writes:
> 
>> On Thu, Nov 27, 2014 at 1:44 PM, Michael Blume <blume.mike@gmail.com> wrote:
>>> 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.

> 
>  mailmap.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/mailmap.c b/mailmap.c
> index 3b00a65..cb26af0 100644
> --- a/mailmap.c
> +++ b/mailmap.c
> @@ -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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-12-01  2:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <xmqq3898w9v4.fsf@gitster.dls.corp.google.com>
2014-11-24 21:52 ` [PATCH 2/3 v2] mailmap: use higher level string list functions Stefan Beller
2014-11-25  2:36   ` Eric Sunshine
2014-11-25  3:44     ` [PATCHv3 2/3] " Stefan Beller
     [not found]       ` <CAO2U3QjNua2HvJKLnq80mPFEp931yLzHKENKo-LHm4CFZWRhBA@mail.gmail.com>
2014-11-27 19:57         ` Eric Sunshine
2014-12-01  0:47           ` Junio C Hamano
2014-12-01  2:33             ` Stefan Beller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).