Skip to content

Commit bdd4da5

Browse files
paskyPetr Baudis
authored andcommitted
[PATCH] Make nsec checking optional
The nsec field of ctime/mtime is now checked only with -DNSEC defined during compilation. nsec acts broken since it is stored in the icache but apparently just gets to zero when flushed to filesystem not supporting it (e.g. ext3), creating illusions of false changes. At least that's my impression. Signed-off-by: Petr Baudis <[email protected]>
1 parent 5c2a7fb commit bdd4da5

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# -DCOLLISION_CHECK if you believe that SHA1's
22
# 1461501637330902918203684832716283019655932542976 hashes do not give you
33
# enough guarantees about no collisions between objects ever hapenning.
4+
#
5+
# -DNSEC if you want git to care about sub-second file mtimes and ctimes.
6+
# Note that you need some new glibc (at least >2.2.4) for this, and it will
7+
# BREAK YOUR LOCAL DIFFS! show-diff and anything using it will likely randomly
8+
# break unless your underlying filesystem supports those sub-second times
9+
# (my ext3 doesn't).
410
CFLAGS=-g -O3 -Wall
511

612
CC=gcc
713

14+
815
PROG= update-cache show-diff init-db write-tree read-tree commit-tree \
916
cat-file fsck-cache checkout-cache diff-tree rev-tree show-files \
1017
check-files ls-tree

read-cache.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,20 @@ int cache_match_stat(struct cache_entry *ce, struct stat *st)
250250
{
251251
unsigned int changed = 0;
252252

253-
if (ce->mtime.sec != (unsigned int)st->st_mtim.tv_sec ||
254-
ce->mtime.nsec != (unsigned int)st->st_mtim.tv_nsec)
253+
/* nsec seems unreliable - not all filesystems support it, so
254+
* as long as it is in the inode cache you get right nsec
255+
* but after it gets flushed, you get zero nsec. */
256+
if (ce->mtime.sec != (unsigned int)st->st_mtim.tv_sec
257+
#ifdef NSEC
258+
|| ce->mtime.nsec != (unsigned int)st->st_mtim.tv_nsec
259+
#endif
260+
)
255261
changed |= MTIME_CHANGED;
256-
if (ce->ctime.sec != (unsigned int)st->st_ctim.tv_sec ||
257-
ce->ctime.nsec != (unsigned int)st->st_ctim.tv_nsec)
262+
if (ce->ctime.sec != (unsigned int)st->st_ctim.tv_sec
263+
#ifdef NSEC
264+
|| ce->ctime.nsec != (unsigned int)st->st_ctim.tv_nsec
265+
#endif
266+
)
258267
changed |= CTIME_CHANGED;
259268
if (ce->st_uid != (unsigned int)st->st_uid ||
260269
ce->st_gid != (unsigned int)st->st_gid)

0 commit comments

Comments
 (0)