From 326c4c0f2f087a1be75657425a362aa05fc47557 Mon Sep 17 00:00:00 2001 From: Manuel Giraud 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