]> git.eshelyaron.com Git - emacs.git/commitdiff
New option vc-find-revision-no-save to not write revision to file
authorJuri Linkov <juri@linkov.net>
Wed, 14 Nov 2018 00:23:04 +0000 (02:23 +0200)
committerJuri Linkov <juri@linkov.net>
Wed, 14 Nov 2018 00:23:04 +0000 (02:23 +0200)
* 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.

etc/NEWS
lisp/vc/diff-mode.el
lisp/vc/vc.el

index 2a2010e9d36c5a2d527f8763c7358821cd17aa8d..44f54894cdb55a4531087ed1887682a5035580b5 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -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.
index 8539423eed5024f0819fd1f3f1a575cf32caf05c..b86c17fe366aa9c4d427a284394f84d13a2e7b07 100644 (file)
@@ -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)
index 6b7ca02440d8b660baf38ae30462b049d12b866f..de43544864f609d1a983a87830a8fde9d18db99d 100644 (file)
@@ -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")
+
 \f
 ;; 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