Code

Record ns-timestamps if possible, but do not use it without USE_NSEC
authorKjetil Barvik <barvik@broadpark.no>
Wed, 4 Mar 2009 17:47:40 +0000 (18:47 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 8 Mar 2009 04:25:16 +0000 (20:25 -0800)
Traditionally, the lack of USE_NSEC meant "do not record nor use the
nanosecond resolution part of the file timestamps".  To avoid problems on
filesystems that lose the ns part when the metadata is flushed to the disk
and then later read back in, disabling USE_NSEC has been a good idea in
general.

If you are on a filesystem without such an issue, it does not hurt to read
and store them in the cached stat data in the index entries even if your
git is compiled without USE_NSEC.  The index left with such a version of
git can be read by git compiled with USE_NSEC and it can make use of the
nanosecond part to optimize the check to see if the path on the filesystem
hsa been modified since we last looked at.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
builtin-fetch-pack.c
git-compat-util.h
read-cache.c
unpack-trees.c

index 27b9569746179e68c635bdaab8e57395f63faf01..65b5b8a63f20624cbe1080d6e61e11a0fc1e4ef0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -126,6 +126,9 @@ all::
 # randomly break unless your underlying filesystem supports those sub-second
 # times (my ext3 doesn't).
 #
+# Define NO_NSEC if your "struct stat" does not have "st_ctim.tv_nsec"
+# available.  This automatically turns USE_NSEC off.
+#
 # Define USE_STDEV below if you want git to care about the underlying device
 # change being considered an inode change from the update-index perspective.
 #
@@ -737,6 +740,7 @@ ifeq ($(uname_S),AIX)
        NO_MEMMEM = YesPlease
        NO_MKDTEMP = YesPlease
        NO_STRLCPY = YesPlease
+       NO_NSEC = YesPlease
        FREAD_READS_DIRECTORIES = UnfortunatelyYes
        INTERNAL_QSORT = UnfortunatelyYes
        NEEDS_LIBICONV=YesPlease
@@ -802,6 +806,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
        RUNTIME_PREFIX = YesPlease
        NO_POSIX_ONLY_PROGRAMS = YesPlease
        NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
+       NO_NSEC = YesPlease
        COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/regex -Icompat/fnmatch
        COMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1
        COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
@@ -923,6 +928,9 @@ endif
 ifdef NO_ST_BLOCKS_IN_STRUCT_STAT
        BASIC_CFLAGS += -DNO_ST_BLOCKS_IN_STRUCT_STAT
 endif
+ifdef NO_NSEC
+       BASIC_CFLAGS += -DNO_NSEC
+endif
 ifdef NO_C99_FORMAT
        BASIC_CFLAGS += -DNO_C99_FORMAT
 endif
index 3b210c7fdfd0e5a75e5627099fc8fa183b8c0269..59b0b0a796b65b23ff0b9c4d219869b4293f60c7 100644 (file)
@@ -801,9 +801,7 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
                int fd;
 
                mtime.sec = st.st_mtime;
-#ifdef USE_NSEC
-               mtime.nsec = st.st_mtim.tv_nsec;
-#endif
+               mtime.nsec = ST_MTIME_NSEC(st);
                if (stat(shallow, &st)) {
                        if (mtime.sec)
                                die("shallow file was removed during fetch");
index 079cbe9440dc73ba8703fe2efb70bd6677535a05..9b495dcad849cc103c9b03699df8d33b7d871235 100644 (file)
@@ -384,4 +384,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
+#define ST_CTIME_NSEC(st) 0
+#define ST_MTIME_NSEC(st) 0
+#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
+
 #endif
index 91f1d03c0957c54121156c6c0b685a91bb452c3e..b819abbd0003577a2b1f9576a09bce59aacbcdb0 100644 (file)
@@ -69,13 +69,8 @@ void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)
 {
        ce->ce_ctime.sec = (unsigned int)st->st_ctime;
        ce->ce_mtime.sec = (unsigned int)st->st_mtime;
-#ifdef USE_NSEC
-       ce->ce_ctime.nsec = (unsigned int)st->st_ctim.tv_nsec;
-       ce->ce_mtime.nsec = (unsigned int)st->st_mtim.tv_nsec;
-#else
-       ce->ce_ctime.nsec = 0;
-       ce->ce_mtime.nsec = 0;
-#endif
+       ce->ce_ctime.nsec = ST_CTIME_NSEC(*st);
+       ce->ce_mtime.nsec = ST_MTIME_NSEC(*st);
        ce->ce_dev = st->st_dev;
        ce->ce_ino = st->st_ino;
        ce->ce_uid = st->st_uid;
@@ -1183,13 +1178,8 @@ static void convert_from_disk(struct ondisk_cache_entry *ondisk, struct cache_en
 
        ce->ce_ctime.sec = ntohl(ondisk->ctime.sec);
        ce->ce_mtime.sec = ntohl(ondisk->mtime.sec);
-#ifdef USE_NSEC
        ce->ce_ctime.nsec = ntohl(ondisk->ctime.nsec);
        ce->ce_mtime.nsec = ntohl(ondisk->mtime.nsec);
-#else
-       ce->ce_ctime.nsec = 0;
-       ce->ce_mtime.nsec = 0;
-#endif
        ce->ce_dev   = ntohl(ondisk->dev);
        ce->ce_ino   = ntohl(ondisk->ino);
        ce->ce_mode  = ntohl(ondisk->mode);
@@ -1309,11 +1299,7 @@ int read_index_from(struct index_state *istate, const char *path)
                dst_offset += ce_size(ce);
        }
        istate->timestamp.sec = st.st_mtime;
-#ifdef USE_NSEC
-       istate->timestamp.nsec = (unsigned int)st.st_mtim.tv_nsec;
-#else
-       istate->timestamp.nsec = 0;
-#endif
+       istate->timestamp.nsec = ST_MTIME_NSEC(st);
 
        while (src_offset <= mmap_size - 20 - 8) {
                /* After an array of active_nr index entries,
@@ -1500,13 +1486,8 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
 
        ondisk->ctime.sec = htonl(ce->ce_ctime.sec);
        ondisk->mtime.sec = htonl(ce->ce_mtime.sec);
-#ifdef USE_NSEC
        ondisk->ctime.nsec = htonl(ce->ce_ctime.nsec);
        ondisk->mtime.nsec = htonl(ce->ce_mtime.nsec);
-#else
-       ondisk->ctime.nsec = 0;
-       ondisk->mtime.nsec = 0;
-#endif
        ondisk->dev  = htonl(ce->ce_dev);
        ondisk->ino  = htonl(ce->ce_ino);
        ondisk->mode = htonl(ce->ce_mode);
@@ -1583,9 +1564,7 @@ int write_index(struct index_state *istate, int newfd)
        if (ce_flush(&c, newfd) || fstat(newfd, &st))
                return -1;
        istate->timestamp.sec = (unsigned int)st.st_ctime;
-#ifdef USE_NSEC
-       istate->timestamp.nsec = (unsigned int)st.st_ctim.tv_nsec;
-#endif
+       istate->timestamp.nsec = ST_CTIME_NSEC(st);
        return 0;
 }
 
index 9fe0cd5f9b4e39dc8685a29c293a6138c02dcf4f..da2e3c09158195e98c20a08fb97f9b37a5d5a5a5 100644 (file)
@@ -362,9 +362,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
        o->result.initialized = 1;
        if (o->src_index) {
                o->result.timestamp.sec = o->src_index->timestamp.sec;
-#ifdef USE_NSEC
                o->result.timestamp.nsec = o->src_index->timestamp.nsec;
-#endif
        }
        o->merge_size = len;