Skip to content

Commit b38c072

Browse files
committed
Merge branch 'dont-clean-junctions-fscache'
We already avoid traversing NTFS junction points in `git clean -dfx`. With this topic branch, we do that when the FSCache is enabled, too. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 0c6fe58 + 342f360 commit b38c072

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

builtin/clean.c

+2
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
10161016

10171017
if (read_cache() < 0)
10181018
die(_("index file corrupt"));
1019+
enable_fscache(active_nr);
10191020

10201021
pl = add_pattern_list(&dir, EXC_CMDL, "--exclude option");
10211022
for (i = 0; i < exclude_list.nr; i++)
@@ -1092,6 +1093,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
10921093
}
10931094
}
10941095

1096+
disable_fscache();
10951097
strbuf_release(&abs_path);
10961098
strbuf_release(&buf);
10971099
string_list_clear(&del_list, 0);

compat/mingw.c

+2
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,8 @@ pid_t waitpid(pid_t pid, int *status, int options)
26592659
return -1;
26602660
}
26612661

2662+
int (*win32_is_mount_point)(struct strbuf *path) = mingw_is_mount_point;
2663+
26622664
int mingw_is_mount_point(struct strbuf *path)
26632665
{
26642666
WIN32_FIND_DATAW findbuf = { 0 };

compat/mingw.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ static inline void convert_slashes(char *path)
464464
}
465465
struct strbuf;
466466
int mingw_is_mount_point(struct strbuf *path);
467-
#define is_mount_point mingw_is_mount_point
467+
extern int (*win32_is_mount_point)(struct strbuf *path);
468+
#define is_mount_point win32_is_mount_point
468469
#define CAN_UNLINK_MOUNT_POINTS 1
469470
#define PATH_SEP ';'
470471
char *mingw_query_user_email(void);

compat/win32/fscache.c

+40
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static struct trace_key trace_fscache = TRACE_KEY_INIT(FSCACHE);
4141
struct fsentry {
4242
struct hashmap_entry ent;
4343
mode_t st_mode;
44+
ULONG reparse_tag;
4445
/* Pointer to the directory listing, or NULL for the listing itself. */
4546
struct fsentry *list;
4647
/* Pointer to the next file entry of the list. */
@@ -189,6 +190,10 @@ static struct fsentry *fseentry_create_entry(struct fscache *cache,
189190

190191
fse = fsentry_alloc(cache, list, buf, len);
191192

193+
fse->reparse_tag =
194+
fdata->FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT ?
195+
fdata->EaSize : 0;
196+
192197
fse->st_mode = file_attr_to_st_mode(fdata->FileAttributes);
193198
fse->dirent.d_type = S_ISDIR(fse->st_mode) ? DT_DIR : DT_REG;
194199
fse->u.s.st_size = fdata->EndOfFile.LowPart |
@@ -456,6 +461,7 @@ int fscache_enable(size_t initial_size)
456461
/* redirect opendir and lstat to the fscache implementations */
457462
opendir = fscache_opendir;
458463
lstat = fscache_lstat;
464+
win32_is_mount_point = fscache_is_mount_point;
459465
}
460466
initialized++;
461467
LeaveCriticalSection(&fscache_cs);
@@ -516,6 +522,7 @@ void fscache_disable(void)
516522
/* reset opendir and lstat to the original implementations */
517523
opendir = dirent_opendir;
518524
lstat = mingw_lstat;
525+
win32_is_mount_point = mingw_is_mount_point;
519526
}
520527
LeaveCriticalSection(&fscache_cs);
521528

@@ -584,6 +591,39 @@ int fscache_lstat(const char *filename, struct stat *st)
584591
return 0;
585592
}
586593

594+
/*
595+
* is_mount_point() replacement, uses cache if enabled, otherwise falls
596+
* back to mingw_is_mount_point().
597+
*/
598+
int fscache_is_mount_point(struct strbuf *path)
599+
{
600+
int dirlen, base, len;
601+
struct heap_fsentry key[2];
602+
struct fsentry *fse;
603+
struct fscache *cache = fscache_getcache();
604+
605+
if (!cache || !do_fscache_enabled(cache, path->buf))
606+
return mingw_is_mount_point(path);
607+
608+
cache->lstat_requests++;
609+
/* split path into path + name */
610+
len = path->len;
611+
if (len && is_dir_sep(path->buf[len - 1]))
612+
len--;
613+
base = len;
614+
while (base && !is_dir_sep(path->buf[base - 1]))
615+
base--;
616+
dirlen = base ? base - 1 : 0;
617+
618+
/* lookup entry for path + name in cache */
619+
fsentry_init(&key[0].ent, NULL, path->buf, dirlen);
620+
fsentry_init(&key[1].ent, &key[0].ent, path->buf + base, len - base);
621+
fse = fscache_get(cache, &key[1].ent);
622+
if (!fse)
623+
return mingw_is_mount_point(path);
624+
return fse->reparse_tag == IO_REPARSE_TAG_MOUNT_POINT;
625+
}
626+
587627
typedef struct fscache_DIR {
588628
struct DIR base_dir; /* extend base struct DIR */
589629
struct fsentry *pfsentry;

compat/win32/fscache.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void fscache_flush(void);
2222

2323
DIR *fscache_opendir(const char *dir);
2424
int fscache_lstat(const char *file_name, struct stat *buf);
25+
int fscache_is_mount_point(struct strbuf *path);
2526

2627
/* opaque fscache structure */
2728
struct fscache;

0 commit comments

Comments
 (0)