treewide: migrate from legacy utime.h to utimensat - #2209
Conversation
Welcome to GitGitGadgetHi @vonosmas, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests. Please make sure that either:
You can CC potential reviewers by adding a footer to the PR description with the following syntax: NOTE: DO NOT copy/paste your CC list from a previous GGG PR's description, Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:
It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code. Contributing the patchesBefore you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form Both the person who commented An alternative is the channel Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment If you want to see what email(s) would be sent for a After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail). If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the curl -g --user "<EMailAddress>:<Password>" \
--url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txtTo iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description): To send a new iteration, just add another PR comment with the contents: Need help?New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join. You may also be able to find help in real time in the developer IRC channel, |
In POSIX.1-2008, utime(3p) was marked as obsolescent in favor of utimensat(2) and futimens(2). In the recent POSIX.1-2024 (Issue 8) specification, <utime.h> and utime(3p) were officially removed. utimensat(2) operates on `struct timespec` rather than the second-only `struct utimbuf`, allowing sub-second timestamp updates while also providing support for UTIME_NOW and UTIME_OMIT flags to selectively update or preserve individual access and modification timestamps. Introduce a compatibility layer for utimensat(2): - Provide fallback definitions for AT_FDCWD, UTIME_NOW, and UTIME_OMIT in case the system headers lack them. - Introduce `ST_ATIME_NSEC(st)` to complement `ST_MTIME_NSEC(st)` and `ST_CTIME_NSEC(st)`. - Implement `git_utimensat()` in `compat/utimensat.c` as a fallback using utimes(2) on platforms that define NO_UTIMENSAT. - Implement `mingw_utimensat()` in `compat/mingw.c` converting `struct timespec` to Windows FILETIME with 100ns precision. - Wire up NO_UTIMENSAT support in Makefile, meson.build, contrib/buildsystems/CMakeLists.txt, and configure.ac. Subsequent commits will migrate callers across the codebase to utimensat(2) and drop the legacy <utime.h> header. Signed-off-by: Alexey Samsonov <vonosmas@gmail.com>
Now that a compatibility wrapper for utimensat(2) has been introduced, migrate all call sites across the codebase to use utimensat(2) instead of the legacy utime(3p) interface: - In `commit-graph.c`, use utimensat(2) with UTIME_OMIT and the computed timestamp `now` to bump the commit-graph modification time consistently across all files without needing an extra stat(2) call to preserve atime. - In `copy.c`, use utimensat(2) to copy full sub-second access and modification timestamps from the source file. - In `odb/source-packed.c`, `odb/source-loose.c`, and `object-file.c`, use utimensat(2) with `struct timespec` to freshen file timestamps. - In `builtin/pack-objects.c`, update the pack timestamp with utimensat(2). - In `rerere.c`, touch the postimage file with utimensat(2) passing NULL to set both atime and mtime to current time. - In `t/helper/test-chmtime.c`, update file modification times using utimensat(2). Signed-off-by: Alexey Samsonov <vonosmas@gmail.com>
With all callers across the codebase now converted to utimensat(2), we no longer need to include the legacy <utime.h> header in `compat/posix.h`. Remove `#include <utime.h>` from `compat/posix.h` and test fixtures, remove `mingw_utime()` from `compat/mingw.c`, and delete the legacy header shims in `compat/vcbuild/include/`. Signed-off-by: Alexey Samsonov <vonosmas@gmail.com>
utime() function for setting access/modification time for files
(and a corresponding <utime.h> header) have been officially removed
from POSIX starting from POSIX.1-2024. While existing system library
implementations still provide this function for compatibility reasons,
its implementation may be removed in the future, or otherwise degrade
over time. Some newer libc implementations (e.g. LLVM-libc, currently
under development) don't provide utime() function at all.
This PR switches the git codebase to recommended alternative:
utimensat() POSIX function (which supports nanosecond-level precision)
from <fcntl.h>, and, as a possible fallback for older systems
compatibility, utimes() function from <sys/stat.h>.
It also provides the corresponding MinGW wrapper.
The alternative is to unconditionally use utimes() where possible, but
given that utimensat is available in glibc starting from 2007, and on
BSD systems since 2012 or so, it makes sense to use the newer variant
by default.
No behavior changes is intended or expected (except for Git explicitly
passing nanosecond-precision timestamps to kernel, where
previously only second-level precision was used).
This change is generated by Gemini Flash from Antigravity, but all the
code has been manually verified by me, and, where applicable,
adjusted to match the existing behavior as closely as possible.
Signed-off-by: Alexey Samsonov vonosmas@gmail.com