aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Whitton2025-02-17 15:40:38 +0800
committerSean Whitton2025-02-17 15:40:38 +0800
commit2d59974da71ec7ae20175d74269d4ca3d9be1cc7 (patch)
tree4599251bb03cc8d7661ab7edac6af92625407e99
parent05a96fd39809f11a3820e2164b23ebf9df192b13 (diff)
downloademacs-2d59974da71ec7ae20175d74269d4ca3d9be1cc7.tar.gz
emacs-2d59974da71ec7ae20175d74269d4ca3d9be1cc7.zip
vc-revert-file: Support reverting directories
* lisp/vc/vc.el (vc-revert-file): Support reverting directories by calling vc-responsible-backend instead of vc-backend when FILE is a directory (bug#37310, bug#43464). Based on an approach by Dmitry Gutov <dmitry@gutov.dev>. (vc-rename-file): Add a FIXME to support reverting directories. * etc/NEWS: Document the new functionality.
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/vc/vc.el20
2 files changed, 21 insertions, 3 deletions
diff --git a/etc/NEWS b/etc/NEWS
index a0d81608103..12d7bd4f41f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1161,6 +1161,10 @@ cloning, or prompts for that, too.
1161When the argument is non-nil, the function switches to a buffer visiting 1161When the argument is non-nil, the function switches to a buffer visiting
1162the directory into which the repository was cloned. 1162the directory into which the repository was cloned.
1163 1163
1164---
1165*** C-x v u ('vc-revert') now works on directories listed in VC-Dir.
1166Reverting a directory means reverting changes to all files inside it.
1167
1164** Package 1168** Package
1165 1169
1166+++ 1170+++
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 551a053b9a8..d66f95578fa 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -3381,14 +3381,19 @@ its name; otherwise return nil."
3381 backup-file))))) 3381 backup-file)))))
3382 3382
3383(defun vc-revert-file (file) 3383(defun vc-revert-file (file)
3384 "Revert FILE back to the repository working revision it was based on." 3384 "Revert FILE back to the repository working revision it was based on.
3385If FILE is a directory, revert all files inside that directory."
3385 (with-vc-properties 3386 (with-vc-properties
3386 (list file) 3387 (list file)
3387 (let ((backup-file (vc-version-backup-file file))) 3388 (let* ((dir (file-directory-p file))
3389 (backup-file (and (not dir) (vc-version-backup-file file))))
3388 (when backup-file 3390 (when backup-file
3389 (copy-file backup-file file 'ok-if-already-exists) 3391 (copy-file backup-file file 'ok-if-already-exists)
3390 (vc-delete-automatic-version-backups file)) 3392 (vc-delete-automatic-version-backups file))
3391 (vc-call revert file backup-file)) 3393 (vc-call-backend (if dir
3394 (vc-responsible-backend file)
3395 (vc-backend file))
3396 'revert file backup-file))
3392 `((vc-state . up-to-date) 3397 `((vc-state . up-to-date)
3393 (vc-checkout-time . ,(file-attribute-modification-time 3398 (vc-checkout-time . ,(file-attribute-modification-time
3394 (file-attributes file))))) 3399 (file-attributes file)))))
@@ -3542,6 +3547,15 @@ buffer's file name if it's under version control."
3542 "Rename file OLD to NEW in both work area and repository. 3547 "Rename file OLD to NEW in both work area and repository.
3543If called interactively, read OLD and NEW, defaulting OLD to the 3548If called interactively, read OLD and NEW, defaulting OLD to the
3544current buffer's file name if it's under version control." 3549current buffer's file name if it's under version control."
3550 ;; FIXME: Support renaming whole directories.
3551 ;; The use of `vc-call' will need to change to something like
3552 ;;
3553 ;; (vc-call-backend (if dir
3554 ;; (vc-responsible-backend file)
3555 ;; (vc-backend file))
3556 ;; 'rename-file old new)
3557 ;;
3558 ;; as was done in `vc-revert-file'; see bug#43464. --spwhitton
3545 (interactive (list (read-file-name "VC rename file: " nil 3559 (interactive (list (read-file-name "VC rename file: " nil
3546 (when (vc-backend buffer-file-name) 3560 (when (vc-backend buffer-file-name)
3547 buffer-file-name) t) 3561 buffer-file-name) t)