branch: elpa/git-commit commit 3cb7f5ba430906bded9e5d9951f5260ab25644d0 Author: robert.irelan <robert.ire...@bytedance.com> Commit: Jonas Bernoulli <jo...@bernoul.li>
Support revisions that match commit message Git supports revisions that match a commit message, such as ":/fix nasty bug". See the description for ":/<text>" in gitrevisons(7). Magit used to fail when encountering such revisions because it appends "^{commit}" in several places to revisions in order to dereference references. This commit teaches it to recognize this special revision syntax and just use such revision without dereferencing or verifying them. Mark the function as private because we might still have to tweak how such special revisions are handled. I.e., we might have to verify such revisions (or not because at least callers already do that), and if we do, we might have to return nil or raise an error (depending on the caller). For now at least, just do the easy thing, because this syntax is only rarely used (never in Magit, once in `orgit'), so putting a lot of effort into this isn't justified (yet?). Co-authored-by: Jonas Bernoulli <jo...@bernoul.li> --- lisp/magit-diff.el | 4 ++-- lisp/magit-git.el | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el index 32e81f371a..72b28b5f8d 100644 --- a/lisp/magit-diff.el +++ b/lisp/magit-diff.el @@ -2517,7 +2517,7 @@ Staging and applying changes is documented in info node "show" "-p" "--cc" "--format=" "--no-prefix" (and (member "--stat" magit-buffer-diff-args) "--numstat") magit-buffer-diff-args - (concat magit-buffer-revision "^{commit}") + (magit--rev-dereference magit-buffer-revision) "--" magit-buffer-diff-files)) (defun magit-insert-revision-tag () @@ -2676,7 +2676,7 @@ or a ref which is not a branch, then it inserts nothing." (--when-let (magit-rev-format "%D" magit-buffer-revision "--decorate=full") (insert (magit-format-ref-labels it) ?\s)) (insert (propertize - (magit-rev-parse (concat magit-buffer-revision "^{commit}")) + (magit-rev-parse (magit--rev-dereference magit-buffer-revision)) 'font-lock-face 'magit-hash)) (magit-insert-heading) (let ((beg (point))) diff --git a/lisp/magit-git.el b/lisp/magit-git.el index fbff019a49..65fa1b4ced 100644 --- a/lisp/magit-git.el +++ b/lisp/magit-git.el @@ -1279,12 +1279,19 @@ string \"true\", otherwise return nil." (defun magit-commit-p (rev) "Return full hash for REV if it names an existing commit." - (magit-rev-verify (concat rev "^{commit}"))) + (magit-rev-verify (magit--rev-dereference rev))) (defalias 'magit-rev-verify-commit #'magit-commit-p) (defalias 'magit-rev-hash #'magit-commit-p) +(defun magit--rev-dereference (rev) + "Return a rev that forces Git to interpret REV as a commit. +If REV has the form \":/TEXT\", instead return it as-is" + (if (string-match-p "^:/" rev) + rev + (concat rev "^{commit}"))) + (defun magit-rev-equal (a b) "Return t if there are no differences between the commits A and B." (magit-git-success "diff" "--quiet" a b)) @@ -2106,14 +2113,16 @@ Return a list of two integers: (A>B B>A)." (defun magit-rev-format (format &optional rev args) (let ((str (magit-git-string "show" "--no-patch" (concat "--format=" format) args - (if rev (concat rev "^{commit}") "HEAD") "--"))) + (if rev (magit--rev-dereference rev) "HEAD") + "--"))) (unless (string-equal str "") str))) (defun magit-rev-insert-format (format &optional rev args) (magit-git-insert "show" "--no-patch" (concat "--format=" format) args - (if rev (concat rev "^{commit}") "HEAD") "--")) + (if rev (magit--rev-dereference rev) "HEAD") + "--")) (defun magit-format-rev-summary (rev) (when-let* ((str (magit-rev-format "%h %s" rev))) ;debbugs#31840