From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Manuel Giraud Newsgroups: gmane.emacs.bugs 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 Message-ID: <87y25x3e6g.fsf@elite.giraud> References: <877dfkxyt4.fsf@elite.giraud> <87cznef8ah.fsf@gnus.org> <86ilx5iaze.fsf@gmail.com> <87pmrdb0zv.fsf@gnus.org> <86mtmgx6gg.fsf@gmail.com> <87fe707b-f2b4-febd-d2ae-acc697b4cee1@yandex.ru> <87zgqgjeaz.fsf@gnus.org> <87cznbt2r1.fsf@elite.giraud> <87h7cn803w.fsf@gnus.org> <878rxzszl8.fsf@elite.giraud> <877ddiuhv7.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40272"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (berkeley-unix) Cc: 50572@debbugs.gnu.org, Andy Moreton , Dmitry Gutov To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 09 09:52:14 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mkMrV-000AEF-0O for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 09 Nov 2021 09:52:13 +0100 Original-Received: from localhost ([::1]:45224 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mkMrT-0000J7-Ay for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 09 Nov 2021 03:52:11 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:32898) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mkMrK-0000IV-EL for bug-gnu-emacs@gnu.org; Tue, 09 Nov 2021 03:52:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49219) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mkMrK-0007Yz-6M for bug-gnu-emacs@gnu.org; Tue, 09 Nov 2021 03:52:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mkMrK-0004XI-52 for bug-gnu-emacs@gnu.org; Tue, 09 Nov 2021 03:52:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Manuel Giraud Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 09 Nov 2021 08:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50572 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 50572-submit@debbugs.gnu.org id=B50572.163644787217368 (code B ref 50572); Tue, 09 Nov 2021 08:52:02 +0000 Original-Received: (at 50572) by debbugs.gnu.org; 9 Nov 2021 08:51:12 +0000 Original-Received: from localhost ([127.0.0.1]:60765 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mkMqV-0004W3-Nc for submit@debbugs.gnu.org; Tue, 09 Nov 2021 03:51:12 -0500 Original-Received: from ledu-giraud.fr ([51.159.28.247]:40444) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mkMqQ-0004Vo-BG for 50572@debbugs.gnu.org; Tue, 09 Nov 2021 03:51:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=JOWbfiD3orZGAJ0i fFWDGBHLVzPq2mbto96ctwMJrSc=; h=in-reply-to:date:references:subject: cc:to:from; d=ledu-giraud.fr; b=vlnEA3i6w4lzuaXwFIIIaDIg6Ya773TYfctv62 5eHShP4tZRzbot3hnn93PMosN1t2SEe2tld65dADwprcz/6GuCpg68KqbjZA7/KIbpMGIg hJ8Q5M/3HLeqozvLfOiznGH2uUGWAJo61ERwUIoR/Ae2k2EhRwBwd047KwPfiyoOndLAkQ pvpftjSa/VQ/4yaFWqsSWNB2YnoxJW+FndlqTNnY1iuMgdlbdevpWKxocZ5Dg7dD7z0Vce 5L61kPzIoqRvdgDriXLkNOj8vXb8Wa0wqtYDOcOZpz5qkHJ4xi2myNnhvKGkjMKvivVSOo xJvUCAqwx+LPu83KkDbiKI9Q== Original-Received: from elite.giraud ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id 03eade00 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Tue, 9 Nov 2021 09:51:04 +0100 (CET) In-Reply-To: <877ddiuhv7.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 09 Nov 2021 04:29:16 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:219430 Archived-At: --=-=-= Content-Type: text/plain Lars Ingebrigtsen writes: > Manuel Giraud 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Use-file-depth-for-most-specific-path-in-vc-backend-.patch >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 --=-=-= Content-Type: text/plain -- Manuel Giraud --=-=-=--