From deb86a578d89e7ed52f1a6823a46d5f1f4184d23 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 29 Sep 2024 04:00:32 +0300 Subject: [PATCH] project--vc-list-files: Use '--sparse' with 'git ls-files' When dealing with exceptionally large Git repositories, the performance of `project-find-file` can suffer dramatically as the list of files is collected for completion. This adds insult to injury when you consider cases where the developer has configured the repository to use a sparse checkout where the vast majority of these files are not even present on disk and are not valid candidates for completion. * lisp/progmodes/project.el (project--vc-list-files): Pass 'sparse' to 'git ls-files' when Git is recent enough. Filter out file names that end with '/' (bug#73320). (cherry picked from commit 8d9a4647fbc6c57e82045ecd2b3f157ece399e9e) --- lisp/progmodes/project.el | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 714acc5faca..c9e2dab100e 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -658,7 +658,7 @@ See `project-vc-extra-root-markers' for the marker value format.") (pcase backend (`Git (let* ((default-directory (expand-file-name (file-name-as-directory dir))) - (args '("-z")) + (args '("-z" "-c" "--exclude-standard")) (vc-git-use-literal-pathspecs nil) (include-untracked (project--value-in-dir 'project-vc-include-untracked @@ -666,7 +666,8 @@ See `project-vc-extra-root-markers' for the marker value format.") (submodules (project--git-submodules)) files) (setq args (append args - '("-c" "--exclude-standard") + (and (version<= "2.35" (vc-git--program-version)) + '("--sparse")) (and include-untracked '("-o")))) (when extra-ignores (setq args (append args @@ -698,7 +699,10 @@ See `project-vc-extra-root-markers' for the marker value format.") (delq nil (mapcar (lambda (file) - (unless (member file submodules) + (unless (or (member file submodules) + ;; Should occur for sparse directories + ;; only, when sparse index is enabled. + (directory-name-p file)) (if project-files-relative-names file (concat default-directory file)))) -- 2.39.5