(eval-when-compile (require 'cl-lib))
(autoload 'vc-find-revision "vc")
+(defvar vc-find-revision-no-save)
(defvar add-log-buffer-file-name-function)
(revision (and other diff-vc-backend
(nth (if reverse 1 0) diff-vc-revisions)))
(buf (if revision
- (vc-find-revision file revision diff-vc-backend)
+ (let ((vc-find-revision-no-save t))
+ (vc-find-revision file revision diff-vc-backend))
(find-file-noselect file))))
;; Update the user preference if he so wished.
(when (> (prefix-numeric-value other-file) 8)
(string :tag "Comment End")))
:group 'vc)
+(defcustom vc-find-revision-no-save nil
+ "If non-nil, `vc-find-revision' doesn't write the created buffer to file."
+ :type 'boolean
+ :group 'vc
+ :version "27.1")
+
\f
;; File property caching
(defun vc-find-revision (file revision &optional backend)
"Read REVISION of FILE into a buffer and return the buffer.
Use BACKEND as the VC backend if specified."
+ (if vc-find-revision-no-save
+ (vc-find-revision-no-save file revision backend)
+ (vc-find-revision-save file revision backend)))
+
+(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)))
(set (make-local-variable 'vc-parent-buffer) filebuf))
result-buf)))
+(defun vc-find-revision-no-save (file revision &optional backend)
+ "Read REVISION of FILE into a buffer and return the buffer.
+Unlike `vc-find-revision-save', doesn't save the created buffer to file."
+ (let ((filebuf (or (get-file-buffer file) (current-buffer)))
+ (filename (vc-version-backup-file-name file revision 'manual)))
+ (unless (or (get-file-buffer filename)
+ (file-exists-p filename))
+ (with-current-buffer filebuf
+ (let ((failed t))
+ (unwind-protect
+ (let ((coding-system-for-read 'no-conversion)
+ (coding-system-for-write 'no-conversion))
+ (with-current-buffer (create-file-buffer filename)
+ (setq buffer-file-name filename)
+ (let ((outbuf (current-buffer)))
+ (with-current-buffer filebuf
+ (if backend
+ (vc-call-backend backend 'find-revision file revision outbuf)
+ (vc-call find-revision file revision outbuf))))
+ (goto-char (point-min))
+ (normal-mode)
+ (set-buffer-modified-p nil)
+ (setq buffer-read-only t))
+ (setq failed nil))
+ (when (and failed (get-file-buffer filename))
+ (kill-buffer (get-file-buffer filename)))))))
+ (let ((result-buf (or (get-file-buffer filename)
+ (find-file-noselect filename))))
+ (with-current-buffer result-buf
+ (set (make-local-variable 'vc-parent-buffer) filebuf))
+ result-buf)))
+
;; Header-insertion code
;;;###autoload