]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'pe/time-use-gettimeofday'
authorJunio C Hamano <gitster@pobox.com>
Tue, 28 Mar 2023 17:51:52 +0000 (10:51 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Mar 2023 17:51:52 +0000 (10:51 -0700)
time(2) on glib 2.31+, especially on Linux, goes out of sync with
higher resolution timers used for gettimeofday(2) and by the
filesystem.  Replace all calls to it with a git_time() wrapper and
use gettimeofday(2) in its implementation.

* pe/time-use-gettimeofday:
  git-compat-util: use gettimeofday(2) for time(2)

git-compat-util.h

index 1e6592624d09321428b03b6e77361ca2f94ba792..4a200a9fb41123e1d945ae9a397f09d7c0456367 100644 (file)
@@ -339,6 +339,25 @@ static inline const char *precompose_string_if_needed(const char *in)
 int compat_mkdir_wo_trailing_slash(const char*, mode_t);
 #endif
 
+#ifdef time
+#undef time
+#endif
+static inline time_t git_time(time_t *tloc)
+{
+       struct timeval tv;
+
+       /*
+        * Avoid time(NULL), which can disagree with gettimeofday(2)
+        * and filesystem timestamps.
+        */
+       gettimeofday(&tv, NULL);
+
+       if (tloc)
+               *tloc = tv.tv_sec;
+       return tv.tv_sec;
+}
+#define time git_time
+
 #ifdef NO_STRUCT_ITIMERVAL
 struct itimerval {
        struct timeval it_interval;