index: make relative comparison use the checksum as well This is used by the submodule in order to figure out if the index has changed since it last read it. Using a timestamp is racy, so let's make it use the checksum, just like we now do for reloading the index itself.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
diff --git a/src/index.c b/src/index.c
index ba101ea..1fb3c48 100644
--- a/src/index.c
+++ b/src/index.c
@@ -679,15 +679,13 @@ int git_index_read(git_index *index, int force)
}
int git_index__changed_relative_to(
- git_index *index, const git_futils_filestamp *fs)
+ git_index *index, const git_oid *checksum)
{
/* attempt to update index (ignoring errors) */
if (git_index_read(index, false) < 0)
giterr_clear();
- return (index->stamp.mtime != fs->mtime ||
- index->stamp.size != fs->size ||
- index->stamp.ino != fs->ino);
+ return !!git_oid_cmp(&index->checksum, checksum);
}
/*
diff --git a/src/index.h b/src/index.h
index 615d703..9c60b01 100644
--- a/src/index.h
+++ b/src/index.h
@@ -81,7 +81,7 @@ GIT_INLINE(const git_futils_filestamp *) git_index__filestamp(git_index *index)
return &index->stamp;
}
-extern int git_index__changed_relative_to(git_index *index, const git_futils_filestamp *fs);
+extern int git_index__changed_relative_to(git_index *index, const git_oid *checksum);
/* Copy the current entries vector *and* increment the index refcount.
* Call `git_index__release_snapshot` when done.
diff --git a/src/submodule.c b/src/submodule.c
index 1139df9..246502e 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -1946,7 +1946,7 @@ static int submodule_cache_refresh(git_submodule_cache *cache, int refresh)
update_index = update_head = update_gitmod = true;
else {
update_index =
- !idx || git_index__changed_relative_to(idx, &cache->index_stamp);
+ !idx || git_index__changed_relative_to(idx, &cache->index_checksum);
update_head =
!head || !git_oid_equal(&cache->head_id, git_tree_id(head));
@@ -1984,8 +1984,7 @@ static int submodule_cache_refresh(git_submodule_cache *cache, int refresh)
if ((error = submodule_cache_refresh_from_index(cache, idx)) < 0)
goto cleanup;
- git_futils_filestamp_set(
- &cache->index_stamp, git_index__filestamp(idx));
+ git_oid_cpy(&cache->index_checksum, git_index_checksum(idx));
}
/* add submodule information from HEAD */
diff --git a/src/submodule.h b/src/submodule.h
index a6182be..7a9bf9c 100644
--- a/src/submodule.h
+++ b/src/submodule.h
@@ -110,7 +110,7 @@ typedef struct {
/* cache invalidation data */
git_oid head_id;
- git_futils_filestamp index_stamp;
+ git_oid index_checksum;
git_buf gitmodules_path;
git_futils_filestamp gitmodules_stamp;
git_futils_filestamp config_stamp;