aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@toptal.com>2026-04-26 11:17:16 +0100
committerBozhidar Batsov <bozhidar@toptal.com>2026-04-26 11:17:16 +0100
commit1ed5e991582a07688d794a03fe648d71afb53771 (patch)
treeb1cf0a76e75a77176bf05faddc26ed4b5104e61a
parent80d858dbb91368772c2fee659ae27b3094e06eec (diff)
Avoid recomputing VCS in projectile-dir-files-alien
The dispatcher in `projectile-dir-files` already resolves the VCS for the hybrid path. Thread it through to `projectile-dir-files-alien` via a new optional argument so we don't pay for a second `projectile-project-vcs` call on every indexing run. Single-argument callers (and the spies in the test suite) keep working unchanged. Also drop the post-hoc `(member local-f '("." ".."))` filter in `projectile-index-directory` in favour of `directory-files`' `directory-files-no-dot-files-regexp`, which handles the same case at the C level.
-rw-r--r--CHANGELOG.md2
-rw-r--r--projectile.el35
2 files changed, 23 insertions, 14 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3e16240..8a7f0ce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,8 @@
### Changes
+* `projectile-dir-files-alien` now accepts an optional `vcs` argument so the dispatcher can thread through the already-resolved VCS instead of recomputing it. Existing single-argument callers are unaffected.
+* `projectile-index-directory` (native indexing) now relies on `directory-files-no-dot-files-regexp` to filter out `.` and `..` at the C level instead of walking past them in Elisp.
* `projectile-project-root-cache` now keys entries on cons cells (`(FUNC . DIR)` for per-function results, `('none . DIR)` for the overall failure marker) instead of formatted strings. This is internal state, but third-party code that reaches into the cache directly will need to update.
* `projectile-parse-dirconfig-file' now returns a `projectile-dirconfig' struct (with `keep', `ignore', `ensure', and `prefixless-ignore' slots) instead of a positional 3-tuple. External callers should use the accessors (`projectile-dirconfig-keep' etc.) rather than `car'/`cadr'/`caddr'.
* Soft-deprecate prefix-less ignore entries in `.projectile'. Lines without a `+'/`-'/`!' prefix are still treated as ignore patterns for backward compatibility, but a one-time warning is now shown for each project that uses them. Set `projectile-warn-on-prefixless-dirconfig-lines' to nil to silence.
diff --git a/projectile.el b/projectile.el
index bcdf1a3..638642e 100644
--- a/projectile.el
+++ b/projectile.el
@@ -1599,13 +1599,14 @@ Files are returned as relative paths to DIRECTORY."
(gethash directory projectile-projects-cache))))
;; cache disabled or cache miss
(or files-list
- (let ((vcs (projectile-project-vcs directory)))
- (pcase projectile-indexing-method
- ('native (projectile-dir-files-native directory))
- ;; use external tools to get the project files
- ('hybrid (projectile-adjust-files directory vcs (projectile-dir-files-alien directory)))
- ('alien (projectile-dir-files-alien directory))
- (_ (user-error "Unsupported indexing method `%S'" projectile-indexing-method)))))))
+ (pcase projectile-indexing-method
+ ('native (projectile-dir-files-native directory))
+ ;; use external tools to get the project files
+ ('hybrid (let ((vcs (projectile-project-vcs directory)))
+ (projectile-adjust-files directory vcs
+ (projectile-dir-files-alien directory vcs))))
+ ('alien (projectile-dir-files-alien directory))
+ (_ (user-error "Unsupported indexing method `%S'" projectile-indexing-method))))))
;;; Native Project Indexing
;;
@@ -1637,8 +1638,7 @@ IGNORED-DIRECTORIES may optionally be provided."
(mapcar
(lambda (f)
(let ((local-f (file-name-nondirectory (directory-file-name f))))
- (unless (or (and patterns (projectile-ignored-rel-p f directory patterns))
- (member local-f '("." "..")))
+ (unless (and patterns (projectile-ignored-rel-p f directory patterns))
(progress-reporter-update progress-reporter)
(if (file-directory-p f)
(unless (projectile-ignored-directory-p
@@ -1651,17 +1651,24 @@ IGNORED-DIRECTORIES may optionally be provided."
(list f))))))
;; Use ignore-errors to skip unreadable directories (e.g.
;; .Spotlight-V100 on macOS) instead of aborting the entire
- ;; indexing operation.
- (ignore-errors (directory-files directory t))))))
+ ;; indexing operation. `directory-files-no-dot-files-regexp'
+ ;; filters out . and .. at the C level so we don't have to
+ ;; do it again in the loop.
+ (ignore-errors
+ (directory-files directory t directory-files-no-dot-files-regexp))))))
;;; Alien Project Indexing
;;
;; This corresponds to `projectile-indexing-method' being set to hybrid or alien.
;; The only difference between the two methods is that alien doesn't do
;; any post-processing of the files obtained via the external command.
-(defun projectile-dir-files-alien (directory)
- "Get the files for DIRECTORY using external tools."
- (let ((vcs (projectile-project-vcs directory)))
+(defun projectile-dir-files-alien (directory &optional vcs)
+ "Get the files for DIRECTORY using external tools.
+VCS, when supplied, must be the project's VCS as returned by
+`projectile-project-vcs'. It is computed from DIRECTORY when
+omitted; callers that already resolved the VCS can pass it in to
+avoid the redundant work."
+ (let ((vcs (or vcs (projectile-project-vcs directory))))
(cond
((eq vcs 'git)
(let* ((files (nconc (projectile-files-via-ext-command directory (projectile-get-ext-command vcs))