emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A project-files implementation for Git projects


From: Tassilo Horn
Subject: A project-files implementation for Git projects
Date: Fri, 06 Sep 2019 11:19:55 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Hi all,

I'm struggling a bit with the performance of `project-files' for large
projects so I've tried coming up with a faster implementation for Git
projects which uses "git ls-files" instead of "find".

--8<---------------cut here---------------start------------->8---
(cl-defmethod project-files ((project (head vc)) &optional dirs)
  "Implementation of `project-files' for Git projects."
  (cl-mapcan
   (lambda (dir)
     (if-let ((git (and (file-exists-p
                         (expand-file-name ".git/config" dir))
                        (executable-find "git"))))
         (let ((default-directory dir))
           (sort (split-string
                  (shell-command-to-string
                   (concat git " ls-files -z"))
                  "\0" t)
                 #'string<))
       ;; No Git project, so go with the default.
       (cl-call-next-method)))
   (or dirs (project-roots project))))
--8<---------------cut here---------------end--------------->8---

Some benchmarking shows that it's about 8 times faster on my system.
Would something like this be worthwhile to have in project.el?

Some notes:

- Actually, that hasn't to be a cl-defmethod because the project type vc
  doesn't tell if it's a git project and we still need to test each dir
  separately.  So basically the default implementation could do that
  just as well.  Or maybe the project types could be transient or (vc
  . <backend>) where <backend> is some vc-backend?

- It changes the semantics a bit.  The default implementation finds all
  files (minus the ignored) from a project's directory while git
  ls-files just lists the tracked files.

Bye,
Tassilo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]