git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* git emacs mode patch
@ 2007-03-15 13:03 Gábor Melis
  2007-03-17 10:04 ` Alexandre Julliard
  0 siblings, 1 reply; 4+ messages in thread
From: Gábor Melis @ 2007-03-15 13:03 UTC (permalink / raw
  To: git

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

The attached patch makes it possible to toggle show/hide of files with 
up-to-date and unknown statuses with M-d and M-u.

Cheers,
Gábor Melis

Please CC me, I'm not on the list.

[-- Attachment #2: git-el.patch --]
[-- Type: text/x-diff, Size: 3635 bytes --]

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index db87a37..2f993de 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -97,6 +97,16 @@ if there is already one that displays the same directory."
   :group 'git
   :type 'string)
 
+(defcustom git-hide-up-to-date t
+  "Hide files with up-to-date status by default."
+  :group 'git
+  :type 'boolean)
+
+(defcustom git-hide-unknown t
+  "Hide files with unknown status by default."
+  :group 'git
+  :type 'boolean)
+
 
 (defface git-status-face
   '((((class color) (background light)) (:foreground "purple")))
@@ -428,6 +438,7 @@ and returns the process output as a string."
     (?A 'added)
     (?D 'deleted)
     (?U 'unmerged)
+    (?H 'uptodate)
     (t nil)))
 
 (defun git-status-code-as-string (code)
@@ -1017,15 +1028,18 @@ and returns the process output as a string."
       (with-temp-buffer
         (git-run-command t nil "diff-index" "-z" "-M" "HEAD")
         (git-parse-status status)))
+    (unless (member 'up-to-date hidden-statuses)
       (with-temp-buffer
-        (git-run-command t nil "ls-files" "-z" "-u")
-        (git-parse-ls-unmerged status))
+        (git-run-command t nil "ls-files" "-z" "-t")
+        (git-parse-ls-files status 'unknown)))
+    (unless (member 'unknown hidden-statuses)
       (when (file-readable-p ".git/info/exclude")
         (with-temp-buffer
           (git-run-command t nil "ls-files" "-z" "-t" "-o"
                            "--exclude-from=.git/info/exclude"
-                           (concat "--exclude-per-directory=" git-per-dir-ignore-file))
-          (git-parse-ls-files status 'unknown)))
+                           (concat "--exclude-per-directory="
+                                   git-per-dir-ignore-file))
+          (git-parse-ls-files status 'unknown))))
     (git-refresh-files)
     (git-refresh-ewoc-hf status)
     ; move point to the current file name if any
@@ -1080,6 +1094,8 @@ and returns the process output as a string."
     (define-key map "U"   'git-revert-file)
     (define-key map "v"   'git-view-file)
     (define-key map "x"   'git-remove-handled)
+    (define-key map "\M-d" 'git-toggle-up-to-date)
+    (define-key map "\M-u" 'git-toggle-unknown)
     (define-key map "\C-?" 'git-unmark-file-up)
     (define-key map "\M-\C-?" 'git-unmark-all)
     ; the diff submap
@@ -1093,6 +1109,20 @@ and returns the process output as a string."
     (define-key diff-map "o" 'git-diff-file-other)
     (setq git-status-mode-map map)))
 
+(defun git-toggle-up-to-date ()
+  (interactive)
+  (if (member 'up-to-date hidden-statuses)
+      (setq hidden-statuses (remove 'up-to-date hidden-statuses))
+    (push 'up-to-date hidden-statuses))
+  (git-refresh-status))
+
+(defun git-toggle-unknown ()
+  (interactive)
+  (if (member 'unknown hidden-statuses)
+      (setq hidden-statuses (remove 'unknown hidden-statuses))
+    (push 'unknown hidden-statuses))
+  (git-refresh-status))
+
 ;; git mode should only run in the *git status* buffer
 (put 'git-status-mode 'mode-class 'special)
 
@@ -1112,6 +1142,11 @@ Commands:
   (let ((status (ewoc-create 'git-fileinfo-prettyprint "" "")))
     (set (make-local-variable 'git-status) status))
   (set (make-local-variable 'list-buffers-directory) default-directory)
+  (set (make-local-variable 'hidden-statuses) ())
+  (when git-hide-up-to-date
+    (push 'up-to-date hidden-statuses))
+  (when git-hide-unknown
+    (push 'unknown hidden-statuses))
   (run-hooks 'git-status-mode-hook)))
 
 (defun git-find-status-buffer (dir)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: git emacs mode patch
  2007-03-15 13:03 git emacs mode patch Gábor Melis
@ 2007-03-17 10:04 ` Alexandre Julliard
  2007-03-25 17:03   ` Gábor Melis
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Julliard @ 2007-03-17 10:04 UTC (permalink / raw
  To: Gábor Melis; +Cc: git

Gábor Melis <mega@retes.hu> writes:

> +(defcustom git-hide-unknown t
> +  "Hide files with unknown status by default."
> +  :group 'git
> +  :type 'boolean)

This one should default to nil for backwards compatibility.

> @@ -1017,15 +1028,18 @@ and returns the process output as a string."
>        (with-temp-buffer
>          (git-run-command t nil "diff-index" "-z" "-M" "HEAD")
>          (git-parse-status status)))
> +    (unless (member 'up-to-date hidden-statuses)
>        (with-temp-buffer
> -        (git-run-command t nil "ls-files" "-z" "-u")
> -        (git-parse-ls-unmerged status))
> +        (git-run-command t nil "ls-files" "-z" "-t")
> +        (git-parse-ls-files status 'unknown)))
> +    (unless (member 'unknown hidden-statuses)

Why are you removing the ls-files -u?  This will break the detection
of unmerged files.

> +(defun git-toggle-up-to-date ()
> +  (interactive)
> +  (if (member 'up-to-date hidden-statuses)
> +      (setq hidden-statuses (remove 'up-to-date hidden-statuses))
> +    (push 'up-to-date hidden-statuses))

The status should be named 'uptodate instead of 'up-to-date since
that's what's used for individual files. Having two different
spellings for the same word would be very confusing.

-- 
Alexandre Julliard
julliard@winehq.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: git emacs mode patch
  2007-03-17 10:04 ` Alexandre Julliard
@ 2007-03-25 17:03   ` Gábor Melis
  2007-03-26 10:02     ` Alexandre Julliard
  0 siblings, 1 reply; 4+ messages in thread
From: Gábor Melis @ 2007-03-25 17:03 UTC (permalink / raw
  To: Alexandre Julliard; +Cc: git

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

On Saturday 17 March 2007 11:04, Alexandre Julliard wrote:
> Gábor Melis <mega@retes.hu> writes:
> > +(defcustom git-hide-unknown t
> > +  "Hide files with unknown status by default."
> > +  :group 'git
> > +  :type 'boolean)
>
> This one should default to nil for backwards compatibility.
>
> > @@ -1017,15 +1028,18 @@ and returns the process output as a
> > string." (with-temp-buffer
> >          (git-run-command t nil "diff-index" "-z" "-M" "HEAD")
> >          (git-parse-status status)))
> > +    (unless (member 'up-to-date hidden-statuses)
> >        (with-temp-buffer
> > -        (git-run-command t nil "ls-files" "-z" "-u")
> > -        (git-parse-ls-unmerged status))
> > +        (git-run-command t nil "ls-files" "-z" "-t")
> > +        (git-parse-ls-files status 'unknown)))
> > +    (unless (member 'unknown hidden-statuses)
>
> Why are you removing the ls-files -u?  This will break the detection
> of unmerged files.
>
> > +(defun git-toggle-up-to-date ()
> > +  (interactive)
> > +  (if (member 'up-to-date hidden-statuses)
> > +      (setq hidden-statuses (remove 'up-to-date hidden-statuses))
> > +    (push 'up-to-date hidden-statuses))
>
> The status should be named 'uptodate instead of 'up-to-date since
> that's what's used for individual files. Having two different
> spellings for the same word would be very confusing.

Attached updated patch that adresses these valid objections and only 
lists files once.

Gábor

[-- Attachment #2: hide-show.patch --]
[-- Type: text/x-diff, Size: 5809 bytes --]

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 5f22dec..72d41bd 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -97,6 +97,16 @@ if there is already one that displays the same directory."
   :group 'git
   :type 'string)
 
+(defcustom git-hide-uptodate t
+  "Hide files with up-to-date status by default."
+  :group 'git
+  :type 'boolean)
+
+(defcustom git-hide-unknown nil
+  "Hide files with unknown status by default."
+  :group 'git
+  :type 'boolean)
+
 
 (defface git-status-face
   '((((class color) (background light)) (:foreground "purple")))
@@ -437,6 +447,7 @@ and returns the process output as a string."
       (setf (git-fileinfo->orig-name info) nil)
       (setf (git-fileinfo->needs-refresh info) t))))
 
+;;; This is an unholy mix of git-ls-files and git-diff-index state codes.
 (defun git-state-code (code)
   "Convert from a string to a added/deleted/modified state."
   (case (string-to-char code)
@@ -445,6 +456,7 @@ and returns the process output as a string."
     (?A 'added)
     (?D 'deleted)
     (?U 'unmerged)
+    (?H 'uptodate)
     (t nil)))
 
 (defun git-status-code-as-string (code)
@@ -515,15 +527,21 @@ and returns the process output as a string."
       (setq node (ewoc-next status node)))
     node))
 
-(defun git-parse-ls-files (status default-state &optional skip-existing)
+(defun git-parse-ls-files (status &optional default-state skip-existing)
   "Parse the output of git-ls-files in the current buffer."
   (goto-char (point-min))
   (let (infolist)
     (while (re-search-forward "\\([HMRCK?]\\) \\([^\0]*\\)\0" nil t 1)
-      (let ((state (match-string 1))
-            (name (match-string 2)))
-        (unless (and skip-existing (git-find-status-file status name))
-          (push (git-create-fileinfo (or (git-state-code state) default-state) name) infolist))))
+      (let* ((state (or default-state
+                        (git-state-code (match-string 1))))
+             (name (match-string 2))
+             (node (git-find-status-file status name)))
+        (if skip-existing
+            (unless node
+              (push (git-create-fileinfo state name) infolist))
+          (if node
+              (git-set-files-state (list (ewoc-data node)) state)
+            (push (git-create-fileinfo state name) infolist)))))
     (dolist (info (nreverse infolist))
       (ewoc-enter-last status info))))
 
@@ -1043,25 +1061,31 @@ and returns the process output as a string."
     (git-clear-status status)
     (git-run-command nil nil "update-index" "--info-only" "--refresh")
     (if (git-empty-db-p)
-        ; we need some special handling for an empty db
+        ;; we need some special handling for an empty db
         (with-temp-buffer
           (git-run-command t nil "ls-files" "-z" "-t" "-c")
           (git-parse-ls-files status 'added))
       (with-temp-buffer
         (git-run-command t nil "diff-index" "-z" "-M" "HEAD")
         (git-parse-status status)))
+    (with-temp-buffer
+      (git-run-command t nil "ls-files" "-z" "-u")
+      (git-parse-ls-unmerged status))
+    (unless (member 'uptodate hidden-statuses)
       (with-temp-buffer
-        (git-run-command t nil "ls-files" "-z" "-u")
-        (git-parse-ls-unmerged status))
+        (git-run-command t nil "ls-files" "-z" "-t" "-c")
+        (git-parse-ls-files status nil t)))
+    (unless (member 'unknown hidden-statuses)
       (when (file-readable-p ".git/info/exclude")
         (with-temp-buffer
           (git-run-command t nil "ls-files" "-z" "-t" "-o"
                            "--exclude-from=.git/info/exclude"
-                           (concat "--exclude-per-directory=" git-per-dir-ignore-file))
-          (git-parse-ls-files status 'unknown)))
+                           (concat "--exclude-per-directory="
+                                   git-per-dir-ignore-file))
+          (git-parse-ls-files status nil t))))
     (git-refresh-files)
     (git-refresh-ewoc-hf status)
-    ; move point to the current file name if any
+    ;; move point to the current file name if any
     (let ((node (and cur-name (git-find-status-file status cur-name))))
       (when node (ewoc-goto-node status node)))))
 
@@ -1113,6 +1137,8 @@ and returns the process output as a string."
     (define-key map "U"   'git-revert-file)
     (define-key map "v"   'git-view-file)
     (define-key map "x"   'git-remove-handled)
+    (define-key map "\M-u" 'git-toggle-uptodate)
+    (define-key map "\M-k" 'git-toggle-unknown)
     (define-key map "\C-?" 'git-unmark-file-up)
     (define-key map "\M-\C-?" 'git-unmark-all)
     ; the diff submap
@@ -1126,6 +1152,20 @@ and returns the process output as a string."
     (define-key diff-map "o" 'git-diff-file-other)
     (setq git-status-mode-map map)))
 
+(defun git-toggle-uptodate ()
+  (interactive)
+  (if (member 'uptodate hidden-statuses)
+      (setq hidden-statuses (remove 'uptodate hidden-statuses))
+    (push 'uptodate hidden-statuses))
+  (git-refresh-status))
+
+(defun git-toggle-unknown ()
+  (interactive)
+  (if (member 'unknown hidden-statuses)
+      (setq hidden-statuses (remove 'unknown hidden-statuses))
+    (push 'unknown hidden-statuses))
+  (git-refresh-status))
+
 ;; git mode should only run in the *git status* buffer
 (put 'git-status-mode 'mode-class 'special)
 
@@ -1145,6 +1185,11 @@ Commands:
   (let ((status (ewoc-create 'git-fileinfo-prettyprint "" "")))
     (set (make-local-variable 'git-status) status))
   (set (make-local-variable 'list-buffers-directory) default-directory)
+  (set (make-local-variable 'hidden-statuses) ())
+  (when git-hide-uptodate
+    (push 'uptodate hidden-statuses))
+  (when git-hide-unknown
+    (push 'unknown hidden-statuses))
   (run-hooks 'git-status-mode-hook)))
 
 (defun git-find-status-buffer (dir)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: git emacs mode patch
  2007-03-25 17:03   ` Gábor Melis
@ 2007-03-26 10:02     ` Alexandre Julliard
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Julliard @ 2007-03-26 10:02 UTC (permalink / raw
  To: Gábor Melis; +Cc: git

Gábor Melis <mega@retes.hu> writes:

> @@ -515,15 +527,21 @@ and returns the process output as a string."
>        (setq node (ewoc-next status node)))
>      node))
>  
> -(defun git-parse-ls-files (status default-state &optional skip-existing)
> +(defun git-parse-ls-files (status &optional default-state skip-existing)
>    "Parse the output of git-ls-files in the current buffer."
>    (goto-char (point-min))
>    (let (infolist)
>      (while (re-search-forward "\\([HMRCK?]\\) \\([^\0]*\\)\0" nil t 1)
> -      (let ((state (match-string 1))
> -            (name (match-string 2)))
> -        (unless (and skip-existing (git-find-status-file status name))
> -          (push (git-create-fileinfo (or (git-state-code state) default-state) name) infolist))))
> +      (let* ((state (or default-state
> +                        (git-state-code (match-string 1))))
> +             (name (match-string 2))
> +             (node (git-find-status-file status name)))
> +        (if skip-existing
> +            (unless node
> +              (push (git-create-fileinfo state name) infolist))
> +          (if node
> +              (git-set-files-state (list (ewoc-data node)) state)
> +            (push (git-create-fileinfo state name) infolist)))))

You don't want to do a git-find-status-file in all cases, this is
O(n^2) and becomes much too slow on a large project. That's the reason
there's a skip-existing flag, to avoid that cost in the common case.

-- 
Alexandre Julliard
julliard@winehq.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-03-26 10:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-15 13:03 git emacs mode patch Gábor Melis
2007-03-17 10:04 ` Alexandre Julliard
2007-03-25 17:03   ` Gábor Melis
2007-03-26 10:02     ` Alexandre Julliard

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).