Re: [PATCH v2 03/10] mailmap: remove email copy and length limitation
- From
Antoine Pelisse <apelisse@gmail.com>
- Date
- Jan 9, 2013, 17:35 UTC
- Message-ID
- <CALWbr2wp7rV7Vh0=gwmWaZE5hLHQNL+UciDsL+z-1GyhS9pTkQ@mail.gmail.com>
- In-Reply-To
- <1357603821-8647-4-git-send-email-gitster@pobox.com>
Show 10 quoted lines
> +static struct string_list_item *lookup_prefix(struct string_list *map,
> + const char *string, size_t len)
> +{
> + int i = string_list_find_insert_index(map, string, 1);
> + if (i < 0) {
> + /* exact match */
> + i = -1 - i;
> + /* does it match exactly? */
> + if (!map->items[i].string[len])
> + return &map->items[i];I'm not sure the condition above is necessary, as I don't see why an exact match would not be an exact match. We have to trust the cmp function (that mailmap sets itself) to not return 0 when the lengths are different.
Show 27 quoted lines
> + }
> +
> + /*
> + * i is at the exact match to an overlong key, or
> + * location the possibly overlong key would be inserted,
> + * which must be after the real location of the key.
> + */
> + while (0 <= --i && i < map->nr) {
> + int cmp = strncasecmp(map->items[i].string, string, len);
> + if (cmp < 0)
> + /*
> + * "i" points at a key definitely below the prefix;
> + * the map does not have string[0:len] in it.
> + */
> + break;
> + else if (!cmp && !map->items[i].string[len])
> + /* found it */
> + return &map->items[i];
> + /*
> + * otherwise, the string at "i" may be string[0:len]
> + * followed by a string that sorts later than string[len:];
> + * keep trying.
> + */
> + }
> + return NULL;
> +}
> +I've tried to think about nasty use cases but everything seems fine.