diff options
| author | Jonas Bernoulli <jonas@bernoul.li> | 2025-09-18 09:09:03 +0200 |
|---|---|---|
| committer | Jonas Bernoulli <jonas@bernoul.li> | 2025-09-18 09:09:03 +0200 |
| commit | d3f65e92fc83d9d63d947eb95c64b372c28abb03 (patch) | |
| tree | 57b79490ed52324c2e3e69858ec1ef7a0cab8c3c /lisp | |
| parent | f70d2f622f874acb32b368b397dfe3974eb2951c (diff) | |
magit-discard-apply: Absorb magit-discard-apply
Here "primus" is short for "primus inter pares".
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/magit-apply.el | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/lisp/magit-apply.el b/lisp/magit-apply.el index d797f3e..5a2bfec 100644 --- a/lisp/magit-apply.el +++ b/lisp/magit-apply.el @@ -516,34 +516,22 @@ of a side, then keep that side without prompting." ('(?U ?U) (magit-smerge-keep-current)) (_ (magit-discard-apply section #'magit-apply-hunk))))) -(defun magit-discard-apply (section apply) - (cond ((eq (magit-diff-type section) 'unstaged) - (funcall apply section "--reverse")) - ((magit-anything-unstaged-p - nil (if (magit-file-section-p section) - (oref section value) - (magit-section-parent-value section))) - (let ((magit-inhibit-refresh t)) - (funcall apply section "--reverse" "--cached") - (funcall apply section "--reverse" "--reject")) - (magit-refresh)) - ((funcall apply section "--reverse" "--index")))) - (defun magit-discard-hunks (sections) (magit-confirm 'discard (list "Discard %d hunks from %s" (length sections) (magit-section-parent-value (car sections)))) - (magit-discard-apply-n sections #'magit-apply-hunks)) + (magit-discard-apply sections #'magit-apply-hunks)) -(defun magit-discard-apply-n (sections apply) - (let ((section (car sections))) - (cond ((eq (magit-diff-type section) 'unstaged) +(defun magit-discard-apply (sections apply) + (let* ((sections (ensure-list sections)) + (primus (car sections))) + (cond ((eq (magit-diff-type primus) 'unstaged) (funcall apply sections "--reverse")) ((magit-anything-unstaged-p - nil (if (magit-file-section-p section) - (oref section value) - (magit-section-parent-value section))) + nil (if (magit-file-section-p primus) + (oref primus value) + (magit-section-parent-value primus))) (let ((magit-inhibit-refresh t)) (funcall apply sections "--reverse" "--cached") (funcall apply sections "--reverse" "--reject")) @@ -676,10 +664,8 @@ of a side, then keep that side without prompting." (setq sections (seq-remove (##member (oref % value) binaries) sections))) - (cond ((length= sections 1) - (magit-discard-apply (car sections) 'magit-apply-diff)) - (sections - (magit-discard-apply-n sections #'magit-apply-diffs))) + (when sections + (magit-discard-apply sections #'magit-apply-diffs)) (when binaries (let ((modified (magit-unstaged-files t))) (setq binaries (magit--separate (##member % modified) binaries))) |
