* Shallow clones: ctime shouldn't be used on FreeBSD with UFS + soft-updates
@ 2026-12-02 18:10 Jessica Clarke
2026-12-02 22:43 ` brian m. carlson
0 siblings, 1 reply; 2+ messages in thread
From: Jessica Clarke @ 2026-12-02 18:10 UTC (permalink / raw)
To: git
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.
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.
I doubt it matters, but this is with Git 2.56.0, for what it’s worth.
Also, here’s an illustration this behaviour (whole script is set -x):
> $ ./ctime-after-mv
> + rm -fv foo bar
> bar
> + touch foo
> + stat -f %Fc foo
> 1796226770.687840000
> + sleep 2
> + stat -f %Fc foo
> 1796226770.687840000
> + sleep 2
> + mv foo bar
> + stat -f %Fc bar
> 1796226774.694149000
> + sleep 2
> + stat -f %Fc bar
> 1796226775.523101000
Thanks,
Jessica
[1] https://cgit.freebsd.org/src/commit/?id=1a75045196a26c2dd00a03a3d6d231dd5b422a9b
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Shallow clones: ctime shouldn't be used on FreeBSD with UFS + soft-updates
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
0 siblings, 0 replies; 2+ messages in thread
From: brian m. carlson @ 2026-12-02 22:43 UTC (permalink / raw)
To: Jessica Clarke; +Cc: git
[-- 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 --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 22:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox