Skip to content

Commit

Permalink
fscache: make fscache_enabled() public
Browse files Browse the repository at this point in the history
Make fscache_enabled() function public rather than static.
Remove unneeded fscache_is_enabled() function.
Change is_fscache_enabled() macro to call fscache_enabled().

is_fscache_enabled() now takes a pathname so that the answer
is more precise and mean "is fscache enabled for this pathname",
since fscache only stores repo-relative paths and not absolute
paths, we can avoid attempting lookups for absolute paths.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
  • Loading branch information
jeffhostetler authored and dscho committed Sep 18, 2024
1 parent 6cc1649 commit 5a2c256
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
7 changes: 1 addition & 6 deletions compat/win32/fscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ static struct hashmap map;
static CRITICAL_SECTION mutex;
static struct trace_key trace_fscache = TRACE_KEY_INIT(FSCACHE);

int fscache_is_enabled(void)
{
return enabled;
}

/*
* An entry in the file system cache. Used for both entire directory listings
* and file entries.
Expand Down Expand Up @@ -273,7 +268,7 @@ static void fscache_clear(void)
/*
* Checks if the cache is enabled for the given path.
*/
static inline int fscache_enabled(const char *path)
int fscache_enabled(const char *path)
{
return enabled > 0 && !is_absolute_path(path);
}
Expand Down
4 changes: 2 additions & 2 deletions compat/win32/fscache.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
int fscache_enable(int enable);
#define enable_fscache(x) fscache_enable(x)

int fscache_is_enabled(void);
#define is_fscache_enabled() (fscache_is_enabled())
int fscache_enabled(const char *path);
#define is_fscache_enabled(path) fscache_enabled(path)

DIR *fscache_opendir(const char *dir);
int fscache_lstat(const char *file_name, struct stat *buf);
Expand Down
2 changes: 1 addition & 1 deletion dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ static int add_patterns(const char *fname, const char *base, int baselen,
size_t size = 0;
char *buf;

if (is_fscache_enabled()) {
if (is_fscache_enabled(fname)) {
if (lstat(fname, &st) < 0) {
fd = -1;
} else {
Expand Down
2 changes: 1 addition & 1 deletion git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ static inline int is_missing_file_error(int errno_)
#endif

#ifndef is_fscache_enabled
#define is_fscache_enabled() (0)
#define is_fscache_enabled(path) (0)
#endif

int cmd_main(int, const char **);
Expand Down

0 comments on commit 5a2c256

Please sign in to comment.