unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Manuel Giraud <manuel@ledu-giraud.fr>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 50572@debbugs.gnu.org, Andy Moreton <andrewjmoreton@gmail.com>,
	Dmitry Gutov <dgutov@yandex.ru>
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	[thread overview]
Message-ID: <87y25x3e6g.fsf@elite.giraud> (raw)
In-Reply-To: <877ddiuhv7.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 09 Nov 2021 04:29:16 +0100")

[-- Attachment #1: Type: text/plain, Size: 731 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Use-file-depth-for-most-specific-path-in-vc-backend-.patch --]
[-- Type: text/x-patch, Size: 1636 bytes --]

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


[-- Attachment #3: Type: text/plain, Size: 18 bytes --]

-- 
Manuel Giraud

  parent reply	other threads:[~2021-11-09  8:51 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-13 15:47 bug#50572: 28.0.50; [PATCH] fix VC to find the responsible backend with the most specific path Manuel Giraud
2021-09-13 16:10 ` Eli Zaretskii
2021-09-13 23:48   ` Dmitry Gutov
2021-09-14  2:28     ` Eli Zaretskii
2021-09-14  7:57     ` Manuel Giraud
2021-09-14  7:50   ` Manuel Giraud
2021-09-14 11:38     ` Eli Zaretskii
2021-09-14 12:08       ` Manuel Giraud
2021-09-14 12:57         ` Eli Zaretskii
2021-09-14 15:15       ` Manuel Giraud
2021-09-14 16:03         ` Eli Zaretskii
2021-09-15  9:17           ` Manuel Giraud
2021-09-15 10:35           ` Dmitry Gutov
2021-09-15 11:20             ` Eli Zaretskii
2021-09-15 11:36               ` Dmitry Gutov
2021-09-15 10:41       ` Dmitry Gutov
2021-09-15 11:22         ` Eli Zaretskii
2021-09-15 11:37           ` Dmitry Gutov
2021-09-15 11:44             ` Eli Zaretskii
2021-09-15 11:47               ` Dmitry Gutov
2021-09-16 12:55                 ` Lars Ingebrigtsen
2021-11-06  0:16 ` Lars Ingebrigtsen
2021-11-06 15:01   ` Andy Moreton
2021-11-06 18:19     ` Lars Ingebrigtsen
2021-11-06 22:30       ` Andy Moreton
2021-11-06 22:35         ` Dmitry Gutov
2021-11-07 13:17           ` Lars Ingebrigtsen
2021-11-08  9:28             ` Manuel Giraud
2021-11-08  9:31               ` Lars Ingebrigtsen
2021-11-08 10:37                 ` Manuel Giraud
2021-11-09  3:29                   ` Lars Ingebrigtsen
2021-11-09  8:09                     ` Juri Linkov
2021-11-09 22:55                       ` Lars Ingebrigtsen
2021-11-09  8:51                     ` Manuel Giraud [this message]
2021-11-09 23:30                       ` Lars Ingebrigtsen
2021-11-10  0:06                         ` Dmitry Gutov
2021-11-10  0:20                           ` Lars Ingebrigtsen
2021-11-10  0:29                             ` Dmitry Gutov
2021-11-10  0:39                               ` Lars Ingebrigtsen
2021-11-10 12:54                                 ` Eli Zaretskii
2021-11-10 12:59                                   ` Lars Ingebrigtsen
2021-11-10 14:23                                     ` Eli Zaretskii
2021-11-11  2:56                                       ` Lars Ingebrigtsen
2021-11-11  7:06                                         ` Eli Zaretskii
2021-11-11  7:46                                           ` Michael Albinus
2021-11-11  8:04                                             ` Eli Zaretskii
2021-11-11 10:46                                               ` Michael Albinus
2021-11-11 12:21                                           ` Lars Ingebrigtsen
2021-11-11 15:09                                             ` Eli Zaretskii
2021-11-12  3:01                                               ` Lars Ingebrigtsen
2021-11-12  9:51                         ` Manuel Giraud
2021-11-12 12:05                           ` Eli Zaretskii
2021-11-12 15:09                             ` Manuel Giraud
2021-11-12 15:20                               ` Eli Zaretskii
2021-11-12 15:41                                 ` Manuel Giraud
2021-11-12 19:21                                 ` Manuel Giraud
2021-11-12 19:40                                   ` Eli Zaretskii
2021-11-14  0:51                                   ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y25x3e6g.fsf@elite.giraud \
    --to=manuel@ledu-giraud.fr \
    --cc=50572@debbugs.gnu.org \
    --cc=andrewjmoreton@gmail.com \
    --cc=dgutov@yandex.ru \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).