feat(magit): introduce +magit-auto-revert option

Provides more control over our auto-reverting feature, and changes its
behavior to only target non-remote buffers by default, because reverting
remote buffers could be tremendously slow.

This could be later improved to treat TRAMP buffers with local
methods (like sudo) as local buffers.

Fix: #8354
This commit is contained in:
Henrik Lissner
2025-04-10 18:02:10 -04:00
parent ae2cdd1c91
commit 0150f879ea
2 changed files with 34 additions and 1 deletions

View File

@ -98,6 +98,17 @@ window that already exists in that direction. It will split otherwise."
(defvar +magit--stale-p nil)
(defun +magit--revertable-buffer-p (buffer)
(when (buffer-live-p buffer)
(pcase +magit-auto-revert
(`t t)
(`local
(not (file-remote-p
(or (buffer-file-name buffer)
(buffer-local-value 'default-directory buffer)))))
((pred functionp)
(funcall +magit-auto-revert buffer)))))
(defun +magit--revert-buffer (buffer)
(with-current-buffer buffer
(kill-local-variable '+magit--stale-p)
@ -116,7 +127,7 @@ Stale buffers are reverted when they are switched to, assuming they haven't been
modified."
(let ((visible-buffers (doom-visible-buffers nil t)))
(dolist (buffer (buffer-list))
(when (buffer-live-p buffer)
(when (+magit--revertable-buffer-p buffer)
(if (memq buffer visible-buffers)
(progn
(+magit--revert-buffer buffer)

View File

@ -12,6 +12,28 @@ left and right fringe.
Only has an effect in GUI Emacs.")
(defvar +magit-auto-revert 'local
"If non-nil, revert associated buffers after Git operations with side-effects.
These buffers are auto-reverted immediately if they're visible or reverted next
time they're switched to. This is intended to be a much more efficient
replacement for `magit-auto-revert-mode' and `global-auto-revert-mode', and
should not be used together with them! Set this to `nil' if you plan to use the
above.
Accepts one of three values OR a predicate function:
t
Revert any associated buffers.
local
Same as `t', except remote (TRAMP) buffers are ignored.
nil
Don't do any auto-reverting at all.
FUNCTION
If given a function, it will be passed a buffer associated with the current
Magit session and must return non-nil to signal this is buffer is safe to
revert (now or later, when switched to).")
;;
;;; Packages