Commit de1126c5 authored by Jonas Bernoulli's avatar Jonas Bernoulli

magit-{stage,unstage}-hook: New hooks

Running these hooks inside `magit-refresh' has the benefit, that
the refresh cache is used, possibly making expensive calculations
unnecessary.  Using variables to control the commands for which
the hooks should be called has the benefit that it is easy to add
new commands (including third-party commands) without having to
complicate their implementations.

See #3496.
parent 15ffc8a4
......@@ -91,6 +91,28 @@ rejected reversals."
:group 'magit-commands
:type 'boolean)
(defcustom magit-post-stage-hook nil
"Hook run after staging changes.
This hook is run by `magit-refresh' if `this-command'
is a member of `magit-post-stage-hook-commands'."
:package-version '(magit . "2.90.0")
:group 'magit-commands
:type 'hook)
(defvar magit-post-stage-hook-commands
'(magit-stage magit-stage-file magit-stage-modified))
(defcustom magit-post-unstage-hook nil
"Hook run after unstaging changes.
This hook is run by `magit-refresh' if `this-command'
is a member of `magit-post-unstage-hook-commands'."
:package-version '(magit . "2.90.0")
:group 'magit-commands
:type 'hook)
(defvar magit-post-unstage-hook-commands
'(magit-unstage magit-unstage-file magit-unstage-all))
;;; Commands
;;;; Apply
......
......@@ -41,6 +41,9 @@
;; For `magit-xref-insert-buttons' from `magit'
(defvar magit-diff-show-xref-buttons)
(defvar magit-revision-show-xref-buttons)
;; For `magit-refresh'
(defvar magit-post-stage-hook-commands)
(defvar magit-post-unstage-hook-commands)
;; For `magit-refresh' and `magit-refresh-all'
(declare-function magit-auto-revert-buffers "magit-autorevert" ())
;; For `magit-refresh-buffer'
......@@ -1013,6 +1016,11 @@ Run hooks `magit-pre-refresh-hook' and `magit-post-refresh-hook'."
(with-current-buffer it
(magit-refresh-buffer)))
(magit-auto-revert-buffers)
(cond
((memq this-command magit-post-stage-hook-commands)
(magit-run-hook-with-benchmark 'magit-post-stage-hook))
((memq this-command magit-post-unstage-hook-commands)
(magit-run-hook-with-benchmark 'magit-post-unstage-hook)))
(magit-run-hook-with-benchmark 'magit-post-refresh-hook)
(when magit-refresh-verbose
(message "Refreshing magit...done (%.3fs, cached %s/%s)"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment