Skip to content

Commit 98acc3f

Browse files
julliardgitster
authored andcommitted
git.el: Allow selecting whether to display uptodate/unknown/ignored files.
The default behavior for each state can be customized, and it can also be toggled directly from the status buffer. Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1b65504 commit 98acc3f

File tree

1 file changed

+77
-15
lines changed

1 file changed

+77
-15
lines changed

contrib/emacs/git.el

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ if there is already one that displays the same directory."
9797
:group 'git
9898
:type 'string)
9999

100+
(defcustom git-show-uptodate nil
101+
"Whether to display up-to-date files."
102+
:group 'git
103+
:type 'boolean)
104+
105+
(defcustom git-show-ignored nil
106+
"Whether to display ignored files."
107+
:group 'git
108+
:type 'boolean)
109+
110+
(defcustom git-show-unknown t
111+
"Whether to display unknown files."
112+
:group 'git
113+
:type 'boolean)
114+
100115

101116
(defface git-status-face
102117
'((((class color) (background light)) (:foreground "purple"))
@@ -646,23 +661,30 @@ Return the list of files that haven't been handled."
646661
(push config files))
647662
files))
648663

664+
(defun git-run-ls-files-with-excludes (status files default-state &rest options)
665+
"Run git-ls-files on FILES with appropriate --exclude-from options."
666+
(let ((exclude-files (git-get-exclude-files)))
667+
(apply #'git-run-ls-files status files default-state
668+
(concat "--exclude-per-directory=" git-per-dir-ignore-file)
669+
(append options (mapcar (lambda (f) (concat "--exclude-from=" f)) exclude-files)))))
670+
649671
(defun git-update-status-files (files &optional default-state)
650672
"Update the status of FILES from the index."
651673
(unless git-status (error "Not in git-status buffer."))
652-
(let* ((status git-status)
653-
(remaining-files
674+
(unless files
675+
(when git-show-uptodate (git-run-ls-files git-status nil 'uptodate "-c")))
676+
(let* ((remaining-files
654677
(if (git-empty-db-p) ; we need some special handling for an empty db
655-
(git-run-ls-files status files 'added "-c")
656-
(git-run-diff-index status files))))
657-
(git-run-ls-unmerged status files)
658-
(when (or (not files) remaining-files)
659-
(let ((exclude-files (git-get-exclude-files)))
660-
(setq remaining-files (apply #'git-run-ls-files status remaining-files 'unknown "-o"
661-
(concat "--exclude-per-directory=" git-per-dir-ignore-file)
662-
(mapcar (lambda (f) (concat "--exclude-from=" f)) exclude-files)))))
663-
(git-set-filenames-state status remaining-files default-state)
678+
(git-run-ls-files git-status files 'added "-c")
679+
(git-run-diff-index git-status files))))
680+
(git-run-ls-unmerged git-status files)
681+
(when (or remaining-files (and git-show-unknown (not files)))
682+
(setq remaining-files (git-run-ls-files-with-excludes git-status remaining-files 'unknown "-o")))
683+
(when (or remaining-files (and git-show-ignored (not files)))
684+
(setq remaining-files (git-run-ls-files-with-excludes git-status remaining-files 'ignored "-o" "-i")))
685+
(git-set-filenames-state git-status remaining-files default-state)
664686
(git-refresh-files)
665-
(git-refresh-ewoc-hf status)))
687+
(git-refresh-ewoc-hf git-status)))
666688

667689
(defun git-marked-files ()
668690
"Return a list of all marked files, or if none a list containing just the file at cursor position."
@@ -943,11 +965,41 @@ Return the list of files that haven't been handled."
943965
(interactive)
944966
(ewoc-filter git-status
945967
(lambda (info)
946-
(not (or (eq (git-fileinfo->state info) 'ignored)
947-
(eq (git-fileinfo->state info) 'uptodate)))))
968+
(case (git-fileinfo->state info)
969+
('ignored git-show-ignored)
970+
('uptodate git-show-uptodate)
971+
('unknown git-show-unknown)
972+
(t t))))
948973
(unless (ewoc-nth git-status 0) ; refresh header if list is empty
949974
(git-refresh-ewoc-hf git-status)))
950975

976+
(defun git-toggle-show-uptodate ()
977+
"Toogle the option for showing up-to-date files."
978+
(interactive)
979+
(if (setq git-show-uptodate (not git-show-uptodate))
980+
(git-refresh-status)
981+
(git-remove-handled)))
982+
983+
(defun git-toggle-show-ignored ()
984+
"Toogle the option for showing ignored files."
985+
(interactive)
986+
(if (setq git-show-ignored (not git-show-ignored))
987+
(progn
988+
(git-run-ls-files-with-excludes git-status nil 'ignored "-o" "-i")
989+
(git-refresh-files)
990+
(git-refresh-ewoc-hf git-status))
991+
(git-remove-handled)))
992+
993+
(defun git-toggle-show-unknown ()
994+
"Toogle the option for showing unknown files."
995+
(interactive)
996+
(if (setq git-show-unknown (not git-show-unknown))
997+
(progn
998+
(git-run-ls-files-with-excludes git-status nil 'unknown "-o")
999+
(git-refresh-files)
1000+
(git-refresh-ewoc-hf git-status))
1001+
(git-remove-handled)))
1002+
9511003
(defun git-setup-diff-buffer (buffer)
9521004
"Setup a buffer for displaying a diff."
9531005
(let ((dir default-directory))
@@ -1173,7 +1225,8 @@ Return the list of files that haven't been handled."
11731225

11741226
(unless git-status-mode-map
11751227
(let ((map (make-keymap))
1176-
(diff-map (make-sparse-keymap)))
1228+
(diff-map (make-sparse-keymap))
1229+
(toggle-map (make-sparse-keymap)))
11771230
(suppress-keymap map)
11781231
(define-key map "?" 'git-help)
11791232
(define-key map "h" 'git-help)
@@ -1197,6 +1250,7 @@ Return the list of files that haven't been handled."
11971250
(define-key map "q" 'git-status-quit)
11981251
(define-key map "r" 'git-remove-file)
11991252
(define-key map "R" 'git-resolve-file)
1253+
(define-key map "t" toggle-map)
12001254
(define-key map "T" 'git-toggle-all-marks)
12011255
(define-key map "u" 'git-unmark-file)
12021256
(define-key map "U" 'git-revert-file)
@@ -1213,6 +1267,11 @@ Return the list of files that haven't been handled."
12131267
(define-key diff-map "h" 'git-diff-file-merge-head)
12141268
(define-key diff-map "m" 'git-diff-file-mine)
12151269
(define-key diff-map "o" 'git-diff-file-other)
1270+
; the toggle submap
1271+
(define-key toggle-map "u" 'git-toggle-show-uptodate)
1272+
(define-key toggle-map "i" 'git-toggle-show-ignored)
1273+
(define-key toggle-map "k" 'git-toggle-show-unknown)
1274+
(define-key toggle-map "m" 'git-toggle-all-marks)
12161275
(setq git-status-mode-map map)))
12171276

12181277
;; git mode should only run in the *git status* buffer
@@ -1234,6 +1293,9 @@ Commands:
12341293
(let ((status (ewoc-create 'git-fileinfo-prettyprint "" "")))
12351294
(set (make-local-variable 'git-status) status))
12361295
(set (make-local-variable 'list-buffers-directory) default-directory)
1296+
(make-local-variable 'git-show-uptodate)
1297+
(make-local-variable 'git-show-ignored)
1298+
(make-local-variable 'git-show-unknown)
12371299
(run-hooks 'git-status-mode-hook)))
12381300

12391301
(defun git-find-status-buffer (dir)

0 commit comments

Comments
 (0)