* [PATCH 0/3] Convert USE_NSEC to runtime config
@ 2026-08-07 11:56 D. Ben Knoble
2026-08-07 11:56 ` [PATCH 1/3] meson: expose knob for xmlto relative links in manuals D. Ben Knoble
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: D. Ben Knoble @ 2026-08-07 11:56 UTC (permalink / raw)
To: git; +Cc: D. Ben Knoble
Topic name: dk/use-nsec-runtime
Topic summary: Expose USE_NSEC as a runtime configuration, since
build-time is too early for distributing Git [1]. As a result, common
index-related options, like git-diff, are less likely to hit "racy git"
problems on supported filesystems.
[1]: https://git.github.io/rev_news/2026/07/31/edition-137/
Built on master (2c78326f81 (The 11th batch, 2026-08-05)).
Hi all, this series follows up on the previous racy Git/USE_NSEC
conversations.
- The first patch is a mostly-unrelated documentation fix for Meson, but
it came out of something I spotted while reviewing the outputs of the
final (main) patch.
- The second patch is a preliminary no-op reorganization of
repo_config_values_init.
- The third patch is the meat, converting USE_NSEC into core.useNanosec.
There is a small textual and semantic conflict with
'ty/repo-config-cleanups' in 'seen', since that branch removes the
comments in 'struct repo_config_values' which this series adds to. (The
semantic conflict is that, if we drop those comments, we should probably
not add them to repo_config_values_init like I do in patch 2.)
Todo: I haven't touched any tests; I saw a bunch of hits for "git grep
racy t" but wasn't sure how to fit this particular change in, especially
since it won't be equally valid on all systems? Advice welcome.
Todo: I wonder if "useNanosec" paints us into too much of a corner; that
is (slightly more abstractly), we are using *extended precision* in the
index. Maybe the name and documentation should reflect that, so we
aren't too committed to "nanoseconds"?
- Some platforms could offer extended precision that is not as
precise as nanoseconds
- Some could offer precision _beyond_ nanoseconds
idk.
[1/3] meson: expose knob for xmlto relative links in manuals
[2/3] environment: align repo_config_values_init with struct declaration
[3/3] core: convert build-time USE_NSEC into runtime core.useNanosec
Documentation/config/core.adoc | 6 ++++++
Documentation/meson.build | 7 ++++++-
Documentation/technical/racy-git.adoc | 11 ++++++-----
Makefile | 12 +-----------
builtin/update-index.c | 2 +-
compat/posix.h | 1 -
configure.ac | 6 ------
environment.c | 25 ++++++++++++++++++-------
environment.h | 1 +
meson_options.txt | 2 ++
read-cache.c | 17 +++++++++--------
statinfo.c | 14 +++++++-------
12 files changed, 57 insertions(+), 47 deletions(-)
base-commit: 2c78326f810173a4f3aefd8021f1e07575412481
--
2.55.0.340.g8e2bf96aa5.dirty
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] meson: expose knob for xmlto relative links in manuals
2026-08-07 11:56 [PATCH 0/3] Convert USE_NSEC to runtime config D. Ben Knoble
@ 2026-08-07 11:56 ` D. Ben Knoble
2026-08-07 11:56 ` [PATCH 2/3] environment: align repo_config_values_init with struct declaration D. Ben Knoble
2026-08-07 11:56 ` [PATCH 3/3] core: convert build-time USE_NSEC into runtime core.useNanosec D. Ben Knoble
2 siblings, 0 replies; 6+ messages in thread
From: D. Ben Knoble @ 2026-08-07 11:56 UTC (permalink / raw)
To: git; +Cc: D. Ben Knoble, Junio C Hamano, Patrick Steinhardt
Makefile-based builds have had this knob for most of the project's life,
since a479a564dc (Documentation/Makefile: allow
man.base.url.for.relative.link to be set from Make, 2009-12-03).
Meson, however, hard-codes the equivalent of $prefix/$mandir, which is
not really where all the HTML docs are stored in most distro builds.
Plus, this value is missing a trailing slash, so links come out broken,
like this in git.1:
1. Git User’s Manual
/usr/share/manuser-manual.html
Of course we can do better:
1. Change the default to match Make: use file://$(htmldir)/ (with
trailing slash!) to form a local URL pointing at the HTML docs. This
is safe because all current uses of link:<relative> point at HTML
docs:
git grep 'link:[[:alnum:]]' Documentation | grep -ve html -e http
produces only a single result (Documentation/howto/howto-index.sh)
which can be ignored. Since nothing else [*] in the normal build sets
MAN_BASE_URL, this seems like the right default.
2. Provide a configurable knob, just like the Makefile, so distributions
that build with Meson (like Gentoo) can decide where to make the
links if they need to. Those that set htmldir probably won't need to
tweak this any further, though.
[*]: Well, Git's todo branch has a script dodoc.sh to build and archive
docs for kernel.org; these docs are pulled by Homebrew
installations, for example. It sets MAN_BASE_URL to "git_htmldocs",
so the equivalent note on macOS + Homebrew is
1. Git User’s Manual
git-htmldocs/user-manual.html
which is not functional either, but that's a problem for
downstream. In any case, users can recover the right path with
"git --html-path".
Signed-off-by: D. Ben Knoble <ben.knoble@gmail.com>
---
Notes (benknoble/commits):
This patch is mostly because I noticed the link I added in a later patch
didn't come out right.
I did an internet search for "MAN_BASE_URL" and got no real hits, so I'm
not sure if any distros today actually use it, but that's not a proper
audit in that I didn't look at any distro _code_ besides Gentoo (which,
as noted, uses Meson).
Documentation/meson.build | 7 ++++++-
meson_options.txt | 2 ++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/Documentation/meson.build b/Documentation/meson.build
index f4854f802d..cfa9c67609 100644
--- a/Documentation/meson.build
+++ b/Documentation/meson.build
@@ -379,13 +379,18 @@ foreach manpage, category : manpages
output: fs.stem(manpage) + '.xml',
)
+ man_base_url = 'file://' + htmldir + '/'
+ if get_option('man_base_url') != ''
+ man_base_url = get_option('man_base_url')
+ endif
+
doc_targets += custom_target(
command: [
xmlto,
'-m', '@INPUT0@',
'-m', '@INPUT1@',
'--stringparam',
- 'man.base.url.for.relative.links=' + get_option('prefix') / get_option('mandir'),
+ 'man.base.url.for.relative.links=' + man_base_url,
'man',
manpage_xml_target,
'-o',
diff --git a/meson_options.txt b/meson_options.txt
index dc88f130d7..d590c21648 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -111,6 +111,8 @@ option('default_help_format', type: 'combo', choices: ['man', 'html', 'platform'
description: 'Default format used when executing git-help(1).')
option('docs_backend', type: 'combo', choices: ['asciidoc', 'asciidoctor', 'auto'], value: 'auto',
description: 'Which backend to use to generate documentation.')
+option('man_base_url', type: 'string', value: '',
+ description: 'The base URL to use for relative links in manuals')
# Testing.
option('benchmarks', type: 'feature', value: 'auto',
--
2.55.0.340.g8e2bf96aa5.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] environment: align repo_config_values_init with struct declaration
2026-08-07 11:56 [PATCH 0/3] Convert USE_NSEC to runtime config D. Ben Knoble
2026-08-07 11:56 ` [PATCH 1/3] meson: expose knob for xmlto relative links in manuals D. Ben Knoble
@ 2026-08-07 11:56 ` D. Ben Knoble
2026-08-07 11:56 ` [PATCH 3/3] core: convert build-time USE_NSEC into runtime core.useNanosec D. Ben Knoble
2 siblings, 0 replies; 6+ messages in thread
From: D. Ben Knoble @ 2026-08-07 11:56 UTC (permalink / raw)
To: git; +Cc: D. Ben Knoble, Olamide Caleb Bello, Junio C Hamano, Tian Yuchen
The order of assignments in repo_config_values_init is chaotic and hard
to follow, especially when comparing with the struct definition to
ensure all members are initialized. As new members will be added in the
future, make it easier to validate changes by aligning the two.
Refactor assignment order with no behavioral changes.
Signed-off-by: D. Ben Knoble <ben.knoble@gmail.com>
---
environment.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/environment.c b/environment.c
index 76ee65e62b..6676e6f5ae 100644
--- a/environment.c
+++ b/environment.c
@@ -745,6 +745,7 @@ int git_default_config(const char *var, const char *value,
void repo_config_values_init(struct repo_config_values *cfg)
{
+ /* section "core" config values */
cfg->attributes_file = NULL;
cfg->excludes_file = NULL;
cfg->editor_program = NULL;
@@ -756,20 +757,24 @@ void repo_config_values_init(struct repo_config_values *cfg)
cfg->autorebase = AUTOREBASE_NEVER;
cfg->object_creation_mode = OBJECT_CREATION_MODE;
cfg->apply_sparse_checkout = 0;
- cfg->protect_hfs = PROTECT_HFS_DEFAULT;
- cfg->protect_ntfs = PROTECT_NTFS_DEFAULT;
- cfg->ignore_case = 0;
- cfg->trust_executable_bit = 1;
- cfg->has_symlinks = platform_has_symlinks();
- cfg->branch_track = BRANCH_TRACK_REMOTE;
cfg->trust_ctime = 1;
cfg->check_stat = 1;
cfg->zlib_compression_level = Z_BEST_SPEED;
cfg->pack_compression_level = Z_DEFAULT_COMPRESSION;
cfg->precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
cfg->core_sparse_checkout_cone = 0;
- cfg->sparse_expect_files_outside_of_patterns = 0;
cfg->warn_on_object_refname_ambiguity = 1;
+ cfg->protect_hfs = PROTECT_HFS_DEFAULT;
+ cfg->protect_ntfs = PROTECT_NTFS_DEFAULT;
+ cfg->ignore_case = 0;
+ cfg->trust_executable_bit = 1;
+ cfg->has_symlinks = platform_has_symlinks();
+
+ /* section "sparse" config values */
+ cfg->sparse_expect_files_outside_of_patterns = 0;
+
+ /* section "branch" config values */
+ cfg->branch_track = BRANCH_TRACK_REMOTE;
}
void repo_config_values_clear(struct repo_config_values *cfg)
--
2.55.0.340.g8e2bf96aa5.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] core: convert build-time USE_NSEC into runtime core.useNanosec
2026-08-07 11:56 [PATCH 0/3] Convert USE_NSEC to runtime config D. Ben Knoble
2026-08-07 11:56 ` [PATCH 1/3] meson: expose knob for xmlto relative links in manuals D. Ben Knoble
2026-08-07 11:56 ` [PATCH 2/3] environment: align repo_config_values_init with struct declaration D. Ben Knoble
@ 2026-08-07 11:56 ` D. Ben Knoble
2026-08-07 21:17 ` Junio C Hamano
2 siblings, 1 reply; 6+ messages in thread
From: D. Ben Knoble @ 2026-08-07 11:56 UTC (permalink / raw)
To: git
Cc: D. Ben Knoble, Tian Yuchen, Todd Zullinger, Patrick Steinhardt,
Olamide Caleb Bello, Junio C Hamano
Racy Git problems persist today, manifesting themselves in the
performance of commands like "git diff" in new worktrees [1]. We have
long had a build knob "USE_NSEC" to tell Git to use in-core nanosecond
precision when available, which mitigates most if not all racy issues,
but most builds we know about it don't use it. In part, that's because
someone distributing Git can't safely enable it at compile-time if they
don't know exactly what platforms their distribution will be used on.
[1]: https://lore.kernel.org/git/CALnO6CADMJSixqYvL1Yo8qKX5rWhKQ+2OoSEuPUh-yoeK9TseQ@mail.gmail.com
These days, most platforms are likely to be safe for the USE_NSEC code.
Regardless, we want to give users the ability to benefit from it. This
requires exposing the compile-time gated code as a runtime option.
In addition, update the Racy Git documentation and other mentions of
USE_NSEC in the code.
Best-viewed-with: --ignore-space-change
Signed-off-by: D. Ben Knoble <ben.knoble@gmail.com>
---
Notes (benknoble/commits):
Repeating the benchmark from my original mail [1] shows an improvement
# git worktree add -d ../perf-test HEAD
# hyperfine -N --warmup=10 './build/bin-wrappers/git diff'
Benchmark 1: ./build/bin-wrappers/git diff
Time (mean ± σ): 3.8 ms ± 0.4 ms [User: 4.7 ms, System: 4.4 ms]
Range (min … max): 3.2 ms … 5.6 ms 780 runs
# (pushd ../perf-test && hyperfine -N --warmup=10 $OLDPWD/'./build/bin-wrappers/git diff')
Benchmark 1: /home/benknoble/code/git/./build/bin-wrappers/git diff
Time (mean ± σ): 217.5 ms ± 2.9 ms [User: 202.1 ms, System: 23.4 ms]
Range (min … max): 213.9 ms … 223.3 ms 13 runs
# (pushd ../perf-test && hyperfine -N --warmup=10 $OLDPWD/'./build/bin-wrappers/git -c core.useNanosec=true diff')
Benchmark 1: /home/benknoble/code/git/./build/bin-wrappers/git -c core.useNanosec=true diff
Time (mean ± σ): 3.8 ms ± 0.4 ms [User: 5.3 ms, System: 4.2 ms]
Range (min … max): 3.2 ms … 6.9 ms 541 runs
[1]: <CALnO6CADMJSixqYvL1Yo8qKX5rWhKQ+2OoSEuPUh-yoeK9TseQ@mail.gmail.com>
Passing CI: https://github.com/benknoble/git/actions/runs/31104581195
Documentation/config/core.adoc | 6 ++++++
Documentation/technical/racy-git.adoc | 11 ++++++-----
Makefile | 12 +-----------
builtin/update-index.c | 2 +-
compat/posix.h | 1 -
configure.ac | 6 ------
environment.c | 6 ++++++
environment.h | 1 +
read-cache.c | 17 +++++++++--------
statinfo.c | 14 +++++++-------
10 files changed, 37 insertions(+), 39 deletions(-)
diff --git a/Documentation/config/core.adoc b/Documentation/config/core.adoc
index 340329edc3..33104444ab 100644
--- a/Documentation/config/core.adoc
+++ b/Documentation/config/core.adoc
@@ -118,6 +118,12 @@ core.trustctime::
crawlers and some backup systems).
See linkgit:git-update-index[1]. True by default.
+core.useNanosec::
+ If true, use nanosecond precision for ctime and mtime
+ comparisions between the index and the working tree (if Git
+ was compiled to store it).
+ See link:technical/racy-git.html[Racy Git]. False by default.
+
core.splitIndex::
If true, the split-index feature of the index will be used.
See linkgit:git-update-index[1]. False by default.
diff --git a/Documentation/technical/racy-git.adoc b/Documentation/technical/racy-git.adoc
index 59bea66c0f..499231585b 100644
--- a/Documentation/technical/racy-git.adoc
+++ b/Documentation/technical/racy-git.adoc
@@ -39,8 +39,8 @@ files) from `st_mode` member, `st_mtime` and `st_ctime`
timestamps, `st_uid`, `st_gid`, `st_ino`, and `st_size` members.
With a `USE_STDEV` compile-time option, `st_dev` is also
compared, but this is not enabled by default because this member
-is not stable on network filesystems. With `USE_NSEC`
-compile-time option, `st_mtim.tv_nsec` and `st_ctim.tv_nsec`
+is not stable on network filesystems. With 'core.useNanosec'
+config setting, `st_mtim.tv_nsec` and `st_ctim.tv_nsec`
members are also compared. On Linux, this is not enabled by default
because in-core timestamps can have finer granularity than
on-disk timestamps, resulting in meaningless changes when an
@@ -49,9 +49,10 @@ of git://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git
([PATCH] Sync in core time granularity with filesystems,
2005-01-04). This patch is included in kernel 2.6.11 and newer, but
only fixes the issue for file systems with exactly 1 ns or 1 s
-resolution. Other file systems are still broken in current Linux
-kernels (e.g. CEPH, CIFS, NTFS, UDF), see
-https://lore.kernel.org/lkml/5577240D.7020309@gmail.com/
+resolution. As of kernel 4.3, other file systems (CEPH, CIFS, NTFS, UFS, FUSE)
+were fixed; see https://public-inbox.org/git/5605D88A.20104%40gmail.com/. FAT
+has been fixed since 2015. The usual suspects (ext2, ext4, XFS) are known to
+work, too.
Racy Git
--------
diff --git a/Makefile b/Makefile
index fac3e8879c..b4ebcb9e83 100644
--- a/Makefile
+++ b/Makefile
@@ -197,18 +197,11 @@ include shared.mak
# Define NO_NORETURN if using buggy versions of gcc 4.6+ and profile feedback,
# as the compiler can crash (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49299)
#
-# Define USE_NSEC below if you want git to care about sub-second file mtimes
-# and ctimes. Note that you need recent glibc (at least 2.2.4) for this. On
-# Linux, kernel 2.6.11 or newer is required for reliable sub-second file times
-# on file systems with exactly 1 ns or 1 s resolution. If you intend to use Git
-# on other file systems (e.g. CEPH, CIFS, NTFS, UDF), don't enable USE_NSEC. See
-# Documentation/technical/racy-git.adoc for details.
-#
# Define USE_ST_TIMESPEC if your "struct stat" uses "st_ctimespec" instead of
# "st_ctim"
#
# Define NO_NSEC if your "struct stat" does not have "st_ctim.tv_nsec"
-# available. This automatically turns USE_NSEC off.
+# available.
#
# Define USE_STDEV below if you want git to care about the underlying device
# change being considered an inode change from the update-index perspective.
@@ -1935,9 +1928,6 @@ endif
ifdef NO_ST_BLOCKS_IN_STRUCT_STAT
BASIC_CFLAGS += -DNO_ST_BLOCKS_IN_STRUCT_STAT
endif
-ifdef USE_NSEC
- BASIC_CFLAGS += -DUSE_NSEC
-endif
ifdef USE_ST_TIMESPEC
BASIC_CFLAGS += -DUSE_ST_TIMESPEC
endif
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 241abd4332..8e0c25655f 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -130,7 +130,7 @@ static void xrmdir(const char *path)
static void avoid_racy(void)
{
/*
- * not use if we could usleep(10) if USE_NSEC is defined. The
+ * not use if we could usleep(10) if core.useNanosec is defined. The
* field nsec could be there, but the OS could choose to
* ignore it?
*/
diff --git a/compat/posix.h b/compat/posix.h
index e2e794cad7..51ee03233b 100644
--- a/compat/posix.h
+++ b/compat/posix.h
@@ -487,7 +487,6 @@ int git_qsort_s(void *base, size_t nmemb, size_t size,
} while (0)
#ifdef NO_NSEC
-#undef USE_NSEC
#define ST_CTIME_NSEC(st) 0
#define ST_MTIME_NSEC(st) 0
#else
diff --git a/configure.ac b/configure.ac
index cfb50112bf..fc956776ab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -351,12 +351,6 @@ GIT_PARSE_WITH(iconv))
## --enable-FEATURE[=ARG] and --disable-FEATURE
#
-# Define USE_NSEC below if you want git to care about sub-second file mtimes
-# and ctimes. Note that you need recent glibc (at least 2.2.4) for this, and
-# it will BREAK YOUR LOCAL DIFFS! show-diff and anything using it will likely
-# randomly break unless your underlying filesystem supports those sub-second
-# times (my ext3 doesn't).
-#
# Define USE_STDEV below if you want git to care about the underlying device
# change being considered an inode change from the update-index perspective.
diff --git a/environment.c b/environment.c
index 6676e6f5ae..e6a50060e8 100644
--- a/environment.c
+++ b/environment.c
@@ -571,6 +571,11 @@ int git_default_core_config(const char *var, const char *value,
return 0;
}
+ if (!strcmp(var, "core.usenanosec")) {
+ cfg->use_nanosec = git_config_bool(var, value);
+ return 0;
+ }
+
/* Add other config variables here and to Documentation/config.adoc. */
return platform_core_config(var, value, ctx, cb);
}
@@ -769,6 +774,7 @@ void repo_config_values_init(struct repo_config_values *cfg)
cfg->ignore_case = 0;
cfg->trust_executable_bit = 1;
cfg->has_symlinks = platform_has_symlinks();
+ cfg->use_nanosec = 0;
/* section "sparse" config values */
cfg->sparse_expect_files_outside_of_patterns = 0;
diff --git a/environment.h b/environment.h
index e7ec5b0437..a35534afe5 100644
--- a/environment.h
+++ b/environment.h
@@ -139,6 +139,7 @@ struct repo_config_values {
int ignore_case;
int trust_executable_bit;
int has_symlinks;
+ int use_nanosec;
/* section "sparse" config values */
int sparse_expect_files_outside_of_patterns;
diff --git a/read-cache.c b/read-cache.c
index 6c449f393d..297646c357 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -353,15 +353,16 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
static int is_racy_stat(const struct index_state *istate,
const struct stat_data *sd)
{
+ int use_nsec = 0;
+ repo_config_get_bool(the_repository, "core.useNanosec", &use_nsec);
+
return (istate->timestamp.sec &&
-#ifdef USE_NSEC
- /* nanosecond timestamped files can also be racy! */
- (istate->timestamp.sec < sd->sd_mtime.sec ||
- (istate->timestamp.sec == sd->sd_mtime.sec &&
- istate->timestamp.nsec <= sd->sd_mtime.nsec))
-#else
- istate->timestamp.sec <= sd->sd_mtime.sec
-#endif
+ /* nanosecond timestamped files can also be racy! */
+ use_nsec
+ ? (istate->timestamp.sec < sd->sd_mtime.sec ||
+ (istate->timestamp.sec == sd->sd_mtime.sec &&
+ istate->timestamp.nsec <= sd->sd_mtime.nsec))
+ : istate->timestamp.sec <= sd->sd_mtime.sec
);
}
diff --git a/statinfo.c b/statinfo.c
index 5e00af127d..d9ddcf9382 100644
--- a/statinfo.c
+++ b/statinfo.c
@@ -72,13 +72,13 @@ int match_stat_data(const struct stat_data *sd, struct stat *st)
sd->sd_ctime.sec != (unsigned int)st->st_ctime)
changed |= CTIME_CHANGED;
-#ifdef USE_NSEC
- if (cfg->check_stat && sd->sd_mtime.nsec != ST_MTIME_NSEC(*st))
- changed |= MTIME_CHANGED;
- if (cfg->trust_ctime && cfg->check_stat &&
- sd->sd_ctime.nsec != ST_CTIME_NSEC(*st))
- changed |= CTIME_CHANGED;
-#endif
+ if (cfg->use_nanosec) {
+ if (cfg->check_stat && sd->sd_mtime.nsec != ST_MTIME_NSEC(*st))
+ changed |= MTIME_CHANGED;
+ if (cfg->trust_ctime && cfg->check_stat &&
+ sd->sd_ctime.nsec != ST_CTIME_NSEC(*st))
+ changed |= CTIME_CHANGED;
+ }
if (cfg->check_stat) {
if (sd->sd_uid != (unsigned int) st->st_uid ||
--
2.55.0.340.g8e2bf96aa5.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] core: convert build-time USE_NSEC into runtime core.useNanosec
2026-08-07 11:56 ` [PATCH 3/3] core: convert build-time USE_NSEC into runtime core.useNanosec D. Ben Knoble
@ 2026-08-07 21:17 ` Junio C Hamano
2026-08-08 16:31 ` SZEDER Gábor
0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2026-08-07 21:17 UTC (permalink / raw)
To: D. Ben Knoble
Cc: git, Tian Yuchen, Todd Zullinger, Patrick Steinhardt,
Olamide Caleb Bello
"D. Ben Knoble" <ben.knoble@gmail.com> writes:
> Racy Git problems persist today, manifesting themselves in the
> performance of commands like "git diff" in new worktrees [1]. We have
> long had a build knob "USE_NSEC" to tell Git to use in-core nanosecond
> precision when available, which mitigates most if not all racy issues,
> but most builds we know about it don't use it. In part, that's because
> someone distributing Git can't safely enable it at compile-time if they
> don't know exactly what platforms their distribution will be used on.
>
> [1]: https://lore.kernel.org/git/CALnO6CADMJSixqYvL1Yo8qKX5rWhKQ+2OoSEuPUh-yoeK9TseQ@mail.gmail.com
>
> These days, most platforms are likely to be safe for the USE_NSEC code.
> Regardless, we want to give users the ability to benefit from it. This
> requires exposing the compile-time gated code as a runtime option.
>
> In addition, update the Racy Git documentation and other mentions of
> USE_NSEC in the code.
>
> Best-viewed-with: --ignore-space-change
Don't do this. It probably is helpful to have something like that
below the three-dash lines, though.
> Signed-off-by: D. Ben Knoble <ben.knoble@gmail.com>
> ---
> diff --git a/environment.c b/environment.c
> index 6676e6f5ae..e6a50060e8 100644
> --- a/environment.c
> +++ b/environment.c
> @@ -571,6 +571,11 @@ int git_default_core_config(const char *var, const char *value,
> return 0;
> }
>
> + if (!strcmp(var, "core.usenanosec")) {
> + cfg->use_nanosec = git_config_bool(var, value);
> + return 0;
> + }
OK.
> diff --git a/read-cache.c b/read-cache.c
> index 6c449f393d..297646c357 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -353,15 +353,16 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
> static int is_racy_stat(const struct index_state *istate,
> const struct stat_data *sd)
> {
> + int use_nsec = 0;
> + repo_config_get_bool(the_repository, "core.useNanosec", &use_nsec);
Yeek. Isn't this a relatively hot code path? If it is, it is
criminal to force string parsing and matching like this, every time
somebody calls the function.
Doesn't istate know what repository it is working with and in there
you should be able find its repo_settings struct cheaply, no?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] core: convert build-time USE_NSEC into runtime core.useNanosec
2026-08-07 21:17 ` Junio C Hamano
@ 2026-08-08 16:31 ` SZEDER Gábor
0 siblings, 0 replies; 6+ messages in thread
From: SZEDER Gábor @ 2026-08-08 16:31 UTC (permalink / raw)
To: Junio C Hamano
Cc: D. Ben Knoble, git, Tian Yuchen, Todd Zullinger,
Patrick Steinhardt, Olamide Caleb Bello
On Fri, Aug 07, 2026 at 02:17:39PM -0700, Junio C Hamano wrote:
> "D. Ben Knoble" <ben.knoble@gmail.com> writes:
>
> > Racy Git problems persist today, manifesting themselves in the
> > performance of commands like "git diff" in new worktrees [1]. We have
> > long had a build knob "USE_NSEC" to tell Git to use in-core nanosecond
> > precision when available, which mitigates most if not all racy issues,
> > but most builds we know about it don't use it. In part, that's because
> > someone distributing Git can't safely enable it at compile-time if they
> > don't know exactly what platforms their distribution will be used on.
> >
> > [1]: https://lore.kernel.org/git/CALnO6CADMJSixqYvL1Yo8qKX5rWhKQ+2OoSEuPUh-yoeK9TseQ@mail.gmail.com
> >
> > These days, most platforms are likely to be safe for the USE_NSEC code.
> > Regardless, we want to give users the ability to benefit from it. This
> > requires exposing the compile-time gated code as a runtime option.
> >
> > In addition, update the Racy Git documentation and other mentions of
> > USE_NSEC in the code.
> >
> > Best-viewed-with: --ignore-space-change
>
> Don't do this. It probably is helpful to have something like that
> below the three-dash lines, though.
Including this hint in the commit message could be useful for anyone
who stumbles upon this commit in a couple of months or years time.
Whether it should be a trailer or not is another question.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-08-08 16:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-07 11:56 [PATCH 0/3] Convert USE_NSEC to runtime config D. Ben Knoble
2026-08-07 11:56 ` [PATCH 1/3] meson: expose knob for xmlto relative links in manuals D. Ben Knoble
2026-08-07 11:56 ` [PATCH 2/3] environment: align repo_config_values_init with struct declaration D. Ben Knoble
2026-08-07 11:56 ` [PATCH 3/3] core: convert build-time USE_NSEC into runtime core.useNanosec D. Ben Knoble
2026-08-07 21:17 ` Junio C Hamano
2026-08-08 16:31 ` SZEDER Gábor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox