Subject: bug#77529: 31.0.50; [Feature Request][VC] How can I get the current revision of the buffer opened by =vc-find-revision=?

From: jixiuf <[email-masked]>
Date: Sat, 05 Apr 2025 15:41:28 +0800

Eli Zaretskii <[email-masked]> writes:

>
> Emacs already has vc-git-next-revision, so if you need this only
> for Git, the function is already there, you just need to wrap it with
> a command.
>
> As for vc-prev-revision, isn't that just SHA^, where SHA is the hash
> of the revision used to call vc-prev-revision?

But how can I get the SHA of the current revision when I am in a buffer
opened by =vc-find-revision=?

Getting the SHA from the buffer name is not easy, as shown in the demo
below:

- 7f855b5297b..: Eli Zaretskii 2023-01-07 ; Fix description of etc/DOC  
- (origin/emacs-29)e9341119fe4..: Eli Zaretskii 2023-01-07 ; Fix documentation of etc/DOC  
- cae528457cb..: Eli Zaretskii 2023-01-01 ; Add 2023 to copyright years.  

(vc-git-previous-revision "doc/lispref/help.texi" "7f855b5297b")  
=> "remotes/origin/emacs-29"  

(vc-git-next-revision "doc/lispref/help.texi" "cae528457cb")  
=> "remotes/origin/emacs-29"  

(vc-find-revision "doc/lispref/help.texi" "remotes/origin/emacs-29")  
=> buffer-name: help.texi.~remotes_origin_emacs-29~  

As you can see, the SHA is "remotes_origin_emacs-29" (obtained from the
buffer name). I don’t know the true branch/tag name of
"remotes_origin_emacs-29"; it could be "remotes/origin/emacs-29" or
"remotes_origin_emacs-29."