[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with
From: |
Manuel Giraud |
Subject: |
bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path. |
Date: |
Tue, 09 Nov 2021 09:51:03 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (berkeley-unix) |
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Manuel Giraud <manuel@ledu-giraud.fr> writes:
>
>> I thought that we might already have a function for this. Does counting
>> slashes will work with Windows path?
>
> Hm... Actually, I'm not sure. Perhaps doing a series of
> file-name-directory/directory-file-name in a loop (to peel off the
> directory components) would be the best algorithm here? And I don't
> think we have a function for this -- at least I can't find anything
> promising while poking around.
That was what I found also inspired from dired-up-directory. So here is
what I've done. What bothers me is that it introduce two general purpose
(and probably buggy) functions that should reside somewhere else IMO.
>From 326c4c0f2f087a1be75657425a362aa05fc47557 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
Date: Tue, 9 Nov 2021 09:44:26 +0100
Subject: [PATCH] Use file depth for most specific path in
vc-backend-for-registration
---
lisp/vc/vc.el | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index c9500f454a..70c9434a20 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -927,6 +927,15 @@ with-vc-properties
property (cdr setting))))))))
;;; Code for deducing what fileset and backend to assume
+(defun parent-directory (filename)
+ (file-name-directory (directory-file-name filename)))
+
+(defun file-depth (filename)
+ (cl-loop for oparent = nil then parent
+ for parent = (parent-directory (expand-file-name filename)) then
(parent-directory parent)
+ for i from 0
+ until (string= parent oparent)
+ finally (return i)))
(defun vc-backend-for-registration (file)
"Return a backend that can be used for registering FILE.
@@ -944,9 +953,9 @@ vc-backend-for-registration
(dolist (backend vc-handled-backends)
(when (not (vc-call-backend backend 'registered file))
(let* ((path (vc-call-backend backend 'responsible-p file))
- (len (length path)))
- (when (and len (> len max))
- (setq max len bk backend)))))
+ (depth (and path (file-depth path))))
+ (when (and depth (> depth max))
+ (setq max depth bk backend)))))
(when bk
(throw 'found bk)))
;; no responsible backend
--
2.33.1
--
Manuel Giraud
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., (continued)
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Lars Ingebrigtsen, 2021/11/06
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Andy Moreton, 2021/11/06
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Dmitry Gutov, 2021/11/06
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Lars Ingebrigtsen, 2021/11/07
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Manuel Giraud, 2021/11/08
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Lars Ingebrigtsen, 2021/11/08
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Manuel Giraud, 2021/11/08
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Lars Ingebrigtsen, 2021/11/08
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Juri Linkov, 2021/11/09
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Lars Ingebrigtsen, 2021/11/09
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path.,
Manuel Giraud <=
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Lars Ingebrigtsen, 2021/11/09
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Dmitry Gutov, 2021/11/09
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Lars Ingebrigtsen, 2021/11/09
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Dmitry Gutov, 2021/11/09
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Lars Ingebrigtsen, 2021/11/09
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Eli Zaretskii, 2021/11/10
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Lars Ingebrigtsen, 2021/11/10
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Eli Zaretskii, 2021/11/10
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Lars Ingebrigtsen, 2021/11/10
- bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path., Eli Zaretskii, 2021/11/11