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

USE_NSEC bug?

From
ARAndrew Rodland <andrew@cleverdomain.org>
Date
Mar 20, 2013, 06:36 UTC
Message-ID
<CABFQKmP6=Thhph4Ug+4LOBmzsVK42qBQYW2QHw87QD3019n+Kw@mail.gmail.com>

While investigating this StackOverflow question: http://stackoverflow.com/questions/15516168/how-to-cross-compile-git-for-arm I found that fetch-pack.c uses ST_MTIME_NSEC outside of the protection of #ifdef USE_NSEC. This results in a broken build if !defined(USE_NSEC) && !defined(NO_NSEC) and the target system doesn't happen to be recent glibc.

I'm not sure where to pin the bug exactly — on fetch-pack.c, on git-compat-util.h, on configure for not seeing if one of those fields actually exists and setting NO_NSEC otherwise, or elsewhere, but I would be tempted to fix it in one of the two below ways, which should always be foolproof when !defined(USE_NSEC). That seems right to me, since USE_NSEC is an experimental-ish feature.

Please Cc any replies as I'm not subscribed.
Way one (smaller diff for an uglier result):
--
diff --git a/git-compat-util.h b/git-compat-util.h
index 90e0372..222caaa 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -638,10 +638,13 @@ void git_qsort(void *base, size_t nmemb, size_t size,
 # define FORCE_DIR_SET_GID 0
 #endif

 #ifdef NO_NSEC
 #undef USE_NSEC
+#endif
+
+#ifndef USE_NSEC
 #define ST_CTIME_NSEC(st) 0
 #define ST_MTIME_NSEC(st) 0
 #else
 #ifdef USE_ST_TIMESPEC
 #define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctimespec.tv_nsec))

--

Way two (bigger diff for a prettier result):

diff --git a/git-compat-util.h b/git-compat-util.h
index 90e0372..0a15b1a 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -638,20 +638,23 @@ void git_qsort(void *base, size_t nmemb, size_t size,
 # define FORCE_DIR_SET_GID 0
 #endif

 #ifdef NO_NSEC
 #undef USE_NSEC
-#define ST_CTIME_NSEC(st) 0
-#define ST_MTIME_NSEC(st) 0
-#else
-#ifdef USE_ST_TIMESPEC
-#define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctimespec.tv_nsec))
-#define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtimespec.tv_nsec))
-#else
-#define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctim.tv_nsec))
-#define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtim.tv_nsec))
 #endif
+
+#ifdef USE_NSEC
+# ifdef USE_ST_TIMESPEC
+#  define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctimespec.tv_nsec))
+#  define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtimespec.tv_nsec))
+# else
+#  define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctim.tv_nsec))
+#  define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtim.tv_nsec))
+# endif
+#else /* !USE_NSEC */
+# define ST_CTIME_NSEC(st) 0
+# define ST_MTIME_NSEC(st) 0
 #endif

 #ifdef UNRELIABLE_FSTAT
 #define fstat_is_reliable() 0
 #else
Next: Jeff King
Message 1 of 9 in “USE_NSEC bug?”
  1. Andrew RodlandMar 20, 2013
  2. Jeff KingMar 20, 2013
  3. Junio C HamanoMar 20, 2013
  4. Jeff KingMar 20, 2013
  5. Junio C HamanoMar 20, 2013
  6. Andrew RodlandMar 20, 2013
  7. Jeff KingMar 20, 2013
  8. Junio C HamanoMar 20, 2013
  9. Jeff KingMar 20, 2013

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.