@matheusbsbs / matheus-bagliano / commits / c06ff4908b
Fork 0

Record ns-timestamps if possible, but do not use it without USE_NSEC

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>

Kjetil Barvik committed Mar 4, 2009 at 18:47 UTC c06ff4908bf9ad8bf2448439a3574321c9399b17
5 files changed +22 -30
Makefile
+8
@@ -126,6 +126,9 @@ all::
126 # randomly break unless your underlying filesystem supports those sub-second
127 # times (my ext3 doesn't).
128 #
129 +# Define NO_NSEC if your "struct stat" does not have "st_ctim.tv_nsec"
130 +# available. This automatically turns USE_NSEC off.
131 +#
132 # Define USE_STDEV below if you want git to care about the underlying device
133 # change being considered an inode change from the update-index perspective.
134 #
@@ -737,6 +740,7 @@ ifeq ($(uname_S),AIX)
740 NO_MEMMEM = YesPlease
741 NO_MKDTEMP = YesPlease
742 NO_STRLCPY = YesPlease
743 + NO_NSEC = YesPlease
744 FREAD_READS_DIRECTORIES = UnfortunatelyYes
745 INTERNAL_QSORT = UnfortunatelyYes
746 NEEDS_LIBICONV=YesPlease
@@ -802,6 +806,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
806 RUNTIME_PREFIX = YesPlease
807 NO_POSIX_ONLY_PROGRAMS = YesPlease
808 NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
809 + NO_NSEC = YesPlease
810 COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/regex -Icompat/fnmatch
811 COMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1
812 COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
@@ -923,6 +928,9 @@ endif
928 ifdef NO_ST_BLOCKS_IN_STRUCT_STAT
929 BASIC_CFLAGS += -DNO_ST_BLOCKS_IN_STRUCT_STAT
930 endif
931 +ifdef NO_NSEC
932 + BASIC_CFLAGS += -DNO_NSEC
933 +endif
934 ifdef NO_C99_FORMAT
935 BASIC_CFLAGS += -DNO_C99_FORMAT
936 endif
builtin-fetch-pack.c
+1 -3
@@ -801,9 +801,7 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
801 int fd;
802
803 mtime.sec = st.st_mtime;
804 -#ifdef USE_NSEC
805 - mtime.nsec = st.st_mtim.tv_nsec;
806 -#endif
804 + mtime.nsec = ST_MTIME_NSEC(st);
805 if (stat(shallow, &st)) {
806 if (mtime.sec)
807 die("shallow file was removed during fetch");
git-compat-util.h
+9
@@ -384,4 +384,13 @@ void git_qsort(void *base, size_t nmemb, size_t size,
384 # define FORCE_DIR_SET_GID 0
385 #endif
386
387 +#ifdef NO_NSEC
388 +#undef USE_NSEC
389 +#define ST_CTIME_NSEC(st) 0
390 +#define ST_MTIME_NSEC(st) 0
391 +#else
392 +#define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctim.tv_nsec))
393 +#define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtim.tv_nsec))
394 +#endif
395 +
396 #endif
read-cache.c
+4 -25
@@ -69,13 +69,8 @@ void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)
69 {
70 ce->ce_ctime.sec = (unsigned int)st->st_ctime;
71 ce->ce_mtime.sec = (unsigned int)st->st_mtime;
72 -#ifdef USE_NSEC
73 - ce->ce_ctime.nsec = (unsigned int)st->st_ctim.tv_nsec;
74 - ce->ce_mtime.nsec = (unsigned int)st->st_mtim.tv_nsec;
75 -#else
76 - ce->ce_ctime.nsec = 0;
77 - ce->ce_mtime.nsec = 0;
78 -#endif
72 + ce->ce_ctime.nsec = ST_CTIME_NSEC(*st);
73 + ce->ce_mtime.nsec = ST_MTIME_NSEC(*st);
74 ce->ce_dev = st->st_dev;
75 ce->ce_ino = st->st_ino;
76 ce->ce_uid = st->st_uid;
@@ -1183,13 +1178,8 @@ static void convert_from_disk(struct ondisk_cache_entry *ondisk, struct cache_en
1178
1179 ce->ce_ctime.sec = ntohl(ondisk->ctime.sec);
1180 ce->ce_mtime.sec = ntohl(ondisk->mtime.sec);
1186 -#ifdef USE_NSEC
1181 ce->ce_ctime.nsec = ntohl(ondisk->ctime.nsec);
1182 ce->ce_mtime.nsec = ntohl(ondisk->mtime.nsec);
1189 -#else
1190 - ce->ce_ctime.nsec = 0;
1191 - ce->ce_mtime.nsec = 0;
1192 -#endif
1183 ce->ce_dev = ntohl(ondisk->dev);
1184 ce->ce_ino = ntohl(ondisk->ino);
1185 ce->ce_mode = ntohl(ondisk->mode);
@@ -1309,11 +1299,7 @@ int read_index_from(struct index_state *istate, const char *path)
1299 dst_offset += ce_size(ce);
1300 }
1301 istate->timestamp.sec = st.st_mtime;
1312 -#ifdef USE_NSEC
1313 - istate->timestamp.nsec = (unsigned int)st.st_mtim.tv_nsec;
1314 -#else
1315 - istate->timestamp.nsec = 0;
1316 -#endif
1302 + istate->timestamp.nsec = ST_MTIME_NSEC(st);
1303
1304 while (src_offset <= mmap_size - 20 - 8) {
1305 /* 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)
1486
1487 ondisk->ctime.sec = htonl(ce->ce_ctime.sec);
1488 ondisk->mtime.sec = htonl(ce->ce_mtime.sec);
1503 -#ifdef USE_NSEC
1489 ondisk->ctime.nsec = htonl(ce->ce_ctime.nsec);
1490 ondisk->mtime.nsec = htonl(ce->ce_mtime.nsec);
1506 -#else
1507 - ondisk->ctime.nsec = 0;
1508 - ondisk->mtime.nsec = 0;
1509 -#endif
1491 ondisk->dev = htonl(ce->ce_dev);
1492 ondisk->ino = htonl(ce->ce_ino);
1493 ondisk->mode = htonl(ce->ce_mode);
@@ -1583,9 +1564,7 @@ int write_index(struct index_state *istate, int newfd)
1564 if (ce_flush(&c, newfd) || fstat(newfd, &st))
1565 return -1;
1566 istate->timestamp.sec = (unsigned int)st.st_ctime;
1586 -#ifdef USE_NSEC
1587 - istate->timestamp.nsec = (unsigned int)st.st_ctim.tv_nsec;
1588 -#endif
1567 + istate->timestamp.nsec = ST_CTIME_NSEC(st);
1568 return 0;
1569 }
1570
unpack-trees.c
-2
@@ -362,9 +362,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
362 o->result.initialized = 1;
363 if (o->src_index) {
364 o->result.timestamp.sec = o->src_index->timestamp.sec;
365 -#ifdef USE_NSEC
365 o->result.timestamp.nsec = o->src_index->timestamp.nsec;
367 -#endif
366 }
367 o->merge_size = len;
368