]> git.eshelyaron.com Git - emacs.git/commitdiff
project--vc-list-files: Use '--sparse' with 'git ls-files'
authorSean Allred <allred.sean@gmail.com>
Sun, 29 Sep 2024 01:00:32 +0000 (04:00 +0300)
committerEshel Yaron <me@eshelyaron.com>
Mon, 30 Sep 2024 19:41:17 +0000 (21:41 +0200)
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

index 714acc5faca14c8dfafb3376fc3e25a7702bfa38..c9e2dab100e2fe0379c031c9140025eb40783982 100644 (file)
@@ -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))))