threads / patch / 11937

patch, 4 partsgit.el: Support for showing unknown/ignored directories.

Subject: [PATCH 1/4] git.el: Support for showing unknown/ignored directories.

## tl;dr

8 messages between Feb 7, 2008 and Feb 28, 2008. Diffs are folded; open one to read it.

replies: 7people: 3as markdown or json

Alexandre Julliard· Feb 7, 2008, 12:50 UTC · lore

Instead of recursing into directories that only contain unknown files, display only the directory itself. Its contents can be expanded with git-find-file (bound to C-m).

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 contrib/emacs/git.el |   38 +++++++++++++++++++++++++++++---------
 1 files changed, 29 insertions(+), 9 deletions(-)
Show changes to contrib/emacs/git.el +29 −9
diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index d8a0638..58d72a5 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -558,12 +558,15 @@ and returns the process output as a string."
 		     (?\100 "   (type change file -> subproject)")
 		     (?\120 "   (type change symlink -> subproject)")
 		     (t "   (subproject)")))
+                  (?\110 nil)  ;; directory (internal, not a real git state)
 		  (?\000  ;; deleted or unknown
 		   (case old-type
 		     (?\120 "   (symlink)")
 		     (?\160 "   (subproject)")))
 		  (t (format "   (unknown type %o)" new-type)))))
-    (if str (propertize str 'face 'git-status-face) "")))
+    (cond (str (propertize str 'face 'git-status-face))
+          ((eq new-type ?\110) "/")
+          (t ""))))
 
 (defun git-rename-as-string (info)
   "Return a string describing the copy or rename associated with INFO, or an empty string if none."
@@ -666,9 +669,11 @@ Return the list of files that haven't been handled."
     (with-temp-buffer
       (apply #'git-call-process-env t nil "ls-files" "-z" (append options (list "--") files))
       (goto-char (point-min))
-      (while (re-search-forward "\\([^\0]*\\)\0" nil t 1)
+      (while (re-search-forward "\\([^\0]*?\\)\\(/?\\)\0" nil t 1)
         (let ((name (match-string 1)))
-          (push (git-create-fileinfo default-state name) infolist)
+          (push (git-create-fileinfo default-state name 0
+                                     (if (string-equal "/" (match-string 2)) (lsh ?\110 9) 0))
+                infolist)
           (setq files (delete name files)))))
     (git-insert-info-list status infolist)
     files))
@@ -713,7 +718,7 @@ Return the list of files that haven't been handled."
 (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
+    (apply #'git-run-ls-files status files default-state "--directory"
            (concat "--exclude-per-directory=" git-per-dir-ignore-file)
            (append options (mapcar (lambda (f) (concat "--exclude-from=" f)) exclude-files)))))
 
@@ -957,6 +962,7 @@ Return the list of files that haven't been handled."
   "Add marked file(s) to the index cache."
   (interactive)
   (let ((files (git-get-filenames (git-marked-files-state 'unknown 'ignored))))
+    ;; FIXME: add support for directories
     (unless files
       (push (file-relative-name (read-file-name "File to add: " nil nil t)) files))
     (apply #'git-call-process-env nil nil "update-index" "--add" "--" files)
@@ -983,7 +989,10 @@ Return the list of files that haven't been handled."
          (format "Remove %d file%s? " (length files) (if (> (length files) 1) "s" "")))
         (progn
           (dolist (name files)
-            (when (file-exists-p name) (delete-file name)))
+            (ignore-errors
+              (if (file-directory-p name)
+                  (delete-directory name)
+                (delete-file name))))
           (apply #'git-call-process-env nil nil "update-index" "--remove" "--" files)
           (git-update-status-files files nil)
           (git-success-message "Removed" files))
@@ -992,7 +1001,7 @@ Return the list of files that haven't been handled."
 (defun git-revert-file ()
   "Revert changes to the marked file(s)."
   (interactive)
-  (let ((files (git-marked-files))
+  (let ((files (git-marked-files-state 'added 'deleted 'modified 'unmerged))
         added modified)
     (when (and files
                (yes-or-no-p
@@ -1063,6 +1072,16 @@ Return the list of files that haven't been handled."
         (message "Inserting unknown files...done"))
     (git-remove-handled)))
 
+(defun git-expand-directory (info)
+  "Expand the directory represented by INFO to list its files."
+  (when (eq (lsh (git-fileinfo->new-perm info) -9) ?\110)
+    (let ((dir (git-fileinfo->name info)))
+      (git-set-filenames-state git-status (list dir) nil)
+      (git-run-ls-files-with-excludes git-status (list (concat dir "/")) 'unknown "-o")
+      (git-refresh-files)
+      (git-refresh-ewoc-hf git-status)
+      t)))
+
 (defun git-setup-diff-buffer (buffer)
   "Setup a buffer for displaying a diff."
   (let ((dir default-directory))
@@ -1237,9 +1256,10 @@ Return the list of files that haven't been handled."
   (interactive)
   (unless git-status (error "Not in git-status buffer."))
   (let ((info (ewoc-data (ewoc-locate git-status))))
-    (find-file (git-fileinfo->name info))
-    (when (eq 'unmerged (git-fileinfo->state info))
-      (smerge-mode 1))))
+    (unless (git-expand-directory info)
+      (find-file (git-fileinfo->name info))
+      (when (eq 'unmerged (git-fileinfo->state info))
+        (smerge-mode 1)))))
 
 (defun git-find-file-other-window ()
   "Visit the current file in its own buffer in another window."
-- 
1.5.4.38.g0d380

-- 
Alexandre Julliard
julliard@winehq.org
Karl Hasselström· Feb 22, 2008, 15:30 UTC · re: Alexandre Julliard · lore

Re: [PATCH 1/4] git.el: Support for showing unknown/ignored directories.

On 2008-02-07 13:50:19 +0100, Alexandre Julliard wrote:
> Instead of recursing into directories that only contain unknown
> files, display only the directory itself. Its contents can be
> expanded with git-find-file (bound to C-m).

I have a bunch of directories in my tree with only ignored files in them. They used to not show up at all, but now they do. If I press return with the cursor on top of one of them, it vanishes (which is equivalent to expanding to all the 0 non-ignored files in that directory, I guess).

I presume this wasn't the intended behavior? I like the idea for subdirectories that actually contain non-ignored files, but directories with only ignored files should really not be shown at all.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Alexandre Julliard· Feb 22, 2008, 15:53 UTC · re: Karl Hasselström · lore

Re: [PATCH 1/4] git.el: Support for showing unknown/ignored directories.

Karl Hasselström <kha@treskal.com> writes:
Show 15 quoted lines
> On 2008-02-07 13:50:19 +0100, Alexandre Julliard wrote:
>
>> Instead of recursing into directories that only contain unknown
>> files, display only the directory itself. Its contents can be
>> expanded with git-find-file (bound to C-m).
>
> I have a bunch of directories in my tree with only ignored files in
> them. They used to not show up at all, but now they do. If I press
> return with the cursor on top of one of them, it vanishes (which is
> equivalent to expanding to all the 0 non-ignored files in that
> directory, I guess).
>
> I presume this wasn't the intended behavior? I like the idea for
> subdirectories that actually contain non-ignored files, but
> directories with only ignored files should really not be shown at all.
It probably needs something like this:
From b32a397a64eec64d433aa0ee00147003723cfeee Mon Sep 17 00:00:00 2001
From: Alexandre Julliard <julliard@winehq.org>
Date: Fri, 22 Feb 2008 16:48:53 +0100
Subject: [PATCH] git.el: Do not display empty directories.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 contrib/emacs/git.el |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to contrib/emacs/git.el +1 −1
diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index d91fbb8..7cb86df 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -753,7 +753,7 @@ Return the list of files that haven't been handled."
 (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"
+    (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)))))
 
-- 
1.5.4.1.132.gd85f75

-- 
Alexandre Julliard
julliard@winehq.org
Karl Hasselström· Feb 22, 2008, 17:10 UTC · re: Alexandre Julliard · lore

Re: [PATCH 1/4] git.el: Support for showing unknown/ignored directories.

On 2008-02-22 16:53:16 +0100, Alexandre Julliard wrote:
Show 6 quoted lines
> Karl Hasselström <kha@treskal.com> writes:
>
> > I have a bunch of directories in my tree with only ignored files
> > in them. They used to not show up at all, but now they do.
>
> It probably needs something like this:
That fixed the problem. Thanks!
> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
Tested-by: Karl Hasselström <kha@treskal.com>
-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Karl Hasselström· Feb 27, 2008, 11:27 UTC · re: Karl Hasselström · lore

Re: [PATCH 1/4] git.el: Support for showing unknown/ignored directories.

On 2008-02-22 18:10:52 +0100, Karl Hasselström wrote:
Show 14 quoted lines
> On 2008-02-22 16:53:16 +0100, Alexandre Julliard wrote:
>
> > Karl Hasselström <kha@treskal.com> writes:
> >
> > > I have a bunch of directories in my tree with only ignored files
> > > in them. They used to not show up at all, but now they do.
> >
> > It probably needs something like this:
>
> That fixed the problem. Thanks!
>
> > Signed-off-by: Alexandre Julliard <julliard@winehq.org>
>
> Tested-by: Karl Hasselström <kha@treskal.com>

Junio, did you see this bugfix? (I just realized you weren't cc'ed, so I guess not.)

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Junio C Hamano· Feb 27, 2008, 19:48 UTC · re: Karl Hasselström · lore

Re: [PATCH 1/4] git.el: Support for showing unknown/ignored directories.

Karl Hasselström <kha@treskal.com> writes:
Show 10 quoted lines
> On 2008-02-22 18:10:52 +0100, Karl Hasselström wrote:
> ...
>> That fixed the problem. Thanks!
>>
>> > Signed-off-by: Alexandre Julliard <julliard@winehq.org>
>>
>> Tested-by: Karl Hasselström <kha@treskal.com>
>
> Junio, did you see this bugfix? (I just realized you weren't cc'ed, so
> I guess not.)
No, and thanks.
So I'll take
    From: Alexandre Julliard <julliard@winehq.org>
    Message-ID: <8763whkmxf.fsf@wine.dyndns.org>
    
aka
    http://article.gmane.org/gmane.comp.version-control.git/74730

in this thread with your Tested-by: and apply to fix 3f3d564 (git.el: Support for showing unknown/ignored directories.)?

Karl Hasselström· Feb 28, 2008, 07:06 UTC · re: Junio C Hamano · lore

Re: [PATCH 1/4] git.el: Support for showing unknown/ignored directories.

On 2008-02-27 11:48:30 -0800, Junio C Hamano wrote:
Show 18 quoted lines
> Karl Hasselström <kha@treskal.com> writes:
>
> > Junio, did you see this bugfix? (I just realized you weren't
> > cc'ed, so I guess not.)
>
> No, and thanks.
>
> So I'll take
>
>     From: Alexandre Julliard <julliard@winehq.org>
>     Message-ID: <8763whkmxf.fsf@wine.dyndns.org>
>
> aka
>
>     http://article.gmane.org/gmane.comp.version-control.git/74730
>
> in this thread with your Tested-by: and apply to fix 3f3d564
> (git.el: Support for showing unknown/ignored directories.)?
Yes, exactly. Thanks.

(Would you like this kind of detailed pointer in a reminder, or is the threading support in your mailer good enough that just replying to the right mail will do it?)

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Junio C Hamano· Feb 28, 2008, 07:46 UTC · re: Karl Hasselström · lore

Re: [PATCH 1/4] git.el: Support for showing unknown/ignored directories.

Karl Hasselström <kha@treskal.com> writes:
> (Would you like this kind of detailed pointer in a reminder, or is the
> threading support in your mailer good enough that just replying to the
> right mail will do it?)

I'd actually like a forwarded message that I can directly feed to "git am", with Sign-offs and Acked-bys, but being explicit would be good enough.

I often do not have enough mental and time bandwidth to hunt for messages more than 2 weeks old in the list archive, so unless the response is direct reply to the original, I'd rather not rely on the threading feature. IOW, I can move to grandparent by typing ^ just fine, but uncles and aunts are harder to find without reloading my MUA full message archive for N weeks worth.

← back to recent threads