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

Re: [PATCH 2/2] git-compat-util: use gettimeofday for current time

From
Paul Eggert <eggert@cs.ucla.edu>
Date
Mar 20, 2023, 19:00 UTC
Message-ID
<047178a8-ccf5-1cab-e670-8f1c64f9ca3c@cs.ucla.edu>
In-Reply-To
<xmqqr0tjmk6d.fsf@gitster.g>
On 3/20/23 10:01, Junio C Hamano wrote:
Show 5 quoted lines
>> I however wonder if we should follow our
>> usual pattern of implementing git_time() with the identical function
>> signature as what we replace (i.e. system's time()), and #undef/#define
>> the symbol we replace with git_time, though.  Wouldn't it make [1/2]
>> a lot smaller and future-proof?

Yes, something like that would work too. (Sorry, I didn't know about the usual pattern.)

Show 5 quoted lines
> +# Define OVERRIDE_TIME to override time(2) and replace it with an
> +# implementation based on gettimeofday(2).  THis is necessary when
> +# glibc 2.31+ on Linux is used, where in the first 1 to 2.5 ms of
> +# every second, time(NULL) returns a value that is one less than the
> +# tv_sec part of higher-resolution timestamps used in the file system.
THis -> This

It might be simpler to use the gettimeofday workaround on all platforms, rather than having an OVERRIDE_TIME flag and complicating config.mak.uname. gettimeofday should be portable, as it's already used elsewhere in Git without configury.

If we're going with the more-complicated solution, config.mak.uname will need changes in its AIX and MS-Windows sections because the problem is known to occur there too. Although AIX configuration is simple, I'm not sure how to go about the MS-Windows part as there seem to be a lot of ifdefs there. Also, because the time problem does not occur with musl libc (used in Alpine Linux 3.17), on the Linux side the workaround could be employed only if glibc 2.31+ is in use.

Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 19 in “use gettimeofday for current time”
  1. 0/2 use gettimeofday for current timePaul Eggert, Mar 19, 2023
  2. 2/2 git-compat-util: use gettimeofday for current timePaul Eggert, Mar 19, 2023
  3. Eric WongMar 19, 2023
  4. Junio C HamanoMar 20, 2023
  5. Junio C HamanoMar 20, 2023
  6. Paul EggertMar 20, 2023
  7. Junio C HamanoMar 20, 2023
  8. Taylor BlauMar 20, 2023
  9. Taylor BlauMar 20, 2023
  10. 1/2 git-compat-util: time_now for current timePaul Eggert, Mar 19, 2023
  11. git-compat-util: use gettimeofday(2) for time(2)Junio C Hamano, Mar 20, 2023
  12. Paul EggertMar 20, 2023
  13. Junio C HamanoMar 21, 2023
  14. Konstantin KhomoutovMar 21, 2023
  15. Junio C HamanoMar 21, 2023
  16. Jeff KingMar 21, 2023
  17. Taylor BlauMar 21, 2023
  18. Junio C HamanoMar 21, 2023
  19. Jeff KingMar 22, 2023

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.