all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: Dmitry Gutov <dmitry@gutov.dev>, 66806@debbugs.gnu.org
Subject: bug#66806: 30.0.50; [PATCH] 'project-find-regexp' passes Git submodules to the search program
Date: Sun, 29 Oct 2023 17:58:01 -0700	[thread overview]
Message-ID: <64f0f8b9-ea72-4bba-7d90-0e6c300e6154@gmail.com> (raw)
In-Reply-To: <7136cdaa-25ea-17f7-396c-e217d845e837@gutov.dev>

[-- Attachment #1: Type: text/plain, Size: 1092 bytes --]

On 10/29/2023 2:41 PM, Dmitry Gutov wrote:
> And that's not to mention usage over Tramp (which would be affected by 
> the +1 process call that you mentioned as well, but that seems 
> unavoidable).

Yeah, I don't see a way around that, unless we constructed a complex 
command to run via Tramp that does it all in one go.

(I looked into using the "--stage" argument for "git ls-files", which 
gets most of the way to fixing this, but you could break that logic with 
evil file names not in the tree...)

> Anyway, after recent experience micro-optimizing list operations, I came 
> up with this version where the impact seems minimal.
> 
> WDYT?

Thanks, that helped form the basis for the attached patch. It moves the 
'member' call into the lambda for the original 'mapcar', and then we can 
just 'delq' all the nil elements. Benchmarking against the Emacs repo, 
this still seems to have a minimal perf impact.

There might also be a benefit to using "git ls-files 
--recurse-submodules" when we can (i.e. when not using "-o"), but maybe 
we can leave that optimization for another day.

[-- Attachment #2: 0001-Exclude-Git-submodules-from-project-files.patch --]
[-- Type: text/plain, Size: 3625 bytes --]

From b0e01806e36c8671279e6ffeb6ba2397655a3f5a Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Sat, 28 Oct 2023 22:20:41 -0700
Subject: [PATCH] Exclude Git submodules from 'project-files'

* lisp/progmodes/project.el (project--vc-list-files): Exclude Git
submodules.
(project-search, project-query-replace-regexp): Remove now-unneeded
workaround.
---
 lisp/progmodes/project.el | 41 +++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index fda1081eb62..bb44cfefa54 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -647,6 +647,7 @@ project--vc-list-files
             (include-untracked (project--value-in-dir
                                 'project-vc-include-untracked
                                 dir))
+            (submodules (project--git-submodules))
             files)
        (setq args (append args
                           '("-c" "--exclude-standard")
@@ -678,23 +679,25 @@ project--vc-list-files
                                         i)))
                                    extra-ignores)))))
        (setq files
-             (mapcar
-              (lambda (file) (concat default-directory file))
-              (split-string
-               (apply #'vc-git--run-command-string nil "ls-files" args)
-               "\0" t)))
+             (delq nil
+                   (mapcar
+                    (lambda (file)
+                      (unless (member file submodules)
+                        (concat default-directory file)))
+                    (split-string
+                     (apply #'vc-git--run-command-string nil "ls-files" args)
+                     "\0" t))))
        (when (project--vc-merge-submodules-p default-directory)
          ;; Unfortunately, 'ls-files --recurse-submodules' conflicts with '-o'.
-         (let* ((submodules (project--git-submodules))
-                (sub-files
-                 (mapcar
-                  (lambda (module)
-                    (when (file-directory-p module)
-                      (project--vc-list-files
-                       (concat default-directory module)
-                       backend
-                       extra-ignores)))
-                  submodules)))
+         (let ((sub-files
+                (mapcar
+                 (lambda (module)
+                   (when (file-directory-p module)
+                     (project--vc-list-files
+                      (concat default-directory module)
+                      backend
+                      extra-ignores)))
+                 submodules)))
            (setq files
                  (apply #'nconc files sub-files))))
        ;; 'git ls-files' returns duplicate entries for merge conflicts.
@@ -1326,8 +1329,7 @@ project-search
   (interactive "sSearch (regexp): ")
   (fileloop-initialize-search
    regexp
-   ;; XXX: See the comment in project-query-replace-regexp.
-   (cl-delete-if-not #'file-regular-p (project-files (project-current t)))
+   (project-files (project-current t))
    'default)
   (fileloop-continue))
 
@@ -1348,10 +1350,7 @@ project-query-replace-regexp
        (list from to))))
   (fileloop-initialize-replace
    from to
-   ;; XXX: Filter out Git submodules, which are not regular files.
-   ;; `project-files' can return those, which is arguably suboptimal,
-   ;; but removing them eagerly has performance cost.
-   (cl-delete-if-not #'file-regular-p (project-files (project-current t)))
+   (project-files (project-current t))
    'default)
   (fileloop-continue))
 
-- 
2.25.1


  reply	other threads:[~2023-10-30  0:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-29  5:36 bug#66806: 30.0.50; [PATCH] 'project-find-regexp' passes Git submodules to the search program Jim Porter
2023-10-29  6:06 ` Eli Zaretskii
2023-10-29 17:54   ` Jim Porter
2023-10-29 19:22     ` Eli Zaretskii
2023-10-29 22:14   ` Dmitry Gutov
2023-10-29 21:41 ` Dmitry Gutov
2023-10-30  0:58   ` Jim Porter [this message]
2023-10-30  2:00     ` Dmitry Gutov
2023-10-30  3:53       ` Jim Porter
2023-10-29 22:02 ` Dmitry Gutov
2023-10-30  0:25   ` Jim Porter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=64f0f8b9-ea72-4bba-7d90-0e6c300e6154@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=66806@debbugs.gnu.org \
    --cc=dmitry@gutov.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.