summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/checkout.c3
-rw-r--r--src/diff.c49
-rw-r--r--src/diff.h1
-rw-r--r--src/index.c20
-rw-r--r--src/index.h39
-rw-r--r--src/win32/win32-compat.h2
-rw-r--r--tests/config/global.c2
-rw-r--r--tests/config/stress.c3
-rw-r--r--tests/win32/longpath.c2
9 files changed, 53 insertions, 68 deletions
diff --git a/src/checkout.c b/src/checkout.c
index d09357f2a..a92ad0825 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -200,8 +200,7 @@ static bool checkout_is_workdir_modified(
* out.)
*/
if ((ie = git_index_get_bypath(data->index, wditem->path, 0)) != NULL) {
- if (wditem->mtime.seconds == ie->mtime.seconds &&
- wditem->mtime.nanoseconds == ie->mtime.nanoseconds &&
+ if (git_index_time_eq(&wditem->mtime, &ie->mtime) &&
wditem->file_size == ie->file_size)
return !is_workdir_base_or_new(&ie->id, baseitem, newitem);
}
diff --git a/src/diff.c b/src/diff.c
index 0ab3b8d1f..9402b6e61 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -494,11 +494,6 @@ static int diff_list_apply_options(
/* Don't set GIT_DIFFCAPS_USE_DEV - compile time option in core git */
- /* Don't trust nanoseconds; we do not load nanos from disk */
-#ifdef GIT_USE_NSEC
- diff->diffcaps = diff->diffcaps | GIT_DIFFCAPS_TRUST_NANOSECS;
-#endif
-
/* If not given explicit `opts`, check `diff.xyz` configs */
if (!opts) {
int context = git_config__get_int_force(cfg, "diff.context", 3);
@@ -699,38 +694,6 @@ int git_diff__oid_for_entry(
return error;
}
-static bool diff_time_eq(
- const git_index_time *a, const git_index_time *b, bool use_nanos)
-{
- return a->seconds == b->seconds &&
- (!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;
@@ -863,11 +826,6 @@ 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);
@@ -886,13 +844,12 @@ static int maybe_modified(
modified_uncertain =
(oitem->file_size <= 0 && nitem->file_size > 0);
}
- else if (!diff_time_eq(&oitem->mtime, &nitem->mtime, use_nanos) ||
- (use_ctime &&
- !diff_time_eq(&oitem->ctime, &nitem->ctime, use_nanos)) ||
+ else if (!git_index_time_eq(&oitem->mtime, &nitem->mtime) ||
+ (use_ctime && !git_index_time_eq(&oitem->ctime, &nitem->ctime)) ||
oitem->ino != nitem->ino ||
oitem->uid != nitem->uid ||
oitem->gid != nitem->gid ||
- diff_newer_than_index(&nitem->mtime, index, use_nanos))
+ git_index_entry_newer_than_index(nitem, index))
{
status = GIT_DELTA_MODIFIED;
modified_uncertain = true;
diff --git a/src/diff.h b/src/diff.h
index 2dfc2c615..47743f88b 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -28,7 +28,6 @@ enum {
GIT_DIFFCAPS_TRUST_MODE_BITS = (1 << 2), /* use st_mode? */
GIT_DIFFCAPS_TRUST_CTIME = (1 << 3), /* use st_ctime? */
GIT_DIFFCAPS_USE_DEV = (1 << 4), /* use st_dev? */
- GIT_DIFFCAPS_TRUST_NANOSECS = (1 << 5), /* use stat time nanoseconds */
};
#define DIFF_FLAGS_KNOWN_BINARY (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)
diff --git a/src/index.c b/src/index.c
index bce16348c..ca5b2c46e 100644
--- a/src/index.c
+++ b/src/index.c
@@ -720,27 +720,13 @@ int git_index__changed_relative_to(
return !!git_oid_cmp(&index->checksum, checksum);
}
-static bool is_racy_timestamp(const struct timespec *stamp, git_index_entry *entry)
+static bool is_racy_entry(git_index *index, const git_index_entry *entry)
{
/* Git special-cases submodules in the check */
if (S_ISGITLINK(entry->mode))
return false;
- /* If we never read the index, we can't have this race either */
- if(stamp->tv_sec == 0)
- return false;
-
- /* If the timestamp is the same or newer than the index, it's racy */
-#if defined(GIT_USE_NSEC)
- if((int32_t) stamp->tv_sec < entry->mtime.seconds)
- return true;
- else if((int32_t) stamp->tv_sec > entry->mtime.seconds)
- return false;
- else
- return (uint32_t) stamp->tv_nsec <= entry->mtime.nanoseconds;
-#else
- return ((int32_t) stamp->tv_sec) <= entry->mtime.seconds;
-#endif
+ return git_index_entry_newer_than_index(entry, index);
}
/*
@@ -768,7 +754,7 @@ static int truncate_racily_clean(git_index *index)
diff_opts.flags |= GIT_DIFF_INCLUDE_TYPECHANGE | GIT_DIFF_IGNORE_SUBMODULES | GIT_DIFF_DISABLE_PATHSPEC_MATCH;
git_vector_foreach(&index->entries, i, entry) {
if ((entry->flags_extended & GIT_IDXENTRY_UPTODATE) == 0 &&
- is_racy_timestamp(&index->stamp.mtime, entry))
+ is_racy_entry(index, entry))
git_vector_insert(&paths, (char *)entry->path);
}
diff --git a/src/index.h b/src/index.h
index 546e677be..9baf976ee 100644
--- a/src/index.h
+++ b/src/index.h
@@ -65,6 +65,45 @@ extern int git_index_entry_icmp(const void *a, const void *b);
extern int git_index_entry_srch(const void *a, const void *b);
extern int git_index_entry_isrch(const void *a, const void *b);
+/* Index time handling functions */
+GIT_INLINE(bool) git_index_time_eq(const git_index_time *one, const git_index_time *two)
+{
+ if (one->seconds != two->seconds)
+ return false;
+
+#ifdef GIT_USE_NSEC
+ if (one->nanoseconds != two->nanoseconds)
+ return false;
+#endif
+
+ return true;
+}
+
+/*
+ * 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.
+ */
+GIT_INLINE(bool) git_index_entry_newer_than_index(
+ const git_index_entry *entry, git_index *index)
+{
+ /* If we never read the index, we can't have this race either */
+ if (!index || index->stamp.mtime.tv_sec == 0)
+ return false;
+
+ /* If the timestamp is the same or newer than the index, it's racy */
+#if defined(GIT_USE_NSEC)
+ if ((int32_t)index->stamp.tv_sec < entry->mtime.seconds)
+ return true;
+ else if ((int32_t)index->stamp.mtime.tv_sec > entry->mtime.seconds)
+ return false;
+ else
+ return (uint32_t)index->stamp.mtime.tv_nsec <= entry->mtime.nanoseconds;
+#else
+ return ((int32_t)index->stamp.mtime.tv_sec) <= entry->mtime.seconds;
+#endif
+}
+
/* Search index for `path`, returning GIT_ENOTFOUND if it does not exist
* (but not setting an error message).
*
diff --git a/src/win32/win32-compat.h b/src/win32/win32-compat.h
index 8b4070df7..d3a5b68a3 100644
--- a/src/win32/win32-compat.h
+++ b/src/win32/win32-compat.h
@@ -28,7 +28,7 @@ struct p_stat {
short st_uid;
short st_gid;
_dev_t st_rdev;
- uint64_t st_size;
+ __int64 st_size;
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
diff --git a/tests/config/global.c b/tests/config/global.c
index 0ddd204ad..a149dc0be 100644
--- a/tests/config/global.c
+++ b/tests/config/global.c
@@ -73,7 +73,7 @@ void test_config_global__open_programdata(void)
git_buf config_path = GIT_BUF_INIT;
git_buf var_contents = GIT_BUF_INIT;
- if (!cl_getenv("GITTEST_INVASIVE_FS_STRUCTURE"))
+ if (cl_is_env_set("GITTEST_INVASIVE_FS_STRUCTURE"))
cl_skip();
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH,
diff --git a/tests/config/stress.c b/tests/config/stress.c
index 6e960425c..a6b665590 100644
--- a/tests/config/stress.c
+++ b/tests/config/stress.c
@@ -126,4 +126,7 @@ void test_config_stress__quick_write(void)
cl_git_pass(git_config_get_int32(&val, config_r, key));
cl_assert_equal_i(i, val);
}
+
+ git_config_free(config_r);
+ git_config_free(config_w);
}
diff --git a/tests/win32/longpath.c b/tests/win32/longpath.c
index 6de7d389a..07eecd394 100644
--- a/tests/win32/longpath.c
+++ b/tests/win32/longpath.c
@@ -46,6 +46,8 @@ void assert_name_too_long(void)
/* check the suffix */
cl_assert_equal_s(expected_msg, err->message + (actual_len - expected_len));
+
+ git__free(expected_msg);
}
#endif