aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@bernoul.li>2025-07-12 10:12:08 +0200
committerJonas Bernoulli <jonas@bernoul.li>2025-07-12 10:12:08 +0200
commit7b0c2da9f18c5f44649a64ac5baf52cde7bfc45e (patch)
tree69ecd9a22caf97454863b81a4ba9340cfd4dd78e /lisp
parent537be882b66fa547af58cd05e7c8b08676f535c9 (diff)
magit-list-refs: Respect order given in magit-list-refs-namespaces
According to `magit-list-refs-namespaces's docstring, that was already the intention.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/magit-git.el39
1 files changed, 21 insertions, 18 deletions
diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index 308afdd..7588f09 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -194,9 +194,10 @@ that change the upstream and many that create new branches."
"refs/tags")
"List of ref namespaces considered when reading a ref.
-This controls the order of refs returned by `magit-list-refs',
-which is called by functions like `magit-list-branch-names' to
-generate the collection of refs."
+This controls which refs are returned by `magit-list-refs', which
+is called by functions like `magit-list-branch-names' to generate
+the collection of refs. Additionally namespaces appear in the same
+order as specified here."
:package-version '(magit . "4.3.9")
:group 'magit-commands
:type '(repeat string))
@@ -216,6 +217,9 @@ recent committer or tagger dates earlier in the list. A list of
strings can also be given in order to pass multiple sort keys to
\"git for-each-ref\".
+Regardless of what is specified here, refs are first sorted by
+namespace, according to the order of `magit-list-refs-namespaces'.
+
Note that, depending on the completion framework you use, this
may not be sufficient to change the order in which the refs are
displayed. It only controls the order of the collection passed
@@ -1972,21 +1976,20 @@ rather than those from `magit-list-refs-namespaces'.
FORMAT is passed to the `--format' flag of `git for-each-ref'
and defaults to \"%(refname)\".
-SORTBY is a key or list of keys to pass to the `--sort' flag of
-`git for-each-ref'. When nil, use `magit-list-refs-sortby'"
- (unless format
- (setq format "%(refname)"))
- (seq-keep (lambda (line)
- (pcase-let* ((`(,symrefp ,value)
- (split-string line " "))
- (symrefp (not (equal symrefp ""))))
- (and (not symrefp) value)))
- (magit-git-lines "for-each-ref"
- (concat "--format=%(symref) " format)
- (mapcar (##concat "--sort=" %)
- (ensure-list
- (or sortby magit-list-refs-sortby)))
- (or namespaces magit-list-refs-namespaces))))
+SORTBY is a key or list of keys to pass to the `--sort' flag
+of `git for-each-ref' to sort the refs within each namespace.
+When nil, use `magit-list-refs-sortby'."
+ (let ((format (concat "--format=%(symref) " (or format "%(refname)")))
+ (sortby (mapcar (##concat "--sort=" %)
+ (ensure-list (or sortby magit-list-refs-sortby)))))
+ (seq-keep (lambda (line)
+ (pcase-let* ((`(,symrefp ,value)
+ (split-string line " "))
+ (symrefp (not (equal symrefp ""))))
+ (and (not symrefp) value)))
+ (mapcan (##magit-git-lines "for-each-ref" format sortby %)
+ (ensure-list
+ (or namespaces magit-list-refs-namespaces))))))
(defun magit-list-branches ()
(magit-list-refs (list "refs/heads" "refs/remotes")))