Thread (14 messages) flat view 14 messages, 3 authors, 2016-06-15

Re: [PATCH v2 03/10] mailmap: remove email copy and length limitation

From: Antoine Pelisse <hidden>
Date: 2016-06-15 22:55:42

+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.
+       }
+
+       /*
+        * 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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help