Function: magit-format-ref-labels
magit-format-ref-labels is a byte-compiled function defined in
magit-git.el.
Signature
(magit-format-ref-labels STRING)
Source Code
;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-git.el
(defun magit-format-ref-labels (string)
(save-match-data
(let ((refs (split-string
(replace-regexp-in-string "\\(tag: \\|HEAD -> \\)" "" string)
", " t))
state head upstream tags branches remotes other combined)
(dolist (ref refs)
(let* ((face (cdr (seq-find (##string-match (car %) ref)
magit-ref-namespaces)))
(name (match-str 1 ref))
(name (if (and name
(not (string-prefix-p "refs/tags/" ref))
(magit-rev-verify (concat "refs/tags/" name)))
(magit-ref-abbrev ref)
(or name ref)))
(name (magit--propertize-face name face)))
(cl-case face
((magit-bisect-bad magit-bisect-skip magit-bisect-good)
(setq state name))
(magit-head
(setq head (magit--propertize-face "@" 'magit-head)))
(magit-tag (push name tags))
(magit-branch-local (push name branches))
(magit-branch-remote (push name remotes))
(t (push name other)))))
(setq remotes
(seq-keep
(lambda (name)
(if (string-match "\\`\\([^/]*\\)/\\(.*\\)\\'" name)
(let ((r (match-str 1 name))
(b (match-str 2 name)))
(and (not (equal b "HEAD"))
(if (equal (concat "refs/remotes/" name)
(magit-git-string
"symbolic-ref"
(format "refs/remotes/%s/HEAD" r)))
(magit--propertize-face
name 'magit-branch-remote-head)
name)))
name))
remotes))
(let* ((current (magit-get-current-branch))
(target (magit-get-upstream-branch current)))
(dolist (name branches)
(let ((push (car (member (magit-get-push-branch name) remotes))))
(when push
(setq remotes (delete push remotes))
(string-match "^[^/]*/" push)
(setq push (substring push 0 (match-end 0))))
(cond
((equal name current)
(setq head
(concat push
(magit--propertize-face
name 'magit-branch-current))))
((equal name target)
(setq upstream
(concat push
(magit--propertize-face
name '(magit-branch-upstream
magit-branch-local)))))
((push (concat push name) combined)))))
(cond-let
((or upstream (not target)))
((member target remotes)
(magit--add-face-text-property
0 (length target) 'magit-branch-upstream nil target)
(setq upstream target)
(setq remotes (delete target remotes)))
([target (car (member target combined))]
(magit--add-face-text-property
0 (length target) 'magit-branch-upstream nil target)
(setq upstream target)
(setq combined (delete target combined)))))
(string-join (flatten-tree `(,state
,head
,upstream
,@(nreverse tags)
,@(nreverse combined)
,@(nreverse remotes)
,@other))
" "))))