Subject: bug#12492: 24.2.50; Open vc-dir buffer easier and faster

From: Dmitry Gutov <[email-masked]>
Date: Sun, 23 Sep 2012 03:04:01 +0400

Tags: patch

Two changes:
1) All version controlled buffers have after-save-hook set up to call 
vc-dir-resynch-file. So if we're just bringing up a buried vc-dir 
buffer, we (almost?) never need to refresh it. This cuts about 1 second 
or more on my machine, depending on the backend.
2) For almost all backends we can easily deduce the repository root 
directory (exceptions: cvs, rcs, sccs), and I believe that in almost all 
cases the user wants to see the status of this directory, not of some 
subdirectory or any directory unrelated to the current buffer.
Hence the function vc-root-dir, which I think should be bound to 'C-x v 
d' and the respective menu item.
In the rare case when the user need to do something unusual, they can do 
M-x vc-dir.
When the backend doesn't have the function vc-xx-root, vc-root-dir 
interactively delegates to vc-dir, so for CVS, for example, the behavior 
will not change.
=== modified file 'lisp/vc/vc-dir.el'
--- lisp/vc/vc-dir.el	2012-08-13 21:31:56 +0000
+++ lisp/vc/vc-dir.el	2012-09-22 22:43:38 +0000
@@ -1227,12 +1227,25 @@
     (setq backend (vc-responsible-backend dir)))
   (let (pop-up-windows)		      ; based on cvs-examine; bug#6204
     (pop-to-buffer (vc-dir-prepare-status-buffer "*vc-dir*" dir backend)))
-  (if (derived-mode-p 'vc-dir-mode)
-      (vc-dir-refresh)
+  ;; If the mode matches, the buffer was only buried and should be up to date.
+  (unless (derived-mode-p 'vc-dir-mode)
     ;; FIXME: find a better way to pass the backend to `vc-dir-mode'.
     (let ((use-vc-backend backend))
       (vc-dir-mode))))
 
+;;;###autoload
+(defun vc-root-dir ()
+  "Show the VC status of the current buffer's repository.
+If the buffer is not visiting a version controlled file, or if
+the backend does not support function `root', prompt for
+directory.  See `vc-dir' for more details."
+  (interactive)
+  (let* ((backend (vc-backend (buffer-file-name)))
+         (dir (and backend (vc-call-backend backend 'root buffer-file-name))))
+    (if dir
+        (vc-dir dir backend)
+      (call-interactively 'vc-dir))))
+
 (defun vc-default-dir-extra-headers (_backend _dir)
   ;; Be loud by default to remind people to add code to display
   ;; backend specific headers.

=== modified file 'lisp/vc/vc-hooks.el'
--- lisp/vc/vc-hooks.el	2012-07-11 23:13:41 +0000
+++ lisp/vc/vc-hooks.el	2012-09-22 21:31:00 +0000
@@ -923,7 +923,7 @@
     (define-key map "a" 'vc-update-change-log)
     (define-key map "b" 'vc-switch-backend)
     (define-key map "c" 'vc-rollback)
-    (define-key map "d" 'vc-dir)
+    (define-key map "d" 'vc-root-dir)
     (define-key map "g" 'vc-annotate)
     (define-key map "h" 'vc-insert-headers)
     (define-key map "i" 'vc-register)
@@ -1005,9 +1005,9 @@
     (bindings--define-key map [vc-register]
       '(menu-item "Register" vc-register
 		  :help "Register file set into a version control system"))
-    (bindings--define-key map [vc-dir]
-      '(menu-item "VC Dir"  vc-dir
-		  :help "Show the VC status of files in a directory"))
+    (bindings--define-key map [vc-root-dir]
+      '(menu-item "VC Dir"  vc-root-dir
+		  :help "Show the VC status of the repository"))
     map))
 
 (defalias 'vc-menu-map vc-menu-map)