git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v6 3/5] promisor-remote: refactor how we parse advertised fields

From
Christian Couder <christian.couder@gmail.com>
Date
Jul 31, 2025, 07:22 UTC
Message-ID
<CAP8UFD0urQ_0dbHjyF16w9HeTVxwo_r3Yi62hbwcC49m=aPZHw@mail.gmail.com>
In-Reply-To
<xmqq1pq9xoqe.fsf@gitster.g>
On Mon, Jul 21, 2025 at 10:39 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 20 quoted lines
>
> Christian Couder <christian.couder@gmail.com> writes:
>
> > +static struct promisor_info *parse_one_advertised_remote(struct strbuf *remote_info)
> > +{
> > +     struct promisor_info *info = xcalloc(1, sizeof(*info));
> > +     struct strbuf **elems = strbuf_split(remote_info, ',');
>
> Unless the primary use of an array is about passing it around as a
> whole "set", name such a variable singular, so that element[4] can
> be naturally read as "fourth element"---"fourth elements" is not as
> natural.
>
> Also, can't we do this without strbuf_split(), which is a wrong API
> to use in general [*]?  strbuf is a very good data structure to work
> with when editing string data, but an array of strbuf is not---you
> would not be editing many pieces of string data in parallel.
>
>     [*] often string_list_split_in_place() is a better alternative,
>     especially when you do not have to heavily edit the substrings.
Yeah, string_list_split_in_place() is used in v7 and it looks better.
Show 13 quoted lines
> > +     for (size_t i = 0; elems[i]; i++) {
> > +             char *elem = elems[i]->buf;
> > +             char *value;
> > +             char *p = strchr(elem, '=');
>
>         The pointer elem points at the name, and the pointer p
>         points at the beginning of value, which could contain '='.
>
> > +             strbuf_strip_suffix(elems[i], ",");
>
> This does not even count as "editing"; split_in_place() would have
> removed the trailing comma (and replaced it with NUL to terminate
> the string).
Yeah, right. This is fixed in v7.
Show 23 quoted lines
> > +             if (!p) {
> > +                     warning(_("invalid element '%s' from remote info"), elem);
> > +                     continue;
> > +             }
>
>         elem pointed at "foo" or "foo,"; we may have stripped the
>         trailing comma, but we didn't see the equal sign to start
>         the value at all.  Bad input.
>
> > +             *p = '\0';
>
>         Terminate the name by replacing '=' with NUL.
>
> > +             value = url_percent_decode(p + 1);
>
>         Can this helper function fail and signal that it saw a
>         malformed data?  If not already, shouldn't it be taught to
>         do so?
>
> We are inventing the syntax for this data in this series, so if this
> helper takes garbage data silently, and if we are not willing to fix
> it, then we can even consider changing the syntax to something with
> a helper we can use that already has a good error checking.

I am not sure what the interface would look like. Should a version of url_percent_decode() that returns NULL in case of error would be enough, or should it use `return error("...");`in case of error?

And it seems to me that an error can only happen when the string passed to url_percent_decode() contains a '%' which is not followed by 2 hexadecimal characters, or do you see other possible errors?

For now I haven't changed this in v7, but I am open to suggestions about the best way to implement it in a v8 or maybe a separate series.

Show 18 quoted lines
> > +             if (!strcmp(elem, "name"))
> > +                     info->name = value;
> > +             else if (!strcmp(elem, "url"))
> > +                     info->url = value;
> > +             else
> > +                     free(value);
>
> As url_percent_decode() always allocate a new copy of string even
> when there is nothing to decode, value will always be an allocated
> string, and if we are not storing it away, it will leak.  The copies
> we kept in info->{name,url} are ours to own.  Makes sense.
>
> > +     strbuf_list_free(elems);
>
> And because [elem..p] (name) we only peeked, we can safely release
> the whole thing.  If you used string_list_split_in_place(), you
> would only free the string_list shell without having to free the
> underlying string.
Yeah, it's better with string_list_split_in_place().
Thanks.
Previous: Junio C HamanoNext: Christian Couder
Message 82 of 107 in “Make the "promisor-remote" capability support extra fields”
  1. 0/4 Make the "promisor-remote" capability support extra fieldsChristian Couder, Apr 14, 2025
  2. 1/4 config: move is_config_key_char() to "config.h"Christian Couder, Apr 14, 2025
  3. 2/4 promisor-remote: refactor to get rid of 'struct strvec'Christian Couder, Apr 14, 2025
  4. Patrick SteinhardtApr 22, 2025
  5. Christian CouderApr 29, 2025
  6. 3/4 promisor-remote: allow a server to advertise extra fieldsChristian Couder, Apr 14, 2025
  7. Junio C HamanoApr 14, 2025
  8. Patrick SteinhardtApr 22, 2025
  9. Christian CouderApr 29, 2025
  10. Christian CouderApr 29, 2025
  11. 4/4 promisor-remote: allow a client to check extra fieldsChristian Couder, Apr 14, 2025
  12. 0/3 Make the "promisor-remote" capability support more fieldsChristian Couder, Apr 29, 2025
  13. 1/3 promisor-remote: refactor to get rid of 'struct strvec'Christian Couder, Apr 29, 2025
  14. Patrick SteinhardtMay 7, 2025
  15. Christian CouderMay 19, 2025
  16. Karthik NayakMay 7, 2025
  17. Christian CouderMay 19, 2025
  18. 2/3 promisor-remote: allow a server to advertise more fieldsChristian Couder, Apr 29, 2025
  19. Patrick SteinhardtMay 7, 2025
  20. Christian CouderMay 19, 2025
  21. Patrick SteinhardtMay 27, 2025
  22. Junio C HamanoMay 27, 2025
  23. Christian CouderJun 11, 2025
  24. Karthik NayakMay 7, 2025
  25. Christian CouderMay 19, 2025
  26. 3/3 promisor-remote: allow a client to check fieldsChristian Couder, Apr 29, 2025
  27. Patrick SteinhardtMay 7, 2025
  28. Christian CouderMay 19, 2025
  29. Christian CouderMay 2, 2025
  30. 0/5 Make the "promisor-remote" capability support more fieldsChristian Couder, May 19, 2025
  31. 1/5 promisor-remote: refactor to get rid of 'struct strvec'Christian Couder, May 19, 2025
  32. Karthik NayakMay 20, 2025
  33. Christian CouderMay 20, 2025
  34. Junio C HamanoMay 20, 2025
  35. Christian CouderMay 21, 2025
  36. Junio C HamanoMay 21, 2025
  37. Christian CouderJun 11, 2025
  38. 2/5 promisor-remote: allow a server to advertise more fieldsChristian Couder, May 19, 2025
  39. Justin ToblerMay 21, 2025
  40. Christian CouderJun 11, 2025
  41. Patrick SteinhardtMay 27, 2025
  42. Christian CouderJun 11, 2025
  43. 3/5 promisor-remote: refactor how we parse advertised fieldsChristian Couder, May 19, 2025
  44. 4/5 promisor-remote: allow a client to check fieldsChristian Couder, May 19, 2025
  45. 5/5 promisor-remote: use string constants for 'name' and 'url' tooChristian Couder, May 19, 2025
  46. 0/5 Make the "promisor-remote" capability support more fieldsChristian Couder, Jun 11, 2025
  47. 1/5 promisor-remote: refactor to get rid of 'struct strvec'Christian Couder, Jun 11, 2025
  48. Karthik NayakJun 19, 2025
  49. Christian CouderJun 25, 2025
  50. Justin ToblerJun 23, 2025
  51. Christian CouderJun 25, 2025
  52. 2/5 promisor-remote: allow a server to advertise more fieldsChristian Couder, Jun 11, 2025
  53. Karthik NayakJun 19, 2025
  54. Christian CouderJun 25, 2025
  55. Justin ToblerJun 23, 2025
  56. Christian CouderJun 25, 2025
  57. 3/5 promisor-remote: refactor how we parse advertised fieldsChristian Couder, Jun 11, 2025
  58. 4/5 promisor-remote: allow a client to check fieldsChristian Couder, Jun 11, 2025
  59. 5/5 promisor-remote: use string constants for 'name' and 'url' tooChristian Couder, Jun 11, 2025
  60. Karthik NayakJun 19, 2025
  61. 0/5 Make the "promisor-remote" capability support more fieldsChristian Couder, Jun 25, 2025
  62. 1/5 promisor-remote: refactor to get rid of 'struct strvec'Christian Couder, Jun 25, 2025
  63. Junio C HamanoJun 25, 2025
  64. Christian CouderJul 21, 2025
  65. 3/5 promisor-remote: refactor how we parse advertised fieldsChristian Couder, Jun 25, 2025
  66. 2/5 promisor-remote: allow a server to advertise more fieldsChristian Couder, Jun 25, 2025
  67. Junio C HamanoJun 25, 2025
  68. Christian CouderJul 21, 2025
  69. Junio C HamanoJul 21, 2025
  70. Christian CouderJul 31, 2025
  71. Jean-Noël AvilaJun 27, 2025
  72. Christian CouderJul 21, 2025
  73. 4/5 promisor-remote: allow a client to check fieldsChristian Couder, Jun 25, 2025
  74. 5/5 promisor-remote: use string constants for 'name' and 'url' tooChristian Couder, Jun 25, 2025
  75. Junio C HamanoJul 7, 2025
  76. Christian CouderJul 8, 2025
  77. 0/5 Make the "promisor-remote" capability support more fieldsChristian Couder, Jul 21, 2025
  78. 1/5 promisor-remote: refactor to get rid of 'struct strvec'Christian Couder, Jul 21, 2025
  79. 2/5 promisor-remote: allow a server to advertise more fieldsChristian Couder, Jul 21, 2025
  80. 3/5 promisor-remote: refactor how we parse advertised fieldsChristian Couder, Jul 21, 2025
  81. Junio C HamanoJul 21, 2025
  82. Christian CouderJul 31, 2025
  83. 4/5 promisor-remote: allow a client to check fieldsChristian Couder, Jul 21, 2025
  84. Junio C HamanoJul 21, 2025
  85. Christian CouderJul 31, 2025
  86. 5/5 promisor-remote: use string constants for 'name' and 'url' tooChristian Couder, Jul 21, 2025
  87. Junio C HamanoJul 21, 2025
  88. 0/5 Make the "promisor-remote" capability support more fieldsChristian Couder, Jul 31, 2025
  89. 1/5 promisor-remote: refactor to get rid of 'struct strvec'Christian Couder, Jul 31, 2025
  90. 2/5 promisor-remote: allow a server to advertise more fieldsChristian Couder, Jul 31, 2025
  91. 3/5 promisor-remote: refactor how we parse advertised fieldsChristian Couder, Jul 31, 2025
  92. Junio C HamanoJul 31, 2025
  93. Christian CouderSep 8, 2025
  94. 4/5 promisor-remote: allow a client to check fieldsChristian Couder, Jul 31, 2025
  95. 5/5 promisor-remote: use string constants for 'name' and 'url' tooChristian Couder, Jul 31, 2025
  96. Junio C HamanoJul 31, 2025
  97. Junio C HamanoAug 28, 2025
  98. Christian CouderSep 8, 2025
  99. 0/7 Make the "promisor-remote" capability support more fieldsChristian Couder, Sep 8, 2025
  100. 1/7 promisor-remote: refactor to get rid of 'struct strvec'Christian Couder, Sep 8, 2025
  101. 2/7 promisor-remote: allow a server to advertise more fieldsChristian Couder, Sep 8, 2025
  102. 3/7 promisor-remote: use string constants for 'name' and 'url' tooChristian Couder, Sep 8, 2025
  103. 4/7 promisor-remote: refactor how we parse advertised fieldsChristian Couder, Sep 8, 2025
  104. 5/7 promisor-remote: use string_list_split() in filter_promisor_remote()Christian Couder, Sep 8, 2025
  105. 6/7 promisor-remote: allow a client to check fieldsChristian Couder, Sep 8, 2025
  106. 7/7 promisor-remote: use string_list_split() in mark_remotes_as_accepted()Christian Couder, Sep 8, 2025
  107. Junio C HamanoSep 8, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.