Subject: Re: bug#55632: [PATCH] Add new user option project-vc-find-tracked-only

From: [email-masked]
Date: Thu, 02 Jun 2022 19:01:53 +0000

>> Thank you for the review. I addressed your comments in the new version 
>> of the patch.
> 
> Thanks.
> 
> One last thing here. The manual addition says:
> 
> +Also, some VC back-ends consider ``untracked'' files by default.
> +That behavior is controllable with the variable
> +@code{project-vc-include-untracked}.
> 
> Should that say "some Project back-ends ..."? Or better yet, "the VC
> Project back-end". Because that's the only one in the core that has
> any notion of "untracked files".
> 
> And that behavior is so for all VC backends, with Git and Hg simply
> having custom file listing code (for better performance). The rest
> delegate to 'find', only picking up the list of ignores (like
> bzrignore, svnignore, etc).
> 
> Consequently, the new variable will only affect the VC Project
> backend's behavior only with Hg and Git.

Fixed.

From ff7eb6529019e98eae320c907c1e9683a21d627e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Syn=C3=A1=C4=8Dek?= <[email-masked]>
Date: Thu, 2 Jun 2022 20:59:53 +0200
Subject: [PATCH] Add new user option project-vc-include-untracked

* doc/emacs/maintaining.texi (Projects): Document it.
* lisp/progmodes/project.el (project--vc-list-files): Use it.
---
 doc/emacs/maintaining.texi |  3 +++
 etc/NEWS                   |  4 ++++
 lisp/progmodes/project.el  | 16 +++++++++++-----
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi
index 3ddea0ae58..edc5acbd65 100644
--- a/doc/emacs/maintaining.texi
+++ b/doc/emacs/maintaining.texi
@@ -1666,6 +1666,9 @@ Projects
   Which files do or don't belong to a project is also determined by
 the project back-end.  For example, the VC back-end doesn't consider
 ``ignored'' files (@pxref{VC Ignore}) to be part of the project.
+Also, the VC Project back-end considers ``untracked'' files by default.
+That behavior is controllable with the variable
+@code{project-vc-include-untracked}.
 
 @menu
 * Project File Commands::   Commands for handling project files.
diff --git a/etc/NEWS b/etc/NEWS
index 71c19c06b4..3867fc8829 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1707,6 +1707,10 @@ Enabling this minor mode turns on hiding header material, like
 'elide-head' does; disabling it shows the header.  The commands
 'elide-head' and 'elide-head-show' are now obsolete.
 
++++
+*** New user option 'project-vc-include-untracked'.
+When non-nil, the VC project backend includes the untracked files.
+
 ---
 ** The autoarg.el library is now marked obsolete.
 This library provides the 'autoarg-mode' and 'autoarg-kp-mode' minor
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 4dc4762176..49e07fe840 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -382,6 +382,11 @@ project-vc-merge-submodules
   :package-version '(project . "0.2.0")
   :safe #'booleanp)
 
+(defcustom project-vc-include-untracked t
+  "When non-nil, the VC project backend includes the untracked files."
+  :type 'boolean
+  :safe #'booleanp)
+
 ;; FIXME: Using the current approach, major modes are supposed to set
 ;; this variable to a buffer-local value.  So we don't have access to
 ;; the "external roots" of language A from buffers of language B, which
@@ -512,8 +517,9 @@ project--vc-list-files
            (args '("-z"))
            (vc-git-use-literal-pathspecs nil)
            files)
-       ;; Include unregistered.
-       (setq args (append args '("-c" "-o" "--exclude-standard")))
+       (setq args (append args
+                          '("-c" "--exclude-standard")
+                          (when project-vc-include-untracked '("-o"))))
        (when extra-ignores
          (setq args (append args
                             (cons "--"
@@ -565,9 +571,9 @@ project--vc-list-files
        (delete-consecutive-dups files)))
     (`Hg
      (let ((default-directory (expand-file-name (file-name-as-directory dir)))
-           args)
-       ;; Include unregistered.
-       (setq args (nconc args '("-mcardu" "--no-status" "-0")))
+           (args (list (concat "-mcard" (when project-vc-include-untracked "u"))
+                       "--no-status"
+                       "-0")))
        (when extra-ignores
          (setq args (nconc args
                            (mapcan
-- 
2.36.1