Subject: bug#23436: [PATCH] Attemp to use the true name of a file to determine responsible vc if the genuine name does not work.

From: Hong Xu <[email-masked]>
Date: Sat, 29 Oct 2016 17:42:01 -0700

On 2016-10-25 Tue 16:12 GMT-0700, Dmitry Gutov <[email-masked]> wrote:

> On 25.10.2016 22:05, Hong Xu wrote:
>
>> I don't understand why find-alternate-file should be used.
>
> For no reason other than the resulting command could be useful in more 
> situations than just this one.
>
>> The reason we
>> used (vc-follow-link) is to pass the correct file path to
>> vc-responsible-backend. I don't see how find-alternate-file can be used here.
>
> It would open the file (or directory) than is the true name of the 
> currently visited file (or directory), and kill the previous buffer.
>
> vc-responsible-backend would be called with the true name automatically. 
> This is close to what vc-follow-link does already.
>
> But if that's definitely not what you want, how about a command like this?
>
> (defun vc-refresh-as-link-target ()
>    (interactive)
>    (let ((buffer-file-name (file-truename buffer-file-name)))
>      (vc-refresh-state)))
>
> By the way, please remind us why vc-follow-symlinks (the variable) with 
> the default value `ask' is not sufficient for you?

OK, I think I have screwed it up. vc-responsible-backend looks like a function
mainly provided for elisp programming purpose, which people can make use
in their own customization. Thus, none of these functions should be
used. Instead, file-truename or file-chase-links should be used. That
is,

    (vc-responsible-backend (file-chase-links file))

>
>>> OK, mention where?
>>
>> In the doc string.
>
> The docstring of what? Please be more precise, the less I have to think 
> about or make choices regarding documentation, the happier I am.
>
>> Maybe we should also mention `vc-responsible-backend'
>> in the info doc "Supported Version Control Systems" in general.
>
> Care to send the proposed addition in the form of a patch?

The attachment is a draft of my proposed doc change. Feel free to adjust
the contents and the language.

Hong

diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi
index aca29910b7d3..8f31fa168c23 100644
--- a/doc/emacs/maintaining.texi
+++ b/doc/emacs/maintaining.texi
@@ -223,7 +223,7 @@ Version Control Systems
 @cindex SRC
 @cindex src
 @item
-SRC (src) is RCS, reloaded - a specialized version-control system
+SRC (src) is RCS, reloaded---a specialized version-control system
 designed for single-file projects worked on by only one person.  It
 allows multiple files with independent version-control histories to
 exist in one directory, and is thus particularly well suited for
@@ -233,6 +233,22 @@ Version Control Systems
 supports almost all SRC operations.
 @end itemize
 
+@defun vc-responsible-backend file
+This function can be used to determine the responsible VC backend of
+the given file path @var{file}.  For example, if @code{emacs.c} is a
+file tracked by git, @code{(vc-responsible-backend "emacs.c")} returns
+@code{"Git"}.  Note that if @var{file} is a symbolic link,
+@code{vc-responsible-backend} will not resolve it---it always reports
+the backend of the symbolic link file itself.  Instead, to get the
+backend VC of the file to which @var{file} refers, wrap @var{file}
+with a symbolic link resolving function such as
+@code{file-chase-links}:
+
+@smallexample
+(vc-responsible-backend (file-chase-links "emacs.c"))
+@end smallexample
+@end defun
+
 @node VCS Concepts
 @subsubsection Concepts of Version Control
 
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index ac020d095397..a1e4388f6e5c 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -959,7 +959,11 @@ vc-responsible-backend
 If FILE is already registered, return the
 backend of FILE.  If FILE is not registered, then the
 first backend in `vc-handled-backends' that declares itself
-responsible for FILE is returned."
+responsible for FILE is returned.
+
+Note that if FILE is a symbolic link, it will not be resolved --
+it will report the responsible backend system for the symbolic
+link itself."
   (or (and (not (file-directory-p file)) (vc-backend file))
       (catch 'found
 	;; First try: find a responsible backend.  If this is for registration,