[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/git-commit 41b08daabf 08/10: magit-commit-diff-1: Determin
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/git-commit 41b08daabf 08/10: magit-commit-diff-1: Determine arguments only here |
Date: |
Tue, 7 Jun 2022 10:58:26 -0400 (EDT) |
branch: elpa/git-commit
commit 41b08daabf40c7e14eddcca78f7efc5c691e5200
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
magit-commit-diff-1: Determine arguments only here
The logic is the same as before but instead of determining the
appropriate diff command and calling that, we determine the
appropriate diff arguments and then call `magit-diff-setup-buffer'
directly instead of the respective command.
---
lisp/magit-commit.el | 46 ++++++++++++++++++++++++++++++++--------------
lisp/magit-diff.el | 25 ++++---------------------
2 files changed, 36 insertions(+), 35 deletions(-)
diff --git a/lisp/magit-commit.el b/lisp/magit-commit.el
index 89679edf95..2bb0a166bd 100644
--- a/lisp/magit-commit.el
+++ b/lisp/magit-commit.el
@@ -559,8 +559,37 @@ See `magit-commit-absorb' for an alternative
implementation."
(quit)))))
(defun magit-commit-diff-1 ()
- (let ((args (car (magit-diff-arguments))))
- (progn
+ (let ((rev nil)
+ (arg "--cached")
+ (msg nil))
+ (pcase last-command
+ ((guard (eq this-command 'magit-diff-while-committing))
+ (if-let ((diff-buf (magit-get-mode-buffer 'magit-diff-mode 'selected)))
+ (with-current-buffer diff-buf
+ (cond ((and (equal magit-buffer-range "HEAD^")
+ (equal magit-buffer-typearg "--cached"))
+ )
+ ((and (equal magit-buffer-range nil)
+ (equal magit-buffer-typearg "--cached"))
+ (setq rev "HEAD^"))
+ ((magit-anything-staged-p)
+ )
+ (t
+ (setq rev "HEAD^"))))
+ (unless (magit-anything-staged-p)
+ (setq rev "HEAD^"))))
+ (`magit-commit-commit
+ )
+ (`magit-commit--all
+ (setq arg nil))
+ ((or `magit-commit-amend
+ `magit-commit-reword
+ `magit-rebase-reword-commit)
+ (setq rev "HEAD^"))
+ ((guard (not (magit-anything-staged-p)))
+ (setq rev "HEAD^")))
+ (if msg
+ (message (if (eq msg t) "No alternative diff" msg))
(let ((magit-inhibit-save-previous-winconf 'unset)
(magit-display-buffer-noselect t)
(display-buffer-overriding-action
@@ -568,18 +597,7 @@ See `magit-commit-absorb' for an alternative
implementation."
(when magit-commit-diff-inhibit-same-window
(setq display-buffer-overriding-action
'(nil (inhibit-same-window t))))
- (cl-case last-command
- (magit-commit-create
- (magit-diff-staged nil args))
- (magit-commit--all
- (magit-diff-working-tree nil args))
- ((magit-commit-amend
- magit-commit-reword
- magit-rebase-reword-commit)
- (magit-diff-while-amending args))
- (t (if (magit-anything-staged-p)
- (magit-diff-staged nil args)
- (magit-diff-while-amending args))))))))
+ (magit-diff-setup-buffer rev arg (car (magit-diff-arguments)) nil)))))
(add-hook 'server-switch-hook #'magit-commit-diff)
(add-hook 'with-editor-filter-visit-hook #'magit-commit-diff)
diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index e1256091db..38872a5a94 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -41,6 +41,7 @@
(declare-function magit-find-file-noselect "magit-files" (rev file))
(declare-function magit-status-setup-buffer "magit-status" (&optional
directory))
;; For `magit-diff-while-committing'
+(declare-function magit-commit-diff-1 "magit-commit" ())
(declare-function magit-commit-message-buffer "magit-commit" ())
;; For `magit-insert-revision-gravatar'
(defvar gravatar-size)
@@ -1229,37 +1230,19 @@ a commit read from the minibuffer."
(magit-diff-setup-buffer (magit--merge-range) nil args files))
;;;###autoload
-(defun magit-diff-while-committing (&optional args)
+(defun magit-diff-while-committing ()
"While committing, show the changes that are about to be committed.
While amending, invoking the command again toggles between
showing just the new changes or all the changes that will
be committed."
- (interactive (list (car (magit-diff-arguments))))
+ (interactive)
(unless (magit-commit-message-buffer)
(user-error "No commit in progress"))
- (let ((magit-display-buffer-noselect t))
- (if-let ((diff-buf (magit-get-mode-buffer 'magit-diff-mode 'selected)))
- (with-current-buffer diff-buf
- (cond ((and (equal magit-buffer-range "HEAD^")
- (equal magit-buffer-typearg "--cached"))
- (magit-diff-staged nil args))
- ((and (equal magit-buffer-range nil)
- (equal magit-buffer-typearg "--cached"))
- (magit-diff-while-amending args))
- ((magit-anything-staged-p)
- (magit-diff-staged nil args))
- (t
- (magit-diff-while-amending args))))
- (if (magit-anything-staged-p)
- (magit-diff-staged nil args)
- (magit-diff-while-amending args)))))
+ (magit-commit-diff-1))
(define-key git-commit-mode-map
(kbd "C-c C-d") #'magit-diff-while-committing)
-(defun magit-diff-while-amending (&optional args)
- (magit-diff-setup-buffer "HEAD^" "--cached" args nil))
-
;;;###autoload
(defun magit-diff-buffer-file ()
"Show diff for the blob or file visited in the current buffer.
- [nongnu] elpa/git-commit updated (9b48dd7e36 -> 2dfeaa6839), ELPA Syncer, 2022/06/07
- [nongnu] elpa/git-commit e0abcbd22f 01/10: Change name of fake command used when adding --all argument, ELPA Syncer, 2022/06/07
- [nongnu] elpa/git-commit e400987d1f 05/10: Remove outdated commit-diff comment, ELPA Syncer, 2022/06/07
- [nongnu] elpa/git-commit 41b08daabf 08/10: magit-commit-diff-1: Determine arguments only here,
ELPA Syncer <=
- [nongnu] elpa/git-commit c0f4e43c58 02/10: magit-commit-diff: Fix name of a supported command, ELPA Syncer, 2022/06/07
- [nongnu] elpa/git-commit f34913f669 06/10: magit-diff-refresh-buffer: Use nicer title while committing --all, ELPA Syncer, 2022/06/07
- [nongnu] elpa/git-commit 3af07129bc 09/10: magit-commit-diff: Remember commit command, ELPA Syncer, 2022/06/07
- [nongnu] elpa/git-commit 2dfeaa6839 10/10: magit-commit-diff-1: Use different heuristics, ELPA Syncer, 2022/06/07
- [nongnu] elpa/git-commit 34365a2c5c 03/10: magit-commit-assert: Use --all instead of explicitly staging all, ELPA Syncer, 2022/06/07
- [nongnu] elpa/git-commit c9a738f7d3 04/10: magit-commit-diff-1: New function, ELPA Syncer, 2022/06/07
- [nongnu] elpa/git-commit 3ebc4e84db 07/10: magit-diff-refresh-buffer: Fix magit-set-header-line-format, ELPA Syncer, 2022/06/07