From e7de893ef899705f7b7e2d9894a7fda147b6d091 Mon Sep 17 00:00:00 2001 From: Axel Rasmussen Date: Mon, 1 Jun 2015 13:43:54 -0600 Subject: cmake: add USE_NSEC, and only check nanosec m/ctime if enabled --- src/diff.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/diff.c') diff --git a/src/diff.c b/src/diff.c index d97dcd9d2..b2259c74d 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); -- cgit v1.2.1 From 0226f7dd36c990e9bc1632adbc655fefc797513a Mon Sep 17 00:00:00 2001 From: Axel Rasmussen Date: Sat, 29 Aug 2015 13:59:20 -0700 Subject: diff/index: respect USE_NSEC for racily clean file detection --- src/diff.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/diff.c') diff --git a/src/diff.c b/src/diff.c index b2259c74d..f8e0c53d3 100644 --- a/src/diff.c +++ b/src/diff.c @@ -131,7 +131,7 @@ static int diff_delta__from_one( if (status == GIT_DELTA_UNTRACKED && DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_UNTRACKED)) return 0; - + if (status == GIT_DELTA_UNREADABLE && DIFF_FLAG_ISNT_SET(diff, GIT_DIFF_INCLUDE_UNREADABLE)) return 0; @@ -864,7 +864,10 @@ static int maybe_modified( oitem->ino != nitem->ino || oitem->uid != nitem->uid || oitem->gid != nitem->gid || - (index && nitem->mtime.seconds >= index->stamp.mtime)) + (index && + ((nitem->mtime.seconds > (int32_t) index->stamp.mtime.tv_sec) || + ((nitem->mtime.seconds == (int32_t) index->stamp.mtime.tv_sec) && + (nitem->mtime.nanoseconds >= (uint32_t) index->stamp.mtime.tv_nsec))))) { status = GIT_DELTA_MODIFIED; modified_uncertain = true; -- cgit v1.2.1 From 28659e50d56bb79460c8a1d2315443267d6e6f66 Mon Sep 17 00:00:00 2001 From: Axel Rasmussen Date: Thu, 1 Oct 2015 18:36:10 -0700 Subject: diff: refactor complex timestamp check into its own function --- src/diff.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'src/diff.c') diff --git a/src/diff.c b/src/diff.c index f8e0c53d3..09f29fcee 100644 --- a/src/diff.c +++ b/src/diff.c @@ -79,7 +79,7 @@ static bool diff_pathspec_match( git_diff *diff, const git_index_entry *entry) { - bool disable_pathspec_match = + bool disable_pathspec_match = DIFF_FLAG_IS_SET(diff, GIT_DIFF_DISABLE_PATHSPEC_MATCH); /* If we're disabling fnmatch, then the iterator has already applied @@ -703,6 +703,31 @@ static bool diff_time_eq( (!use_nanos || a->nanoseconds == b->nanoseconds); } +/* + * Test if the given index time is newer than the given existing index entry. + * If the timestamps are exactly equivalent, then the given index time is + * considered "racily newer" than the existing index entry. + */ +static bool diff_newer_than_index( + const git_index_time *a, const git_index *b, bool use_nanos) +{ + bool is_newer = false; + + if(!b) + return false; + + is_newer = is_newer || (a->seconds > (int32_t) b->stamp.mtime.tv_sec); + is_newer = is_newer || (!use_nanos && + (a->seconds == (int32_t) b->stamp.mtime.tv_sec)); + if(use_nanos) + { + is_newer = is_newer || ((a->seconds == (int32_t) b->stamp.mtime.tv_sec) && + (a->nanoseconds >= (uint32_t) b->stamp.mtime.tv_nsec)); + } + + return is_newer; +} + typedef struct { git_repository *repo; git_iterator *old_iter; @@ -864,10 +889,7 @@ static int maybe_modified( oitem->ino != nitem->ino || oitem->uid != nitem->uid || oitem->gid != nitem->gid || - (index && - ((nitem->mtime.seconds > (int32_t) index->stamp.mtime.tv_sec) || - ((nitem->mtime.seconds == (int32_t) index->stamp.mtime.tv_sec) && - (nitem->mtime.nanoseconds >= (uint32_t) index->stamp.mtime.tv_nsec))))) + diff_newer_than_index(&nitem->mtime, index, use_nanos)) { status = GIT_DELTA_MODIFIED; modified_uncertain = true; -- cgit v1.2.1