Make 'C-x v v' on an unregistered file use the most specific backend

* lisp/vc/vc.el (vc-next-action): Mention this.

* lisp/vc/vc.el (vc-backend-for-registration): Choose the most
specific backend (bug#50572).
This commit is contained in:
Manuel Giraud 2021-11-06 01:13:49 +01:00 committed by Lars Ingebrigtsen
parent ec2939c379
commit cfd4d45f11
2 changed files with 28 additions and 7 deletions

View file

@ -167,6 +167,16 @@ change the terminal used on a remote host.
* Changes in Specialized Modes and Packages in Emacs 29.1
** vc
---
*** 'C-x v v' on an unregistered file will now use the most specific backend.
Previously, if you had an SVN-covered ~/ directory, and a Git-covered
directory in ~/foo/bar, using 'C-x v v' on a new, unregistered file
~/foo/bar/zot would register it in the SVN repository in ~/ instead of
in the Git repository in ~/foo/bar. This makes this command
consistent with 'vc-responsible-backend'.
** Message
---
@ -432,7 +442,7 @@ long lists and vectors.
'pp' formats general Lisp sexps. This function does much the same,
but applies formatting rules appropriate for Emacs Lisp code.
+++
+++,
*** New function 'file-has-changed-p'.
This convenience function is useful when writing code that parses
files at run-time, and allows Lisp programs to re-parse files only

View file

@ -937,11 +937,18 @@ repository, prompting for the directory and the VC backend to
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)
@ -1188,7 +1195,11 @@ For old-style locking-based version control systems, like RCS:
*vc-log* buffer to check in the changes. Leave a
read-only copy of each changed file after checking in.
If every file is locked by you and unchanged, unlock them.
If every file is locked by someone else, offer to steal the lock."
If every file is locked by someone else, offer to steal the lock.
When using this command to register a new file (or files), it
will automatically deduce which VC repository to register it
with, using the most specific one."
(interactive "P")
(let* ((vc-fileset (vc-deduce-fileset nil t 'state-model-only-files))
(backend (car vc-fileset))