git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] diagnose.c: refactor to safely use 'd_type'

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 19, 2022, 01:13 UTC
Message-ID
<xmqqczbsdv41.fsf@gitster.g>
In-Reply-To
<pull.1354.git.1663438615413.gitgitgadget@gmail.com>
"Victoria Dye via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 21 quoted lines
> 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.
Previous: Victoria Dye via GitGitGadget
Message 2 of 2 in “diagnose.c: refactor to safely use 'd_type'”
  1. diagnose.c: refactor to safely use 'd_type'Victoria Dye via GitGitGadget, Sep 17, 2022
  2. Junio C HamanoSep 19, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.