summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAxel Rasmussen <axelrasmussen@google.com>2015-10-01 18:36:10 -0700
committerAxel Rasmussen <axelrasmussen@google.com>2015-10-01 18:36:10 -0700
commit28659e50d56bb79460c8a1d2315443267d6e6f66 (patch)
treee9852cb8a7756c59a4f55bc82a9f752cfeabf4fb
parent973a09a4ca6502e45826ec310aabf931c48f196e (diff)
downloadlibgit2-28659e50d56bb79460c8a1d2315443267d6e6f66.tar.gz
diff: refactor complex timestamp check into its own function
-rw-r--r--src/diff.c32
1 files changed, 27 insertions, 5 deletions
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;