Function: vc-find-revision-no-save

vc-find-revision-no-save is an autoloaded and byte-compiled function defined in vc.el.gz.

Signature

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

Documentation

Read REVISION of FILE into BUFFER and return the buffer.

If BUFFER omitted or nil, this function creates a new buffer and sets buffer-file-name(var)/buffer-file-name(fun) to the name constructed from the file name and the revision number. Unlike vc-find-revision-save, doesn't save the buffer to the file.

Probably introduced at or before Emacs version 27.1.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/vc.el.gz
(defun vc-find-revision-no-save (file revision &optional backend buffer)
  "Read REVISION of FILE into BUFFER and return the buffer.
If BUFFER omitted or nil, this function creates a new buffer and sets
`buffer-file-name' to the name constructed from the file name and the
revision number.
Unlike `vc-find-revision-save', doesn't save the buffer to the file."
  (let* ((buffer (and (buffer-live-p buffer) buffer))
         (filebuf (or buffer (get-file-buffer file) (current-buffer)))
         (filename (and (not buffer)
                        (vc-version-backup-file-name file revision 'manual)))
         (backend (or backend (vc-backend file))))
    (unless (and (not buffer)
                 (or (get-file-buffer filename)
                     (file-exists-p filename)))
      (with-current-buffer filebuf
	(let ((failed t))
	  (unwind-protect
	      (with-current-buffer (or buffer (create-file-buffer filename))
                (unless buffer (setq buffer-file-name filename))
		(let ((outbuf (current-buffer)))
		  (with-current-buffer filebuf
		    (vc-call-backend backend 'find-revision file revision outbuf)))
                (decode-coding-inserted-region (point-min) (point-max) file)
                (after-insert-file-set-coding (- (point-max) (point-min)))
                (goto-char (point-min))
                (if buffer
                    ;; For non-interactive, skip any questions
                    (let ((enable-local-variables
                           (if (memq enable-local-variables '(:safe :all nil))
                               enable-local-variables
                             ;; Ignore other values that query,
                             ;; use `:safe' to find `mode:'.
                             :safe))
                          (buffer-file-name file))
                      ;; Don't run hooks that might assume buffer-file-name
                      ;; really associates buffer with a file (bug#39190).
                      (ignore-errors (delay-mode-hooks (set-auto-mode))))
                  ;; Use non-nil 'find-file' arg of 'normal-mode'
                  ;; to not ignore 'enable-local-variables' when nil.
                  (normal-mode (not enable-local-variables)))
                (set-buffer-modified-p nil)
                (read-only-mode 1)
                (setq failed nil))
	    (when (and failed (unless buffer (get-file-buffer filename)))
	      (with-current-buffer (get-file-buffer filename)
		(set-buffer-modified-p nil))
	      (kill-buffer (get-file-buffer filename)))))))
    (let ((result-buf (or buffer
                          (get-file-buffer filename)
                          (find-file-noselect filename)))
          (file (expand-file-name file))) ; ensure it's absolute
      (with-current-buffer result-buf
        (setq-local vc-parent-buffer filebuf
                    vc-buffer-overriding-fileset `(,backend (,file))
                    vc-buffer-revision revision))
      result-buf)))