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)
}
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);
}
/*
......
......@@ -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.
......
......@@ -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 */
......
......@@ -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;
......
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