aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@batsov.dev>2026-02-28 08:45:26 +0200
committerBozhidar Batsov <bozhidar@batsov.dev>2026-02-28 08:54:10 +0200
commit63cd4eabddb6f49105ac702d1af1fe3bd8394210 (patch)
tree9e519429a158e5d3f391747453466970e0cfa220
parentf8f6ace05247387328e72077030da3f250361cf5 (diff)
Move dirconfig cache defvar and handle nil file-attributes
Move projectile--dirconfig-cache near other cache variables to fix byte-compilation warning. Also skip caching when file-attributes returns nil (e.g. file doesn't exist) to avoid false cache hits.
-rw-r--r--projectile.el16
1 files changed, 9 insertions, 7 deletions
diff --git a/projectile.el b/projectile.el
index ae5bf66..2e3d8cb 100644
--- a/projectile.el
+++ b/projectile.el
@@ -649,6 +649,10 @@ project."
(defvar projectile-project-type-cache (make-hash-table :test 'equal)
"A hashmap used to cache project type to speed up related operations.")
+(defvar projectile--dirconfig-cache (make-hash-table :test 'equal)
+ "Cache for parsed dirconfig files, keyed by project root.
+Each value is a cons of (MTIME . PARSED-RESULT).")
+
(defvar projectile-known-projects nil
"List of locations where we have previously seen projects.
The list of projects is ordered by the time they have been accessed.
@@ -2135,10 +2139,6 @@ Unignored files/directories are not included."
"Return the absolute path to the project's dirconfig file."
(expand-file-name projectile-dirconfig-file (projectile-project-root)))
-(defvar projectile--dirconfig-cache (make-hash-table :test 'equal)
- "Cache for parsed dirconfig files, keyed by project root.
-Each value is a cons of (MTIME . PARSED-RESULT).")
-
(defun projectile--parse-dirconfig-file-uncached ()
"Parse the dirconfig file without caching.
Returns a list of (KEEP IGNORE ENSURE) or nil if the file doesn't exist."
@@ -2184,11 +2184,13 @@ dirconfig file's modification time changes."
(let* ((dirconfig (projectile-dirconfig-file))
(project-root (projectile-project-root))
(cached (gethash project-root projectile--dirconfig-cache))
- (mtime (file-attribute-modification-time (file-attributes dirconfig))))
- (if (and cached (equal (car cached) mtime))
+ (attrs (file-attributes dirconfig))
+ (mtime (when attrs (file-attribute-modification-time attrs))))
+ (if (and cached mtime (equal (car cached) mtime))
(cdr cached)
(let ((result (projectile--parse-dirconfig-file-uncached)))
- (puthash project-root (cons mtime result) projectile--dirconfig-cache)
+ (when mtime
+ (puthash project-root (cons mtime result) projectile--dirconfig-cache))
result))))
(defun projectile-expand-root (name &optional dir)