Function: vc-find-revision-save

vc-find-revision-save is a byte-compiled function defined in vc.el.gz.

Signature

(vc-find-revision-save FILE REVISION &optional BACKEND)

Documentation

Read REVISION of FILE into a buffer and return the buffer.

Saves the buffer to the file.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/vc.el.gz
(defun vc-find-revision-save (file revision &optional backend)
  "Read REVISION of FILE into a buffer and return the buffer.
Saves the buffer to the file."
  (let ((automatic-backup (vc-version-backup-file-name file revision))
	(filebuf (or (get-file-buffer file) (current-buffer)))
        (filename (vc-version-backup-file-name file revision 'manual)))
    (unless (file-exists-p filename)
      (if (file-exists-p automatic-backup)
          (rename-file automatic-backup filename nil)
	(message "Checking out %s..." filename)
	(with-current-buffer filebuf
	  (let ((failed t))
	    (unwind-protect
		(let ((coding-system-for-read 'no-conversion))
		  (with-temp-file filename
		    (let ((outbuf (current-buffer)))
                      ;; We will read the backend's output with no
                      ;; conversions, so we should also save the
                      ;; temporary file with no encoding conversions.
                      (setq buffer-file-coding-system 'no-conversion)
		      ;; Change buffer to get local value of
		      ;; vc-checkout-switches.
		      (with-current-buffer filebuf
			(if backend
			    (vc-call-backend backend 'find-revision file revision outbuf)
			  (vc-call find-revision file revision outbuf)))))
		  (setq failed nil))
	      (when (and failed (file-exists-p filename))
		(delete-file filename))))
	  (vc-mode-line file))
	(message "Checking out %s...done" filename)))
    (let ((result-buf (find-file-noselect filename)))
      (with-current-buffer result-buf
	;; Set the parent buffer so that things like
	;; C-x v g, C-x v l, ... etc work.
        (setq-local vc-parent-buffer filebuf))
      result-buf)))