All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Matheus Tavares Bernardino <matheus.bernardino@usp.br>
Cc: git <git@vger.kernel.org>, Derrick Stolee <stolee@gmail.com>
Subject: Re: [PATCH] entry: check for fstat() errors after checkout
Date: Tue, 21 Jul 2020 13:00:30 -0700	[thread overview]
Message-ID: <xmqq1rl48wpt.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <CAHd-oW4_A7JRmdTqCMrDU7b6-PqBSpNVD-csm3y9Bype6Vn9rA@mail.gmail.com> (Matheus Tavares Bernardino's message of "Tue, 21 Jul 2020 12:39:13 -0300")

Matheus Tavares Bernardino <matheus.bernardino@usp.br> writes:

> I was looking further at this code and noticed that the conditions
> under which we fstat() (or lstat()) an entry are slightly different
> throughout entry.c:
>
> - In write_entry()'s footer, we call lstat() iff stat->refresh_cache.
> - In write_entry()'s `write_file_entry` label, we call fstat_output()
> when !to_tempfile.
> - In streaming_write_entry() we call fstat_output() without checking
> if !to_tempfile.
> - And, finally, in fstat_output() itself, we check
> `state->refresh_cache && !state->base_dir_len`.
>
> I understand we always check state->refresh_cache to avoid getting
> stat information we won't really need later, as we are not updating
> the index. But why do we check !to_tempfile and !state->base_dir_len?
> Doesn't writing to a tempfile or using a checkout prefix already imply
> !state->refresh_cache?

You can easily blame the code back to e4c72923 (write_entry(): use
fstat() instead of lstat() when file is open, 2009-02-09).  Back
then, only a single place assigned 0 to state.refresh_cache and that
is in "checkout-index" with either base_dir_len or to_tempfile set.

I do not remember, and I am fairly sure Stolee does not remember
either.  If I have to guess, this was done merely to be extra
cautious, perhaps? As refresh_cache bit is checked first, check for
!to_tempfile and !base_dir_len would be dead at best and redundant
at worst.



  reply	other threads:[~2020-07-21 20:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-09  2:10 [PATCH] entry: check for fstat() errors after checkout Matheus Tavares
2020-07-09 11:41 ` Derrick Stolee
2020-07-09 14:08   ` Junio C Hamano
2020-07-09 17:08 ` Junio C Hamano
2020-07-09 17:39   ` Matheus Tavares Bernardino
2020-07-09 18:09     ` Junio C Hamano
2020-07-21 15:39 ` Matheus Tavares Bernardino
2020-07-21 20:00   ` Junio C Hamano [this message]
2020-07-21 20:57     ` Derrick Stolee

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=xmqq1rl48wpt.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=matheus.bernardino@usp.br \
    --cc=stolee@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.