cmake: add USE_NSEC, and only check nanosec m/ctime if enabled
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 713640d..5790a03 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,6 +37,7 @@ OPTION( LIBGIT2_FILENAME "Name of the produced binary" OFF )
OPTION( USE_ICONV "Link with and use iconv library" OFF )
OPTION( USE_SSH "Link with libssh to enable SSH support" ON )
OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF )
+OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" OFF )
OPTION( VALGRIND "Configure build for valgrind" OFF )
OPTION( CURL "User curl for HTTP if available" ON)
@@ -500,6 +501,10 @@ IF (THREADSAFE)
ADD_DEFINITIONS(-DGIT_THREADS)
ENDIF()
+IF (USE_NSEC)
+ ADD_DEFINITIONS(-DGIT_USE_NSEC)
+ENDIF()
+
ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64)
# Collect sourcefiles
diff --git a/src/diff.c b/src/diff.c
index d97dcd9..b2259c7 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -835,7 +835,11 @@ static int maybe_modified(
*/
} else if (git_oid_iszero(&nitem->id) && new_is_workdir) {
bool use_ctime = ((diff->diffcaps & GIT_DIFFCAPS_TRUST_CTIME) != 0);
+#ifdef GIT_USE_NSEC
bool use_nanos = ((diff->diffcaps & GIT_DIFFCAPS_TRUST_NANOSECS) != 0);
+#else
+ bool use_nanos = false;
+#endif
git_index *index;
git_iterator_index(&index, info->new_iter);
diff --git a/src/index.c b/src/index.c
index 2e89347..54a8b1e 100644
--- a/src/index.c
+++ b/src/index.c
@@ -858,8 +858,11 @@ void git_index_entry__init_from_stat(
{
entry->ctime.seconds = (git_time_t)st->st_ctime;
entry->mtime.seconds = (git_time_t)st->st_mtime;
- /* entry->mtime.nanoseconds = st->st_mtimensec; */
- /* entry->ctime.nanoseconds = st->st_ctimensec; */
+#if !defined(GIT_WIN32) && !defined(__APPLE__)
+ /* Apple and Windows doesn't provide these struct stat fields. */
+ entry->mtime.nanoseconds = st->st_mtim.tv_nsec;
+ entry->ctime.nanoseconds = st->st_ctim.tv_nsec;
+#endif
entry->dev = st->st_rdev;
entry->ino = st->st_ino;
entry->mode = (!trust_mode && S_ISREG(st->st_mode)) ?
diff --git a/tests/merge/workdir/dirty.c b/tests/merge/workdir/dirty.c
index 4bf984c..ed402bd 100644
--- a/tests/merge/workdir/dirty.c
+++ b/tests/merge/workdir/dirty.c
@@ -163,9 +163,15 @@ static void hack_index(char *files[])
cl_git_pass(p_stat(path.ptr, &statbuf));
entry->ctime.seconds = (git_time_t)statbuf.st_ctime;
- entry->ctime.nanoseconds = 0;
entry->mtime.seconds = (git_time_t)statbuf.st_mtime;
+#if !defined(GIT_WIN32) && !defined(__APPLE__)
+ /* Apple and Windows doesn't provide these struct stat fields. */
+ entry->ctime.nanoseconds = statbuf.st_ctim.tv_nsec;
+ entry->mtime.nanoseconds = statbuf.st_mtim.tv_nsec;
+#else
+ entry->ctime.nanoseconds = 0;
entry->mtime.nanoseconds = 0;
+#endif
entry->dev = statbuf.st_dev;
entry->ino = statbuf.st_ino;
entry->uid = statbuf.st_uid;