untracked cache: avoid racy timestamps
When a directory is updated within the same second that its timestamp is last saved, we cannot realize the directory has been updated by checking timestamps. Assume the worst (something is update). See 29e4d36 (Racy GIT - 2005-12-20) for more information. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Mar 8, 2015 at 17:12 UTC
ed4efab1b17e883b761b4482c40c04a4529be8f9
3 files changed
+12
-2
cache.h
+2
@@ -555,6 +555,8 @@ extern void fill_stat_data(struct stat_data *sd, struct stat *st);
555
* INODE_CHANGED, and DATA_CHANGED.
556
*/
557
extern int match_stat_data(const struct stat_data *sd, struct stat *st);
558
+extern int match_stat_data_racy(const struct index_state *istate,
559
+ const struct stat_data *sd, struct stat *st);
560
561
extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
562
dir.c
+2
-2
@@ -682,7 +682,7 @@ static int add_excludes(const char *fname, const char *base, int baselen,
682
if (sha1_stat) {
683
int pos;
684
if (sha1_stat->valid &&
685
- !match_stat_data(&sha1_stat->stat, &st))
685
+ !match_stat_data_racy(&the_index, &sha1_stat->stat, &st))
686
; /* no content change, ss->sha1 still good */
687
else if (check_index &&
688
(pos = cache_name_pos(fname, strlen(fname))) >= 0 &&
@@ -1539,7 +1539,7 @@ static int valid_cached_dir(struct dir_struct *dir,
1539
return 0;
1540
}
1541
if (!untracked->valid ||
1542
- match_stat_data(&untracked->stat_data, &st)) {
1542
+ match_stat_data_racy(&the_index, &untracked->stat_data, &st)) {
1543
if (untracked->valid)
1544
invalidate_directory(dir->untracked, untracked);
1545
fill_stat_data(&untracked->stat_data, &st);
read-cache.c
+8
@@ -294,6 +294,14 @@ static int is_racy_timestamp(const struct index_state *istate,
294
is_racy_stat(istate, &ce->ce_stat_data));
295
}
296
297
+int match_stat_data_racy(const struct index_state *istate,
298
+ const struct stat_data *sd, struct stat *st)
299
+{
300
+ if (is_racy_stat(istate, sd))
301
+ return MTIME_CHANGED;
302
+ return match_stat_data(sd, st);
303
+}
304
+
305
int ie_match_stat(const struct index_state *istate,
306
const struct cache_entry *ce, struct stat *st,
307
unsigned int options)