{"thread":{"id":"46280","subject":"[PATCH] submodule--helper: do not call utf8_fprintf() unnecessarily","startedAt":"2017-06-28T20:38:55Z","lastAt":"2017-06-28T21:18:29Z","messageCount":4,"participants":["Junio C Hamano","Stefan Beller"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"323441","messageId":"xmqq1sq3x2xz.fsf@gitster.mtv.corp.google.com","threadId":"46280","inReplyTo":null,"subject":"[PATCH] submodule--helper: do not call utf8_fprintf() unnecessarily","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-06-28T20:38:48Z","receivedAt":"2017-06-28T20:38:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The helper function utf8_fprintf(fp, ...) has exactly the same\neffect to the output stream fp as fprintf(fp, ...) does, and the\nonly difference is that its return value counts in display columns\nconsumed (assuming that the payload is encoded in UTF-8), as opposed\nto number of bytes.\n\nThere is no reason to call it unless the caller cares about its\nreturn value.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * The helper was introduced at c0821965 (\"Add utf8_fprintf helper\n   that returns correct number of columns\", 2013-02-09), which also\n   taught the help text output from the parse_options API to use it\n   to align columns.  These original callers naturally do use the\n   returned value and left alone by this fix, which corrects all the\n   later callers that misuses it.\n\n builtin/submodule--helper.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 8517032b3e..50c6af1de7 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -326,7 +326,7 @@ static int module_list(int argc, const char **argv, const char *prefix)\n \t\t\tprintf(\"%06o %s %d\\t\", ce->ce_mode,\n \t\t\t       oid_to_hex(&ce->oid), ce_stage(ce));\n \n-\t\tutf8_fprintf(stdout, \"%s\\n\", ce->name);\n+\t\tfprintf(stdout, \"%s\\n\", ce->name);\n \t}\n \treturn 0;\n }\n@@ -1038,7 +1038,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)\n \t\treturn 1;\n \n \tfor_each_string_list_item(item, &suc.projectlines)\n-\t\tutf8_fprintf(stdout, \"%s\", item->string);\n+\t\tfprintf(stdout, \"%s\", item->string);\n \n \treturn 0;\n }\n"},{"id":"323442","messageId":"CAGZ79kbvncDoSuj8AF_rdDoEzavdzEaLxqr7NXi1_eCLNt01Kg@mail.gmail.com","threadId":"46280","inReplyTo":"xmqq1sq3x2xz.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] submodule--helper: do not call utf8_fprintf() unnecessarily","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-06-28T20:44:08Z","receivedAt":"2017-06-28T20:44:14Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Wed, Jun 28, 2017 at 1:38 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> The helper function utf8_fprintf(fp, ...) has exactly the same\n> effect to the output stream fp as fprintf(fp, ...) does, and the\n> only difference is that its return value counts in display columns\n> consumed (assuming that the payload is encoded in UTF-8), as opposed\n> to number of bytes.\n>\n> There is no reason to call it unless the caller cares about its\n> return value.\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>\n>  * The helper was introduced at c0821965 (\"Add utf8_fprintf helper\n>    that returns correct number of columns\", 2013-02-09), which also\n>    taught the help text output from the parse_options API to use it\n>    to align columns.  These original callers naturally do use the\n>    returned value and left alone by this fix, which corrects all the\n>    later callers that misuses it.\n>\n\nThe patch looks correct.\n\nThanks,\nStefan\n\n>  builtin/submodule--helper.c | 4 ++--\n>  1 file changed, 2 insertions(+), 2 deletions(-)\n>\n> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\n> index 8517032b3e..50c6af1de7 100644\n> --- a/builtin/submodule--helper.c\n> +++ b/builtin/submodule--helper.c\n> @@ -326,7 +326,7 @@ static int module_list(int argc, const char **argv, const char *prefix)\n>                         printf(\"%06o %s %d\\t\", ce->ce_mode,\n>                                oid_to_hex(&ce->oid), ce_stage(ce));\n>\n> -               utf8_fprintf(stdout, \"%s\\n\", ce->name);\n> +               fprintf(stdout, \"%s\\n\", ce->name);\n>         }\n>         return 0;\n>  }\n> @@ -1038,7 +1038,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)\n>                 return 1;\n>\n>         for_each_string_list_item(item, &suc.projectlines)\n> -               utf8_fprintf(stdout, \"%s\", item->string);\n> +               fprintf(stdout, \"%s\", item->string);\n>\n>         return 0;\n>  }\n"},{"id":"323443","messageId":"xmqqwp7vvngg.fsf@gitster.mtv.corp.google.com","threadId":"46280","inReplyTo":"CAGZ79kbvncDoSuj8AF_rdDoEzavdzEaLxqr7NXi1_eCLNt01Kg@mail.gmail.com","subject":"Re: [PATCH] submodule--helper: do not call utf8_fprintf() unnecessarily","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-06-28T20:58:39Z","receivedAt":"2017-06-28T20:58:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Beller <sbeller@google.com> writes:\n\n> On Wed, Jun 28, 2017 at 1:38 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> The helper function utf8_fprintf(fp, ...) has exactly the same\n>> effect to the output stream fp as fprintf(fp, ...) does, and the\n>> only difference is that its return value counts in display columns\n>> consumed (assuming that the payload is encoded in UTF-8), as opposed\n>> to number of bytes.\n>>\n>> There is no reason to call it unless the caller cares about its\n>> return value.\n>>\n>> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n>> ---\n>>\n>>  * The helper was introduced at c0821965 (\"Add utf8_fprintf helper\n>>    that returns correct number of columns\", 2013-02-09), which also\n>>    taught the help text output from the parse_options API to use it\n>>    to align columns.  These original callers naturally do use the\n>>    returned value and left alone by this fix, which corrects all the\n>>    later callers that misuses it.\n>>\n>\n> The patch looks correct.\n\nThanks.  I had a small voice back in my head telling me that I may\nhave misread the code and this patch breaks things, which you\ncleared up for me ;-)\n"},{"id":"323445","messageId":"CAGZ79kY++zFEGDZhPMQebbGBw7UXjUf6f+bOzZ58_5NLQpCcjg@mail.gmail.com","threadId":"46280","inReplyTo":"xmqqwp7vvngg.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] submodule--helper: do not call utf8_fprintf() unnecessarily","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-06-28T21:18:24Z","receivedAt":"2017-06-28T21:18:29Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Wed, Jun 28, 2017 at 1:58 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Stefan Beller <sbeller@google.com> writes:\n>\n>> On Wed, Jun 28, 2017 at 1:38 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>>> The helper function utf8_fprintf(fp, ...) has exactly the same\n>>> effect to the output stream fp as fprintf(fp, ...) does, and the\n>>> only difference is that its return value counts in display columns\n>>> consumed (assuming that the payload is encoded in UTF-8), as opposed\n>>> to number of bytes.\n>>>\n>>> There is no reason to call it unless the caller cares about its\n>>> return value.\n>>>\n>>> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n>>> ---\n>>>\n>>>  * The helper was introduced at c0821965 (\"Add utf8_fprintf helper\n>>>    that returns correct number of columns\", 2013-02-09), which also\n>>>    taught the help text output from the parse_options API to use it\n>>>    to align columns.  These original callers naturally do use the\n>>>    returned value and left alone by this fix, which corrects all the\n>>>    later callers that misuses it.\n>>>\n>>\n>> The patch looks correct.\n\nI said this because I had a similar implementation a couple weeks back\nwhen Peff tried to poke (security) holes into submodule usage.\n\nI tried finding the reason why it was originally introduced, but to no avail.\nIt seems to be randomly introduced.\n\n> Thanks.  I had a small voice back in my head telling me that I may\n> have misread the code and this patch breaks things, which you\n> cleared up for me ;-)\n\nThat said, #include \"utf8.h\" could also go from the file with this\nor after this patch, I believe.\n"}]}