unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#39502: [PATCH] Use one src status -a call for vc-src-dir-status-files
@ 2020-02-07 22:52 Wolfgang Scherer
       [not found] ` <handler.39502.B.158111597418374.ack@debbugs.gnu.org>
  2020-02-08  9:39 ` bug#39502: [PATCH] Use one src status -a call for vc-src-dir-status-files Dmitry Gutov
  0 siblings, 2 replies; 13+ messages in thread
From: Wolfgang Scherer @ 2020-02-07 22:52 UTC (permalink / raw)
  To: 39502

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

While working on the ignore feature for SRC, I found that unregistered files were not displayed in vc-dir-mode.

The source code specified in a comment:

   ;; FIXME: Use one src status -a call for this

Here is a patch that implements that.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Use-one-src-status-a-call-for-vc-src-dir-status-file.patch --]
[-- Type: text/x-patch; name="0001-Use-one-src-status-a-call-for-vc-src-dir-status-file.patch", Size: 4248 bytes --]

From 5c3dd425d30ecb7f6afe4748d10f398dfda11ca8 Mon Sep 17 00:00:00 2001
From: Wolfgang Scherer <wolfgang.scherer@gmx.de>
Date: Fri, 7 Feb 2020 23:46:48 +0100
Subject: [PATCH] Use one src status -a call for vc-src-dir-status-files
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

lisp/vc/vc-src.el: (vc-src--parse-state) new function.
(vc-src-state) use vc-src--parse-state.
(vc-src-dir-status-files) use a single call to ‘src status -a’.
---
 lisp/vc/vc-src.el | 80 ++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 49 insertions(+), 31 deletions(-)

diff --git a/lisp/vc/vc-src.el b/lisp/vc/vc-src.el
index db127ee..8f0836f 100644
--- a/lisp/vc/vc-src.el
+++ b/lisp/vc/vc-src.el
@@ -146,48 +146,66 @@ For a description of possible values, see `vc-check-master-templates'."
 (progn
 (defun vc-src-registered (f) (vc-default-registered 'src f)))

+(defun vc-src--parse-state (out)
+  (when (null (string-match "does not exist or is unreadable" out))
+    (let ((state (aref out 0)))
+      (cond
+       ;; FIXME: What to do about L code?
+       ((eq state ?.) 'up-to-date)
+       ((eq state ?A) 'added)
+       ((eq state ?M) 'edited)
+       ((eq state ?I) 'ignored)
+       ((eq state ?R) 'removed)
+       ((eq state ?!) 'missing)
+       ((eq state ??) 'unregistered)
+       (t 'up-to-date)))))
+
 (defun vc-src-state (file)
   "SRC-specific version of `vc-state'."
   (let*
       ((status nil)
        (default-directory (file-name-directory file))
        (out
-	(with-output-to-string
-	  (with-current-buffer
-	      standard-output
-	    (setq status
-		  ;; Ignore all errors.
-		  (condition-case nil
-		      (process-file
-		       vc-src-program nil t nil
-		       "status" "-a" (file-relative-name file))
-		    (error nil)))))))
+        (with-output-to-string
+          (with-current-buffer
+              standard-output
+            (setq status
+                  ;; Ignore all errors.
+                  (condition-case nil
+                      (process-file
+                       vc-src-program nil t nil
+                       "status" "-a" (file-relative-name file))
+                    (error nil)))))))
     (when (eq 0 status)
-      (when (null (string-match "does not exist or is unreadable" out))
-	(let ((state (aref out 0)))
-	  (cond
-	   ;; FIXME: What to do about A and L codes?
-	   ((eq state ?.) 'up-to-date)
-	   ((eq state ?A) 'added)
-	   ((eq state ?M) 'edited)
-	   ((eq state ?I) 'ignored)
-	   ((eq state ?R) 'removed)
-	   ((eq state ?!) 'missing)
-	   ((eq state ??) 'unregistered)
-	   (t 'up-to-date)))))))
+      (vc-src--parse-state out))))

 (autoload 'vc-expand-dirs "vc")

 (defun vc-src-dir-status-files (dir files update-function)
-  ;; FIXME: Use one src status -a call for this
-  (if (not files) (setq files (vc-expand-dirs (list dir) 'SRC)))
-  (let ((result nil))
-    (dolist (file files)
-      (let ((state (vc-state file))
-	    (frel (file-relative-name file)))
-	(when (and (eq (vc-backend file) 'SRC)
-		   (not (eq state 'up-to-date)))
-	  (push (list frel state) result))))
+  (let*
+      ((result nil)
+       (status nil)
+       (default-directory (or dir default-directory))
+       (out
+        (with-output-to-string
+          (with-current-buffer
+              standard-output
+            (setq status
+                  ;; Ignore all errors.
+                  (condition-case nil
+                      (apply
+                       #'process-file vc-src-program nil t nil
+                       "status" "-a"
+                       (mapcar (lambda (f) (file-relative-name f)) files))
+                    (error nil)))))))
+    (when (eq 0 status)
+      (dolist (line (split-string out "[\n\r]" t))
+        (let* ((pair (split-string line "[\t]" t))
+               (state (vc-src--parse-state (car pair)))
+               (frel (cadr pair)))
+          (when (not (eq state 'up-to-date))
+            (push (list frel state) result))
+          )))
     (funcall update-function result)))

 (defun vc-src-command (buffer file-or-list &rest flags)
--
2.7.4


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

end of thread, other threads:[~2020-08-09 19:50 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-07 22:52 bug#39502: [PATCH] Use one src status -a call for vc-src-dir-status-files Wolfgang Scherer
     [not found] ` <handler.39502.B.158111597418374.ack@debbugs.gnu.org>
2020-02-08  5:35   ` bug#39502: Acknowledgement ([PATCH] Use one src status -a call for vc-src-dir-status-files) Wolfgang Scherer
2020-02-08  9:39 ` bug#39502: [PATCH] Use one src status -a call for vc-src-dir-status-files Dmitry Gutov
2020-02-10  0:47   ` Wolfgang Scherer
2020-02-10  4:29     ` Dmitry Gutov
2020-02-11  2:54       ` Wolfgang Scherer
2020-02-11  7:46         ` Dmitry Gutov
2020-02-14 10:05         ` Eli Zaretskii
2020-02-15  2:44           ` Wolfgang Scherer
2020-08-09 11:31           ` Lars Ingebrigtsen
2020-08-09 14:13             ` Eli Zaretskii
2020-08-09 17:42               ` Dmitry Gutov
2020-08-09 19:50                 ` Lars Ingebrigtsen

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

	https://git.savannah.gnu.org/cgit/emacs.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).