git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 3/3] core: convert build-time USE_NSEC into runtime core.useNanosec

From
D. Ben Knoble <ben.knoble@gmail.com>
Date
Aug 19, 2026, 12:53 UTC
Message-ID
<CALnO6CAZ-_k=+xTZwi-+s2aeKwgkoY5Z_iJjF6_sBDreKEsTaw@mail.gmail.com>
In-Reply-To
<xmqqh5krxnwd.fsf@gitster.g>
[Patrick, the below probably helps answer some of your questions as well.]
On Tue, Aug 18, 2026 at 2:51 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 48 quoted lines
>
> "D. Ben Knoble" <ben.knoble@gmail.com> writes:
>
> > diff --git a/environment.c b/environment.c
> > index 6676e6f5ae..c7f6b801f4 100644
> > --- a/environment.c
> > +++ b/environment.c
> > @@ -571,6 +571,13 @@ int git_default_core_config(const char *var, const char *value,
> >               return 0;
> >       }
> >
> > +#ifndef NO_NSEC
> > +     if (!strcmp(var, "core.usenanosec")) {
> > +             cfg->use_nanosec = git_config_bool(var, value);
> > +             return 0;
> > +     }
> > +#endif
>
> What this hunk tells us: At build time, you could choose to ignore
> core.usenanosec configuration variable, preventing cfg->use_nanosec
> from getting flipped to true by the configured value.
>
> > @@ -769,6 +776,9 @@ 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();
> > +#ifndef NO_NSEC
> > +     cfg->use_nanosec = 0;
> > +#endif
>
> I think we want to unconditionally initialize it to 0, unless the
> definition of the .use_nanosec member itself in the structure is
> conditional on NO_NSEC.  And ...
>
> >
> >       /* 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;
>
> ... that is not the case.

Doh! I actually intended to send this version with a compiled-out member when NO_NSEC, since that was the only path I had come up with. No point in running around with code that's been asked to be ignored, eh? However…

> Which means that git_default_core_config() does keep the initial
> value of the member without getting affected by the configuration,
> but it does not necessarily be keeping "false".  It may be keeping
> the uninitialized state instead ;-).
[ugly #ifdef trimmed]
Show 19 quoted lines
> Ugly.  How about getting rid of the latter #ifndef/#else/#endif and
> instead keeping the "if use_nsec, pay attention to nsec, otherwise
> only the seconds part" ternary?  As to the early part, as you can
> arrange cfg's '.use_nanosec' to always hold a sensible value, the
> function can become
>
>         return (istate->timestamp.sec &&
>                 (repo_config_values(istate->repo)->use_nanosec
>                  ? (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));
>
> I think.
>
> The code you presented here for is_racy_stat() sprinkled with
> #ifndef/#else/#endif would be sensible if repo_config_values struct
> defined the '.use_nanosec' member conditionally.  But that is not
> what is happening here.
…I now see a world where we could avoid quite a bit of headache:
- use #if[n]def NO_NSEC to ignore the config variable, but otherwise
- unconditionally compile the cfg->use_nanosec checks

That is, future readers/writers won't have to remember that they can only use the use_nanosec member under compiler conditionals; it will always be initialized to a safe value (either always false or from config). If we're lucky, the compiler will optimize the checks away in NO_NSEC builds ;)

I think this is what you are suggesting Junio, so let me see what I can come up with.

-- 
D. Ben Knoble
Previous: Junio C HamanoNext: Patrick Steinhardt
Message 27 of 74 in “Convert USE_NSEC to runtime config”
  1. 0/3 Convert USE_NSEC to runtime configD. Ben Knoble, Aug 7, 2026
  2. 1/3 meson: expose knob for xmlto relative links in manualsD. Ben Knoble, Aug 7, 2026
  3. Patrick SteinhardtAug 10, 2026
  4. 2/3 environment: align repo_config_values_init with struct declarationD. Ben Knoble, Aug 7, 2026
  5. 3/3 core: convert build-time USE_NSEC into runtime core.useNanosecD. Ben Knoble, Aug 7, 2026
  6. Junio C HamanoAug 7, 2026
  7. SZEDER GáborAug 8, 2026
  8. D. Ben KnobleAug 10, 2026
  9. D. Ben KnobleAug 10, 2026
  10. Patrick SteinhardtAug 10, 2026
  11. Ben KnobleAug 11, 2026
  12. D. Ben KnobleAug 13, 2026
  13. Patrick SteinhardtAug 14, 2026
  14. Ben KnobleAug 14, 2026
  15. Patrick SteinhardtAug 10, 2026
  16. 0/3 Convert USE_NSEC to runtime configD. Ben Knoble, Aug 14, 2026
  17. 1/3 meson: expose knob for xmlto relative links in manualsD. Ben Knoble, Aug 14, 2026
  18. 2/3 environment: align repo_config_values_init with struct declarationD. Ben Knoble, Aug 14, 2026
  19. 3/3 core: convert build-time USE_NSEC into runtime core.useNanosecD. Ben Knoble, Aug 14, 2026
  20. Junio C HamanoAug 14, 2026
  21. D. Ben KnobleAug 14, 2026
  22. 0/3 Convert USE_NSEC to runtime configD. Ben Knoble, Aug 18, 2026
  23. 1/3 meson: expose knob for xmlto relative links in manualsD. Ben Knoble, Aug 18, 2026
  24. 2/3 environment: align repo_config_values_init with struct declarationD. Ben Knoble, Aug 18, 2026
  25. 3/3 core: convert build-time USE_NSEC into runtime core.useNanosecD. Ben Knoble, Aug 18, 2026
  26. Junio C HamanoAug 18, 2026
  27. D. Ben KnobleAug 19, 2026
  28. Patrick SteinhardtAug 19, 2026
  29. D. Ben KnobleAug 19, 2026
  30. Patrick SteinhardtAug 20, 2026
  31. D. Ben KnobleAug 20, 2026
  32. Junio C HamanoAug 19, 2026
  33. D. Ben KnobleAug 19, 2026
  34. Patrick SteinhardtAug 20, 2026
  35. 0/3 Convert USE_NSEC to runtime configD. Ben Knoble, Aug 20, 2026
  36. 1/3 meson: expose knob for xmlto relative links in manualsD. Ben Knoble, Aug 20, 2026
  37. 2/3 environment: align repo_config_values_init with struct declarationD. Ben Knoble, Aug 20, 2026
  38. Junio C HamanoAug 20, 2026
  39. D. Ben KnobleAug 21, 2026
  40. 3/3 core: convert build-time USE_NSEC into runtime core.useNanosecD. Ben Knoble, Aug 20, 2026
  41. 0/3 Convert USE_NSEC to runtime configD. Ben Knoble, Aug 29, 2026
  42. 1/3 meson: expose knob for xmlto relative links in manualsD. Ben Knoble, Aug 29, 2026
  43. 2/3 environment: align repo_config_values_init with struct declarationD. Ben Knoble, Aug 29, 2026
  44. 3/3 core: convert build-time USE_NSEC into runtime core.useNanosecD. Ben Knoble, Aug 29, 2026
  45. Junio C HamanoAug 30, 2026
  46. D. Ben KnobleAug 31, 2026
  47. Patrick SteinhardtAug 31, 2026
  48. D. Ben KnobleAug 31, 2026
  49. Patrick SteinhardtAug 31, 2026
  50. Ben KnobleAug 31, 2026
  51. 0/3 Convert USE_NSEC to runtime configD. Ben Knoble, Aug 31, 2026
  52. 1/3 meson: expose knob for xmlto relative links in manualsD. Ben Knoble, Aug 31, 2026
  53. 2/3 environment: align repo_config_values_init with struct declarationD. Ben Knoble, Aug 31, 2026
  54. 3/3 core: convert build-time USE_NSEC into runtime core.useNanosecD. Ben Knoble, Aug 31, 2026
  55. Junio C HamanoSep 1, 2026
  56. D. Ben KnobleSep 1, 2026
  57. Junio C HamanoSep 1, 2026
  58. Jeff KingSep 1, 2026
  59. D. Ben KnobleSep 1, 2026
  60. Jeff KingSep 2, 2026
  61. Ben KnobleSep 2, 2026
  62. Junio C HamanoSep 2, 2026
  63. Ben KnobleSep 3, 2026
  64. Junio C HamanoSep 3, 2026
  65. Ben KnobleSep 3, 2026
  66. D. Ben KnobleAug 31, 2026
  67. 0/3 Convert USE_NSEC to runtime configD. Ben Knoble, Sep 11, 2026
  68. 1/3 meson: expose knob for xmlto relative links in manualsD. Ben Knoble, Sep 11, 2026
  69. 2/3 environment: align repo_config_values_init with struct declarationD. Ben Knoble, Sep 11, 2026
  70. 3/3 core: convert build-time USE_NSEC into runtime core.useNanosecD. Ben Knoble, Sep 11, 2026
  71. Junio C HamanoSep 11, 2026
  72. Ben KnobleSep 11, 2026
  73. Patrick SteinhardtAug 31, 2026
  74. Ben KnobleSep 1, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.