master b66c995d5fb: Improve 'vc-dir-unmark-all-files' (bug#81249)

Stephen Berman via Mailing list for Emacs changes <[email protected]>
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: master
commit b66c995d5fb060b79bf866aa8d760ff0857ae32e
Author: Stephen Berman <[email protected]>
Commit: Stephen Berman <[email protected]>

    Improve 'vc-dir-unmark-all-files' (bug#81249)
    
    * lisp/vc/vc-dir.el (vc-dir-unmark-all-files): Confine the scope
    of this command, when called on a VC Dir directory entry, to the
    immediate child files of that directory.  This is in accordance
    with the command's doc string and makes it behave analgously to
    'vc-dir-mark-all-files', whose behavior was change to be like this
    much earlier.
    
    * test/lisp/vc/vc-tests/vc-test-misc.el
    (vc-test-vc-dir-mark/unmark-all-dir-entry): New test.
---
 lisp/vc/vc-dir.el                     | 11 +++---
 test/lisp/vc/vc-tests/vc-test-misc.el | 68 +++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 5 deletions(-)

diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el
index 596c2fe7362..393a2ebdbc3 100644
--- a/lisp/vc/vc-dir.el
+++ b/lisp/vc/vc-dir.el
@@ -1079,11 +1079,12 @@ that share the same state."
 	   (data (ewoc-data crt)))
       (if (vc-dir-fileinfo->directory data)
 	  ;; It's a directory, unmark child files.
-	  (while (setq crt (ewoc-next vc-ewoc crt))
-	    (let ((crt-data (ewoc-data crt)))
-	      (unless (vc-dir-fileinfo->directory crt-data)
-		(setf (vc-dir-fileinfo->marked crt-data) nil)
-		(ewoc-invalidate vc-ewoc crt))))
+          (let (crt-data)
+	    (while (and (setq crt (ewoc-next vc-ewoc crt))
+			(setq crt-data (ewoc-data crt))
+			(not (vc-dir-fileinfo->directory crt-data)))
+	      (setf (vc-dir-fileinfo->marked crt-data) nil)
+	      (ewoc-invalidate vc-ewoc crt)))
 	;; It's a file
 	(let ((crt-state (vc-dir-fileinfo->state (ewoc-data crt))))
 	  (ewoc-map
diff --git a/test/lisp/vc/vc-tests/vc-test-misc.el b/test/lisp/vc/vc-tests/vc-test-misc.el
index 83a69867220..049cef3c253 100644
--- a/test/lisp/vc/vc-tests/vc-test-misc.el
+++ b/test/lisp/vc/vc-tests/vc-test-misc.el
@@ -358,5 +358,73 @@ See bug#80803 and bug#80967."
           (should (and (looking-at "\\./$") (looking-back "^ +")))
           (kill-buffer vc-dir-buf))))))
 
+(ert-deftest vc-test-vc-dir-mark/unmark-all-dir-entry ()
+  "Test `vc-dir-{un}mark-all' called on directory entry."
+  (skip-unless (executable-find vc-git-program))
+  (vc-test--with-author-identity 'Git
+    (let ((vc-handled-backends '(Git)))
+      (ert-with-temp-directory tempdir
+        (let ((default-directory tempdir)
+              (files '("file01" "file02" "dir1/file11" "dir1/file12"
+                       "dir2/file21" "dir2/file22"))
+              vc-dir-buf
+              dir-children)
+          (vc-test--create-repo-function 'Git)
+          (dolist (file files)
+            (make-empty-file file t))
+          (vc-dir default-directory 'Git)
+          (while (vc-dir-busy) (sit-for 0.05))
+          (setq vc-dir-buf (current-buffer))
+          ;; Put point on line of "./" entry.
+          (goto-char (ewoc-location (ewoc-nth vc-ewoc 0)))
+          ;; Cumulatively mark file entries directory-wise.
+          (let ((next t))
+            (while next
+             (vc-dir-mark-all-files nil)
+             ;; Can't use this to set dir-children because it returns
+             ;; all files below directory entry, so loop over file
+             ;; entries until next directory entry.
+             ;; (vc-dir-find-child-files
+             ;;  (expand-file-name
+             ;;   (vc-dir-fileinfo->name
+             ;;    (ewoc-data (ewoc-locate vc-ewoc)))))
+             (catch 'done
+               (while t
+                 (vc-dir-next-line 1)
+                 (cond ((vc-dir-fileinfo->directory
+                          (ewoc-data (ewoc-locate vc-ewoc)))
+                        (throw 'done nil))
+                         ;; After last entry.
+                       ((looking-at "^$")
+                        (throw 'done (setq next nil)))
+                       (t
+                        (push (expand-file-name
+                               (vc-dir-fileinfo->name
+                                (ewoc-data (ewoc-locate vc-ewoc))))
+                              dir-children)))))
+             (should (seq-set-equal-p (vc-dir-marked-files) dir-children))))
+          (goto-char (ewoc-location (ewoc-nth vc-ewoc 0)))
+          ;; Cumulatively unmark file entries directory-wise.
+          (let ((next t))
+            (while next
+              (vc-dir-unmark-all-files nil)
+              (catch 'done
+                (while t
+                  (vc-dir-next-line 1)
+                  (cond ((vc-dir-fileinfo->directory
+                           (ewoc-data (ewoc-locate vc-ewoc)))
+                         (throw 'done nil))
+                          ;; After last entry.
+                        ((looking-at "^$")
+                         (throw 'done (setq next nil)))
+                        (t
+                         (setq dir-children
+                               (delete (expand-file-name
+                                        (vc-dir-fileinfo->name
+                                         (ewoc-data (ewoc-locate vc-ewoc))))
+                                       dir-children))))))
+              (should (seq-set-equal-p (vc-dir-marked-files) dir-children))))
+          (kill-buffer vc-dir-buf))))))
+
 (provide 'vc-test-misc)
 ;;; vc-test-misc.el ends here
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.