Subject: 30.0.50; Want VC command to view a single revision like a patch
From: Sean Whitton <[email-masked]>
To: [email-masked]
Date: Mon, 10 Jun 2024 16:00:44 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

X-debbugs-cc: [email-masked], [email-masked]

Hello,

I do security work which involves backporting specific upstream commits
to older versions of the software.  I often end up with a list of
revision hashes and I use 'git cherry-pick -x' to grab them.

While resolving conflicts, I often just want to look at a summary of a
single revision.  I want to see the revision's root diff, and sometimes
also its log message.

This isn't very easy with VC at present.  There is
    C-x v b L <revision> RET =
and
    C-u C-x v D <revision>~1 RET <revision> RET
but neither are very nice (and the latter requires you to specify the
previous revision using VCS-specific notation).

Could we add a backend-generic command for this?
And might we bind it under 'C-x v' ?

I came up with the following as a start; it's not great.

--8<---------------cut here---------------start------------->8---
(defun vc-root-revision (rev)
  (interactive (list (vc-read-revision "Revision to show: ")))
  (let ((patch (vc-call-backend (vc-responsible-backend default-directory)
				'prepare-patch rev))
	(buf (get-buffer-create "*vc-revision*")))
    (set-buffer buf)
    (let ((inhibit-read-only t))
      (erase-buffer)
      (insert-buffer-substring (plist-get patch :buffer)
			       (plist-get patch :body-start)
			       (plist-get patch :body-end)))
    (setq buffer-read-only t)
    (diff-mode)
    (pop-to-buffer buf)
    (goto-char (point-min))))
--8<---------------cut here---------------end--------------->8---

-- 
Sean Whitton