From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Kyle Evans <kevans@freebsd.org>, Jeff King <peff@peff.net>,
Brandon Casey <drafnel@gmail.com>
Subject: Re: fread reading directories
Date: Mon, 08 Jun 2020 10:18:07 -0700 [thread overview]
Message-ID: <xmqqlfkxlbn4.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <CACNAnaHBPeg1SMMGUdErKnn12bGo8t3O7LU6Yktw40B7bKfBGA@mail.gmail.com> (Kyle Evans's message of "Sun, 7 Jun 2020 12:16:26 -0500")
Kyle Evans <kevans@freebsd.org> writes:
> On Sun, Jun 7, 2020 at 12:05 PM Junio C Hamano <gitster@pobox.com> wrote:
>>
>> Kyle Evans <kevans@freebsd.org> writes:
>>
>> > I was looking at FREAD_READS_DIRECTORIES to measure some performance
>> > differences, then stumbled upon [0] that dropped fread() from the
>> > autoconf test that causes git to use its git_fopen shim [1] even on
>> > Linux.
>>
>> I thought we saw this mentioned recently? I do not recall if
>> any concrete improvement came out of it.
>>
>
> Ah, this is my bad. =-( I had searched the archives (I'm not typically
> subscribed to this list) and noticed the related patch for GNU/Hurd,
> but completely missed that a more active discussion had taken place
> within that thread. I have now read that, and have no further
> questions.
For the benefit of those who are watching from sidelines, the
relevant thread ends at
https://lore.kernel.org/git/20200424055106.GG1648190@coredump.intra.peff.net/
In short, many callers of fopen() in our code rely on our variant of
fopen() that notices that the caller fed us a directory for error
reporting. Unless the caller somehow knows the argument it calls
fopen() with is a file and not a directory, somebody needs to
fopen() and fstat() (or stat() and then fopen()) to catch it as an
error to give that caller a directory. In the current arrangement,
we let our fopen() wrapper do that task, instead of the callers.
It may make sense to do one of the two things:
- The lighter weight one is to rename the macro to the reflect the
trait we are trying to capture more faithfully: "fopen opens
directories" and leave the code and performance characteristics
as-is.
- Heavier weight one is to audit callers of fopen() and only let
those that know they do not have a directory directly call
fopen(). The other callers would call our wrapper under a
different name. This way, the former won't have to pay the
overhead of checking for "you gave me a directory but I only take
a file" error twice. This is what Brandon proposed in the
thread.
Doing neither would leave this seed of confusion for later readers,
which is not ideal. I am tempted to say that we for now should do
an even lighter variant of the former, which is to give a comment.
Thoughts?
Makefile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 09f98b777c..a0bef206a9 100644
--- a/Makefile
+++ b/Makefile
@@ -19,8 +19,7 @@ all::
# have been written to the final string if enough space had been available.
#
# Define FREAD_READS_DIRECTORIES if you are on a system which succeeds
-# when attempting to read from an fopen'ed directory (or even to fopen
-# it at all).
+# when an fopen() on a directory does not result in an error.
#
# Define NO_OPENSSL environment variable if you do not have OpenSSL.
#
next prev parent reply other threads:[~2020-06-08 17:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-06 22:36 fread reading directories Kyle Evans
2020-06-07 17:05 ` Junio C Hamano
2020-06-07 17:16 ` Kyle Evans
2020-06-08 17:18 ` Junio C Hamano [this message]
2020-06-08 19:08 ` Brandon Casey
2020-06-08 19:41 ` Randall S. Becker
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=xmqqlfkxlbn4.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=drafnel@gmail.com \
--cc=git@vger.kernel.org \
--cc=kevans@freebsd.org \
--cc=peff@peff.net \
/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 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).