From: Manuel Giraud Date: Sat, 6 Nov 2021 00:13:49 +0000 (+0100) Subject: Make 'C-x v v' on an unregistered file use the most specific backend X-Git-Tag: emacs-29.0.90~3671^2~217 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=cfd4d45f1164fb86bdad306ed0d532150a88f7e7;p=emacs.git 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). --- diff --git a/etc/NEWS b/etc/NEWS index 9b4112a8f2b..78c848126a6 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -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 diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index df8990c1187..c9500f454ae 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -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))