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

    Use cond more
---
 lisp/git-rebase.el     |  7 +++----
 lisp/magit-apply.el    | 44 +++++++++++++++++++-------------------
 lisp/magit-blame.el    | 39 +++++++++++++++++-----------------
 lisp/magit-diff.el     | 38 ++++++++++++++++-----------------
 lisp/magit-ediff.el    | 30 +++++++++++++-------------
 lisp/magit-git.el      | 36 +++++++++++++++----------------
 lisp/magit-mode.el     | 12 +++++------
 lisp/magit-process.el  | 28 ++++++++++++-------------
 lisp/magit-push.el     |  8 +++----
 lisp/magit-repos.el    | 11 +++++-----
 lisp/magit-section.el  | 19 ++++++++---------
 lisp/magit-sequence.el | 57 +++++++++++++++++++++++++-------------------------
 12 files changed, 164 insertions(+), 165 deletions(-)

diff --git a/lisp/git-rebase.el b/lisp/git-rebase.el
index c5b7989ed46..614887f0bea 100644
--- a/lisp/git-rebase.el
+++ b/lisp/git-rebase.el
@@ -416,10 +416,9 @@ of its action type."
             ;; other lines with other action types, empty lines, and
             ;; "Branch" comments interspersed.  Move along.
             ((forward-line)))))
-       (goto-char
-        (if git-rebase-auto-advance
-            end-marker
-          (if pt-below-p (1- end-marker) beg)))
+       (goto-char (cond (git-rebase-auto-advance end-marker)
+                        (pt-below-p (1- end-marker))
+                        (beg)))
        (goto-char (line-beginning-position))))
     (_ (ding))))
 
diff --git a/lisp/magit-apply.el b/lisp/magit-apply.el
index a5b19efb343..d797f3e4229 100644
--- a/lisp/magit-apply.el
+++ b/lisp/magit-apply.el
@@ -517,17 +517,17 @@ of a side, then keep that side without prompting."
       (_ (magit-discard-apply section #'magit-apply-hunk)))))
 
 (defun magit-discard-apply (section apply)
-  (if (eq (magit-diff-type section) 'unstaged)
-      (funcall apply section "--reverse")
-    (if (magit-anything-unstaged-p
-         nil (if (magit-file-section-p section)
-                 (oref section value)
-               (magit-section-parent-value section)))
-        (progn (let ((magit-inhibit-refresh t))
-                 (funcall apply section "--reverse" "--cached")
-                 (funcall apply section "--reverse" "--reject"))
-               (magit-refresh))
-      (funcall apply section "--reverse" "--index"))))
+  (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
@@ -538,17 +538,17 @@ of a side, then keep that side without prompting."
 
 (defun magit-discard-apply-n (sections apply)
   (let ((section (car sections)))
-    (if (eq (magit-diff-type section) 'unstaged)
-        (funcall apply sections "--reverse")
-      (if (magit-anything-unstaged-p
-           nil (if (magit-file-section-p section)
-                   (oref section value)
-                 (magit-section-parent-value section)))
-          (progn (let ((magit-inhibit-refresh t))
-                   (funcall apply sections "--reverse" "--cached")
-                   (funcall apply sections "--reverse" "--reject"))
-                 (magit-refresh))
-        (funcall apply sections "--reverse" "--index")))))
+    (cond ((eq (magit-diff-type section) 'unstaged)
+           (funcall apply sections "--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 sections "--reverse" "--cached")
+             (funcall apply sections "--reverse" "--reject"))
+           (magit-refresh))
+          ((funcall apply sections "--reverse" "--index")))))
 
 (defun magit-discard-file (section)
   (magit-discard-files (list section)))
diff --git a/lisp/magit-blame.el b/lisp/magit-blame.el
index dce85fa2e2f..14d4b6f7d78 100644
--- a/lisp/magit-blame.el
+++ b/lisp/magit-blame.el
@@ -265,21 +265,22 @@ Also see option `magit-blame-styles'."
                             (magit-file-relative-name
                              nil (not magit-buffer-file-name))))
                  (line (format "%d,+1" (line-number-at-pos))))
-             (cond (file (with-temp-buffer
-                           (magit-with-toplevel
-                             (magit-git-insert
-                              "blame" "--porcelain"
-                              (if (memq magit-blame-type '(final removal))
-                                  (cons "--reverse" (magit-blame-arguments))
-                                (magit-blame-arguments))
-                              "-L" line rev "--" file)
-                             (goto-char (point-min))
-                             (if (eobp)
-                                 (unless noerror
-                                   (error "Cannot get blame chunk at eob"))
-                               (car (magit-blame--parse-chunk type))))))
-                   (noerror nil)
-                   ((error "Buffer does not visit a tracked file")))))))
+             (cond (file
+                    (with-temp-buffer
+                      (magit-with-toplevel
+                        (magit-git-insert
+                         "blame" "--porcelain"
+                         (if (memq magit-blame-type '(final removal))
+                             (cons "--reverse" (magit-blame-arguments))
+                           (magit-blame-arguments))
+                         "-L" line rev "--" file)
+                        (goto-char (point-min))
+                        (cond ((not (eobp))
+                               (car (magit-blame--parse-chunk type)))
+                              ((not noerror)
+                               (error "Cannot get blame chunk at eob"))))))
+                   ((not noerror)
+                    (error "Buffer does not visit a tracked file")))))))
 
 (defun magit-blame-chunk-at (pos)
   (seq-some (##overlay-get % 'magit-blame-chunk)
@@ -459,10 +460,10 @@ modes is toggled, then this mode also gets toggled 
automatically.
             (message "Blaming...done"))
         (magit-blame-assert-buffer process)
         (with-current-buffer (process-get process 'command-buf)
-          (if magit-blame-mode
-              (progn (magit-blame-mode -1)
-                     (message "Blaming...failed"))
-            (message "Blaming...aborted"))))
+          (cond (magit-blame-mode
+                 (magit-blame-mode -1)
+                 (message "Blaming...failed"))
+                ((message "Blaming...aborted")))))
       (kill-local-variable 'magit-blame-process))))
 
 (defun magit-blame-process-filter (process string)
diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index 3838cd48734..1e5fbaf1b6b 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -1482,31 +1482,29 @@ for a revision."
   "Convert diff range type.
 Change \"revA..revB\" to \"revA...revB\", or vice versa."
   (interactive)
-  (if (and magit-buffer-range
-           (derived-mode-p 'magit-diff-mode)
-           (string-match magit-range-re magit-buffer-range))
-      (setq magit-buffer-range
-            (replace-match (if (string= (match-str 2 magit-buffer-range) "..")
-                               "..."
-                             "..")
-                           t t magit-buffer-range 2))
-    (user-error "No range to change"))
-  (magit-refresh))
+  (cond ((and magit-buffer-range
+              (derived-mode-p 'magit-diff-mode)
+              (string-match magit-range-re magit-buffer-range))
+         (setq magit-buffer-range
+               (replace-match
+                (if (string= (match-str 2 magit-buffer-range) "..") "..." "..")
+                t t magit-buffer-range 2))
+         (magit-refresh))
+        ((user-error "No range to change"))))
 
 (defun magit-diff-flip-revs ()
   "Swap revisions in diff range.
 Change \"revA..revB\" to \"revB..revA\"."
   (interactive)
-  (if (and magit-buffer-range
-           (derived-mode-p 'magit-diff-mode)
-           (string-match magit-range-re magit-buffer-range))
-      (progn
-        (setq magit-buffer-range
-              (concat (match-str 3 magit-buffer-range)
-                      (match-str 2 magit-buffer-range)
-                      (match-str 1 magit-buffer-range)))
-        (magit-refresh))
-    (user-error "No range to swap")))
+  (cond ((and magit-buffer-range
+              (derived-mode-p 'magit-diff-mode)
+              (string-match magit-range-re magit-buffer-range))
+         (setq magit-buffer-range
+               (concat (match-str 3 magit-buffer-range)
+                       (match-str 2 magit-buffer-range)
+                       (match-str 1 magit-buffer-range)))
+         (magit-refresh))
+        ((user-error "No range to swap"))))
 
 (defun magit-diff-toggle-file-filter ()
   "Toggle the file restriction of the current buffer's diffs.
diff --git a/lisp/magit-ediff.el b/lisp/magit-ediff.el
index 54acf4561de..0390d452397 100644
--- a/lisp/magit-ediff.el
+++ b/lisp/magit-ediff.el
@@ -266,21 +266,21 @@ and alternative commands."
                            (goto-char (point-min))
                            (unless (re-search-forward "^<<<<<<< " nil t)
                              (magit-stage-files (list file)))))))))
-        (if fileC
-            (magit-ediff-buffers
-             ((magit-get-revision-buffer revA fileA)
-              (magit-find-file-noselect  revA fileA))
-             ((magit-get-revision-buffer revB fileB)
-              (magit-find-file-noselect  revB fileB))
-             ((magit-get-revision-buffer revC fileC)
-              (magit-find-file-noselect  revC fileC))
-             setup quit file)
-          (magit-ediff-buffers
-           ((magit-get-revision-buffer revA fileA)
-            (magit-find-file-noselect  revA fileA))
-           ((magit-get-revision-buffer revB fileB)
-            (magit-find-file-noselect  revB fileB))
-           nil setup quit file))))))
+        (cond (fileC
+               (magit-ediff-buffers
+                ((magit-get-revision-buffer revA fileA)
+                 (magit-find-file-noselect  revA fileA))
+                ((magit-get-revision-buffer revB fileB)
+                 (magit-find-file-noselect  revB fileB))
+                ((magit-get-revision-buffer revC fileC)
+                 (magit-find-file-noselect  revC fileC))
+                setup quit file))
+              ((magit-ediff-buffers
+                ((magit-get-revision-buffer revA fileA)
+                 (magit-find-file-noselect  revA fileA))
+                ((magit-get-revision-buffer revB fileB)
+                 (magit-find-file-noselect  revB fileB))
+                nil setup quit file)))))))
 
 ;;;###autoload
 (defun magit-ediff-resolve-rest (file)
diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index bc7519dd9ac..7e62da80408 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -1670,9 +1670,9 @@ The amount of time spent searching is limited by
   (let ((t0 (float-time))
         (current (magit-get-current-branch))
         (i 1) prev)
-    (while (if (> (- (float-time) t0) magit-get-previous-branch-timeout)
-               (setq prev nil) ;; Timed out.
-             (and (setq prev (magit-rev-verify (format "@{-%d}" i)))
+    (while (cond ((> (- (float-time) t0) magit-get-previous-branch-timeout)
+                  (setq prev nil))
+                 ((setq prev (magit-rev-verify (format "@{-%d}" i)))
                   (or (not (setq prev (magit-rev-branch prev)))
                       (equal prev current))))
       (cl-incf i))
@@ -2880,21 +2880,21 @@ out.  Only existing branches can be selected."
   ;; and some repositories have thousands of submodules.
   (let ((magit--refresh-cache (list (cons 0 0)))
         (modules nil))
-    (if current-prefix-arg
-        (progn
-          (setq modules (magit-list-module-paths))
-          (when predicate
-            (setq modules (seq-filter predicate modules)))
-          (unless modules
-            (if predicate
-                (user-error "No modules satisfying %s available" predicate)
-              (user-error "No modules available"))))
-      (setq modules (magit-region-values 'module))
-      (when modules
-        (when predicate
-          (setq modules (seq-filter predicate modules)))
-        (unless modules
-          (user-error "No modules satisfying %s selected" predicate))))
+    (cond (current-prefix-arg
+           (setq modules (magit-list-module-paths))
+           (when predicate
+             (setq modules (seq-filter predicate modules)))
+           (unless modules
+             (if predicate
+                 (user-error "No modules satisfying %s available" predicate)
+               (user-error "No modules available"))))
+          (t
+           (setq modules (magit-region-values 'module))
+           (when modules
+             (when predicate
+               (setq modules (seq-filter predicate modules)))
+             (unless modules
+               (user-error "No modules satisfying %s selected" predicate)))))
     (if (or (length> modules 1) current-prefix-arg)
         (magit-confirm t nil (format "%s %%d modules" verb) nil modules)
       (list (magit-read-module-path (format "%s module" verb) predicate)))))
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index 74c34af9ac8..07942a57ef8 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -1355,12 +1355,12 @@ argument (the prefix) non-nil means save all with no 
questions."
 
 Later, when the buffer is buried, it may be restored by
 `magit-restore-window-configuration'."
-  (if magit-inhibit-save-previous-winconf
-      (when (eq magit-inhibit-save-previous-winconf 'unset)
-        (setq magit-previous-window-configuration nil))
-    (unless (get-buffer-window (current-buffer) (selected-frame))
-      (setq magit-previous-window-configuration
-            (current-window-configuration)))))
+  (cond (magit-inhibit-save-previous-winconf
+         (when (eq magit-inhibit-save-previous-winconf 'unset)
+           (setq magit-previous-window-configuration nil)))
+        ((not (get-buffer-window (current-buffer) (selected-frame)))
+         (setq magit-previous-window-configuration
+               (current-window-configuration)))))
 
 (defun magit-restore-window-configuration (&optional kill-buffer)
   "Bury or kill the current buffer and restore previous window configuration."
diff --git a/lisp/magit-process.el b/lisp/magit-process.el
index 87188045a9d..7d4cc829a45 100644
--- a/lisp/magit-process.el
+++ b/lisp/magit-process.el
@@ -1291,16 +1291,16 @@ Limited by `magit-process-error-tooltip-max-lines'."
     (when (eq magit-process-apply-ansi-colors t)
       (ansi-color-apply-on-region (oref section content)
                                   (oref section end)))
-    (if (= (oref section end)
-           (+ (line-end-position) 2))
-        (save-excursion
-          (goto-char (1+ (line-end-position)))
-          (delete-char -1)
-          (oset section content nil))
-      (when (and (= exit-code 0)
-                 (not (seq-some (##eq (window-buffer %) buffer)
-                                (window-list))))
-        (magit-section-hide section)))))
+    (cond ((= (oref section end)
+              (+ (line-end-position) 2))
+           (save-excursion
+             (goto-char (1+ (line-end-position)))
+             (delete-char -1)
+             (oset section content nil)))
+          ((and (= exit-code 0)
+                (not (seq-some (##eq (window-buffer %) buffer)
+                               (window-list))))
+           (magit-section-hide section)))))
 
 (defun magit-process-display-buffer (process)
   (when (process-live-p process)
@@ -1323,10 +1323,10 @@ Limited by `magit-process-error-tooltip-max-lines'."
 
 (defun magit--log-action (summary line list)
   (let (heading lines)
-    (if (cdr list)
-        (progn (setq heading (funcall summary list))
-               (setq lines (mapcar line list)))
-      (setq heading (funcall line (car list))))
+    (cond ((cdr list)
+           (setq lines (mapcar line list))
+           (setq heading (funcall summary list)))
+          ((setq heading (funcall line (car list)))))
     (with-current-buffer (magit-process-buffer t)
       (goto-char (1- (point-max)))
       (let ((inhibit-read-only t))
diff --git a/lisp/magit-push.el b/lisp/magit-push.el
index f603250b052..3c8c806a512 100644
--- a/lisp/magit-push.el
+++ b/lisp/magit-push.el
@@ -192,10 +192,10 @@ Both the source and the target are read in the 
minibuffer."
      (list source
            (magit-read-remote-branch
             (format "Push %s to" source) nil
-            (if (magit-local-branch-p source)
-                (or (magit-get-push-branch source)
-                    (magit-get-upstream-branch source))
-              (and (magit-rev-ancestor-p source "HEAD")
+            (cond ((magit-local-branch-p source)
+                   (or (magit-get-push-branch source)
+                       (magit-get-upstream-branch source)))
+                  ((magit-rev-ancestor-p source "HEAD")
                    (or (magit-get-push-branch)
                        (magit-get-upstream-branch))))
             source 'confirm)
diff --git a/lisp/magit-repos.el b/lisp/magit-repos.el
index 874e6db4bc3..44b05e599c3 100644
--- a/lisp/magit-repos.el
+++ b/lisp/magit-repos.el
@@ -390,11 +390,12 @@ Usually this is just its basename."
                    (string-match-p magit-repolist-column-version-resume-regexp
                                    (magit-rev-format "%s")))
           (setq v (replace-match (propertize "+" 'face 'shadow) t t v 1))))
-      (if (and v (string-match "\\`[0-9]" v))
-          (concat " " v)
-        (when (and v (string-match "\\`[^0-9]+" v))
-          (magit--put-face 0 (match-end 0) 'shadow v))
-        v))))
+      (cond ((not v) nil)
+            ((string-match "\\`[0-9]" v)
+             (concat " " v))
+            ((string-match "\\`[^0-9]+" v)
+             (magit--put-face 0 (match-end 0) 'shadow v)
+             v)))))
 
 (defun magit-repolist-version< (a b)
   (save-match-data
diff --git a/lisp/magit-section.el b/lisp/magit-section.el
index 244f212fc54..e4a562aa4bd 100644
--- a/lisp/magit-section.el
+++ b/lisp/magit-section.el
@@ -2078,16 +2078,15 @@ When `magit-section-preserve-visibility' is nil, return 
nil."
     (let ((section (magit-current-section)))
       (while section
         (let ((content (oref section content)))
-          (if (and (magit-section-invisible-p section)
-                   (<= (or content (oref section start))
-                       beg
-                       (oref section end)))
-              (progn
-                (when content
-                  (magit-section-show section)
-                  (push section magit-section--opened-sections))
-                (setq section (oref section parent)))
-            (setq section nil))))))
+          (cond ((and (magit-section-invisible-p section)
+                      (<= (or content (oref section start))
+                          beg
+                          (oref section end)))
+                 (when content
+                   (magit-section-show section)
+                   (push section magit-section--opened-sections))
+                 (setq section (oref section parent)))
+                ((setq section nil)))))))
   (or (eq search-invisible t)
       (not (isearch-range-invisible beg end))))
 
diff --git a/lisp/magit-sequence.el b/lisp/magit-sequence.el
index a67fdeee82c..50891894f8f 100644
--- a/lisp/magit-sequence.el
+++ b/lisp/magit-sequence.el
@@ -654,15 +654,15 @@ START has to be selected from a list of recent commits."
                       (magit-get-upstream-branch))
                      nil
                      (magit-rebase-arguments)))
-  (if start
-      (progn (message "Rebasing...")
-             (magit-run-git-sequencer "rebase" "--onto" newbase start args)
-             (message "Rebasing...done"))
-    (magit-log-select
-      `(lambda (commit)
-         (magit-rebase-subset ,newbase (concat commit "^") (list ,@args)))
-      (concat "Type %p on a commit to rebase it "
-              "and commits above it onto " newbase ","))))
+  (cond (start
+         (message "Rebasing...")
+         (magit-run-git-sequencer "rebase" "--onto" newbase start args)
+         (message "Rebasing...done"))
+        ((magit-log-select
+           `(lambda (commit)
+              (magit-rebase-subset ,newbase (concat commit "^") (list ,@args)))
+           (concat "Type %p on a commit to rebase it "
+                   "and commits above it onto " newbase ",")))))
 
 (defvar magit-rebase-interactive-include-selected t)
 
@@ -818,25 +818,26 @@ argument, prompt for the first commit to potentially 
squash into."
 In some cases this pops up a commit message buffer for you do
 edit.  With a prefix argument the old message is reused as-is."
   (interactive "P")
-  (if (magit-rebase-in-progress-p)
-      (if (magit-anything-unstaged-p t)
-          (user-error "Cannot continue rebase with unstaged changes")
-        (let ((dir (magit-gitdir)))
-          (when (and (magit-anything-staged-p)
-                     (file-exists-p (expand-file-name "rebase-merge" dir))
-                     (not (member (magit-toplevel)
-                                  magit--rebase-public-edit-confirmed)))
-            (magit-commit-amend-assert
-             (magit-file-line
-              (expand-file-name "rebase-merge/orig-head" dir)))))
-        (if noedit
-            (with-environment-variables (("GIT_EDITOR" "true"))
-              (magit-run-git-async (magit--rebase-resume-command) "--continue")
-              (set-process-sentinel magit-this-process
-                                    #'magit-sequencer-process-sentinel)
-              magit-this-process)
-          (magit-run-git-sequencer (magit--rebase-resume-command) 
"--continue")))
-    (user-error "No rebase in progress")))
+  (cond
+   ((not (magit-rebase-in-progress-p))
+    (user-error "No rebase in progress"))
+   ((not (magit-anything-unstaged-p t))
+    (user-error "Cannot continue rebase with unstaged changes"))
+   (t
+    (let ((dir (magit-gitdir)))
+      (when (and (magit-anything-staged-p)
+                 (file-exists-p (expand-file-name "rebase-merge" dir))
+                 (not (member (magit-toplevel)
+                              magit--rebase-public-edit-confirmed)))
+        (magit-commit-amend-assert
+         (magit-file-line (expand-file-name "rebase-merge/orig-head" dir)))))
+    (if noedit
+        (with-environment-variables (("GIT_EDITOR" "true"))
+          (magit-run-git-async (magit--rebase-resume-command) "--continue")
+          (set-process-sentinel magit-this-process
+                                #'magit-sequencer-process-sentinel)
+          magit-this-process)
+      (magit-run-git-sequencer (magit--rebase-resume-command) "--continue")))))
 
 ;;;###autoload
 (defun magit-rebase-skip ()

Reply via email to