[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master f561c6a: New option vc-find-revision-no-save to not
From: |
Juri Linkov |
Subject: |
[Emacs-diffs] master f561c6a: New option vc-find-revision-no-save to not write revision to file |
Date: |
Tue, 13 Nov 2018 19:23:13 -0500 (EST) |
branch: master
commit f561c6a1124d4a1d79c264a9cb79ac0e7cb1650f
Author: Juri Linkov <address@hidden>
Commit: Juri Linkov <address@hidden>
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.
---
etc/NEWS | 3 +++
lisp/vc/diff-mode.el | 4 +++-
lisp/vc/vc.el | 45 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/etc/NEWS b/etc/NEWS
index 2a2010e..44f5489 100644
--- 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.
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 8539423..b86c17f 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -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)
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 6b7ca02..de43544 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master f561c6a: New option vc-find-revision-no-save to not write revision to file,
Juri Linkov <=