Commit 624c949f01ca553fdd0b42fbac439e822c1bdd5f

Carlos Martín Nieto 2015-06-20T16:17:28

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.

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;