All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Victoria Dye via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, rsbecker@nexbridge.com,
	Victoria Dye <vdye@github.com>
Subject: Re: [PATCH] diagnose.c: refactor to safely use 'd_type'
Date: Sun, 18 Sep 2022 18:13:34 -0700	[thread overview]
Message-ID: <xmqqczbsdv41.fsf@gitster.g> (raw)
In-Reply-To: <pull.1354.git.1663438615413.gitgitgadget@gmail.com> (Victoria Dye via GitGitGadget's message of "Sat, 17 Sep 2022 18:16:55 +0000")

"Victoria Dye via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Victoria Dye <vdye@github.com>
>
> Refactor usage of the 'd_type' property of 'struct dirent' in 'diagnose.c'
> to instead utilize the compatibility macro 'DTYPE()'. On systems where
> 'd_type' is not present in 'struct dirent', this macro will always return
> 'DT_UNKNOWN'. In that case, instead fall back on using the 'stat.st_mode' to
> determine whether the dirent points to a dir, file, or link.
>
> Additionally, add a test to 't0092-diagnose.sh' to verify that files (e.g.,
> loose objects) are counted properly.
>
> Note that the new function 'get_dtype()' is based on 'resolve_dtype()' in
> 'dir.c' (which itself was refactored from a prior 'get_dtype()' in
> ad6f2157f9 (dir: restructure in a way to avoid passing around a struct
> dirent, 2020-01-16)), but differs in that it is meant for use on arbitrary
> files, such as those inside the '.git' dir. Because of this, it does not
> search the index for a matching entry to derive the 'd_type'.
>
> Reported-by: Randall S. Becker <rsbecker@nexbridge.com>
> Signed-off-by: Victoria Dye <vdye@github.com>
> ---

Beautiful.  Use of DTYPE() macro that already hides the platform
specifics, and get_dtype() implementation that calls lstat() lazily,
are exactly the solution I was expecting to see.

Nicely done.  Will queue.  Thanks.

      reply	other threads:[~2022-09-19  1:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-17 18:16 [PATCH] diagnose.c: refactor to safely use 'd_type' Victoria Dye via GitGitGadget
2022-09-19  1:13 ` Junio C Hamano [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=xmqqczbsdv41.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=rsbecker@nexbridge.com \
    --cc=vdye@github.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
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.