[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/git-commit e94b6ebfdb 6/7: Record diff-type in magit-diff-
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/git-commit e94b6ebfdb 6/7: Record diff-type in magit-diff-mode buffers |
Date: |
Fri, 17 Mar 2023 19:59:48 -0400 (EDT) |
branch: elpa/git-commit
commit e94b6ebfdbe4fe6253e69cc9783e8e2aa1af2700
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
Record diff-type in magit-diff-mode buffers
Closes #4900.
---
lisp/magit-commit.el | 5 ++++-
lisp/magit-diff.el | 34 ++++++++++++++++++++++------------
lisp/magit-git.el | 1 +
lisp/magit-mode.el | 1 +
4 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/lisp/magit-commit.el b/lisp/magit-commit.el
index 5dc514ece8..d22c39eb23 100644
--- a/lisp/magit-commit.el
+++ b/lisp/magit-commit.el
@@ -625,7 +625,10 @@ 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))))
- (magit-diff-setup-buffer rev arg (car (magit-diff-arguments)) nil)))))
+ (magit-diff-setup-buffer rev arg (car (magit-diff-arguments)) nil
+ (cond ((equal rev "HEAD") 'staged)
+ ((equal rev "HEAD^..HEAD") 'committed)
+ ('undefined)))))))
(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 dc4c17ec73..65afdaa7a3 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -1222,7 +1222,7 @@ revisions (i.e., use a \"...\" range)."
(interactive (cons (magit-diff-read-range-or-commit "Diff for range"
nil current-prefix-arg)
(magit-diff-arguments)))
- (magit-diff-setup-buffer rev-or-range nil args files))
+ (magit-diff-setup-buffer rev-or-range nil args files 'committed))
;;;###autoload
(defun magit-diff-working-tree (&optional rev args files)
@@ -1233,7 +1233,7 @@ a commit read from the minibuffer."
(cons (and current-prefix-arg
(magit-read-branch-or-commit "Diff working tree and commit"))
(magit-diff-arguments)))
- (magit-diff-setup-buffer (or rev "HEAD") nil args files))
+ (magit-diff-setup-buffer (or rev "HEAD") nil args files 'unstaged))
;;;###autoload
(defun magit-diff-staged (&optional rev args files)
@@ -1244,13 +1244,13 @@ a commit read from the minibuffer."
(cons (and current-prefix-arg
(magit-read-branch-or-commit "Diff index and commit"))
(magit-diff-arguments)))
- (magit-diff-setup-buffer rev "--cached" args files))
+ (magit-diff-setup-buffer rev "--cached" args files 'staged))
;;;###autoload
(defun magit-diff-unstaged (&optional args files)
"Show changes between the working tree and the index."
(interactive (magit-diff-arguments))
- (magit-diff-setup-buffer nil nil args files))
+ (magit-diff-setup-buffer nil nil args files 'unstaged))
;;;###autoload
(defun magit-diff-unmerged (&optional args files)
@@ -1258,7 +1258,7 @@ a commit read from the minibuffer."
(interactive (magit-diff-arguments))
(unless (magit-merge-in-progress-p)
(user-error "No merge is in progress"))
- (magit-diff-setup-buffer (magit--merge-range) nil args files))
+ (magit-diff-setup-buffer (magit--merge-range) nil args files 'committed))
;;;###autoload
(defun magit-diff-while-committing ()
@@ -1296,6 +1296,7 @@ the file or blob."
nil
(car (magit-diff-arguments))
(list file)
+ 'unstaged
magit-diff-buffer-file-locked)
(magit-diff--goto-position file line col))))
(user-error "Buffer isn't visiting a file")))
@@ -1305,11 +1306,12 @@ the file or blob."
"Show changes between any two files on disk."
(interactive (list (read-file-name "First file: " nil nil t)
(read-file-name "Second file: " nil nil t)))
- (magit-diff-setup-buffer nil "--no-index"
- nil (list (magit-convert-filename-for-git
- (expand-file-name a))
- (magit-convert-filename-for-git
- (expand-file-name b)))))
+ (magit-diff-setup-buffer nil "--no-index" nil
+ (list (magit-convert-filename-for-git
+ (expand-file-name a))
+ (magit-convert-filename-for-git
+ (expand-file-name b)))
+ 'undefined))
(defun magit-show-commit--arguments ()
(pcase-let ((`(,args ,diff-files)
@@ -1935,11 +1937,13 @@ Staging and applying changes is documented in info node
(put 'magit-diff-mode 'magit-diff-default-arguments
'("--stat" "--no-ext-diff"))
-(defun magit-diff-setup-buffer (range typearg args files &optional locked)
+(defun magit-diff-setup-buffer ( range typearg args files
+ &optional type locked)
(require 'magit)
(magit-setup-buffer #'magit-diff-mode locked
(magit-buffer-range range)
(magit-buffer-typearg typearg)
+ (magit-buffer-diff-type type)
(magit-buffer-diff-args args)
(magit-buffer-diff-files files)
(magit-buffer-diff-files-suspended nil)))
@@ -2521,6 +2525,7 @@ Staging and applying changes is documented in info node
(magit-setup-buffer #'magit-revision-mode nil
(magit-buffer-revision rev)
(magit-buffer-range (format "%s^..%s" rev rev))
+ (magit-buffer-diff-type 'committed)
(magit-buffer-diff-args args)
(magit-buffer-diff-files files)
(magit-buffer-diff-files-suspended nil)))
@@ -2980,6 +2985,8 @@ It the SECTION has a different type, then do nothing."
;;; Diff Type
+(defvar magit--diff-use-recorded-type-p t)
+
(defun magit-diff-type (&optional section)
"Return the diff type of SECTION.
@@ -3008,8 +3015,11 @@ Do not confuse this with `magit-diff-scope' (which see)."
((derived-mode-p 'magit-diff-mode)
(let ((range magit-buffer-range)
(const magit-buffer-typearg))
- (cond ((equal const "--no-index") 'undefined)
+ (cond ((and magit--diff-use-recorded-type-p
+ magit-buffer-diff-type))
+ ((equal const "--no-index") 'undefined)
((or (not range)
+ (equal range "HEAD")
(magit-rev-eq range "HEAD"))
(if (equal const "--cached")
'staged
diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index 2ef8602635..522a57051c 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -43,6 +43,7 @@
(declare-function magit-refresh "magit-mode" ())
(defvar magit-buffer-gitdir)
(defvar magit-buffer-topdir)
+(defvar magit-buffer-diff-type)
(defvar magit-buffer-diff-args)
(defvar magit-buffer-file-name)
(defvar magit-buffer-log-args)
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index 28293c4b5f..98daf538cf 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -529,6 +529,7 @@ Magit is documented in info node `(magit)'."
(defvar-local magit-buffer-gitdir nil)
(defvar-local magit-buffer-topdir nil)
(defvar-local magit-buffer-arguments nil)
+(defvar-local magit-buffer-diff-type nil)
(defvar-local magit-buffer-diff-args nil)
(defvar-local magit-buffer-diff-files nil)
(defvar-local magit-buffer-diff-files-suspended nil)
- [nongnu] elpa/git-commit updated (eb66aed3b4 -> 564a5ceeb0), ELPA Syncer, 2023/03/17
- [nongnu] elpa/git-commit e23846ec2d 1/7: magit-save-repository-buffers: Cosmetics, ELPA Syncer, 2023/03/17
- [nongnu] elpa/git-commit 8606488578 2/7: magit-save-repository-buffers: Rev-parse only once per directory, ELPA Syncer, 2023/03/17
- [nongnu] elpa/git-commit e94b6ebfdb 6/7: Record diff-type in magit-diff-mode buffers,
ELPA Syncer <=
- [nongnu] elpa/git-commit 564a5ceeb0 7/7: magit-git-debug: Fix key binding in docstring, ELPA Syncer, 2023/03/17
- [nongnu] elpa/git-commit c5c8f79167 4/7: magit-toplevel: Cosmetics, ELPA Syncer, 2023/03/17
- [nongnu] elpa/git-commit ff4710afa6 3/7: Deprecate magit-git-dir to avoid needlessly repeating work, ELPA Syncer, 2023/03/17
- [nongnu] elpa/git-commit 623d335b4d 5/7: Memorize gitdir and topdir for each Magit buffer, ELPA Syncer, 2023/03/17