From: Sean Whitton Date: Wed, 9 Apr 2025 04:37:32 +0000 (+0800) Subject: VC-Dir: Offer to register files before checking in X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=36ef9ac17e4f37567a5aed4bbbf2a9ea1c06b9d3;p=emacs.git VC-Dir: Offer to register files before checking in * lisp/vc/vc.el (vc-only-files-state-and-model): Rewrite checking that all files are in compatible VC states. In particular, consistently return 'edited' when all files are either added, removed or edited, instead of allowing the return value to depend on the order of the files in VC-Dir, and offer to registered unregistered files if doing so would allow the operation to proceed. (vc-compatible-state): Delete. (vc-next-action): Replace call to vc-compatible-state. Document, in this command's docstring, the new feature implemented in vc-only-files-state-and-model. * etc/NEWS: Announce the new feature. (cherry picked from commit 253364e2c71bfaaa3ca623ed23f1cae6548a16c7) --- diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index f2c863bf0c2..28fc71c937a 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -1285,17 +1285,40 @@ BEWARE: this function may change the current buffer." "Compute last three `vc-deduce-fileset' return value elements for FILES. FILES should be a pair, or list of pairs, of files and their VC states. BACKEND is the VC backend responsible for FILES." - (let ((state (cdar files)) - (files* (mapcar #'car - (if (proper-list-p files) files (list files))))) + (let* ((files (if (proper-list-p files) files (list files))) + files* states-alist states state) ;; Check that all files are in a consistent state, since we use that ;; state to decide which operation to perform. - (dolist (crt (cdr files)) - (unless (vc-compatible-state (cdr crt) state) - (error "\ + (pcase-dolist (`(,file . ,state) files) + (push file files*) + (push file (alist-get state states-alist nil nil #'eq))) + (setq states (mapcar #'car states-alist)) + (cond ((length= states 1) + (setq state (car states))) + ((cl-subsetp states '(added removed edited)) + (setq state 'edited)) + + ;; Special, but common case: + ;; checking in both changes and new files at once. + ((and (cl-subsetp states '(added removed edited unregistered)) + (y-or-n-p "Some files are unregistered; register them first?")) + (vc-register (list backend + (cdr (assq 'unregistered states-alist)))) + (setq state 'edited)) + + (t + (let* ((pred (lambda (elt) + (memq (car elt) '(added removed edited)))) + (compat-alist (cl-remove-if-not pred states-alist)) + (other-alist (cl-remove-if pred states-alist)) + (first (car (or compat-alist other-alist))) + (second (if compat-alist + (car other-alist) + (cadr other-alist)))) + (error "\ To apply VC operations to multiple files, the files must be in similar VC states. %s in state %s clashes with %s in state %s" - (car crt) (cdr crt) (caar files) state))) + (cadr first) (car first) (cadr second) (car second))))) (list files* state (and state (not (eq state 'unregistered)) (vc-checkout-model backend files*))))) @@ -1311,12 +1334,6 @@ To apply VC operations to multiple files, the files must be in similar VC states (or (eq (vc-checkout-model backend (list file)) 'implicit) (memq (vc-state file) '(edited needs-merge conflict)))))) -(defun vc-compatible-state (p q) - "Control which states can be in the same commit." - (or - (eq p q) - (and (member p '(edited added removed)) (member q '(edited added removed))))) - (defun vc-read-backend (prompt &optional backends default) (let ((backends (or backends vc-handled-backends)) (completion-ignore-case t)) @@ -1341,6 +1358,8 @@ For modern merging-based version control systems: backend with which to register the fileset. If every work file in the VC fileset is either added or modified, pop up a *vc-log* buffer to commit the fileset changes. + (If some are added or modified and some are unregistered, offer to + register the unregistered ones, first.) For a centralized version control system, if any work file in the VC fileset is out of date, offer to update the fileset. @@ -1428,7 +1447,7 @@ from which to check out the file(s)." ;; do nothing (message "Fileset is up-to-date")))) ;; Files have local changes - ((vc-compatible-state state 'edited) + ((memq state '(added removed edited)) (let ((ready-for-commit files)) ;; CVS, SVN and bzr don't care about read-only (bug#9781). ;; RCS does, SCCS might (someone should check...).