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

    Unconditionally revert blob buffers for now
    
    The next step will be to automatically revert when necessary and not
    revert when not necessary.  Deciding which it is should neither be the
    job of the user nor of the callers (which didn't do a good job, which
    is why this commit first resets the behavior to a reasonable baseline).
---
 lisp/magit-diff.el  |  2 +-
 lisp/magit-ediff.el |  8 ++---
 lisp/magit-files.el | 85 +++++++++++++++++++++--------------------------------
 3 files changed, 39 insertions(+), 56 deletions(-)

diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index cdfb4227a52..7c3c33fdf0b 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -40,7 +40,7 @@
 ;; For `magit-diff-popup'
 (declare-function magit-stash-show "magit-stash" (stash &optional args files))
 ;; For `magit-diff-visit-file'
-(declare-function magit-find-file-noselect "magit-files" (rev file &optional 
revert))
+(declare-function magit-find-file-noselect "magit-files" (rev file))
 (declare-function magit-status-setup-buffer "magit-status" (&optional 
directory))
 ;; For `magit-diff-wash-diff'
 (defvar magit-log-heading-re)
diff --git a/lisp/magit-ediff.el b/lisp/magit-ediff.el
index c5c4b587ff1..76a04dbb576 100644
--- a/lisp/magit-ediff.el
+++ b/lisp/magit-ediff.el
@@ -332,8 +332,8 @@ FILE has to be relative to the top directory of the 
repository."
            (bufC* (or bufC (find-file-noselect file)))
            (coding-system-for-read
             (buffer-local-value 'buffer-file-coding-system bufC*))
-           (bufA* (magit-find-file-noselect "HEAD" file t))
-           (bufB* (magit-find-file-index-noselect file t)))
+           (bufA* (magit-find-file-noselect "HEAD" file))
+           (bufB* (magit-find-file-index-noselect file)))
       (with-current-buffer bufB* (setq buffer-read-only nil))
       (magit-ediff-buffers
        (bufA bufA*)
@@ -505,7 +505,7 @@ FILE must be relative to the top directory of the 
repository."
   (magit-ediff-buffers ((magit-get-revision-buffer "HEAD" file)
                         (magit-find-file-noselect "HEAD" file))
                        ((get-buffer (concat file ".~{index}~"))
-                        (magit-find-file-index-noselect file t))))
+                        (magit-find-file-index-noselect file))))
 
 ;;;###autoload
 (defun magit-ediff-show-unstaged (file)
@@ -520,7 +520,7 @@ FILE must be relative to the top directory of the 
repository."
                                   (magit-unstaged-files)
                                   "No unstaged files")))
   (magit-ediff-buffers ((get-buffer (concat file ".~{index}~"))
-                        (magit-find-file-index-noselect file t))
+                        (magit-find-file-index-noselect file))
                        ((get-file-buffer file)
                         (find-file-noselect file))))
 
diff --git a/lisp/magit-files.el b/lisp/magit-files.el
index c11ff57ae24..a8ed4865750 100644
--- a/lisp/magit-files.el
+++ b/lisp/magit-files.el
@@ -110,11 +110,9 @@ the line and column corresponding to that location."
         (move-to-column col)))
     buf))
 
-(defun magit-find-file-noselect (rev file &optional revert)
+(defun magit-find-file-noselect (rev file)
   "Read FILE from REV into a buffer and return the buffer.
-REV is a revision or one of \"{worktree}\" or \"{index}\".  Non-nil
-REVERT means to revert the buffer.  If `ask-revert', then only after
-asking.  A non-nil value for REVERT is ignored if REV is \"{worktree}\"."
+REV is a revision or one of \"{worktree}\" or \"{index}\"."
   (when (and (equal rev "{index}")
              (length> (magit--file-index-stages file) t))
     (setq rev "{worktree}"))
@@ -136,17 +134,12 @@ asking.  A non-nil value for REVERT is ignored if REV is 
\"{worktree}\"."
      (with-current-buffer (magit-get-revision-buffer-create
                            rev
                            (file-relative-name file topdir))
-       (when (or (not magit-buffer-file-name)
-                 (if (eq revert 'ask-revert)
-                     (y-or-n-p (format "%s already exists; revert it? "
-                                       (buffer-name))))
-                 revert)
-         (setq magit-buffer-revision rev)
-         (setq magit-buffer-file-name file)
-         (setq default-directory (if (file-exists-p defdir) defdir topdir))
-         (setq-local revert-buffer-function #'magit--revert-blob-buffer)
-         (revert-buffer t t)
-         (run-hooks 'magit-find-blob-hook))
+       (setq magit-buffer-revision rev)
+       (setq magit-buffer-file-name file)
+       (setq default-directory (if (file-exists-p defdir) defdir topdir))
+       (setq-local revert-buffer-function #'magit--revert-blob-buffer)
+       (revert-buffer t t)
+       (run-hooks 'magit-find-blob-hook)
        (current-buffer)))
     ((error "%s isn't inside a Git repository" file))))
 
@@ -157,40 +150,30 @@ asking.  A non-nil value for REVERT is ignored if REV is 
\"{worktree}\"."
   (funcall (if create #'get-buffer-create #'get-buffer)
            (format "%s.~%s~" file (subst-char-in-string ?/ ?_ rev))))
 
-(defun magit--revert-blob-buffer (_ignore-auto noconfirm)
-  (when (or noconfirm
-            (and (not (buffer-modified-p))
-                 (catch 'found
-                   (dolist (regexp revert-without-query)
-                     (when (string-match regexp magit-buffer-file-name)
-                       (throw 'found t)))))
-            (yes-or-no-p (format "Revert buffer from Git %s? "
-                                 (if (equal magit-buffer-revision "{index}")
-                                     "index"
-                                   (concat "revision " 
magit-buffer-revision)))))
-    (let* ((inhibit-read-only t)
-           (file (magit-file-relative-name))
-           (coding-system-for-read (or coding-system-for-read 'undecided)))
-      (erase-buffer)
-      (save-excursion
-        (magit-git-insert "cat-file" "-p"
-                          (if (equal magit-buffer-revision "{index}")
-                              (concat ":" file)
-                            (concat magit-buffer-revision ":" file))))
-      (setq buffer-file-coding-system last-coding-system-used))
-    (let ((buffer-file-name magit-buffer-file-name)
-          (after-change-major-mode-hook
-           (seq-difference after-change-major-mode-hook
-                           '(global-diff-hl-mode-enable-in-buffer ; Emacs >= 30
-                             global-diff-hl-mode-enable-in-buffers ; Emacs < 30
-                             eglot--maybe-activate-editing-mode)
-                           #'eq)))
-      ;; We want `normal-mode' to respect nil `enable-local-variables'.
-      ;; The FIND-FILE argument wasn't designed for our use case, so we
-      ;; have to use this strange invocation to achieve that.
-      (normal-mode (not enable-local-variables)))
-    (setq buffer-read-only t)
-    (set-buffer-modified-p nil)))
+(defun magit--revert-blob-buffer (_ignore-auto _noconfirm)
+  (let ((inhibit-read-only t)
+        (file (magit-file-relative-name))
+        (coding-system-for-read (or coding-system-for-read 'undecided)))
+    (erase-buffer)
+    (save-excursion
+      (magit-git-insert "cat-file" "-p"
+                        (if (equal magit-buffer-revision "{index}")
+                            (concat ":" file)
+                          (concat magit-buffer-revision ":" file))))
+    (setq buffer-file-coding-system last-coding-system-used))
+  (let ((buffer-file-name magit-buffer-file-name)
+        (after-change-major-mode-hook
+         (seq-difference after-change-major-mode-hook
+                         '(global-diff-hl-mode-enable-in-buffer ; Emacs >= 30
+                           global-diff-hl-mode-enable-in-buffers ; Emacs < 30
+                           eglot--maybe-activate-editing-mode)
+                         #'eq)))
+    ;; We want `normal-mode' to respect nil `enable-local-variables'.
+    ;; The FIND-FILE argument wasn't designed for our use case, so we
+    ;; have to use this strange invocation to achieve that.
+    (normal-mode (not enable-local-variables)))
+  (setq buffer-read-only t)
+  (set-buffer-modified-p nil))
 
 (define-advice lsp (:around (fn &rest args) magit-find-file)
   "Do nothing when visiting blob using `magit-find-file' and similar.
@@ -200,9 +183,9 @@ See also https://github.com/doomemacs/doomemacs/pull/6309.";
 
 ;;; Find Index
 
-(defun magit-find-file-index-noselect (file &optional revert)
+(defun magit-find-file-index-noselect (file)
   "Read FILE from the index into a buffer and return the buffer."
-  (magit-find-file-noselect "{index}" file (or revert 'ask-revert)))
+  (magit-find-file-noselect "{index}" file))
 
 (defun magit-update-index ()
   "Update the index with the contents of the current buffer.

Reply via email to