From 9e673edc28f84a75f3bf0f53e7fba01c2f50e51c Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Mon, 13 Sep 2021 17:31:31 +0200 Subject: [PATCH] let VC find a responsible backend with the most specific path. --- lisp/vc/vc.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 4fcba65ab4..7160c98820 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -937,11 +937,16 @@ vc-backend-for-registration use." (catch 'found ;; First try: find a responsible backend, it must be a backend - ;; under which FILE is not yet registered. - (dolist (backend vc-handled-backends) - (and (not (vc-call-backend backend 'registered file)) - (vc-call-backend backend 'responsible-p file) - (throw 'found backend))) + ;; under which FILE is not yet registered and with the most + ;; specific path to FILE. + (let ((max 0) bk) + (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))))) + (when bk (throw 'found bk))) ;; no responsible backend (let* ((possible-backends (let (pos) -- 2.33.0