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

Re: [PATCH v3 24/34] mailinfo: move content/content_top to struct mailinfo

From
Stefan Beller <sbeller@google.com>
Date
Oct 21, 2015, 20:36 UTC
Message-ID
<CAGZ79kbRLVaNNR=ZuMZNtJD2vorV5K1-wZ+R9CY5FY_zS3i95Q@mail.gmail.com>
In-Reply-To
<1445239731-10677-25-git-send-email-gitster@pobox.com>
On Mon, Oct 19, 2015 at 12:28 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 32 quoted lines
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  builtin/mailinfo.c | 45 ++++++++++++++++++++++++++-------------------
>  1 file changed, 26 insertions(+), 19 deletions(-)
>
> diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
> index 2c194da..ec65805 100644
> --- a/builtin/mailinfo.c
> +++ b/builtin/mailinfo.c
> @@ -7,6 +7,8 @@
>  #include "utf8.h"
>  #include "strbuf.h"
>
> +#define MAX_BOUNDARIES 5
> +
>  struct mailinfo {
>         FILE *input;
>         FILE *output;
> @@ -22,6 +24,8 @@ struct mailinfo {
>         int use_inbody_headers; /* defaults to 1 */
>         const char *metainfo_charset;
>
> +       struct strbuf *content[MAX_BOUNDARIES];
> +       struct strbuf **content_top;
>         struct strbuf charset;
>         char *message_id;
>         enum  {
> @@ -35,7 +39,6 @@ struct mailinfo {
>  };
>
>  #define MAX_HDR_PARSED 10
> -#define MAX_BOUNDARIES 5

Would it make sense to also move MAX_HDR_PARSED, such that we have all defines in one place? The previous patch moved HDR related stuff around, so either there or here?

Show 122 quoted lines
>
>  static void cleanup_space(struct strbuf *sb);
>
> @@ -180,10 +183,6 @@ static int slurp_attr(const char *line, const char *name, struct strbuf *attr)
>         return 1;
>  }
>
> -static struct strbuf *content[MAX_BOUNDARIES];
> -
> -static struct strbuf **content_top = content;
> -
>  static void handle_content_type(struct mailinfo *mi, struct strbuf *line)
>  {
>         struct strbuf *boundary = xmalloc(sizeof(struct strbuf));
> @@ -191,11 +190,11 @@ static void handle_content_type(struct mailinfo *mi, struct strbuf *line)
>
>         if (slurp_attr(line->buf, "boundary=", boundary)) {
>                 strbuf_insert(boundary, 0, "--", 2);
> -               if (++content_top >= &content[MAX_BOUNDARIES]) {
> +               if (++mi->content_top >= &mi->content[MAX_BOUNDARIES]) {
>                         fprintf(stderr, "Too many boundaries to handle\n");
>                         exit(1);
>                 }
> -               *content_top = boundary;
> +               *(mi->content_top) = boundary;
>                 boundary = NULL;
>         }
>         slurp_attr(line->buf, "charset=", &mi->charset);
> @@ -223,10 +222,12 @@ static void handle_content_transfer_encoding(struct mailinfo *mi,
>                 mi->transfer_encoding = TE_DONTCARE;
>  }
>
> -static int is_multipart_boundary(const struct strbuf *line)
> +static int is_multipart_boundary(struct mailinfo *mi, const struct strbuf *line)
>  {
> -       return (((*content_top)->len <= line->len) &&
> -               !memcmp(line->buf, (*content_top)->buf, (*content_top)->len));
> +       struct strbuf *content_top = *(mi->content_top);
> +
> +       return ((content_top->len <= line->len) &&
> +               !memcmp(line->buf, content_top->buf, content_top->len));
>  }
>
>  static void cleanup_subject(struct mailinfo *mi, struct strbuf *subject)
> @@ -799,7 +800,7 @@ static void handle_filter(struct mailinfo *mi, struct strbuf *line)
>  static int find_boundary(struct mailinfo *mi, struct strbuf *line)
>  {
>         while (!strbuf_getline(line, mi->input, '\n')) {
> -               if (*content_top && is_multipart_boundary(line))
> +               if (*(mi->content_top) && is_multipart_boundary(mi, line))
>                         return 1;
>         }
>         return 0;
> @@ -811,18 +812,18 @@ static int handle_boundary(struct mailinfo *mi, struct strbuf *line)
>
>         strbuf_addch(&newline, '\n');
>  again:
> -       if (line->len >= (*content_top)->len + 2 &&
> -           !memcmp(line->buf + (*content_top)->len, "--", 2)) {
> +       if (line->len >= (*(mi->content_top))->len + 2 &&
> +           !memcmp(line->buf + (*(mi->content_top))->len, "--", 2)) {
>                 /* we hit an end boundary */
>                 /* pop the current boundary off the stack */
> -               strbuf_release(*content_top);
> -               free(*content_top);
> -               *content_top = NULL;
> +               strbuf_release(*(mi->content_top));
> +               free(*(mi->content_top));
> +               *(mi->content_top) = NULL;
>
>                 /* technically won't happen as is_multipart_boundary()
>                    will fail first.  But just in case..
>                  */
> -               if (--content_top < content) {
> +               if (--mi->content_top < mi->content) {
>                         fprintf(stderr, "Detected mismatched boundaries, "
>                                         "can't recover\n");
>                         exit(1);
> @@ -857,14 +858,14 @@ static void handle_body(struct mailinfo *mi, struct strbuf *line)
>         struct strbuf prev = STRBUF_INIT;
>
>         /* Skip up to the first boundary */
> -       if (*content_top) {
> +       if (*(mi->content_top)) {
>                 if (!find_boundary(mi, line))
>                         goto handle_body_out;
>         }
>
>         do {
>                 /* process any boundary lines */
> -               if (*content_top && is_multipart_boundary(line)) {
> +               if (*(mi->content_top) && is_multipart_boundary(mi, line)) {
>                         /* flush any leftover */
>                         if (prev.len) {
>                                 handle_filter(mi, &prev);
> @@ -1028,6 +1029,7 @@ static void setup_mailinfo(struct mailinfo *mi)
>         strbuf_init(&mi->charset, 0);
>         mi->header_stage = 1;
>         mi->use_inbody_headers = 1;
> +       mi->content_top = mi->content;
>         git_config(git_mailinfo_config, &mi);
>  }
>
> @@ -1046,6 +1048,11 @@ static void clear_mailinfo(struct mailinfo *mi)
>         for (i = 0; mi->s_hdr_data[i]; i++)
>                 strbuf_release(mi->s_hdr_data[i]);
>         free(mi->s_hdr_data);
> +
> +       while (mi->content < mi->content_top) {
> +               free(*(mi->content_top));
> +               mi->content_top--;
> +       }
>  }
>
>  static const char mailinfo_usage[] =
> --
> 2.6.2-383-g144b2e6
>
> --
> 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
Previous: Junio C HamanoNext: Junio C Hamano
Message 102 of 124 in “mailinfo libification”
  1. 00/26 mailinfo libificationJunio C Hamano, Oct 13, 2015
  2. 01/26 mailinfo: remove a no-op call convert_to_utf8(it, "")Junio C Hamano, Oct 13, 2015
  3. 02/26 mailinfo: fix for off-by-one error in boundary stackJunio C Hamano, Oct 13, 2015
  4. Stefan BellerOct 14, 2015
  5. Junio C HamanoOct 14, 2015
  6. 03/26 mailinfo: fold decode_header_bq() into decode_header()Junio C Hamano, Oct 13, 2015
  7. 04/26 mailinfo: move handle_boundary() lowerJunio C Hamano, Oct 13, 2015
  8. 05/26 mailinfo: get rid of function-local static statesJunio C Hamano, Oct 13, 2015
  9. 06/26 mailinfo: always pass "line" as an argumentJunio C Hamano, Oct 13, 2015
  10. Stefan BellerOct 14, 2015
  11. Junio C HamanoOct 14, 2015
  12. 07/26 mailinfo: move global "line" into mailinfo() functionJunio C Hamano, Oct 13, 2015
  13. Stefan BellerOct 14, 2015
  14. 08/26 mailinfo: introduce "struct mailinfo" to hold globalsJunio C Hamano, Oct 13, 2015
  15. 09/26 mailinfo: move keep_subject & keep_non_patch_bracket to struct mailinfoJunio C Hamano, Oct 13, 2015
  16. 10/26 mailinfo: move global "FILE *fin, *fout" to struct mailinfoJunio C Hamano, Oct 13, 2015
  17. 11/26 mailinfo: move filter/header stage to struct mailinfoJunio C Hamano, Oct 13, 2015
  18. 12/26 mailinfo: move patch_lines to struct mailinfoJunio C Hamano, Oct 13, 2015
  19. 13/26 mailinfo: move add_message_id and message_id to struct mailinfoJunio C Hamano, Oct 13, 2015
  20. 14/26 mailinfo: move use_scissors and use_inbody_headers to struct mailinfoJunio C Hamano, Oct 13, 2015
  21. 15/26 mailinfo: move metainfo_charset to struct mailinfoJunio C Hamano, Oct 13, 2015
  22. 16/26 mailinfo: move transfer_encoding to struct mailinfoJunio C Hamano, Oct 13, 2015
  23. 17/26 mailinfo: move charset to struct mailinfoJunio C Hamano, Oct 13, 2015
  24. 18/26 mailinfo: handle_commit_msg() shouldn't be called after finding patchbreakJunio C Hamano, Oct 13, 2015
  25. 19/26 mailinfo: move cmitmsg and patchfile to struct mailinfoJunio C Hamano, Oct 13, 2015
  26. 27/26 mailinfo: close patchfileJunio C Hamano, Oct 14, 2015
  27. 28/26 am: make direct call to mailinfoJunio C Hamano, Oct 14, 2015
  28. 20/26 mailinfo: move [ps]_hdr_data to struct mailinfoJunio C Hamano, Oct 13, 2015
  29. 21/26 mailinfo: keep the parsed log message in a strbufJunio C Hamano, Oct 13, 2015
  30. 22/26 mailinfo: move content/content_top to struct mailinfoJunio C Hamano, Oct 13, 2015
  31. 23/26 mailinfo: handle errors found in decode_header() betterJunio C Hamano, Oct 13, 2015
  32. 24/26 mailinfo: handle charset conversion errors in the callerJunio C Hamano, Oct 13, 2015
  33. 25/26 mailinfo: remove calls to exit() and die() deep in the callchainJunio C Hamano, Oct 13, 2015
  34. 26/26 mailinfo: libify the whole thingJunio C Hamano, Oct 13, 2015
  35. 00/31 libify mailinfo and call it directly from amJunio C Hamano, Oct 14, 2015
  36. 01/31 mailinfo: remove a no-op call convert_to_utf8(it, "")Junio C Hamano, Oct 14, 2015
  37. 02/31 mailinfo: fix for off-by-one error in boundary stackJunio C Hamano, Oct 14, 2015
  38. 03/31 mailinfo: explicitly close file handle to the patch outputJunio C Hamano, Oct 14, 2015
  39. 04/31 mailinfo: fold decode_header_bq() into decode_header()Junio C Hamano, Oct 14, 2015
  40. 05/31 mailinfo: move handle_boundary() lowerJunio C Hamano, Oct 14, 2015
  41. 06/31 mailinfo: get rid of function-local static statesJunio C Hamano, Oct 14, 2015
  42. 07/31 mailinfo: always pass "line" as an argumentJunio C Hamano, Oct 14, 2015
  43. 08/31 mailinfo: move global "line" into mailinfo() functionJunio C Hamano, Oct 14, 2015
  44. 09/31 mailinfo: introduce "struct mailinfo" to hold globalsJunio C Hamano, Oct 14, 2015
  45. 10/31 mailinfo: move keep_subject & keep_non_patch_bracket to struct mailinfoJunio C Hamano, Oct 14, 2015
  46. 11/31 mailinfo: move global "FILE *fin, *fout" to struct mailinfoJunio C Hamano, Oct 14, 2015
  47. 12/31 mailinfo: move filter/header stage to struct mailinfoJunio C Hamano, Oct 14, 2015
  48. 13/31 mailinfo: move patch_lines to struct mailinfoJunio C Hamano, Oct 14, 2015
  49. 14/31 mailinfo: move add_message_id and message_id to struct mailinfoJunio C Hamano, Oct 14, 2015
  50. 15/31 mailinfo: move use_scissors and use_inbody_headers to struct mailinfoJunio C Hamano, Oct 14, 2015
  51. 16/31 mailinfo: move metainfo_charset to struct mailinfoJunio C Hamano, Oct 14, 2015
  52. Eric SunshineOct 15, 2015
  53. 17/31 mailinfo: move transfer_encoding to struct mailinfoJunio C Hamano, Oct 14, 2015
  54. 18/31 mailinfo: move charset to struct mailinfoJunio C Hamano, Oct 14, 2015
  55. 19/31 mailinfo: handle_commit_msg() shouldn't be called after finding patchbreakJunio C Hamano, Oct 14, 2015
  56. 20/31 mailinfo: move cmitmsg and patchfile to struct mailinfoJunio C Hamano, Oct 14, 2015
  57. Junio C HamanoOct 14, 2015
  58. 21/31 mailinfo: move [ps]_hdr_data to struct mailinfoJunio C Hamano, Oct 14, 2015
  59. Junio C HamanoOct 14, 2015
  60. 22/31 mailinfo: keep the parsed log message in a strbufJunio C Hamano, Oct 14, 2015
  61. 23/31 mailinfo: move content/content_top to struct mailinfoJunio C Hamano, Oct 14, 2015
  62. 24/31 mailinfo: move read_one_header_line() closer to its callersJunio C Hamano, Oct 14, 2015
  63. 25/31 mailinfo: move check_header() after the helpers it usesJunio C Hamano, Oct 14, 2015
  64. 26/31 mailinfo: move cleanup_space() before its usersJunio C Hamano, Oct 14, 2015
  65. 27/31 mailinfo: move definition of MAX_HDR_PARSED to closer to its useJunio C Hamano, Oct 14, 2015
  66. 28/31 mailinfo: libifyJunio C Hamano, Oct 14, 2015
  67. 29/31 mailinfo: handle charset conversion errors in the callerJunio C Hamano, Oct 14, 2015
  68. 30/31 mailinfo: remove calls to exit() and die() deep in the callchainJunio C Hamano, Oct 14, 2015
  69. 31/31 am: make direct call to mailinfoJunio C Hamano, Oct 14, 2015
  70. 00/34 libify mailinfo and call it directly from amJunio C Hamano, Oct 19, 2015
  71. 01/34 mailinfo: remove a no-op call convert_to_utf8(it, "")Junio C Hamano, Oct 19, 2015
  72. 02/34 mailinfo: fold decode_header_bq() into decode_header()Junio C Hamano, Oct 19, 2015
  73. 03/34 mailinfo: fix an off-by-one error in the boundary stackJunio C Hamano, Oct 19, 2015
  74. 04/34 mailinfo: explicitly close file handle to the patch outputJunio C Hamano, Oct 19, 2015
  75. 05/34 mailinfo: move handle_boundary() lowerJunio C Hamano, Oct 19, 2015
  76. 06/34 mailinfo: get rid of function-local static statesJunio C Hamano, Oct 19, 2015
  77. 07/34 mailinfo: do not let handle_body() touch global "line" directlyJunio C Hamano, Oct 19, 2015
  78. 08/34 mailinfo: do not let handle_boundary() touch global "line" directlyJunio C Hamano, Oct 19, 2015
  79. 09/34 mailinfo: do not let find_boundary() touch global "line" directlyJunio C Hamano, Oct 19, 2015
  80. 10/34 mailinfo: move global "line" into mailinfo() functionJunio C Hamano, Oct 19, 2015
  81. Eric SunshineOct 19, 2015
  82. Junio C HamanoOct 20, 2015
  83. 11/34 mailinfo: introduce "struct mailinfo" to hold globalsJunio C Hamano, Oct 19, 2015
  84. 12/34 mailinfo: move keep_subject & keep_non_patch_bracket to struct mailinfoJunio C Hamano, Oct 19, 2015
  85. 13/34 mailinfo: move global "FILE *fin, *fout" to struct mailinfoJunio C Hamano, Oct 19, 2015
  86. 14/34 mailinfo: move filter/header stage to struct mailinfoJunio C Hamano, Oct 19, 2015
  87. Stefan BellerOct 21, 2015
  88. 15/34 mailinfo: move patch_lines to struct mailinfoJunio C Hamano, Oct 19, 2015
  89. 16/34 mailinfo: move add_message_id and message_id to struct mailinfoJunio C Hamano, Oct 19, 2015
  90. 17/34 mailinfo: move use_scissors and use_inbody_headers to struct mailinfoJunio C Hamano, Oct 19, 2015
  91. Stefan BellerOct 21, 2015
  92. Junio C HamanoOct 21, 2015
  93. 18/34 mailinfo: move metainfo_charset to struct mailinfoJunio C Hamano, Oct 19, 2015
  94. 19/34 mailinfo: move check for metainfo_charset to convert_to_utf8()Junio C Hamano, Oct 19, 2015
  95. Eric SunshineOct 19, 2015
  96. 20/34 mailinfo: move transfer_encoding to struct mailinfoJunio C Hamano, Oct 19, 2015
  97. 21/34 mailinfo: move charset to struct mailinfoJunio C Hamano, Oct 19, 2015
  98. 22/34 mailinfo: move cmitmsg and patchfile to struct mailinfoJunio C Hamano, Oct 19, 2015
  99. 23/34 mailinfo: move [ps]_hdr_data to struct mailinfoJunio C Hamano, Oct 19, 2015
  100. Stefan BellerOct 21, 2015
  101. 24/34 mailinfo: move content/content_top to struct mailinfoJunio C Hamano, Oct 19, 2015
  102. Stefan BellerOct 21, 2015
  103. Junio C HamanoOct 21, 2015
  104. Stefan BellerOct 21, 2015
  105. 25/34 mailinfo: handle_commit_msg() shouldn't be called after finding patchbreakJunio C Hamano, Oct 19, 2015
  106. 26/34 mailinfo: keep the parsed log message in a strbufJunio C Hamano, Oct 19, 2015
  107. 27/34 mailinfo: move read_one_header_line() closer to its callersJunio C Hamano, Oct 19, 2015
  108. 28/34 mailinfo: move check_header() after the helpers it usesJunio C Hamano, Oct 19, 2015
  109. 29/34 mailinfo: move cleanup_space() before its usersJunio C Hamano, Oct 19, 2015
  110. 30/34 mailinfo: move definition of MAX_HDR_PARSED closer to its useJunio C Hamano, Oct 19, 2015
  111. 31/34 mailinfo: libifyJunio C Hamano, Oct 19, 2015
  112. 32/34 mailinfo: handle charset conversion errors in the callerJunio C Hamano, Oct 19, 2015
  113. 33/34 mailinfo: remove calls to exit() and die() deep in the callchainJunio C Hamano, Oct 19, 2015
  114. 34/34 am: make direct call to mailinfoJunio C Hamano, Oct 19, 2015
  115. Junio C HamanoOct 20, 2015
  116. Stefan BellerOct 20, 2015
  117. Junio C HamanoOct 20, 2015
  118. Stefan BellerOct 20, 2015
  119. Ramsay JonesOct 21, 2015
  120. Johannes SixtOct 21, 2015
  121. Junio C HamanoOct 21, 2015
  122. Johannes SchindelinOct 26, 2015
  123. Junio C HamanoOct 26, 2015
  124. 00/35 libify mailinfo and call it directly from amJunio C Hamano, Oct 21, 2015

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.