[PATCH 1/1] RFC: git: update to v2.41.0-rc2

Christian Hesse list at eworm.de
Fri May 26 14:06:53 UTC 2023


"Jason A. Donenfeld" <Jason at zx2c4.com> on Fri, 2023/05/26 15:42:
> On Fri, May 26, 2023 at 1:07 PM Christian Hesse <list at eworm.de> wrote:
> > @@ -564,9 +566,11 @@ char *get_mimetype_for_filename(const char *filename)
> >         while (fgets(line, sizeof(line), file)) {
> >                 if (!line[0] || line[0] == '#')
> >                         continue;
> > -               mimetype = strtok_r(line, " \t\r\n", &saveptr);
> > -               while ((token = strtok_r(NULL, " \t\r\n", &saveptr))) {
> > -                       if (!strcasecmp(ext, token)) {
> > +               string_list_split_in_place(&list, line, " \t\r\n", -1);
> > +               string_list_remove_empty_items(&list, 0);
> > +               mimetype = list.items[0].string;
> > +               for (i = 1; i < list.nr; i++) {
> > +                       if (!strcasecmp(ext, list.items[i].string)) {
> >                                 fclose(file);
> >                                 return xstrdup(mimetype);
> >                         }  
> 
> What's the motivation here exactly? string_list allocates, I believe,
> for its items array even if you set nostrdup, so that code probably
> needs a free path. But also, what's the point of doing the splitting
> up front and then iterating, rather than just munging the string like
> usual with strtok_r?

Well, `strtok_r()` is now banned...

https://github.com/gitster/git/commit/60ff56f50372c1498718938ef504e744fe011ffb

... and the commit messages suggests to use `string_list_split_in_place()`
instead. In contrast to `string_list_split()` it does not allocate but splits
- as the name suggests - in place. From `string-list.h`:

> Like string_list_split(), except that string is split in-place: the
> delimiter characters in string are overwritten with NULs, and the
> new string_list_items point into string (which therefore must not
> be modified or freed while the string_list is in use).
> list->strdup_strings must *not* be set.

So we should be fine with the change, no?
-- 
main(a){char*c=/*    Schoene Gruesse                         */"B?IJj;MEH"
"CX:;",b;for(a/*    Best regards             my address:    */=0;b=c[a++];)
putchar(b-1/(/*    Chris            cc -ox -xc - && ./x    */b/42*2-3)*42);}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20230526/621c7b2b/attachment.sig>


More information about the CGit mailing list