Subject: Re: bug#7350: 24.0.50; make vc-deduce-backend smarter

From: Bob Rogers <[email-masked]>
Date: Sun, 7 Nov 2010 16:41:08 -0500

From: Stefan Monnier <[email-masked]>
   Date: Sun, 07 Nov 2010 15:03:16 -0500

   >    I notice that vc-root-diff only works if the current buffer is
   > visiting a version-controlled file, and in certain other buffer modes.
   > In particular, it works in dired-mode, where it uses the
   > default-directory, but not in shell-mode, which is not one of the
   > explicit special cases.

   Could you give an example use-case where you'd want vc-deduce-backend to
   be run in a shell-mode buffer?

	   Stefan

I have gotten into the habit of using a shell buffer to disambiguate
which repo I want to use for general VC commands like vc-root-diff and
vc-dir.  Since I bind "shell" to f8, it is often faster to type "f8 C-x
v d RET" than to supply an explicit pathname to vc-dir.  (I'm often in
the right shell buffer already, having just typed "make test".)  Since
vc-root-diff doesn't take a pathname arg, I have to do something
explicit to get into the right tree anyway.  So it makes sense to me
that vc-root-diff should work like vc-dir in a non-VC buffer.  There is
already an exception for dired-mode; why not generalize?

   In fact, this is something of a regression from Emacs 22.x, where
"C-u C-x v = . RET RET RET" would do the equivalent of

	(vc-version-diff (expand-file-name ".") nil nil)

which is nearly vc-root-diff, regardless of buffer mode.  This no longer
works in the brave new world of filesets, so I had to revise my
shorthand command to turn "." into a fileset.  I was hoping that
vc-root-diff (which I only stumbled over recently) would serve as a
replacement, but it doesn't quite match my workflow because of this
insistence on being in a VC buffer.

   As an aside, I often think that VC doesn't have a good enough notion
of "current file set;" there are other times when it doesn't seem to
DTRT.  (Except for the change in vc-diff mentioned in the previous
paragraph, I can't recall any examples off the top of my head).  But so
far I haven't had any ideas.

   In short, I don't have a killer use case -- I could just keep on
using my own command for this -- but on the other hand, I don't see the
need for limiting commands like vc-root-diff in this way.  If you think
that this is the wrong place to make this change, then the alternative
patch below makes the same change to vc-root-diff directly.  (And I'll
let you know if I find any better use cases. ;-)

					-- Bob

------------------------------------------------------------------------
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 665dafb..5c7fa81 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1682,7 +1682,9 @@ saving the buffer."
       ;; that's not what we want here, we want the diff for the VC root dir.
       (call-interactively 'vc-version-diff)
     (when buffer-file-name (vc-buffer-sync not-urgent))
-    (let ((backend (vc-deduce-backend))
+    (let ((backend (or (vc-deduce-backend)
+		       (and default-directory
+			    (vc-responsible-backend default-directory))))
 	  rootdir working-revision)
       (unless backend
 	(error "Buffer is not version controlled"))