[PATCH v2] git.el: handle default excludesfile properly

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

 



The previous version only looked at core.excludesfile for locating the
excludesfile.  So, when core.excludesfile was not defined, it did not
use the relevant default locations for the global excludes file.

The issue is in git-get-exclude-files().  Investigation shows that
git-get-exclude-files() is only called from
git-run-ls-files-with-excludes().  Modifying
git-run-ls-files-with-excludes() to use the "--exclude-standard"
option to git-run-ls-files() obviates the need for
git-get-exclude-files() altogether, which is now removed.  In
addition, the "--exclude-per-directory" option to git-run-ls-files()
is used only when git-per-dir-ignore-file is not the default
(.gitignore), since the default case is handled by the
"--exclude-standard" option.

Looking at the history shows that git-get-exclude-files() was
implemented by commit 274e13e0e9 (git.el: Take into account the
core.excludesfile config option., 2007-07-31), whereas the
"--exclude-standard" option was introduced by commit 8e7b07c8a7
(git-ls-files: add --exclude-standard, 2007-11-15), three and a half
months later.  This explains why the "--exclude-standard" option was
not used in the original code.

Signed-off-by: Dorab Patel <dorabpatel@xxxxxxxxx>
---

Notes:
    The original patch[1] V1 attempted to add code to
    git-get-exclude-files() to handle the case when core.excludesfile was
    not defined.  This involved code to check for the env variable
    XDG_CONFIG_HOME and related processing to find the value of the
    default excludesfile.  Further investigation showed that using the
    "--exclude-standard" option to git-run-ls-files-with-excludes()
    already does similar processing.  Hence the V2 patch uses the
    "--exclude-standard" option and does away with
    git-get-exclude-files().
    
    [1] https://public-inbox.org/git/20180303034803.21589-1-dorabpatel@xxxxxxxxx/

 contrib/emacs/git.el | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 97919f2d7..cef42f1de 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -755,22 +755,13 @@ Return the list of files that haven't been handled."
       (setq unmerged-files (nreverse unmerged-files))  ;; assume it is sorted already
       (git-set-filenames-state status unmerged-files 'unmerged))))
 
-(defun git-get-exclude-files ()
-  "Get the list of exclude files to pass to git-ls-files."
-  (let (files
-        (config (git-config "core.excludesfile")))
-    (when (file-readable-p ".git/info/exclude")
-      (push ".git/info/exclude" files))
-    (when (and config (file-readable-p config))
-      (push config files))
-    files))
-
 (defun git-run-ls-files-with-excludes (status files default-state &rest options)
-  "Run git-ls-files on FILES with appropriate --exclude-from options."
-  (let ((exclude-files (git-get-exclude-files)))
-    (apply #'git-run-ls-files status files default-state "--directory" "--no-empty-directory"
-           (concat "--exclude-per-directory=" git-per-dir-ignore-file)
-           (append options (mapcar (lambda (f) (concat "--exclude-from=" f)) exclude-files)))))
+  "Run git-ls-files on FILES with appropriate exclude options."
+  (apply #'git-run-ls-files status files default-state
+	 "--directory" "--no-empty-directory" "--exclude-standard"
+	 (append (unless (string-equal git-per-dir-ignore-file ".gitignore") ; handled by --exclude-standard
+		   (list (concat "--exclude-per-directory=" git-per-dir-ignore-file)))
+		 options)))
 
 (defun git-update-status-files (&optional files mark-files)
   "Update the status of FILES from the index.
-- 
2.16.2




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux