Skip to content

Commit ed4efab

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2bb4cda commit ed4efab

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,8 @@ extern void fill_stat_data(struct stat_data *sd, struct stat *st);
555555
* INODE_CHANGED, and DATA_CHANGED.
556556
*/
557557
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);
558560

559561
extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
560562

dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ static int add_excludes(const char *fname, const char *base, int baselen,
682682
if (sha1_stat) {
683683
int pos;
684684
if (sha1_stat->valid &&
685-
!match_stat_data(&sha1_stat->stat, &st))
685+
!match_stat_data_racy(&the_index, &sha1_stat->stat, &st))
686686
; /* no content change, ss->sha1 still good */
687687
else if (check_index &&
688688
(pos = cache_name_pos(fname, strlen(fname))) >= 0 &&
@@ -1539,7 +1539,7 @@ static int valid_cached_dir(struct dir_struct *dir,
15391539
return 0;
15401540
}
15411541
if (!untracked->valid ||
1542-
match_stat_data(&untracked->stat_data, &st)) {
1542+
match_stat_data_racy(&the_index, &untracked->stat_data, &st)) {
15431543
if (untracked->valid)
15441544
invalidate_directory(dir->untracked, untracked);
15451545
fill_stat_data(&untracked->stat_data, &st);

read-cache.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,14 @@ static int is_racy_timestamp(const struct index_state *istate,
294294
is_racy_stat(istate, &ce->ce_stat_data));
295295
}
296296

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+
297305
int ie_match_stat(const struct index_state *istate,
298306
const struct cache_entry *ce, struct stat *st,
299307
unsigned int options)

0 commit comments

Comments
 (0)