emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/git-commit 2dfeaa6839 10/10: magit-commit-diff-1: Use diff


From: ELPA Syncer
Subject: [nongnu] elpa/git-commit 2dfeaa6839 10/10: magit-commit-diff-1: Use different heuristics
Date: Tue, 7 Jun 2022 10:58:26 -0400 (EDT)

branch: elpa/git-commit
commit 2dfeaa6839c643a54d96c9f855bae11d5cba2453
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    magit-commit-diff-1: Use different heuristics
    
    Most importantly, do not show an alternative diff unless we are
    confident that doing so is useful, or at least not highly confusing.
    No longer derive the alternative diff from the arguments used for the
    initial diff.  Ignore the last rebase command, because very often that
    has nothing to do with the commit that is being created.
    
    Closes #3246.
---
 lisp/magit-commit.el | 70 ++++++++++++++++++++++++++++++----------------------
 1 file changed, 41 insertions(+), 29 deletions(-)

diff --git a/lisp/magit-commit.el b/lisp/magit-commit.el
index 1617f95d19..79c9304490 100644
--- a/lisp/magit-commit.el
+++ b/lisp/magit-commit.el
@@ -546,7 +546,10 @@ See `magit-commit-absorb' for an alternative 
implementation."
 ;;; Pending Diff
 
 (defun magit-commit-diff ()
-  (magit-repository-local-set 'this-commit-command last-command)
+  (magit-repository-local-set 'this-commit-command
+                              (if (eq this-command 'with-editor-finish)
+                                  'magit-commit--rebase
+                                last-command))
   (when (and git-commit-mode magit-commit-show-diff)
     (when-let ((diff-buffer (magit-get-mode-buffer 'magit-diff-mode)))
       ;; This window just started displaying the commit message
@@ -562,35 +565,44 @@ See `magit-commit-absorb' for an alternative 
implementation."
 (defun magit-commit-diff-1 ()
   (let ((rev nil)
         (arg "--cached")
-        (msg nil))
-    (pcase (magit-repository-local-get 'this-commit-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)
+        (command (magit-repository-local-get 'this-commit-command))
+        (staged (magit-anything-staged-p))
+        (unstaged (magit-anything-unstaged-p))
+        (squash (let ((f (magit-git-dir "rebase-merge/rewritten-pending")))
+                  (and (file-exists-p f) (length (magit-file-lines f)))))
+        (noalt nil))
+    (pcase (list staged unstaged command)
+      ((and `(,_ ,_ magit-commit--rebase)
+            (guard (integerp squash)))
+       (setq rev (format "HEAD~%s" squash)))
+      (`(,_ ,_ magit-commit-amend)
        (setq rev "HEAD^"))
-      ((guard (not (magit-anything-staged-p)))
-       (setq rev "HEAD^")))
-    (if msg
-        (message (if (eq msg t) "No alternative diff" msg))
+      ((or `(,_ ,_ magit-commit-reword)
+           `(nil nil ,_))
+       (setq rev "HEAD^..HEAD")
+       (setq arg nil))
+      (`(,_ t magit-commit--all)
+       (setq rev "HEAD")
+       (setq arg nil))
+      (`(nil t handle-switch-frame)
+       ;; Either --all or --allow-empty. Assume it is the former.
+       (setq rev "HEAD")
+       (setq arg nil)))
+    (cond
+     ((not
+       (and (eq this-command 'magit-diff-while-committing)
+            (and-let* ((buf (magit-get-mode-buffer
+                             'magit-diff-mode nil 'selected)))
+              (and (equal rev (buffer-local-value 'magit-buffer-range buf))
+                   (equal arg (buffer-local-value 'magit-buffer-typearg 
buf)))))))
+     ((eq command 'magit-commit-amend)
+      (setq rev nil))
+     ((or squash (file-exists-p (magit-git-dir "rebase-merge/amend")))
+      (setq rev "HEAD^"))
+     (t
+      (message "No alternative diff while committing")
+      (setq noalt t)))
+    (unless noalt
       (let ((magit-inhibit-save-previous-winconf 'unset)
             (magit-display-buffer-noselect t)
             (display-buffer-overriding-action



reply via email to

[Prev in Thread] Current Thread [Next in Thread]