git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFH PATCH] Teach the emacs git mode about core.excludesfile
@ 2007-07-31  1:13 Karl Hasselström
  2007-07-31  1:58 ` Matthieu Moy
  2007-07-31 10:36 ` Alexandre Julliard
  0 siblings, 2 replies; 5+ messages in thread
From: Karl Hasselström @ 2007-07-31  1:13 UTC (permalink / raw)
  To: Alexandre Julliard; +Cc: git

If there is a core.excludesfile option specified, let the emacs git
mode take exclude patterns from that file, since that's what the docs
say, and what everyone else is already doing.

Signed-off-by: Karl Hasselström <kha@treskal.com>
---

This is a Request For Help. The patch works, but is clearly the work
of someone who is not very fluent in elisp. Just look at all that
duplicated code I've introduced!

 contrib/emacs/git.el |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 53dd703..357e6d2 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -589,6 +589,13 @@ Return the list of files that haven't been handled."
           (when node (push (ewoc-data node) unmerged-files))))
       (git-set-files-state unmerged-files 'unmerged))))
 
+(defun git-core-excludesfile ()
+  "The file core.excludesfile, or nil if it isn't specified."
+  (let ((fn (git-config "core.excludesfile")))
+    (if (and fn (file-readable-p fn))
+        fn
+      nil)))
+
 (defun git-update-status-files (files &optional default-state)
   "Update the status of FILES from the index."
   (unless git-status (error "Not in git-status buffer."))
@@ -600,9 +607,15 @@ Return the list of files that haven't been handled."
     (git-run-ls-unmerged status files)
     (when (and (or (not files) remaining-files)
                (file-readable-p ".git/info/exclude"))
-      (setq remaining-files (git-run-ls-files status remaining-files
-                                              'unknown "-o" "--exclude-from=.git/info/exclude"
-                                              (concat "--exclude-per-directory=" git-per-dir-ignore-file))))
+      (let ((ce (git-core-excludesfile)))
+        (if ce
+            (setq remaining-files (git-run-ls-files status remaining-files
+                                                    'unknown "-o" "--exclude-from=.git/info/exclude"
+                                                    (concat "--exclude-per-directory=" git-per-dir-ignore-file)
+                                                    (concat "--exclude-from=" ce)))
+          (setq remaining-files (git-run-ls-files status remaining-files
+                                                  'unknown "-o" "--exclude-from=.git/info/exclude"
+                                                  (concat "--exclude-per-directory=" git-per-dir-ignore-file))))))
     ; mark remaining files with the default state (or remove them if nil)
     (when remaining-files
       (if default-state

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

* [RFH PATCH] Teach the emacs git mode about core.excludesfile
@ 2007-07-31  1:30 Karl Hasselström
  0 siblings, 0 replies; 5+ messages in thread
From: Karl Hasselström @ 2007-07-31  1:30 UTC (permalink / raw)
  To: Alexandre Julliard; +Cc: git

If there is a core.excludesfile option specified, let the emacs git
mode take exclude patterns from that file, since that's what the docs
say, and what everyone else is already doing.

Signed-off-by: Karl Hasselström <kha@treskal.com>
---

The patch works, but the code is anything but pretty. I need help from
someone who actually knows elisp!

(Apologies if this patch reaches the list twice; the first copy I sent
was seemingly lost, so I tried another route.)

 contrib/emacs/git.el |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 53dd703..357e6d2 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -589,6 +589,13 @@ Return the list of files that haven't been handled."
           (when node (push (ewoc-data node) unmerged-files))))
       (git-set-files-state unmerged-files 'unmerged))))
 
+(defun git-core-excludesfile ()
+  "The file core.excludesfile, or nil if it isn't specified."
+  (let ((fn (git-config "core.excludesfile")))
+    (if (and fn (file-readable-p fn))
+        fn
+      nil)))
+
 (defun git-update-status-files (files &optional default-state)
   "Update the status of FILES from the index."
   (unless git-status (error "Not in git-status buffer."))
@@ -600,9 +607,15 @@ Return the list of files that haven't been handled."
     (git-run-ls-unmerged status files)
     (when (and (or (not files) remaining-files)
                (file-readable-p ".git/info/exclude"))
-      (setq remaining-files (git-run-ls-files status remaining-files
-                                              'unknown "-o" "--exclude-from=.git/info/exclude"
-                                              (concat "--exclude-per-directory=" git-per-dir-ignore-file))))
+      (let ((ce (git-core-excludesfile)))
+        (if ce
+            (setq remaining-files (git-run-ls-files status remaining-files
+                                                    'unknown "-o" "--exclude-from=.git/info/exclude"
+                                                    (concat "--exclude-per-directory=" git-per-dir-ignore-file)
+                                                    (concat "--exclude-from=" ce)))
+          (setq remaining-files (git-run-ls-files status remaining-files
+                                                  'unknown "-o" "--exclude-from=.git/info/exclude"
+                                                  (concat "--exclude-per-directory=" git-per-dir-ignore-file))))))
     ; mark remaining files with the default state (or remove them if nil)
     (when remaining-files
       (if default-state

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

* Re: [RFH PATCH] Teach the emacs git mode about core.excludesfile
  2007-07-31  1:13 [RFH PATCH] Teach the emacs git mode about core.excludesfile Karl Hasselström
@ 2007-07-31  1:58 ` Matthieu Moy
  2007-07-31 10:36 ` Alexandre Julliard
  1 sibling, 0 replies; 5+ messages in thread
From: Matthieu Moy @ 2007-07-31  1:58 UTC (permalink / raw)
  To: Karl Hasselström; +Cc: Alexandre Julliard, git

Karl Hasselström <kha@treskal.com> writes:

> If there is a core.excludesfile option specified, let the emacs git
> mode take exclude patterns from that file, since that's what the docs
> say, and what everyone else is already doing.
>
> Signed-off-by: Karl Hasselström <kha@treskal.com>
> ---
>
> This is a Request For Help. The patch works, but is clearly the work
> of someone who is not very fluent in elisp. Just look at all that
> duplicated code I've introduced!
>
>  contrib/emacs/git.el |   19 ++++++++++++++++---
>  1 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
> index 53dd703..357e6d2 100644
> --- a/contrib/emacs/git.el
> +++ b/contrib/emacs/git.el
> @@ -589,6 +589,13 @@ Return the list of files that haven't been handled."
>            (when node (push (ewoc-data node) unmerged-files))))
>        (git-set-files-state unmerged-files 'unmerged))))
>  
> +(defun git-core-excludesfile ()
> +  "The file core.excludesfile, or nil if it isn't specified."
> +  (let ((fn (git-config "core.excludesfile")))
> +    (if (and fn (file-readable-p fn))
> +        fn
> +      nil)))
> +
>  (defun git-update-status-files (files &optional default-state)
>    "Update the status of FILES from the index."
>    (unless git-status (error "Not in git-status buffer."))
> @@ -600,9 +607,15 @@ Return the list of files that haven't been handled."
>      (git-run-ls-unmerged status files)
>      (when (and (or (not files) remaining-files)
>                 (file-readable-p ".git/info/exclude"))
> -      (setq remaining-files (git-run-ls-files status remaining-files
> -                                              'unknown "-o" "--exclude-from=.git/info/exclude"
> -                                              (concat "--exclude-per-directory=" git-per-dir-ignore-file))))

What you're looking for probably looks like that:

         (let ((ce (git-core-excludesfile)))
           (setq remaining-files (apply 'git-run-ls-files 
                                      `(,status ,remaining-files
                                        unknown "-o" ... ,@(when ce
                                                             (list ce))))))

(the magic is in the backquote and the ,@ in `(... ,@(...)))

(totally untested, probably bogus)

-- 
Matthieu

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

* Re: [RFH PATCH] Teach the emacs git mode about core.excludesfile
  2007-07-31  1:13 [RFH PATCH] Teach the emacs git mode about core.excludesfile Karl Hasselström
  2007-07-31  1:58 ` Matthieu Moy
@ 2007-07-31 10:36 ` Alexandre Julliard
  2007-07-31 19:57   ` Karl Hasselström
  1 sibling, 1 reply; 5+ messages in thread
From: Alexandre Julliard @ 2007-07-31 10:36 UTC (permalink / raw)
  To: Karl Hasselström; +Cc: git

Karl Hasselström <kha@treskal.com> writes:

> This is a Request For Help. The patch works, but is clearly the work
> of someone who is not very fluent in elisp. Just look at all that
> duplicated code I've introduced!

I would do it this way:

From: Alexandre Julliard <julliard@winehq.org>
Date: Tue, 31 Jul 2007 12:19:05 +0200
Subject: [PATCH] git.el: Take into account the core.excludesfile config option.

Also don't require .git/info/exclude to exist in order to list unknown
files.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 contrib/emacs/git.el |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 53dd703..9bcd7c4 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -589,6 +589,16 @@ Return the list of files that haven't been handled."
           (when node (push (ewoc-data node) unmerged-files))))
       (git-set-files-state 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-update-status-files (files &optional default-state)
   "Update the status of FILES from the index."
   (unless git-status (error "Not in git-status buffer."))
@@ -598,11 +608,11 @@ Return the list of files that haven't been handled."
               (git-run-ls-files status files 'added "-c")
             (git-run-diff-index status files))))
     (git-run-ls-unmerged status files)
-    (when (and (or (not files) remaining-files)
-               (file-readable-p ".git/info/exclude"))
-      (setq remaining-files (git-run-ls-files status remaining-files
-                                              'unknown "-o" "--exclude-from=.git/info/exclude"
-                                              (concat "--exclude-per-directory=" git-per-dir-ignore-file))))
+    (when (or (not files) remaining-files)
+      (let ((exclude-files (git-get-exclude-files)))
+        (setq remaining-files (apply #'git-run-ls-files status remaining-files 'unknown "-o"
+                                     (concat "--exclude-per-directory=" git-per-dir-ignore-file)
+                                     (mapcar (lambda (f) (concat "--exclude-from=" f)) exclude-files)))))
     ; mark remaining files with the default state (or remove them if nil)
     (when remaining-files
       (if default-state
-- 
1.5.3.rc3.92.g70c7b

-- 
Alexandre Julliard
julliard@winehq.org

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

* Re: [RFH PATCH] Teach the emacs git mode about core.excludesfile
  2007-07-31 10:36 ` Alexandre Julliard
@ 2007-07-31 19:57   ` Karl Hasselström
  0 siblings, 0 replies; 5+ messages in thread
From: Karl Hasselström @ 2007-07-31 19:57 UTC (permalink / raw)
  To: Alexandre Julliard; +Cc: git

On 2007-07-31 12:36:32 +0200, Alexandre Julliard wrote:

> I would do it this way:
>
> From: Alexandre Julliard <julliard@winehq.org>
> Date: Tue, 31 Jul 2007 12:19:05 +0200
> Subject: [PATCH] git.el: Take into account the core.excludesfile config option.
>
> Also don't require .git/info/exclude to exist in order to list unknown
> files.
>
> Signed-off-by: Alexandre Julliard <julliard@winehq.org>

Acked-by: Karl Hasselström <kha@treskal.com>

Works beautifully, thanks.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

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

end of thread, other threads:[~2007-07-31 19:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-31  1:13 [RFH PATCH] Teach the emacs git mode about core.excludesfile Karl Hasselström
2007-07-31  1:58 ` Matthieu Moy
2007-07-31 10:36 ` Alexandre Julliard
2007-07-31 19:57   ` Karl Hasselström
  -- strict thread matches above, loose matches on Subject: below --
2007-07-31  1:30 Karl Hasselström

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 NNTP newsgroup(s).