Commit 624c949f by Carlos Martín Nieto

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.
parent 5e947c91
...@@ -679,15 +679,13 @@ int git_index_read(git_index *index, int force) ...@@ -679,15 +679,13 @@ int git_index_read(git_index *index, int force)
} }
int git_index__changed_relative_to( 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) */ /* attempt to update index (ignoring errors) */
if (git_index_read(index, false) < 0) if (git_index_read(index, false) < 0)
giterr_clear(); giterr_clear();
return (index->stamp.mtime != fs->mtime || return !!git_oid_cmp(&index->checksum, checksum);
index->stamp.size != fs->size ||
index->stamp.ino != fs->ino);
} }
/* /*
......
...@@ -81,7 +81,7 @@ GIT_INLINE(const git_futils_filestamp *) git_index__filestamp(git_index *index) ...@@ -81,7 +81,7 @@ GIT_INLINE(const git_futils_filestamp *) git_index__filestamp(git_index *index)
return &index->stamp; 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. /* Copy the current entries vector *and* increment the index refcount.
* Call `git_index__release_snapshot` when done. * Call `git_index__release_snapshot` when done.
......
...@@ -1946,7 +1946,7 @@ static int submodule_cache_refresh(git_submodule_cache *cache, int refresh) ...@@ -1946,7 +1946,7 @@ static int submodule_cache_refresh(git_submodule_cache *cache, int refresh)
update_index = update_head = update_gitmod = true; update_index = update_head = update_gitmod = true;
else { else {
update_index = update_index =
!idx || git_index__changed_relative_to(idx, &cache->index_stamp); !idx || git_index__changed_relative_to(idx, &cache->index_checksum);
update_head = update_head =
!head || !git_oid_equal(&cache->head_id, git_tree_id(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) ...@@ -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) if ((error = submodule_cache_refresh_from_index(cache, idx)) < 0)
goto cleanup; goto cleanup;
git_futils_filestamp_set( git_oid_cpy(&cache->index_checksum, git_index_checksum(idx));
&cache->index_stamp, git_index__filestamp(idx));
} }
/* add submodule information from HEAD */ /* add submodule information from HEAD */
......
...@@ -110,7 +110,7 @@ typedef struct { ...@@ -110,7 +110,7 @@ typedef struct {
/* cache invalidation data */ /* cache invalidation data */
git_oid head_id; git_oid head_id;
git_futils_filestamp index_stamp; git_oid index_checksum;
git_buf gitmodules_path; git_buf gitmodules_path;
git_futils_filestamp gitmodules_stamp; git_futils_filestamp gitmodules_stamp;
git_futils_filestamp config_stamp; git_futils_filestamp config_stamp;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment