Function: magit-thingatpt--git-revision
magit-thingatpt--git-revision is a byte-compiled function defined in
magit-git.el.
Signature
(magit-thingatpt--git-revision &optional DISALLOW)
Source Code
;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-git.el
(defun magit-thingatpt--git-revision (&optional disallow)
;; Support hashes and references.
(and-let* ((bounds
(let ((c (concat "\s\n\t~^:?*[\\" disallow)))
(cl-letf
(((get 'git-revision 'beginning-op)
(lambda ()
(if (re-search-backward (format "[%s]" c) nil t)
(forward-char)
(goto-char (point-min)))))
((get 'git-revision 'end-op)
(lambda ()
(re-search-forward (format "\\=[^%s]*" c) nil t))))
(bounds-of-thing-at-point 'git-revision))))
(string (buffer-substring-no-properties (car bounds) (cdr bounds)))
;; References are allowed to contain most parentheses and
;; most punctuation, but if those characters appear at the
;; edges of a possible reference in arbitrary text, then
;; they are much more likely to be intended as just that:
;; punctuation and delimiters.
(string (thread-first string
(string-trim-left "[(</]")
(string-trim-right "[])>/.,;!]"))))
(let (disallow)
(when (or (string-match-p "\\.\\." string)
(string-match-p "/\\." string))
(setq disallow (concat disallow ".")))
(when (string-match-p "@{" string)
(setq disallow (concat disallow "@{")))
(if disallow
;; These additional restrictions overcompensate,
;; but that only matters in rare cases.
(magit-thingatpt--git-revision disallow)
(and (not (equal string "@"))
(or (and (>= (length string) 7)
(string-match-p "[a-z]" string)
(magit-commit-oid string t))
(and (magit-ref-p string)
(member (get-text-property (point) 'face)
magit-revision-faces)))
string)))))