Function: magit-diff--dwim
magit-diff--dwim is a byte-compiled function defined in magit-diff.el.
Signature
(magit-diff--dwim)
Documentation
Return information for performing DWIM diff.
The information can be in three forms:
1. TYPE
A symbol describing a type of diff where no additional information
is needed to generate the diff. One of staged, unstaged,
unmerged, and undefined.
2. (TYPE . VALUE)
Like #1 but the diff requires additional information, which is
given by VALUE. Currently, this includes commit and stash,
where VALUE is the given commit or stash, respectively.
3. RANGE
A string indicating a diff range.
If no DWIM context is found, nil is returned.
Source Code
;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-diff.el
(defun magit-diff--dwim ()
"Return information for performing DWIM diff.
The information can be in three forms:
1. TYPE
A symbol describing a type of diff where no additional information
is needed to generate the diff. One of `staged', `unstaged',
`unmerged', and `undefined'.
2. (TYPE . VALUE)
Like #1 but the diff requires additional information, which is
given by VALUE. Currently, this includes `commit' and `stash',
where VALUE is the given commit or stash, respectively.
3. RANGE
A string indicating a diff range.
If no DWIM context is found, nil is returned."
(cond-let
([commits (magit-region-values '(commit branch) t)]
(deactivate-mark)
(concat (car (last commits)) ".." (car commits)))
((derived-mode-p 'magit-stash-mode)
(cons 'commit
(magit-section-case
(commit (oref it value))
(file (thread-first it
(oref parent)
(oref value)))
(hunk (thread-first it
(oref parent)
(oref parent)
(oref value))))))
(magit-buffer-revision
(cons 'commit magit-buffer-revision))
((derived-mode-p 'magit-diff-mode)
(pcase-exhaustive magit-buffer-diff-type
('committed magit-buffer-diff-range)
((or 'unstaged 'staged 'undefined) magit-buffer-diff-type)))
((magit-section-case
([* unstaged] 'unstaged)
([* staged] 'staged)
(unmerged 'unmerged)
(unpushed (magit-diff--range-to-endpoints (oref it value)))
(unpulled (magit-diff--range-to-endpoints (oref it value)))
(branch (cond-let
[[current (magit-get-current-branch)]
[atpoint (oref it value)]]
((not (equal atpoint current))
(format "%s...%s" (or current "HEAD") atpoint))
([upstream (magit-get-upstream-branch)]
(format "%s...%s" upstream current))
((magit-anything-modified-p)
current)
((cons 'commit current))))
(commit (cons 'commit (oref it value)))
([file commit] (cons 'commit (oref (oref it parent) value)))
([hunk file commit]
(cons 'commit (oref (oref (oref it parent) parent) value)))
(stash (cons 'stash (oref it value)))
(pullreq (forge--pullreq-range (oref it value) t))))))