diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2015-11-12 19:53:09 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-11-12 19:53:09 +0100 |
commit | 75a0ccf52fef2cab281de886730cda595d3736aa (patch) | |
tree | 977b981aca588511e96f20dca4acec983d993a16 /src/diff.c | |
parent | 2c26c8679ffc02b6644e20eba9458121b944beb6 (diff) | |
parent | 28659e50d56bb79460c8a1d2315443267d6e6f66 (diff) | |
download | libgit2-75a0ccf52fef2cab281de886730cda595d3736aa.tar.gz |
Merge pull request #3170 from CmdrMoozy/nsec_fix
git_index_entry__init_from_stat: set nsec fields in entry stats
Diffstat (limited to 'src/diff.c')
-rw-r--r-- | src/diff.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/diff.c b/src/diff.c index c2362358a..0ab3b8d1f 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 @@ -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; @@ -706,6 +706,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; @@ -838,7 +863,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); @@ -863,7 +892,7 @@ static int maybe_modified( oitem->ino != nitem->ino || oitem->uid != nitem->uid || oitem->gid != nitem->gid || - (index && nitem->mtime.seconds >= index->stamp.mtime)) + diff_newer_than_index(&nitem->mtime, index, use_nanos)) { status = GIT_DELTA_MODIFIED; modified_uncertain = true; |