public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: "Carlo Marcelo Arenas Belón" <carenas@gmail•com>
Cc: git@vger•kernel.org,  Jacob Keller <jacob.keller@gmail•com>
Subject: Re: [PATCH] portability: allow building in systems without d_type
Date: Wed, 18 Jun 2025 11:20:50 -0700	[thread overview]
Message-ID: <xmqqwm98ewsd.fsf@gitster.g> (raw)
In-Reply-To: <20250618062331.78059-1-carenas@gmail.com> ("Carlo Marcelo Arenas Belón"'s message of "Tue, 17 Jun 2025 23:23:31 -0700")

Carlo Marcelo Arenas Belón <carenas@gmail•com> writes:

> Since 09fb155f11 (diff --no-index: support limiting by pathspec,
> 2025-05-21) will fail to build in platforms that don't have a
> d_type member on their struct dirent (ex: AIX, NonStop).
>
> Use the DTYPE() macro instead of a nake reference to d_type.

This may allow you to compile and build, but does the resulting
binary do what you want it to?

>  			if (!match_leading_pathspec(NULL, pathspec,
>  						    match.buf, match.len,
> -						    0, NULL, e->d_type == DT_DIR ? 1 : 0))
> +						    0, NULL, DTYPE(e) == DT_DIR ? 1 : 0))

On a platform without d_type member, DTYPE() macro gives DT_UNKNOWN
that is not DT_DIR, so essentially you are always passing 0 even
when you are looking at a directory (in which case you must pass 1)
to match_leading_pathspec().

So I somehow doubt this is a correct fix.

I do not know if get_dtype() helper function is easily applicable to
this codepath, so I wrote this in a longhand...


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

diff --git c/diff-no-index.c w/diff-no-index.c
index 7c95222ba6..677df91fc5 100644
--- c/diff-no-index.c
+++ w/diff-no-index.c
@@ -41,12 +41,28 @@ 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 (dtype != DT_UNKNOWN) {
+				is_dir = dtype == DT_DIR;
+			} else {
+				struct stat st;
+				struct strbuf pathbuf = STRBUF_INIT;
+				strbuf_addstr(&pathbuf, path);
+				strbuf_complete(&pathbuf, '/');
+				strbuf_addstr(&pathbuf, e->d_name);
+				if (!lstat(&st, pathbuf.buf))
+					is_dir = S_ISDIR(st.st_mode);
+				else
+					; /* punt */
+				strbuf_release(&pathbuf);
+			}
 
 			if (!match_leading_pathspec(NULL, pathspec,
 						    match.buf, match.len,
-						    0, NULL, DTYPE(e) == DT_DIR ? 1 : 0))
+						    0, NULL, is_dir))
 				continue;
 		}
 

  parent reply	other threads:[~2025-06-18 18:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18  6:23 [PATCH] portability: allow building in systems without d_type Carlo Marcelo Arenas Belón
2025-06-18  6:39 ` Collin Funk
2025-06-18 14:12 ` Marc Branchaud
2025-06-18 14:32 ` Kristoffer Haugsbakk
2025-06-18 18:20 ` Junio C Hamano [this message]
2025-06-18 19:32   ` Collin Funk

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=xmqqwm98ewsd.fsf@gitster.g \
    --to=gitster@pobox$(echo .)com \
    --cc=carenas@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=jacob.keller@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox