diff options
| author | Jonas Bernoulli <jonas@bernoul.li> | 2026-03-30 13:02:52 +0200 |
|---|---|---|
| committer | Jonas Bernoulli <jonas@bernoul.li> | 2026-03-30 13:02:52 +0200 |
| commit | 89a51310bd8f8087c44f7ac5c902cc82dddbbe2a (patch) | |
| tree | 0ea21a214c0d73f757517f016bce45f14b28c411 | |
| parent | 6c7d3c34b51383f32f6a7a84fb1472e4f5ab7cf2 (diff) | |
Use cond more instead of if and progn
| -rw-r--r-- | lisp/magit-apply.el | 14 | ||||
| -rw-r--r-- | lisp/magit-commit.el | 27 | ||||
| -rw-r--r-- | lisp/magit-diff.el | 40 | ||||
| -rw-r--r-- | lisp/magit-git.el | 23 | ||||
| -rw-r--r-- | lisp/magit-log.el | 26 | ||||
| -rw-r--r-- | lisp/magit-process.el | 39 | ||||
| -rw-r--r-- | lisp/magit-remote.el | 18 | ||||
| -rw-r--r-- | lisp/magit-section.el | 8 |
8 files changed, 97 insertions, 98 deletions
diff --git a/lisp/magit-apply.el b/lisp/magit-apply.el index 4c19681..d8a31a0 100644 --- a/lisp/magit-apply.el +++ b/lisp/magit-apply.el @@ -642,13 +642,13 @@ of a side, then keep that side without prompting." files)) (dolist (file files) (let ((orig (cadr (assoc file status)))) - (if (file-exists-p file) - (progn - (when$ (file-name-directory orig) - (make-directory $ t)) - (magit-call-git "mv" file orig)) - (magit-call-git "rm" "--cached" "--" file) - (magit-call-git "reset" "--" orig))))) + (cond ((file-exists-p file) + (when$ (file-name-directory orig) + (make-directory $ t)) + (magit-call-git "mv" file orig)) + (t + (magit-call-git "rm" "--cached" "--" file) + (magit-call-git "reset" "--" orig)))))) (defun magit-discard-files--discard (sections new-files) (let ((files (mapcar (##oref % value) sections))) diff --git a/lisp/magit-commit.el b/lisp/magit-commit.el index 2e1b730..a8c9aaf 100644 --- a/lisp/magit-commit.el +++ b/lisp/magit-commit.el @@ -549,20 +549,19 @@ is updated: (user-error "There are no modified modules that could be absorbed")) (when commit (setq commit (magit-rebase-interactive-assert commit t))) - (if (and commit (eq phase 'run)) - (progn - (dolist (module modules) - (when-let ((msg (magit-git-string - "log" "-1" "--format=%s" - (concat commit "..") "--" module))) - (magit-git "commit" "-m" (concat "fixup! " msg) - "--only" "--" module))) - (magit-refresh) - t) - (magit-log-select - (lambda (commit) - (magit-commit-absorb-modules 'run commit)) - nil nil nil nil commit)))) + (cond ((and commit (eq phase 'run)) + (dolist (module modules) + (when-let ((msg (magit-git-string + "log" "-1" "--format=%s" + (concat commit "..") "--" module))) + (magit-git "commit" "-m" (concat "fixup! " msg) + "--only" "--" module))) + (magit-refresh) + t) + ((magit-log-select + (lambda (commit) + (magit-commit-absorb-modules 'run commit)) + nil nil nil nil commit))))) ;;;###autoload(autoload 'magit-commit-absorb "magit-commit" nil t) (transient-define-prefix magit-commit-absorb (phase commit args) diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el index 1864c62..2ac16ad 100644 --- a/lisp/magit-diff.el +++ b/lisp/magit-diff.el @@ -2601,17 +2601,18 @@ keymap is the parent of their keymaps." (let ((long-status (match-str 0)) (status "BUG") file orig base) - (if (equal long-status "merged") - (progn (setq status long-status) - (setq long-status nil)) - (setq status (pcase-exhaustive long-status - ("added in remote" "new file") - ("added in both" "new file") - ("added in local" "new file") - ("removed in both" "removed") - ("changed in both" "changed") - ("removed in local" "removed") - ("removed in remote" "removed")))) + (cond ((equal long-status "merged") + (setq status long-status) + (setq long-status nil)) + ((setq status + (pcase-exhaustive long-status + ("added in remote" "new file") + ("added in both" "new file") + ("added in local" "new file") + ("removed in both" "removed") + ("changed in both" "changed") + ("removed in local" "removed") + ("removed in remote" "removed"))))) (magit-delete-line) (while (looking-at "^ \\([^ ]+\\) +[0-9]\\{6\\} \\([a-z0-9]\\{40,\\}\\) \\(.+\\)$") @@ -2988,15 +2989,14 @@ or a ref which is not a branch, then it inserts nothing." (goto-char (match-beginning 0)) (goto-char (point-max))) (insert ?\n)) - (if (re-search-forward "-----BEGIN PGP SIGNATURE-----" nil t) - (progn - (let ((beg (match-beginning 0))) - (re-search-forward "-----END PGP SIGNATURE-----\n") - (delete-region beg (point))) - (save-excursion - (magit-process-git t "verify-tag" magit-buffer-revision)) - (magit-diff-wash-signature magit-buffer-revision)) - (goto-char (point-max))) + (cond ((re-search-forward "-----BEGIN PGP SIGNATURE-----" nil t) + (let ((beg (match-beginning 0))) + (re-search-forward "-----END PGP SIGNATURE-----\n") + (delete-region beg (point))) + (save-excursion + (magit-process-git t "verify-tag" magit-buffer-revision)) + (magit-diff-wash-signature magit-buffer-revision)) + ((goto-char (point-max)))) (insert ?\n)))) (defvar-keymap magit-commit-message-section-map diff --git a/lisp/magit-git.el b/lisp/magit-git.el index fb2398f..7a52a52 100644 --- a/lisp/magit-git.el +++ b/lisp/magit-git.el @@ -1245,13 +1245,12 @@ or if no rename is detected." (y (char-after (1+ pos))) (file (buffer-substring (+ pos 3) (point)))) (forward-char) - (if (memq x '(?R ?C)) - (progn - (setq pos (point)) - (skip-chars-forward "[:print:]") - (push (list file (buffer-substring pos (point)) x y) status) - (forward-char)) - (push (list file nil x y) status))) + (cond ((memq x '(?R ?C)) + (setq pos (point)) + (skip-chars-forward "[:print:]") + (push (list file (buffer-substring pos (point)) x y) status) + (forward-char)) + ((push (list file nil x y) status)))) (setq pos (point))) status))) @@ -2252,11 +2251,11 @@ specified using `core.worktree'." (let* ((default-directory (car worktree)) (wt (and (not (magit-get-boolean "core.bare")) (magit-get "core.worktree")))) - (if (and wt (file-exists-p (expand-file-name wt))) - (progn (setf (nth 0 worktree) (expand-file-name wt)) - (setf (nth 2 worktree) (magit-rev-parse "HEAD")) - (setf (nth 3 worktree) (magit-get-current-branch))) - (setf (nth 3 worktree) t)))) + (cond ((and wt (file-exists-p (expand-file-name wt))) + (setf (nth 0 worktree) (expand-file-name wt)) + (setf (nth 2 worktree) (magit-rev-parse "HEAD")) + (setf (nth 3 worktree) (magit-get-current-branch))) + ((setf (nth 3 worktree) t))))) ((string-equal line "detached") (setf (nth 4 worktree) t)) ((string-prefix-p line "locked") diff --git a/lisp/magit-log.el b/lisp/magit-log.el index 6c2c428..603a853 100644 --- a/lisp/magit-log.el +++ b/lisp/magit-log.el @@ -1187,19 +1187,19 @@ Type \\[magit-reset] to reset `HEAD' to the commit at point. (defvar-local magit-log--color-graph nil) (defun magit-log--maybe-drop-color-graph (args limit) - (if (member "--color" args) - (if (cond ((not (member "--graph" args))) - ((not magit-log-color-graph-limit) nil) - ((not limit) - (message "Dropping --color because -n isn't set (see %s)" - 'magit-log-color-graph-limit)) - ((> limit magit-log-color-graph-limit) - (message "Dropping --color because -n is larger than %s" - 'magit-log-color-graph-limit))) - (progn (setq args (remove "--color" args)) - (setq magit-log--color-graph nil)) - (setq magit-log--color-graph t)) - (setq magit-log--color-graph nil)) + (cond ((not (member "--color" args)) + (setq magit-log--color-graph nil)) + ((cond ((not (member "--graph" args)) t) + ((not magit-log-color-graph-limit) nil) + ((not limit) + (message "Dropping --color because -n isn't set (see %s)" + 'magit-log-color-graph-limit)) + ((> limit magit-log-color-graph-limit) + (message "Dropping --color because -n is larger than %s" + 'magit-log-color-graph-limit))) + (setq args (remove "--color" args)) + (setq magit-log--color-graph nil)) + ((setq magit-log--color-graph t))) args) (cl-defmethod magit-buffer-value (&context (major-mode magit-log-mode)) diff --git a/lisp/magit-process.el b/lisp/magit-process.el index 7e9f47c..cdcea82 100644 --- a/lisp/magit-process.el +++ b/lisp/magit-process.el @@ -572,25 +572,26 @@ flattened before use." ;; On w32, git expects UTF-8 encoded input, ignore any user ;; configuration telling us otherwise (see #3250). (encode-coding-region (point-min) (point-max) 'utf-8-unix)) - (if (file-remote-p default-directory) - ;; We lack `process-file-region', so fall back to asynch + - ;; waiting in remote case. - (progn - (magit-start-git (current-buffer) args) - (while (and magit-this-process - (eq (process-status magit-this-process) 'run)) - (sleep-for 0.005))) - (run-hooks 'magit-pre-call-git-hook) - (pcase-let* ((process-environment (magit-process-environment)) - (default-process-coding-system (magit--process-coding-system)) - (flat-args (magit-process-git-arguments args t)) - (`(,process-buf . ,section) - (magit-process-setup (magit-git-executable) flat-args)) - (inhibit-read-only t)) - (magit-process-finish - (apply #'call-process-region (point-min) (point-max) - (magit-git-executable) nil process-buf nil flat-args) - process-buf nil default-directory section)))) + (cond + ((file-remote-p default-directory) + ;; We lack `process-file-region', so fall back to asynch + + ;; waiting in remote case. + (magit-start-git (current-buffer) args) + (while (and magit-this-process + (eq (process-status magit-this-process) 'run)) + (sleep-for 0.005))) + (t + (run-hooks 'magit-pre-call-git-hook) + (pcase-let* ((process-environment (magit-process-environment)) + (default-process-coding-system (magit--process-coding-system)) + (flat-args (magit-process-git-arguments args t)) + (`(,process-buf . ,section) + (magit-process-setup (magit-git-executable) flat-args)) + (inhibit-read-only t)) + (magit-process-finish + (apply #'call-process-region (point-min) (point-max) + (magit-git-executable) nil process-buf nil flat-args) + process-buf nil default-directory section))))) ;;; Asynchronous Processes diff --git a/lisp/magit-remote.el b/lisp/magit-remote.el index d946880..7f9f8c1 100644 --- a/lisp/magit-remote.el +++ b/lisp/magit-remote.el @@ -108,15 +108,15 @@ has to be used to view and change remote related variables." (string-match "\\([^:/]+\\)/[^/]+\\(\\.git\\)?\\'" origin) (replace-match remote t t origin 1))) (transient-args 'magit-remote)))) - (if (pcase (list magit-remote-add-set-remote.pushDefault - (magit-get "remote.pushDefault")) - (`(,(pred stringp) ,_) t) - ((or `(ask ,_) '(ask-if-unset nil)) - (y-or-n-p (format "Set `remote.pushDefault' to \"%s\"? " remote)))) - (progn (magit-call-git "remote" "add" args remote url) - (setf (magit-get "remote.pushDefault") remote) - (magit-refresh)) - (magit-run-git-async "remote" "add" args remote url))) + (cond ((pcase (list magit-remote-add-set-remote.pushDefault + (magit-get "remote.pushDefault")) + (`(,(pred stringp) ,_) t) + ((or `(ask ,_) '(ask-if-unset nil)) + (y-or-n-p (format "Set `remote.pushDefault' to \"%s\"? " remote)))) + (magit-call-git "remote" "add" args remote url) + (setf (magit-get "remote.pushDefault") remote) + (magit-refresh)) + ((magit-run-git-async "remote" "add" args remote url)))) ;;;###autoload (defun magit-remote-rename (old new) diff --git a/lisp/magit-section.el b/lisp/magit-section.el index 59acff5..9514bcb 100644 --- a/lisp/magit-section.el +++ b/lisp/magit-section.el @@ -885,10 +885,10 @@ If there is no previous sibling section, then move to the parent." (defun magit-section-goto (arg) "Run `magit-section-movement-hook'. See info node `(magit)Section Movement'." - (if (integerp arg) - (progn (forward-line arg) - (setq arg (magit-current-section))) - (goto-char (oref arg start))) + (cond ((integerp arg) + (forward-line arg) + (setq arg (magit-current-section))) + ((goto-char (oref arg start)))) (run-hook-with-args 'magit-section-movement-hook arg)) (defun magit-section-set-window-start (section) |
