branch: elpa/magit
commit d3f65e92fc83d9d63d947eb95c64b372c28abb03
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>

    magit-discard-apply: Absorb magit-discard-apply
    
    Here "primus" is short for "primus inter pares".
---
 lisp/magit-apply.el | 34 ++++++++++------------------------
 1 file changed, 10 insertions(+), 24 deletions(-)

diff --git a/lisp/magit-apply.el b/lisp/magit-apply.el
index d797f3e4229..5a2bfecbeb9 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)))

Reply via email to