Skip to content

Commit c3810de

Browse files
committed
fscache: implement an FSCache-aware is_mount_point()
When FSCache is active, we can cache the reparse tag and use it directly to determine whether a path refers to an NTFS junction, without any additional, costly I/O. Note: this change only makes a difference with the next commit, which will make use of the FSCache in `git clean` (contingent on `core.fscache` set, of course). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 13c7c9e commit c3810de

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

compat/mingw.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,6 +2959,8 @@ pid_t waitpid(pid_t pid, int *status, int options)
29592959
return -1;
29602960
}
29612961

2962+
int (*win32_is_mount_point)(struct strbuf *path) = mingw_is_mount_point;
2963+
29622964
int mingw_is_mount_point(struct strbuf *path)
29632965
{
29642966
WIN32_FIND_DATAW findbuf = { 0 };

compat/mingw.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ static inline void convert_slashes(char *path)
481481
}
482482
struct strbuf;
483483
int mingw_is_mount_point(struct strbuf *path);
484-
#define is_mount_point mingw_is_mount_point
484+
extern int (*win32_is_mount_point)(struct strbuf *path);
485+
#define is_mount_point win32_is_mount_point
485486
#define CAN_UNLINK_MOUNT_POINTS 1
486487
#define PATH_SEP ';'
487488
char *mingw_query_user_email(void);

compat/win32/fscache.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ int fscache_enable(size_t initial_size)
474474
/* redirect opendir and lstat to the fscache implementations */
475475
opendir = fscache_opendir;
476476
lstat = fscache_lstat;
477+
win32_is_mount_point = fscache_is_mount_point;
477478
}
478479
initialized++;
479480
LeaveCriticalSection(&fscache_cs);
@@ -534,6 +535,7 @@ void fscache_disable(void)
534535
/* reset opendir and lstat to the original implementations */
535536
opendir = dirent_opendir;
536537
lstat = mingw_lstat;
538+
win32_is_mount_point = mingw_is_mount_point;
537539
}
538540
LeaveCriticalSection(&fscache_cs);
539541

@@ -609,6 +611,44 @@ int fscache_lstat(const char *filename, struct stat *st)
609611
return 0;
610612
}
611613

614+
/*
615+
* is_mount_point() replacement, uses cache if enabled, otherwise falls
616+
* back to mingw_is_mount_point().
617+
*/
618+
int fscache_is_mount_point(struct strbuf *path)
619+
{
620+
int dirlen, base, len;
621+
#pragma GCC diagnostic push
622+
#ifdef __clang__
623+
#pragma GCC diagnostic ignored "-Wflexible-array-extensions"
624+
#endif
625+
struct heap_fsentry key[2];
626+
#pragma GCC diagnostic pop
627+
struct fsentry *fse;
628+
struct fscache *cache = fscache_getcache();
629+
630+
if (!cache || !do_fscache_enabled(cache, path->buf))
631+
return mingw_is_mount_point(path);
632+
633+
cache->lstat_requests++;
634+
/* split path into path + name */
635+
len = path->len;
636+
if (len && is_dir_sep(path->buf[len - 1]))
637+
len--;
638+
base = len;
639+
while (base && !is_dir_sep(path->buf[base - 1]))
640+
base--;
641+
dirlen = base ? base - 1 : 0;
642+
643+
/* lookup entry for path + name in cache */
644+
fsentry_init(&key[0].u.ent, NULL, path->buf, dirlen);
645+
fsentry_init(&key[1].u.ent, &key[0].u.ent, path->buf + base, len - base);
646+
fse = fscache_get(cache, &key[1].u.ent);
647+
if (!fse)
648+
return mingw_is_mount_point(path);
649+
return fse->reparse_tag == IO_REPARSE_TAG_MOUNT_POINT;
650+
}
651+
612652
typedef struct fscache_DIR {
613653
struct DIR base_dir; /* extend base struct DIR */
614654
struct fsentry *pfsentry;

compat/win32/fscache.h

Lines changed: 1 addition & 0 deletions
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)