From patchwork Tue Jun 18 23:44:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13703184 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 143C018E756 for ; Tue, 18 Jun 2024 23:44:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.228.157.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718754287; cv=none; b=D4uVjZkZPkcsonaCEjlS+fLTjqYZLG+RRoewA7NbIKbxkSdTFEF1fj1iK5bqLKhMPQVHiLsqPI6zbAH5XdR6cNQ2pVgn+Uj1CxY5w5hPPGd6k5tW7JnuHb1Si3oVualOp2XFShEzSrmL0l9a46kyOejMO9lWPbsfhpo1+4Q2LHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718754287; c=relaxed/simple; bh=/LAzRk4xxIuiKwhdFwE96XzRhE+YoeSGqqphbALagF4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NGaGnyJKcj56Tq9S7eUC9gfLTwomZe7w85V+Gm9dl5w9lICMKppxokg6EqTWosbYiPgIg2GywupFmClibmTEVOgOe6yY1IHLMiu335uooptlTxJK0nvARtC4UQ6A13ACMr+hdbH0hGe8NZs0oANuWudUVv59SLr47NHqAI5RYYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=U4Iqw7Xk; arc=none smtp.client-ip=173.228.157.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="U4Iqw7Xk" Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 990191F5F3; Tue, 18 Jun 2024 19:44:45 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=/LAzRk4xxIuiKwhdFwE96XzRh E+YoeSGqqphbALagF4=; b=U4Iqw7Xkv2Nq9toM/Zz7Qvc/AlLcoH6x+ouFQ/nv4 bfN5cfVeFmkXWn+Muta5dlWMAiPxGl8dNg7bxievkbfduSzITxF6puD/1gLrGLCT UjVFeHio+eB8dV3Ab8XBYq7FNHId+he9ksvTshPS2SWlRqCxjLYRUxHs0uwo7qKw Zc= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 929FD1F5F2; Tue, 18 Jun 2024 19:44:45 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.204.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id C7CAB1F5EE; Tue, 18 Jun 2024 19:44:41 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 1/4] .gitignore: introduce GITIGNORE_FILE CPP macro Date: Tue, 18 Jun 2024 16:44:32 -0700 Message-ID: <20240618234436.4107855-2-gitster@pobox.com> X-Mailer: git-send-email 2.45.2-711-gd2c001ca14 In-Reply-To: <20240618234436.4107855-1-gitster@pobox.com> References: <20240618233303.GA188880@coredump.intra.peff.net> <20240618234436.4107855-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: BBC0AF5C-2DCC-11EF-88AF-C38742FD603B-77302942!pb-smtp20.pobox.com GITATTRIBUTES_FILE and GITMODULES_FILE have their own CPP macros that resolve to their string literals to help compilers catch typos. Add one for ".gitignore" as well. Signed-off-by: Junio C Hamano --- builtin/read-tree.c | 3 ++- dir.c | 4 ++-- environment.h | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/builtin/read-tree.c b/builtin/read-tree.c index a8cf8504b8..bc12f5bd16 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -6,6 +6,7 @@ #include "builtin.h" #include "config.h" +#include "environment.h" #include "gettext.h" #include "hex.h" #include "lockfile.h" @@ -65,7 +66,7 @@ static int exclude_per_directory_cb(const struct option *opt, const char *arg, if (!opts->update) die("--exclude-per-directory is meaningless unless -u"); - if (strcmp(arg, ".gitignore")) + if (strcmp(arg, GITIGNORE_FILE)) die("--exclude-per-directory argument must be .gitignore"); return 0; } diff --git a/dir.c b/dir.c index 45be4ad261..ec875e3878 100644 --- a/dir.c +++ b/dir.c @@ -2888,7 +2888,7 @@ static void new_untracked_cache(struct index_state *istate, int flags) { struct untracked_cache *uc = xcalloc(1, sizeof(*uc)); strbuf_init(&uc->ident, 100); - uc->exclude_per_dir = ".gitignore"; + uc->exclude_per_dir = GITIGNORE_FILE; uc->dir_flags = flags >= 0 ? flags : new_untracked_cache_flags(istate); set_untracked_ident(uc); istate->untracked = uc; @@ -3428,7 +3428,7 @@ static GIT_PATH_FUNC(git_path_info_exclude, "info/exclude") void setup_standard_excludes(struct dir_struct *dir) { - dir->exclude_per_dir = ".gitignore"; + dir->exclude_per_dir = GITIGNORE_FILE; /* core.excludesfile defaulting to $XDG_CONFIG_HOME/git/ignore */ if (!excludes_file) diff --git a/environment.h b/environment.h index e9f01d4d11..39c3c24a3f 100644 --- a/environment.h +++ b/environment.h @@ -43,6 +43,7 @@ const char *getenv_safe(struct strvec *argv, const char *name); #define GITMODULES_FILE ".gitmodules" #define GITMODULES_INDEX ":.gitmodules" #define GITMODULES_HEAD "HEAD:.gitmodules" +#define GITIGNORE_FILE ".gitignore" #define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF" #define GIT_NOTES_DEFAULT_REF "refs/notes/commits" #define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF" From patchwork Tue Jun 18 23:44:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13703185 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2634318E75D for ; Tue, 18 Jun 2024 23:44:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.108.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718754288; cv=none; b=uE4j8InlG1fiFOLKwlmKEygu1Sy7oIoS3gD2XU7FyzLXQmGBCAh2Yw8vk3+Q69Q6bHP8wXFejiHL0vLR5HXadUOQfLOjS8NuQwXnsWjPHjwcf0XbEEOVjqFlOrWr+of8SggvOgw019EKH4FfSE+aW7DAjEIfJf6YzKlRCWJIqa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718754288; c=relaxed/simple; bh=gmukrHaFgIZGGfhwgk9yqtSRsLusJU+tXTB+O9rpHDk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=klwYbL6YnK9VapU58caOEZJdU+WWtV7tJbp6wZ3NPg/Zy9RUe05JGYknnuL8OqLi8qcK8UQcPxJcqZDPD3fZhbcCq8Qj5Xr8XcmGOJT1hEd1Y9hP57CMgMxGMeJdx1caN7pYYLqW3KHZ+V0gfVdADzLvNPncxwk+8+8wNpx3hUo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=WbZtME15; arc=none smtp.client-ip=64.147.108.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="WbZtME15" Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id EDFF12DB49; Tue, 18 Jun 2024 19:44:45 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=gmukrHaFgIZGGfhwgk9yqtSRs LusJU+tXTB+O9rpHDk=; b=WbZtME15fAFqjifZ7Pu5n8AVF9VmrNxhJ68MlFdwk CDG/+G24aDvYmZS2RClZfaJok9M62L9krCLs2Diy9/uY461DYTWeCLuumSfYUlP9 qlv61OQaCc5Gc+MnyuQmqTahx7dUU96xyMR0euHlCD5/59BGr+HqFz69CqHEwkG2 WQ= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id E76C12DB48; Tue, 18 Jun 2024 19:44:45 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.204.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 609EF2DB47; Tue, 18 Jun 2024 19:44:45 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 2/4] attr: notice and report read failure of .gitattributes files Date: Tue, 18 Jun 2024 16:44:33 -0700 Message-ID: <20240618234436.4107855-3-gitster@pobox.com> X-Mailer: git-send-email 2.45.2-711-gd2c001ca14 In-Reply-To: <20240618234436.4107855-1-gitster@pobox.com> References: <20240618233303.GA188880@coredump.intra.peff.net> <20240618234436.4107855-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: BDE27D7E-2DCC-11EF-8500-5B6DE52EC81B-77302942!pb-smtp1.pobox.com The code that reads .gitattributes files was careless in dealing in unusual circumstances. - It let read errors silently ignored. - It tried to read ".gitattributes" that is a directory on platforms that allowed open(2) to open directories. To make the latter consistent with what we do for fopen() on directories ("git grep" for FREAD_READS_DIRECTORIES for details), check if we opened a directory, silently close it and return success. Catch all read errors before we close and report as needed. Signed-off-by: Junio C Hamano --- attr.c | 10 +++++++++- t/t0003-attributes.sh | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/attr.c b/attr.c index 300f994ba6..9ab9cf1551 100644 --- a/attr.c +++ b/attr.c @@ -747,6 +747,11 @@ static struct attr_stack *read_attr_from_file(const char *path, unsigned flags) fclose(fp); return NULL; } + if (S_ISDIR(st.st_mode)) { + /* On FREAD_READS_DIRECTORIES platforms */ + fclose(fp); + return NULL; + } if (st.st_size >= ATTR_MAX_FILE_SIZE) { warning(_("ignoring overly large gitattributes file '%s'"), path); fclose(fp); @@ -760,7 +765,10 @@ static struct attr_stack *read_attr_from_file(const char *path, unsigned flags) handle_attr_line(res, buf.buf, path, ++lineno, flags); } - fclose(fp); + if (ferror(fp)) + warning_errno(_("failed while reading gitattributes file '%s'"), path); + if (fclose(fp)) + warning_errno(_("cannot fclose gitattributes file '%s'"), path); strbuf_release(&buf); return res; } diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index 66ccb5889d..783c20146d 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -603,6 +603,15 @@ test_expect_success EXPENSIVE 'large attributes blob ignored' ' test_cmp expect err ' +test_expect_success '.gitattribute directory behaves as if it does not exist' ' + test_when_finished "rm -fr dir" && + mkdir -p dir/.gitattributes && + >dir/ectory && + git -C dir check-attr --all ectory >out 2>err && + test_grep ! "failed while reading" err && + test_grep ! "cannot fclose" err +' + test_expect_success 'builtin object mode attributes work (dir and regular paths)' ' >normal && attr_check_object_mode normal 100644 && From patchwork Tue Jun 18 23:44:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13703187 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E117218E77E for ; Tue, 18 Jun 2024 23:44:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.108.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718754295; cv=none; b=RIPAk5ip6yv8wDwCbTtLX+RjTnViEpDLZ1no3gBghBxu0LpV8gST5tIU/zQgIIgAjzlcirMm7YN0prMZrl4TZnMunbDCVEXUluZbWh46/wC4mFkG/kPP6xvtg+kZH+RYycOXbN4uG7Pvgmvbsv6rwHqsrfpZFV2sTOivaZdEm1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718754295; c=relaxed/simple; bh=Yb0TMbnGaa4vcvNXwbNIMOrUKcazKzoaRmXN/E80iv4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i2uLLRXfOVeZHv5BtxyixJrw0iHexvbmPqLSOi9DeEr7XyIamihCWcrVRDBPS9/Fr1GPChaZX2utTEfvjzIAkVod9D597RO4eWv+Y+oz9D8Gi/rW8HwPFlcLUU5wbZwhgP0uh9h5qaAo5W1EcZ74VKtOxBp/yJC6u3vcobknyws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=q3FurwD6; arc=none smtp.client-ip=64.147.108.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="q3FurwD6" Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id A0B7E29481; Tue, 18 Jun 2024 19:44:47 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=Yb0TMbnGaa4vcvNXwbNIMOrUK cazKzoaRmXN/E80iv4=; b=q3FurwD692TxE4l7QmIiVxoieyARbuGy9tA+1OC/2 xm3FQ8GG7G/gEEuOxBIWtKknPz4tP73GKDzuYKogGWJ3KM/wuMw049eueyz953ty Qv+GutdxW0QYrIulb3m/RItC+fPZtRMnUnWS21TAVEddVc2uuIJwEwcopi+NMEt5 H8= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 987DE29480; Tue, 18 Jun 2024 19:44:47 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.204.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id EC9ED2947F; Tue, 18 Jun 2024 19:44:46 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 3/4] exclude: notice and report read failure of .gitignore files Date: Tue, 18 Jun 2024 16:44:34 -0700 Message-ID: <20240618234436.4107855-4-gitster@pobox.com> X-Mailer: git-send-email 2.45.2-711-gd2c001ca14 In-Reply-To: <20240618234436.4107855-1-gitster@pobox.com> References: <20240618233303.GA188880@coredump.intra.peff.net> <20240618234436.4107855-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: BED3C026-2DCC-11EF-9F21-965B910A682E-77302942!pb-smtp2.pobox.com The code that reads .gitignore files was careless in dealing in unusual circumstances. - It let read errors silently ignored. - It tried to read ".gitignore" that is a directory on platforms that allow open(2) to open directories. To make the latter consistent with what we do for fopen() on directories ("git grep" for FREAD_READS_DIRECTORIES for details), check if we opened a directory, silently close it and return success. Catch all read errors before we close and report as needed. Signed-off-by: Junio C Hamano --- dir.c | 6 ++++++ t/t0008-ignores.sh | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/dir.c b/dir.c index ec875e3878..73f89f4d8c 100644 --- a/dir.c +++ b/dir.c @@ -1127,6 +1127,10 @@ static int add_patterns(const char *fname, const char *base, int baselen, oid_stat); if (r != 1) return r; + } else if (S_ISDIR(st.st_mode)) { + /* On FREAD_READS_DIRECTORIES platforms */ + close(fd); + return 0; } else { size = xsize_t(st.st_size); if (size == 0) { @@ -1140,6 +1144,8 @@ static int add_patterns(const char *fname, const char *base, int baselen, } buf = xmallocz(size); if (read_in_full(fd, buf, size) != size) { + warning_errno(_("failed while reading gitignore file '%s'"), + fname); free(buf); close(fd); return -1; diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh index 02a18d4fdb..c367824c66 100755 --- a/t/t0008-ignores.sh +++ b/t/t0008-ignores.sh @@ -953,4 +953,22 @@ test_expect_success EXPENSIVE 'large exclude file ignored in tree' ' test_cmp expect err ' +test_expect_success POSIXPERM 'unreadable exclude file reported' ' + test_when_finished "rm -f .gitignore" && + >.gitignore && + chmod a= .gitignore && + # we do not care if the pattern matches + { git check-ignore xyzzy 2>err || :; } && + test_grep "unable to access ${SQ}\.gitignore${SQ}:" err +' + +test_expect_success '.gitignore directory ignored' ' + test_when_finished "rm -rf .gitignore" && + rm -f .gitignore && + mkdir .gitignore && + # we do not care if the pattern matches + { git check-ignore xyzzy 2>err || :; } && + test_grep ! "failed while reading gitignore file ${SQ}\.gitignore${SQ}:" err +' + test_done From patchwork Tue Jun 18 23:44:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13703186 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63D2C18E77C for ; Tue, 18 Jun 2024 23:44:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.228.157.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718754294; cv=none; b=hLC6jTmUdgiFi5YilO1UWtDnnwH+hku2nNjkIKSXdQQ8xuptmVuDLBDvytna05knPcQDiBqXO9htaA78iAkoqrPeZEgIvxg7l9RVsAVfm9jg/5hSLM+448LgtBnzxEr8IDXVcFYcuH6V5TBoB28UcNkjCrs9mLvBIJVbktoaxb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718754294; c=relaxed/simple; bh=1P7+4qu4mq0TD0OtwgUMdXi4fgNCP8TISLY79OUxRYA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T7chv+/aPTnLRKUr79z9mJ72nfirILWX1v00rrOvT9YdzucTawHEuqIKllOX6FdpbOrcx2omOXmRokfIl2Wz3eR4JUuAywbucMuqHJXrTSmRTq/F+5YGotj05eXGK5s/fi2OM8uDBPE8VQNYzm0rBIiXMDS7kw7EjupmBRjAuww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=rqRmAWAh; arc=none smtp.client-ip=173.228.157.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="rqRmAWAh" Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id DD5292C5F3; Tue, 18 Jun 2024 19:44:52 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=1P7+4qu4mq0TD0OtwgUMdXi4f gNCP8TISLY79OUxRYA=; b=rqRmAWAhDiR30TWOKLrbGhh4DpaTRFlNK/v9QEH/t rMW1dEd2Jlsg8Ez1QdL5tVD8lKSBXaOuB9Rl7oXneyEzdseY4pdH1bIetrp2Rttk FCZzutFhtBn3q/ZiNUc6kgU5ap/mry3gli/h52fKa8qAXwyx4N37Nt9I1Hi4co7W Bk= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id D724A2C5F2; Tue, 18 Jun 2024 19:44:52 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.204.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 15FAB2C5F1; Tue, 18 Jun 2024 19:44:49 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 4/4] submodule: ignore .gitmodules that is not a regular file Date: Tue, 18 Jun 2024 16:44:35 -0700 Message-ID: <20240618234436.4107855-5-gitster@pobox.com> X-Mailer: git-send-email 2.45.2-711-gd2c001ca14 In-Reply-To: <20240618234436.4107855-1-gitster@pobox.com> References: <20240618233303.GA188880@coredump.intra.peff.net> <20240618234436.4107855-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: C01658AE-2DCC-11EF-AB14-DFF1FEA446E2-77302942!pb-smtp21.pobox.com If .gitmodules exists in the working tree but is a directory, it would have just tried to use it as if it were a file. On a platform that needs FREAD_READS_DIRECTORIES, this would have been hidden by our own fopen() that pretends as if directory did not exist, so it is a no-op. Just to add some documentation value, make sure we check with file_exists_as_file() instead of file_exists(), the latter of which will be happy as long as the given path exists no matter what it is. Signed-off-by: Junio C Hamano --- dir.c | 6 ++++++ dir.h | 1 + submodule-config.c | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/dir.c b/dir.c index 73f89f4d8c..d943da93df 100644 --- a/dir.c +++ b/dir.c @@ -3142,6 +3142,12 @@ int file_exists(const char *f) return lstat(f, &sb) == 0; } +int file_exists_as_file(const char *path) +{ + struct stat st; + return lstat(path, &st) == 0 && S_ISREG(st.st_mode); +} + int repo_file_exists(struct repository *repo, const char *path) { if (repo != the_repository) diff --git a/dir.h b/dir.h index 1398a53fb4..3612dbbf9e 100644 --- a/dir.h +++ b/dir.h @@ -475,6 +475,7 @@ void dir_clear(struct dir_struct *dir); int repo_file_exists(struct repository *repo, const char *path); int file_exists(const char *); +int file_exists_as_file(const char *); int is_inside_dir(const char *dir); int dir_inside_of(const char *subdir, const char *dir); diff --git a/submodule-config.c b/submodule-config.c index ec45ea67b9..6c18ae3764 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -801,7 +801,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void char *oidstr = NULL; file = repo_worktree_path(repo, GITMODULES_FILE); - if (file_exists(file)) { + if (file_exists_as_file(file)) { config_source.file = file; } else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 || repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {