From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: Jessica Clarke <jrtc27@jrtc27.com>
Cc: git@vger.kernel.org
Subject: Re: Shallow clones: ctime shouldn't be used on FreeBSD with UFS + soft-updates
Date: Wed, 2 Dec 2026 22:43:03 +0000 [thread overview]
Message-ID: <axCe9q1zRyMVMtO8@fruit.crustytoothpaste.net> (raw)
In-Reply-To: <41F956FA-64BC-4F68-8619-2E8B9889C26F@jrtc27.com>
[-- Attachment #1: Type: text/plain, Size: 4309 bytes --]
On 2026-12-02 at 18:10:33, Jessica Clarke wrote:
> Hi,
> Git uses ctime in various ways, but one of them is to check that the
> shallow file has not changed since the last time it was read during a
> shallow clone. In the case of the shallow file, it comes into being by
> being renamed from shallow.lock, and is then immediately stat’ed to
> give the before value. However, FreeBSD’s UFS soft-updates
> implementation has slightly surprising semantics for unlink (and
> internally uses link + unlink to implement rename): it will update
> ctime at the point of unlink (and thus rename), but will *also* later
> update it once its asynchronous soft-updates work is finished (see [1]
> that explains this latter update, and introduces the former). This
> means that, if Git is keying off ctime to determine whether shallow has
> changed, it can race with this soft-updates code and potentially sample
> either side of it, seeing the value change solely due to internal
> bookkeeping work in the filesystem.
I'm not sure this is technically POSIX compliant. rename(2) is
documented to update ctime, so that's okay. But it says this:
An implementation may update timestamps that are marked for update
immediately, or it may update such timestamps periodically.
However, it doesn't say you can update them twice for the same
operation. It would be allowed to update them _only_ at the soft-update
point or only immediately, but I don't think twice is allowed.
We do try to accommodate systems that don't fully comply with POSIX, but
it is likely that Git is not the only tool that could be negatively
affected here.
> As a result, I see git submodule update --depth=1 some/path
> sporadically fail on a FreeBSD 15.0-RELEASE-p11 (but as far as I know
> not limited to this version) builder we have, with:
>
> > fatal: shallow file has changed since we read it
>
> I have set core.trustctime to false in the build user’s ~/.gitconfig as
> a workaround. However, I imagine that other uses for ctime might be
> tolerant of this behaviour, just leading to minor inefficiency, and so
> having this default to false on FreeBSD might be a bit too broad a fix?
> I don’t take a strong view on what the right fix is, but would
> appreciate it if Git could by default on FreeBSD not use ctime to
> determine whether the shallow file has changed.
The function that's called is match_stat_data, so I'm pretty sure it
applies to all stat data, including the index, so my guess is pretty
much nothing is going to be tolerant of this behaviour without
core.trustctime. Functions updating the index will probably just
re-read the data and be correct, if inefficient, so you may not have
noticed anything odd in that regard.
My suggestion would be that the FreeBSD Git packages set this in
/etc/gitconfig if this is appropriate there. I don't use FreeBSD except
to test, so I can't really say what the appropriate setting there is.
For instance, UFS without soft-updates might be fine, or ZFS might not
have this problem, and those users might not want to incur the potential
negative consequences in this case. I think the FreeBSD packagers are
best suited to make an appropriate decision and that's consistent with
what other packagers do here[0]. They can also generate that
configuration file on installation to set operations based on what file
systems are in use in a way that would be hard for us to confidently and
correctly do.
I also don't believe we have OS-specific defaults for config options;
usually those are global unless the platform is completely incapable of
something (e.g., symlinks) and we can easily detect that fact at repo
creation time, which I don't think we can do here in a generic way. (For
instance, statfs(2) is notoriously unportable.) This config option
exists, as do many others, to gracefully handle infelicities in system
implementation, including poorly behaved file systems, so using it is
the right solution here.
[0] For instance, Apple and Homebrew ship
`credential.helper=osxkeychain` in the system config, and Git for
Windows also sets a variety of config options suitable for that
platform.
--
brian m. carlson (they/them)
Toronto, Ontario, CA
Speaking for myself only
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 325 bytes --]
prev parent reply other threads:[~2026-12-02 22:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 18:10 Shallow clones: ctime shouldn't be used on FreeBSD with UFS + soft-updates Jessica Clarke
2026-12-02 22:43 ` brian m. carlson [this message]
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=axCe9q1zRyMVMtO8@fruit.crustytoothpaste.net \
--to=sandals@crustytoothpaste.net \
--cc=git@vger.kernel.org \
--cc=jrtc27@jrtc27.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox