{"thread":{"id":"66974","subject":"Shallow clones: ctime shouldn't be used on FreeBSD with UFS + soft-updates","startedAt":"2026-12-02T18:10:33Z","lastAt":"2026-12-02T22:43:03Z","messageCount":2,"participants":["Jessica Clarke","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"559905","messageId":"41F956FA-64BC-4F68-8619-2E8B9889C26F@jrtc27.com","threadId":"66974","inReplyTo":null,"subject":"Shallow clones: ctime shouldn't be used on FreeBSD with UFS + soft-updates","fromName":"Jessica Clarke","fromEmail":"jrtc27@jrtc27.com","sentAt":"2026-12-02T18:10:33Z","receivedAt":"2026-12-02T18:10:33Z","isPatch":false,"sender":{"key":"jrtc27@jrtc27.com","avatar":"https://avatars.githubusercontent.com/u/816232?v=4"},"body":"Hi,\nGit uses ctime in various ways, but one of them is to check that the\nshallow file has not changed since the last time it was read during a\nshallow clone. In the case of the shallow file, it comes into being by\nbeing renamed from shallow.lock, and is then immediately stat’ed to\ngive the before value. However, FreeBSD’s UFS soft-updates\nimplementation has slightly surprising semantics for unlink (and\ninternally uses link + unlink to implement rename): it will update\nctime at the point of unlink (and thus rename), but will *also* later\nupdate it once its asynchronous soft-updates work is finished (see [1]\nthat explains this latter update, and introduces the former). This\nmeans that, if Git is keying off ctime to determine whether shallow has\nchanged, it can race with this soft-updates code and potentially sample\neither side of it, seeing the value change solely due to internal\nbookkeeping work in the filesystem.\n\nAs a result, I see git submodule update --depth=1 some/path\nsporadically fail on a FreeBSD 15.0-RELEASE-p11 (but as far as I know\nnot limited to this version) builder we have, with:\n\n> fatal: shallow file has changed since we read it\n\nI have set core.trustctime to false in the build user’s ~/.gitconfig as\na workaround. However, I imagine that other uses for ctime might be\ntolerant of this behaviour, just leading to minor inefficiency, and so\nhaving this default to false on FreeBSD might be a bit too broad a fix?\nI don’t take a strong view on what the right fix is, but would\nappreciate it if Git could by default on FreeBSD not use ctime to\ndetermine whether the shallow file has changed.\n\nI doubt it matters, but this is with Git 2.56.0, for what it’s worth.\n\nAlso, here’s an illustration this behaviour (whole script is set -x):\n\n> $ ./ctime-after-mv\n> + rm -fv foo bar\n> bar\n> + touch foo\n> + stat -f %Fc foo\n> 1796226770.687840000\n> + sleep 2\n> + stat -f %Fc foo\n> 1796226770.687840000\n> + sleep 2\n> + mv foo bar\n> + stat -f %Fc bar\n> 1796226774.694149000\n> + sleep 2\n> + stat -f %Fc bar\n> 1796226775.523101000\n\n\nThanks,\nJessica\n\n[1] https://cgit.freebsd.org/src/commit/?id=1a75045196a26c2dd00a03a3d6d231dd5b422a9b\n\n\n"},{"id":"559942","messageId":"axCe9q1zRyMVMtO8@fruit.crustytoothpaste.net","threadId":"66974","inReplyTo":"41F956FA-64BC-4F68-8619-2E8B9889C26F@jrtc27.com","subject":"Re: Shallow clones: ctime shouldn't be used on FreeBSD with UFS + soft-updates","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2026-12-02T22:43:03Z","receivedAt":"2026-12-02T22:43:03Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2026-12-02 at 18:10:33, Jessica Clarke wrote:\n> Hi,\n> Git uses ctime in various ways, but one of them is to check that the\n> shallow file has not changed since the last time it was read during a\n> shallow clone. In the case of the shallow file, it comes into being by\n> being renamed from shallow.lock, and is then immediately stat’ed to\n> give the before value. However, FreeBSD’s UFS soft-updates\n> implementation has slightly surprising semantics for unlink (and\n> internally uses link + unlink to implement rename): it will update\n> ctime at the point of unlink (and thus rename), but will *also* later\n> update it once its asynchronous soft-updates work is finished (see [1]\n> that explains this latter update, and introduces the former). This\n> means that, if Git is keying off ctime to determine whether shallow has\n> changed, it can race with this soft-updates code and potentially sample\n> either side of it, seeing the value change solely due to internal\n> bookkeeping work in the filesystem.\n\nI'm not sure this is technically POSIX compliant.  rename(2) is\ndocumented to update ctime, so that's okay.  But it says this:\n\n    An implementation may update timestamps that are marked for update\n    immediately, or it may update such timestamps periodically.\n\nHowever, it doesn't say you can update them twice for the same\noperation.  It would be allowed to update them _only_ at the soft-update\npoint or only immediately, but I don't think twice is allowed.\n\nWe do try to accommodate systems that don't fully comply with POSIX, but\nit is likely that Git is not the only tool that could be negatively\naffected here.\n\n> As a result, I see git submodule update --depth=1 some/path\n> sporadically fail on a FreeBSD 15.0-RELEASE-p11 (but as far as I know\n> not limited to this version) builder we have, with:\n> \n> > fatal: shallow file has changed since we read it\n> \n> I have set core.trustctime to false in the build user’s ~/.gitconfig as\n> a workaround. However, I imagine that other uses for ctime might be\n> tolerant of this behaviour, just leading to minor inefficiency, and so\n> having this default to false on FreeBSD might be a bit too broad a fix?\n> I don’t take a strong view on what the right fix is, but would\n> appreciate it if Git could by default on FreeBSD not use ctime to\n> determine whether the shallow file has changed.\n\nThe function that's called is match_stat_data, so I'm pretty sure it\napplies to all stat data, including the index, so my guess is pretty\nmuch nothing is going to be tolerant of this behaviour without\ncore.trustctime.  Functions updating the index will probably just\nre-read the data and be correct, if inefficient, so you may not have\nnoticed anything odd in that regard.\n\nMy suggestion would be that the FreeBSD Git packages set this in\n/etc/gitconfig if this is appropriate there.  I don't use FreeBSD except\nto test, so I can't really say what the appropriate setting there is.\nFor instance, UFS without soft-updates might be fine, or ZFS might not\nhave this problem, and those users might not want to incur the potential\nnegative consequences in this case.  I think the FreeBSD packagers are\nbest suited to make an appropriate decision and that's consistent with\nwhat other packagers do here[0].  They can also generate that\nconfiguration file on installation to set operations based on what file\nsystems are in use in a way that would be hard for us to confidently and\ncorrectly do.\n\nI also don't believe we have OS-specific defaults for config options;\nusually those are global unless the platform is completely incapable of\nsomething (e.g., symlinks) and we can easily detect that fact at repo\ncreation time, which I don't think we can do here in a generic way. (For\ninstance, statfs(2) is notoriously unportable.) This config option\nexists, as do many others, to gracefully handle infelicities in system\nimplementation, including poorly behaved file systems, so using it is\nthe right solution here.\n\n[0] For instance, Apple and Homebrew ship\n`credential.helper=osxkeychain` in the system config, and Git for\nWindows also sets a variety of config options suitable for that\nplatform.\n-- \nbrian m. carlson (they/them)\nToronto, Ontario, CA\nSpeaking for myself only\n"}]}