git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] diff-no-index: do not reference .d_type member of struct dirent
@ 2025-06-18 20:04 Junio C Hamano
  2025-06-18 20:37 ` Collin Funk
  0 siblings, 1 reply; 2+ messages in thread
From: Junio C Hamano @ 2025-06-18 20:04 UTC (permalink / raw)
  To: git; +Cc: Collin Funk, Jacob Keller, Carlo Marcelo Arenas Belón

Some platforms like AIX lack .d_type member in "struct dirent"; use
the DTYPE(e) macro instead of a direct reference to e->d_type and
when it yields DT_UNKNOWN, find the real type with get_dtype().

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * get_dtype() was designed for a typical

    - prepare the path in a strbuf B
    - opendir(B)
    - loop over readdir(B)
      - do things to path (B + e->d_name)

   code structure, but because this code path does not use a strbuf
   (instead the path given to opendir is a "const char *"), the
   entire thing becomes messier than necessary.  get_dtype() has a
   short-cut to avoid having to concatenate path+e->d_name and run
   (l)stat() when e->d_type exists and known, but we need to open
   code it here.

 diff-no-index.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/diff-no-index.c b/diff-no-index.c
index 4aeeb98cfa..88ae4cee56 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -41,12 +41,24 @@ static int read_directory_contents(const char *path, struct string_list *list,
 
 	while ((e = readdir_skip_dot_and_dotdot(dir))) {
 		if (pathspec) {
+			int is_dir = 0;
+
 			strbuf_setlen(&match, len);
 			strbuf_addstr(&match, e->d_name);
+			if (NOT_CONSTANT(DTYPE(e)) != DT_UNKNOWN) {
+				is_dir = (DTYPE(e) == DT_DIR);
+			} else {
+				struct strbuf pathbuf = STRBUF_INIT;
+
+				strbuf_addstr(&pathbuf, path);
+				strbuf_complete(&pathbuf, '/');
+				is_dir = get_dtype(e, &pathbuf, 0) == DT_DIR;
+				strbuf_release(&pathbuf);
+			}
 
 			if (!match_leading_pathspec(NULL, pathspec,
 						    match.buf, match.len,
-						    0, NULL, e->d_type == DT_DIR ? 1 : 0))
+						    0, NULL, is_dir))
 				continue;
 		}
 
-- 
2.50.0-228-g6e205fdad9



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] diff-no-index: do not reference .d_type member of struct dirent
  2025-06-18 20:04 [PATCH] diff-no-index: do not reference .d_type member of struct dirent Junio C Hamano
@ 2025-06-18 20:37 ` Collin Funk
  0 siblings, 0 replies; 2+ messages in thread
From: Collin Funk @ 2025-06-18 20:37 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Jacob Keller, Carlo Marcelo Arenas Belón

Junio C Hamano <gitster@pobox.com> writes:

> Some platforms like AIX lack .d_type member in "struct dirent"; use
> the DTYPE(e) macro instead of a direct reference to e->d_type and
> when it yields DT_UNKNOWN, find the real type with get_dtype().
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  * get_dtype() was designed for a typical
>
>     - prepare the path in a strbuf B
>     - opendir(B)
>     - loop over readdir(B)
>       - do things to path (B + e->d_name)
>
>    code structure, but because this code path does not use a strbuf
>    (instead the path given to opendir is a "const char *"), the
>    entire thing becomes messier than necessary.  get_dtype() has a
>    short-cut to avoid having to concatenate path+e->d_name and run
>    (l)stat() when e->d_type exists and known, but we need to open
>    code it here.
>
>  diff-no-index.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)

Tested on AIX 7.3 like the previous patch just to be safe and it works
as expected.

Reviewed-by: Collin Funk <collin.funk1@gmail.com>
Tested-by: Collin Funk <collin.funk1@gmail.com>

Thanks,
Collin

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-18 20:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-18 20:04 [PATCH] diff-no-index: do not reference .d_type member of struct dirent Junio C Hamano
2025-06-18 20:37 ` Collin Funk

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 NNTP newsgroup(s).