Function: vc-revert

vc-revert is an autoloaded, interactive and byte-compiled function defined in vc.el.gz.

Signature

(vc-revert)

Documentation

Revert working copies of the selected fileset to their repository contents.

This asks for confirmation if the buffer contents are not identical to the working revision (except for keyword expansion).

View in manual

Probably introduced at or before Emacs version 24.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/vc/vc.el.gz
;;;###autoload
(defun vc-revert ()
  "Revert working copies of the selected fileset to their repository contents.
This asks for confirmation if the buffer contents are not identical
to the working revision (except for keyword expansion)."
  (interactive)
  (let* ((vc-fileset (vc-deduce-fileset))
	 (files (cadr vc-fileset))
	 (queried nil)
	 diff-buffer)
    ;; If any of the files is visited by the current buffer, make sure
    ;; buffer is saved.  If the user says `no', abort since we cannot
    ;; show the changes and ask for confirmation to discard them.
    (when (or (not files) (memq (buffer-file-name) files))
      (vc-buffer-sync nil))
    (dolist (file files)
      (let ((buf (get-file-buffer file)))
	(when (and buf (buffer-modified-p buf))
	  (error "Please kill or save all modified buffers before reverting")))
      (when (vc-up-to-date-p file)
	(if (yes-or-no-p (format "%s seems up-to-date.  Revert anyway? " file))
	    (setq queried t)
	  (error "Revert canceled"))))
    (unwind-protect
	(when (if vc-revert-show-diff
		  (progn
		    (setq diff-buffer (generate-new-buffer "*vc-diff*"))
		    (vc-diff-internal vc-allow-async-revert vc-fileset
				      nil nil nil diff-buffer))
		;; Avoid querying the user again.
		(null queried))
	  (unless (yes-or-no-p
		   (format "Discard changes in %s? "
			   (let ((str (vc-delistify files))
				 (nfiles (length files)))
			     (if (< (length str) 50)
				 str
			       (format "%d file%s" nfiles
				       (if (= nfiles 1) "" "s"))))))
	    (error "Revert canceled")))
      (when diff-buffer
	(quit-windows-on diff-buffer (eq vc-revert-show-diff 'kill))))
    (dolist (file files)
      (message "Reverting %s..." (vc-delistify files))
      (vc-revert-file file)
      (message "Reverting %s...done" (vc-delistify files)))))