Subject: bug#43464: 28.0.50; vc: Error calling vc-revert for repo root

From: Andrii Kolomoiets <[email-masked]>
Date: Wed, 30 Sep 2020 12:13:41 +0300

Andrii Kolomoiets <[email-masked]> writes:

> Dmitry Gutov <[email-masked]> writes:
>> Could you explain both changes in that patch?
>
> The idea is to make the 'vc-backend' function to return backend for
> directory.
>
> `vc-backend` should return correct backend for directory and the
> behavior of `vc-registered` must be kept unchanged.

Please see attached patch.
>From 8b097942a3fbaf5b6d27fa61b2d3e5357d79beb8 Mon Sep 17 00:00:00 2001
From: Andrii Kolomoiets <[email-masked]>
Date: Wed, 30 Sep 2020 12:02:21 +0300
Subject: [PATCH] vc-backend for directory

* lisp/vc/vc-hooks.el (vc-registered): Use 'responsible-p' vc backend function
to find backend for directories.
(vc-backend): Don't depend on 'vc-registered' result because it nil for
directories; always read 'vc-backend' property.
---
 lisp/vc/vc-hooks.el | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el
index f09ceddcb3..b20e2e0b00 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -336,12 +336,15 @@ vc-registered
       ;; There is no file name handler.
       ;; Try vc-BACKEND-registered for each handled BACKEND.
       (catch 'found
-	(let ((backend (vc-file-getprop file 'vc-backend)))
+	(let ((backend (vc-file-getprop file 'vc-backend))
+              (fn-result (if (file-directory-p file)
+                             '(responsible-p)
+                           '(registered . t))))
 	  (mapc
 	   (lambda (b)
-	     (and (vc-call-backend b 'registered file)
+	     (and (vc-call-backend b (car fn-result) file)
 		  (vc-file-setprop file 'vc-backend b)
-		  (throw 'found t)))
+		  (throw 'found (cdr fn-result))))
 	   (if (or (not backend) (eq backend 'none))
 	       vc-handled-backends
 	     (cons backend vc-handled-backends))))
@@ -361,9 +364,8 @@ vc-backend
 	   (cond ((eq property 'none) nil)
 		 (property)
 		 ;; vc-registered sets the vc-backend property
-		 (t (if (vc-registered file-or-list)
-			(vc-file-getprop file-or-list 'vc-backend)
-		      nil)))))
+		 (t (vc-registered file-or-list)
+		    (vc-file-getprop file-or-list 'vc-backend)))))
 	((and file-or-list (listp file-or-list))
 	 (vc-backend (car file-or-list)))
 	(t
-- 
2.15.1