# HG changeset patch # User Eric S. Raymond # Date 1210034251 0 # Node ID 276c5ce5644933ef1cdd0810f3e8d716ec504025 # Parent 6a4a5b1ca5a174f4ce5fe5d945a4b34e118ca50c Move the fileset staleness check from vc-next-action to vc-dispatcher-selection-set. diff -r 6a4a5b1ca5a1 -r 276c5ce56449 lisp/vc-dispatcher.el --- a/lisp/vc-dispatcher.el Mon May 05 22:50:58 2008 +0000 +++ b/lisp/vc-dispatcher.el Tue May 06 00:37:31 2008 +0000 @@ -1602,6 +1602,16 @@ (put 'vc-dir-mode 'mode-class 'special) +(defun vc-buffer-sync (&optional not-urgent) + "Make sure the current buffer and its working file are in sync. +NOT-URGENT means it is ok to continue if the user says not to save." + (when (buffer-modified-p) + (if (or vc-suppress-confirm + (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name)))) + (save-buffer) + (unless not-urgent + (error "Aborted"))))) + (defun vc-dispatcher-browsing () "Are we in a directory browser buffer?" (or vc-dired-mode (eq major-mode 'vc-dir-mode))) @@ -1623,6 +1633,7 @@ return the list of VC files in those directories instead of the directories themselves. Otherwise, throw an error." + (let ((files (cond ;; Browsing with dired (vc-dired-mode @@ -1668,7 +1679,33 @@ ((and allow-ineligible (not (eligible buffer-file-name))) (list buffer-file-name)) ;; No good set here, throw error - (t (error "No fileset is available here.")))) + (t (error "No fileset is available here."))))) + ;; We assume, in order to avoid unpleasant surprises to the user, + ;; that a fileset is not in good shape to be handed to the user if the + ;; buffers visting the fileset don't match the on-disk contents. + (dolist (file files) + (let ((visited (get-file-buffer file))) + (when visited + (if (or vc-dired-mode (eq major-mode 'vc-dir-mode)) + (switch-to-buffer-other-window visited) + (set-buffer visited)) + ;; Check relation of buffer and file, and make sure + ;; user knows what he's doing. First, finding the file + ;; will check whether the file on disk is newer. + ;; Ignore buffer-read-only during this test, and + ;; preserve find-file-literally. + (let ((buffer-read-only (not (file-writable-p file)))) + (find-file-noselect file nil find-file-literally)) + (if (not (verify-visited-file-modtime (current-buffer))) + (if (yes-or-no-p (format "Replace %s on disk with buffer contents? " file)) + (write-file buffer-file-name) + (error "Aborted")) + ;; Now, check if we have unsaved changes. + (vc-buffer-sync t) + (when (buffer-modified-p) + (or (y-or-n-p (message "Use %s on disk, keeping modified buffer? " file)) + (error "Aborted"))))))) + files)) ;; arch-tag: 7d08b17f-5470-4799-914b-bfb9fcf6a246 ;;; vc-dispatcher.el ends here diff -r 6a4a5b1ca5a1 -r 276c5ce56449 lisp/vc.el --- a/lisp/vc.el Mon May 05 22:50:58 2008 +0000 +++ b/lisp/vc.el Tue May 06 00:37:31 2008 +0000 @@ -1046,19 +1046,7 @@ (defun vc-deduce-fileset (&optional allow-directory-wildcard allow-unregistered include-files-not-directories) "Deduce a set of files and a backend to which to apply an operation. - -Return (BACKEND . FILESET). -If we're in VC-dired mode, the fileset is the list of marked files. -Otherwise, if we're looking at a buffer visiting a version-controlled file, -the fileset is a singleton containing this file. -If neither of these things is true, but ALLOW-DIRECTORY-WILDCARD is on -and we're in a dired buffer, select the current directory. -If none of these conditions is met, but ALLOW_UNREGISTERED is on and the -visited file is not registered, return a singleton fileset containing it. -If INCLUDE-FILES-NOT-DIRECTORIES then if directories are marked, -return the list of files VC files in those directories instead of -the directories themselves. -Otherwise, throw an error." +Return (BACKEND . FILESET)." (let* ((fileset (vc-dispatcher-selection-set #'vc-registered allow-directory-wildcard @@ -1101,16 +1089,6 @@ (or (eq (vc-checkout-model backend (list file)) 'implicit) (memq (vc-state file) '(edited needs-merge conflict)))))) -(defun vc-buffer-sync (&optional not-urgent) - "Make sure the current buffer and its working file are in sync. -NOT-URGENT means it is ok to continue if the user says not to save." - (when (buffer-modified-p) - (if (or vc-suppress-confirm - (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name)))) - (save-buffer) - (unless not-urgent - (error "Aborted"))))) - (defun vc-compatible-state (p q) "Controls which states can be in the same commit." (or @@ -1169,29 +1147,6 @@ file (vc-state file) (car files) state)) (unless (eq (vc-checkout-model backend (list file)) model) (error "Fileset has mixed checkout models")))) - ;; Check for buffers in the fileset not matching the on-disk contents. - (dolist (file files) - (let ((visited (get-file-buffer file))) - (when visited - (if (or vc-dired-mode (eq major-mode 'vc-dir-mode)) - (switch-to-buffer-other-window visited) - (set-buffer visited)) - ;; Check relation of buffer and file, and make sure - ;; user knows what he's doing. First, finding the file - ;; will check whether the file on disk is newer. - ;; Ignore buffer-read-only during this test, and - ;; preserve find-file-literally. - (let ((buffer-read-only (not (file-writable-p file)))) - (find-file-noselect file nil find-file-literally)) - (if (not (verify-visited-file-modtime (current-buffer))) - (if (yes-or-no-p (format "Replace %s on disk with buffer contents? " file)) - (write-file buffer-file-name) - (error "Aborted")) - ;; Now, check if we have unsaved changes. - (vc-buffer-sync t) - (when (buffer-modified-p) - (or (y-or-n-p (message "Use %s on disk, keeping modified buffer? " file)) - (error "Aborted"))))))) ;; Do the right thing (cond ((eq state 'missing)