git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
DPDorab Patel <dorabpatel@gmail.com>
Date
Mar 6, 2018, 04:38 UTC
Message-ID
<20180306043846.33733-1-dorabpatel@gmail.com>
In-Reply-To
<20180303034803.21589-1-dorabpatel@gmail.com>

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@gmail.com>
---
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@gmail.com/
 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
Previous: Kyle Meyer
Message 19 of 19 in “git.el: handle default excludesfile properly”
  1. git.el: handle default excludesfile properlyDorab Patel, Mar 3, 2018
  2. Eric SunshineMar 3, 2018
  3. Dorab PatelMar 4, 2018
  4. Eric SunshineMar 4, 2018
  5. Dorab PatelMar 4, 2018
  6. Eric SunshineMar 4, 2018
  7. Junio C HamanoMar 5, 2018
  8. Alexandre JulliardMar 6, 2018
  9. Dorab PatelMar 7, 2018
  10. Ævar Arnfjörð BjarmasonMar 8, 2018
  11. git{,-blame}.el: remove old bitrotting Emacs codeÆvar Arnfjörð Bjarmason, Mar 8, 2018
  12. Junio C HamanoMar 8, 2018
  13. git{,-blame}.el: remove old bitrotting Emacs codeÆvar Arnfjörð Bjarmason, Mar 10, 2018
  14. Martin ÅgrenMar 10, 2018
  15. Junio C HamanoMar 13, 2018
  16. Ævar Arnfjörð BjarmasonMar 13, 2018
  17. Junio C HamanoMar 13, 2018
  18. Kyle MeyerMar 8, 2018
  19. git.el: handle default excludesfile properlyDorab Patel, Mar 6, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.