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