git@vger.kernel.org mailing list mirror (one of many)
 help / Atom feed
From: Stefan Beller <sbeller@google.com>
To: Nguyễn Thái Ngọc Duy  <pclouds@gmail.com>
Cc: git <git@vger.kernel.org>, Prathamesh Chavan <pc44800@gmail.com>,
	Christian Couder <christian.couder@gmail.com>
Subject: Re: [PATCH] submodule--helper: don't print null in 'submodule status'
Date: Wed, 18 Apr 2018 10:34:46 -0700
Message-ID: <CAGZ79ka=z82u_wByO++Ds4uLWi1TB2=Etzbhb3vev8qpYzBMeg@mail.gmail.com> (raw)
In-Reply-To: <20180418145337.7591-1-pclouds@gmail.com>

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
>

  reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-18 14:53 Nguyễn Thái Ngọc Duy
2018-04-18 17:34 ` Stefan Beller [this message]
2018-04-18 21:24   ` Junio C Hamano

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGZ79ka=z82u_wByO++Ds4uLWi1TB2=Etzbhb3vev8qpYzBMeg@mail.gmail.com' \
    --to=sbeller@google.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pc44800@gmail.com \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

git@vger.kernel.org mailing list mirror (one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox