Commit 875f913b authored by Jonas Bernoulli's avatar Jonas Bernoulli

Stop using cl-defun to define certain magit-get-{*} functions

The functions `magit-get-upstream-branch' and `magit-get-push-branch'
recently gained a second optional argument VERIFY.  That is a problem
because the default value of the existing first argument, BRANCH, was
defined using `cl-defun's (VAR INITFORM) format.  The value of the
INITFORM, which is (magit-get-current-branch), is only used when the
VAR isn't provided by the caller at all.  If the VAR is provided, but
`nil', then that provided value `nil' is used.

Previously it wouldn't have made much sense to use (FN nil), but now
it is reasonable to use (FN nil t) and expect the default to be used.
But actually one had to write (FN (magit-get-current-branch) t) until
before this commit.

But that clearly is very cumbersome, and so we stop using `cl-defun'
and instead, if necessary, determine the default value inside the body
of the affected functions.

For consistency, we do the same thing for `magit-get-upstream-ref',
`magit-get-upstream-remote', and `magit-get-push-remote', even though
these functions (currently) do not take a second optional argument.

Fixes #2960.
parent cd2a9b8c
......@@ -8,5 +8,8 @@ Fixes since v2.10.0
when asked to confirm the deletion of these stashes resulted in a
type error. #2917
* In the repository list buffer, the columns that are supposed to list
unpushed and unpulled commit counts, were blank. #2960
Authors
-------
......@@ -861,19 +861,17 @@ which is different from the current branch and still exists."
(cl-incf i))
prev))
(cl-defun magit-get-upstream-ref
(&optional (branch (magit-get-current-branch)))
(when branch
(let ((remote (magit-get "branch" branch "remote"))
(merge (magit-get "branch" branch "merge")))
(when (and remote merge)
(cond ((string-equal remote ".") merge)
((string-prefix-p "refs/heads/" merge)
(concat "refs/remotes/" remote "/" (substring merge 11))))))))
(cl-defun magit-get-upstream-branch
(&optional (branch (magit-get-current-branch)) verify)
(and branch
(defun magit-get-upstream-ref (&optional branch)
(and (or branch (setq branch (magit-get-current-branch)))
(let ((remote (magit-get "branch" branch "remote"))
(merge (magit-get "branch" branch "merge")))
(when (and remote merge)
(cond ((string-equal remote ".") merge)
((string-prefix-p "refs/heads/" merge)
(concat "refs/remotes/" remote "/" (substring merge 11))))))))
(defun magit-get-upstream-branch (&optional branch verify)
(and (or branch (setq branch (magit-get-current-branch)))
(-when-let* ((remote (magit-get "branch" branch "remote"))
(merge (magit-get "branch" branch "merge")))
(and (string-prefix-p "refs/heads/" merge)
......@@ -906,19 +904,17 @@ which is different from the current branch and still exists."
(magit-rev-ancestor-p upstream branch)
upstream)))))
(cl-defun magit-get-upstream-remote
(&optional (branch (magit-get-current-branch)))
(when branch
(magit-get "branch" branch "remote")))
(defun magit-get-upstream-remote (&optional branch)
(and (or branch (setq branch (magit-get-current-branch)))
(magit-get "branch" branch "remote")))
(cl-defun magit-get-push-remote
(&optional (branch (magit-get-current-branch)))
(or (and branch (magit-get "branch" branch "pushRemote"))
(defun magit-get-push-remote (&optional branch)
(or (and (or branch (setq branch (magit-get-current-branch)))
(magit-get "branch" branch "pushRemote"))
(magit-get "remote.pushDefault")))
(cl-defun magit-get-push-branch
(&optional (branch (magit-get-current-branch)) verify)
(and branch
(defun magit-get-push-branch (&optional branch verify)
(and (or branch (setq branch (magit-get-current-branch)))
(-when-let* ((remote (magit-get-push-remote branch))
(push-branch (concat remote "/" branch)))
(and (or (not verify)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment