All of lore.kernel.org
 help / color / mirror / Atom feed
From: Derrick Stolee <stolee@gmail.com>
To: "René Scharfe" <l.s.r@web.de>, "Git Mailing List" <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>, Daniel Ferreira <bnmvco@gmail.com>
Subject: Re: [PATCH] test-dir-iterator: use path argument directly
Date: Wed, 7 Aug 2019 09:57:02 -0400	[thread overview]
Message-ID: <5d24c373-8e27-e166-3019-4812da68ebf9@gmail.com> (raw)
In-Reply-To: <7f428974-9218-fa7c-6f3c-3c0db30a7fec@web.de>

On 8/7/2019 7:15 AM, René Scharfe wrote:
> Avoid allocating and leaking a strbuf for holding a verbatim copy of the
> path argument and pass the latter directly to dir_iterator_begin()
> instead.
> 
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> This test helper was added after v2.22.0 (2019-06-07) by 150791adbf
> (dir-iterator: add tests for dir-iterator API, 2019-07-10).
> 
>  t/helper/test-dir-iterator.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/t/helper/test-dir-iterator.c b/t/helper/test-dir-iterator.c
> index c7c30664da..659b6bfa81 100644
> --- a/t/helper/test-dir-iterator.c
> +++ b/t/helper/test-dir-iterator.c
> @@ -19,7 +19,6 @@ static const char *error_name(int error_number)
>   */
>  int cmd__dir_iterator(int argc, const char **argv)
>  {
> -	struct strbuf path = STRBUF_INIT;
>  	struct dir_iterator *diter;
>  	unsigned int flags = 0;
>  	int iter_status;
> @@ -36,8 +35,7 @@ int cmd__dir_iterator(int argc, const char **argv)
>  	if (!*argv || argc != 1)
>  		die("dir-iterator needs exactly one non-option argument");
> 
> -	strbuf_add(&path, *argv, strlen(*argv));
> -	diter = dir_iterator_begin(path.buf, flags);
> +	diter = dir_iterator_begin(*argv, flags);

LGTM. I had a minor brain fart regarding the type of *argv and how the
const plays in, but dir_iterator_begin takes a "const char *" so this
is safe.

Thanks,
-Stolee

      reply	other threads:[~2019-08-07 13:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-07 11:15 [PATCH] test-dir-iterator: use path argument directly René Scharfe
2019-08-07 13:57 ` Derrick Stolee [this message]

Reply instructions:

You may reply publicly 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

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

  git send-email \
    --in-reply-to=5d24c373-8e27-e166-3019-4812da68ebf9@gmail.com \
    --to=stolee@gmail.com \
    --cc=bnmvco@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.