From: brian m. carlson Date: Wed, 02 Dec 2026 22:43:03 GMT Subject: Re: Shallow clones: ctime shouldn't be used on FreeBSD with UFS + soft-updates Message-ID: In-Reply-To: <41F956FA-64BC-4F68-8619-2E8B9889C26F@jrtc27.com> 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