Commit f561c6a1 authored by Juri Linkov's avatar Juri Linkov

New option vc-find-revision-no-save to not write revision to file

* lisp/vc/vc.el (vc-find-revision-no-save): New defcustom (bug#33319).
(vc-find-revision): Depending on vc-find-revision-no-save,
call either vc-find-revision-no-save or vc-find-revision-save.
(vc-find-revision-save): Rename from vc-find-revision.
(vc-find-revision-no-save): New function.

* lisp/vc/diff-mode.el (diff-find-source-location):
Let-bind vc-find-revision-no-save to t.
parent 2ccfb4b5
Pipeline #63 failed with stage
......@@ -344,6 +344,9 @@ still be used if it exists.) Set the variable to nil to get the
previous behavior of always creating a buffer that visits a ChangeLog
file.
*** New customizable variable 'vc-find-revision-no-save'.
With non-nil, 'vc-find-revision' doesn't write the created buffer to file.
*** New customizable variable 'vc-git-grep-template'.
This new variable allows customizing the default arguments passed to
git-grep when 'vc-git-grep' is used.
......
......@@ -56,6 +56,7 @@
(eval-when-compile (require 'cl-lib))
(autoload 'vc-find-revision "vc")
(defvar vc-find-revision-no-save)
(defvar add-log-buffer-file-name-function)
......@@ -1743,7 +1744,8 @@ NOPROMPT, if non-nil, means not to prompt the user."
(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)
......
......@@ -871,6 +871,12 @@ is sensitive to blank lines."
(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")
;; File property caching
......@@ -1953,6 +1959,13 @@ If `F.~REV~' already exists, use it instead of checking it out again."
(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)))
......@@ -1985,6 +1998,38 @@ Use BACKEND as the VC backend if specified."
(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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment