* [PATCH] submodule--helper: don't print null in 'submodule status'
@ 2018-04-18 14:53 Nguyễn Thái Ngọc Duy
2018-04-18 17:34 ` Stefan Beller
0 siblings, 1 reply; 3+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-04-18 14:53 UTC (permalink / raw)
To: git
Cc: pc44800, christian.couder, sbeller,
Nguyễn Thái Ngọc Duy
The function compute_rev_name() can return NULL sometimes (e.g. right
after 'submodule init'). The current code makes 'submodule status'
print this:
19d97bf5af05312267c2e874ee6bcf584d9e9681 sha1collisiondetection ((null))
This ugly 'null' adds no value to the user using this command. More
importantly printf() on some platform can't handle NULL as a string
and will crash instead of printing '(null)'.
Check for this and skip printing this part (the alternative is
printing '(n/a)' or something but I think that is just noise).
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/submodule--helper.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index a404df3ea4..4dc7d7d29f 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -596,8 +596,12 @@ static void print_status(unsigned int flags, char state, const char *path,
printf("%c%s %s", state, oid_to_hex(oid), displaypath);
- if (state == ' ' || state == '+')
- printf(" (%s)", compute_rev_name(path, oid_to_hex(oid)));
+ if (state == ' ' || state == '+') {
+ const char *name = compute_rev_name(path, oid_to_hex(oid));
+
+ if (name)
+ printf(" (%s)", name);
+ }
printf("\n");
}
--
2.17.0.367.g5dd2e386c3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] submodule--helper: don't print null in 'submodule status'
2018-04-18 14:53 [PATCH] submodule--helper: don't print null in 'submodule status' Nguyễn Thái Ngọc Duy
@ 2018-04-18 17:34 ` Stefan Beller
2018-04-18 21:24 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Beller @ 2018-04-18 17:34 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy
Cc: git, Prathamesh Chavan, Christian Couder
Hi Nguyễn,
On Wed, Apr 18, 2018 at 7:53 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
> The function compute_rev_name() can return NULL sometimes (e.g. right
> after 'submodule init'). The current code makes 'submodule status'
> print this:
>
> 19d97bf5af05312267c2e874ee6bcf584d9e9681 sha1collisiondetection ((null))
>
> This ugly 'null' adds no value to the user using this command. More
> importantly printf() on some platform can't handle NULL as a string
> and will crash instead of printing '(null)'.
>
> Check for this and skip printing this part (the alternative is
> printing '(n/a)' or something but I think that is just noise).
This patch restores the behavior from before a9f8a37584 (submodule:
port submodule subcommand 'status' from shell to C, 2017-10-06),
so this is the right way to go instead of the alternatives you considered.
Thanks!
Reviewed-by: Stefan Beller <sbeller@google.com>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> builtin/submodule--helper.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index a404df3ea4..4dc7d7d29f 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -596,8 +596,12 @@ static void print_status(unsigned int flags, char state, const char *path,
>
> printf("%c%s %s", state, oid_to_hex(oid), displaypath);
>
> - if (state == ' ' || state == '+')
> - printf(" (%s)", compute_rev_name(path, oid_to_hex(oid)));
> + if (state == ' ' || state == '+') {
> + const char *name = compute_rev_name(path, oid_to_hex(oid));
> +
> + if (name)
> + printf(" (%s)", name);
> + }
>
> printf("\n");
> }
> --
> 2.17.0.367.g5dd2e386c3
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] submodule--helper: don't print null in 'submodule status'
2018-04-18 17:34 ` Stefan Beller
@ 2018-04-18 21:24 ` Junio C Hamano
0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2018-04-18 21:24 UTC (permalink / raw)
To: Stefan Beller
Cc: Nguyễn Thái Ngọc Duy, git, Prathamesh Chavan,
Christian Couder
Stefan Beller <sbeller@google.com> writes:
> Hi Nguyễn,
>
> On Wed, Apr 18, 2018 at 7:53 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
>> The function compute_rev_name() can return NULL sometimes (e.g. right
>> after 'submodule init'). The current code makes 'submodule status'
>> print this:
>>
>> 19d97bf5af05312267c2e874ee6bcf584d9e9681 sha1collisiondetection ((null))
>>
>> This ugly 'null' adds no value to the user using this command. More
>> importantly printf() on some platform can't handle NULL as a string
>> and will crash instead of printing '(null)'.
>>
>> Check for this and skip printing this part (the alternative is
>> printing '(n/a)' or something but I think that is just noise).
>
> This patch restores the behavior from before a9f8a37584 (submodule:
> port submodule subcommand 'status' from shell to C, 2017-10-06),
> so this is the right way to go instead of the alternatives you considered.
>
> Thanks!
>
> Reviewed-by: Stefan Beller <sbeller@google.com>
Excellent. Thanks, both.
Will queue.
>
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>> ---
>> builtin/submodule--helper.c | 8 ++++++--
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
>> index a404df3ea4..4dc7d7d29f 100644
>> --- a/builtin/submodule--helper.c
>> +++ b/builtin/submodule--helper.c
>> @@ -596,8 +596,12 @@ static void print_status(unsigned int flags, char state, const char *path,
>>
>> printf("%c%s %s", state, oid_to_hex(oid), displaypath);
>>
>> - if (state == ' ' || state == '+')
>> - printf(" (%s)", compute_rev_name(path, oid_to_hex(oid)));
>> + if (state == ' ' || state == '+') {
>> + const char *name = compute_rev_name(path, oid_to_hex(oid));
>> +
>> + if (name)
>> + printf(" (%s)", name);
>> + }
>>
>> printf("\n");
>> }
>> --
>> 2.17.0.367.g5dd2e386c3
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-04-18 21:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-18 14:53 [PATCH] submodule--helper: don't print null in 'submodule status' Nguyễn Thái Ngọc Duy
2018-04-18 17:34 ` Stefan Beller
2018-04-18 21:24 ` Junio C Hamano
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).