diff options
| author | Bozhidar Batsov <bozhidar@toptal.com> | 2026-04-26 07:13:42 +0100 |
|---|---|---|
| committer | Bozhidar Batsov <bozhidar@toptal.com> | 2026-04-26 07:13:42 +0100 |
| commit | 67981d6d93b957edf3359d94f6216837427834bc (patch) | |
| tree | a425158198f405ee313de72377bf698559406f53 /projectile.el | |
| parent | 183023602f1002f39d6e5c82ca44a317d6b517fe (diff) | |
Skip cache for projectile-root-local (#1211)
projectile-root-local reads the buffer-local projectile-project-root
variable rather than inspecting its DIR argument, so caching its
result by (FUNC . DIR) was wrong: two buffers visiting the same
directory but with different file-local overrides would share the
first buffer's cached answer. Skip the cache for this function
specifically - it's a single variable read, no FS work to amortize.
Adds a regression test that visits two buffers with different
file-local roots from the same default-directory and confirms each
sees its own override.
Diffstat (limited to 'projectile.el')
| -rw-r--r-- | projectile.el | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/projectile.el b/projectile.el index bcd8302..0530925 100644 --- a/projectile.el +++ b/projectile.el @@ -1478,16 +1478,21 @@ If DIR is not supplied it's set to the current directory by default." (unless (or is-local is-connected) 'none)) ;; if the file is local or we're connected to it via TRAMP, run - ;; through the project root functions until we find a project dir + ;; through the project root functions until we find a project dir. + ;; `projectile-root-local' reads a buffer-local variable rather + ;; than inspecting DIR, so its result must not be cached - two + ;; buffers in the same directory can legitimately disagree. (seq-some (lambda (func) - (let* ((cache-key (cons func dir)) - (cache-value (gethash cache-key projectile-project-root-cache))) - (if (and cache-value (file-exists-p cache-value)) - cache-value - (let ((value (funcall func (file-truename dir)))) - (puthash cache-key value projectile-project-root-cache) - value)))) + (if (eq func 'projectile-root-local) + (funcall func dir) + (let* ((cache-key (cons func dir)) + (cache-value (gethash cache-key projectile-project-root-cache))) + (if (and cache-value (file-exists-p cache-value)) + cache-value + (let ((value (funcall func (file-truename dir)))) + (puthash cache-key value projectile-project-root-cache) + value))))) projectile-project-root-functions) ;; if we get here, we have failed to find a root by all ;; conventional means, and we assume the failure isn't transient |
