{"thread":{"id":"48320","subject":"[PATCH] submodule--helper: don't print null in 'submodule status'","startedAt":"2018-04-18T14:54:00Z","lastAt":"2018-04-18T21:24:48Z","messageCount":3,"participants":["Nguyễn Thái Ngọc Duy","Stefan Beller","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"344987","messageId":"20180418145337.7591-1-pclouds@gmail.com","threadId":"48320","inReplyTo":null,"subject":"[PATCH] submodule--helper: don't print null in 'submodule status'","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-04-18T14:53:37Z","receivedAt":"2018-04-18T14:54:00Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"The function compute_rev_name() can return NULL sometimes (e.g. right\nafter 'submodule init'). The current code makes 'submodule status'\nprint this:\n\n 19d97bf5af05312267c2e874ee6bcf584d9e9681 sha1collisiondetection ((null))\n\nThis ugly 'null' adds no value to the user using this command. More\nimportantly printf() on some platform can't handle NULL as a string\nand will crash instead of printing '(null)'.\n\nCheck for this and skip printing this part (the alternative is\nprinting '(n/a)' or something but I think that is just noise).\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/submodule--helper.c | 8 ++++++--\n 1 file changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex a404df3ea4..4dc7d7d29f 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -596,8 +596,12 @@ static void print_status(unsigned int flags, char state, const char *path,\n \n \tprintf(\"%c%s %s\", state, oid_to_hex(oid), displaypath);\n \n-\tif (state == ' ' || state == '+')\n-\t\tprintf(\" (%s)\", compute_rev_name(path, oid_to_hex(oid)));\n+\tif (state == ' ' || state == '+') {\n+\t\tconst char *name = compute_rev_name(path, oid_to_hex(oid));\n+\n+\t\tif (name)\n+\t\t\tprintf(\" (%s)\", name);\n+\t}\n \n \tprintf(\"\\n\");\n }\n-- \n2.17.0.367.g5dd2e386c3\n\n"},{"id":"344997","messageId":"CAGZ79ka=z82u_wByO++Ds4uLWi1TB2=Etzbhb3vev8qpYzBMeg@mail.gmail.com","threadId":"48320","inReplyTo":"20180418145337.7591-1-pclouds@gmail.com","subject":"Re: [PATCH] submodule--helper: don't print null in 'submodule status'","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-04-18T17:34:46Z","receivedAt":"2018-04-18T17:34:54Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Hi Nguyễn,\n\nOn Wed, Apr 18, 2018 at 7:53 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n> The function compute_rev_name() can return NULL sometimes (e.g. right\n> after 'submodule init'). The current code makes 'submodule status'\n> print this:\n>\n>  19d97bf5af05312267c2e874ee6bcf584d9e9681 sha1collisiondetection ((null))\n>\n> This ugly 'null' adds no value to the user using this command. More\n> importantly printf() on some platform can't handle NULL as a string\n> and will crash instead of printing '(null)'.\n>\n> Check for this and skip printing this part (the alternative is\n> printing '(n/a)' or something but I think that is just noise).\n\nThis patch restores the behavior from before a9f8a37584 (submodule:\nport submodule subcommand 'status' from shell to C, 2017-10-06),\nso this is the right way to go instead of the alternatives you considered.\n\nThanks!\n\nReviewed-by: Stefan Beller <sbeller@google.com>\n\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  builtin/submodule--helper.c | 8 ++++++--\n>  1 file changed, 6 insertions(+), 2 deletions(-)\n>\n> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\n> index a404df3ea4..4dc7d7d29f 100644\n> --- a/builtin/submodule--helper.c\n> +++ b/builtin/submodule--helper.c\n> @@ -596,8 +596,12 @@ static void print_status(unsigned int flags, char state, const char *path,\n>\n>         printf(\"%c%s %s\", state, oid_to_hex(oid), displaypath);\n>\n> -       if (state == ' ' || state == '+')\n> -               printf(\" (%s)\", compute_rev_name(path, oid_to_hex(oid)));\n> +       if (state == ' ' || state == '+') {\n> +               const char *name = compute_rev_name(path, oid_to_hex(oid));\n> +\n> +               if (name)\n> +                       printf(\" (%s)\", name);\n> +       }\n>\n>         printf(\"\\n\");\n>  }\n> --\n> 2.17.0.367.g5dd2e386c3\n>\n"},{"id":"345022","messageId":"xmqqmuy0gqcm.fsf@gitster-ct.c.googlers.com","threadId":"48320","inReplyTo":"CAGZ79ka=z82u_wByO++Ds4uLWi1TB2=Etzbhb3vev8qpYzBMeg@mail.gmail.com","subject":"Re: [PATCH] submodule--helper: don't print null in 'submodule status'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-04-18T21:24:41Z","receivedAt":"2018-04-18T21:24:48Z","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> Hi Nguyễn,\n>\n> On Wed, Apr 18, 2018 at 7:53 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n>> The function compute_rev_name() can return NULL sometimes (e.g. right\n>> after 'submodule init'). The current code makes 'submodule status'\n>> print this:\n>>\n>>  19d97bf5af05312267c2e874ee6bcf584d9e9681 sha1collisiondetection ((null))\n>>\n>> This ugly 'null' adds no value to the user using this command. More\n>> importantly printf() on some platform can't handle NULL as a string\n>> and will crash instead of printing '(null)'.\n>>\n>> Check for this and skip printing this part (the alternative is\n>> printing '(n/a)' or something but I think that is just noise).\n>\n> This patch restores the behavior from before a9f8a37584 (submodule:\n> port submodule subcommand 'status' from shell to C, 2017-10-06),\n> so this is the right way to go instead of the alternatives you considered.\n>\n> Thanks!\n>\n> Reviewed-by: Stefan Beller <sbeller@google.com>\n\nExcellent.  Thanks, both.\n\nWill queue.\n\n>\n>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n>> ---\n>>  builtin/submodule--helper.c | 8 ++++++--\n>>  1 file changed, 6 insertions(+), 2 deletions(-)\n>>\n>> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\n>> index a404df3ea4..4dc7d7d29f 100644\n>> --- a/builtin/submodule--helper.c\n>> +++ b/builtin/submodule--helper.c\n>> @@ -596,8 +596,12 @@ static void print_status(unsigned int flags, char state, const char *path,\n>>\n>>         printf(\"%c%s %s\", state, oid_to_hex(oid), displaypath);\n>>\n>> -       if (state == ' ' || state == '+')\n>> -               printf(\" (%s)\", compute_rev_name(path, oid_to_hex(oid)));\n>> +       if (state == ' ' || state == '+') {\n>> +               const char *name = compute_rev_name(path, oid_to_hex(oid));\n>> +\n>> +               if (name)\n>> +                       printf(\" (%s)\", name);\n>> +       }\n>>\n>>         printf(\"\\n\");\n>>  }\n>> --\n>> 2.17.0.367.g5dd2e386c3\n>>\n"}]}