branch: elpa/magit
commit f55bfaf7926d81f0118c2e2760ab87ba0aeee937
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>

    Set new magit-blob-oid in blob buffers and only refresh if necessary
---
 lisp/magit-files.el | 24 ++++++++++++++----------
 lisp/magit-git.el   |  5 +++++
 lisp/magit-mode.el  |  2 ++
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/lisp/magit-files.el b/lisp/magit-files.el
index b5c0f9ef1b9..b1ead4547e4 100644
--- a/lisp/magit-files.el
+++ b/lisp/magit-files.el
@@ -130,16 +130,20 @@ REV is a revision or one of \"{worktree}\" or 
\"{index}\"."
            (format "%s.~%s~" file (subst-char-in-string ?/ ?_ rev))))
 
 (defun magit--revert-blob-buffer (_ignore-auto _noconfirm)
-  (magit--refresh-blob-buffer))
-
-(defun magit--refresh-blob-buffer ()
-  (setq magit-buffer-revision-oid
-        (magit-commit-oid magit-buffer-revision))
-  (let ((inhibit-read-only t))
-    (erase-buffer)
-    (save-excursion
-      (magit--insert-blob-contents magit-buffer-revision
-                                   (magit-file-relative-name))))
+  (magit--refresh-blob-buffer t))
+
+(defun magit--refresh-blob-buffer (&optional force)
+  (let ((old-blob-oid magit-buffer-blob-oid))
+    (setq magit-buffer-revision-oid
+          (magit-commit-oid magit-buffer-revision))
+    (setq magit-buffer-blob-oid
+          (magit-blob-oid magit-buffer-revision magit-buffer-file-name))
+    (when (or force (not (equal old-blob-oid magit-buffer-blob-oid)))
+      (let ((inhibit-read-only t))
+        (erase-buffer)
+        (save-excursion
+          (magit--insert-blob-contents magit-buffer-revision
+                                       (magit-file-relative-name))))))
   (magit--blob-normal-mode))
 
 (defun magit--blob-normal-mode ()
diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index b41d07b4c6a..d3dbca06244 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -1331,6 +1331,11 @@ Sorted from longest to shortest CYGWIN name."
 
 ;;; Blobs
 
+(defun magit-blob-oid (rev file)
+  (if (equal rev "{index}")
+      (cadr (car (magit--file-index-stages file)))
+    (magit-git-string "ls-tree" "--object-only" rev "--" file)))
+
 (defun magit--file-index-stages (file)
   (mapcar (##split-string % " ")
           (magit-git-lines "ls-files" "--stage" "--" file)))
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index 74fe0d563dd..1e72d938e7f 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -581,11 +581,13 @@ Magit is documented in info node `(magit)'."
 (defvaralias 'magit-buffer-refname 'magit-buffer-revision)
 (defvar-local magit-buffer-revision nil)
 (defvar-local magit-buffer-revision-oid nil)
+(defvar-local magit-buffer-blob-oid nil)
 (defvar-local magit-buffer-file-name nil)
 
 ;; Preserve when major-mode is changed in file-visiting buffers.
 (put 'magit-buffer-revision 'permanent-local t)
 (put 'magit-buffer-revision-oid 'permanent-local t)
+(put 'magit-buffer-blob-oid 'permanent-local t)
 (put 'magit-buffer-file-name 'permanent-local t)
 
 (eval-and-compile

Reply via email to