Subject: Re: bug#38044: 27.0.50; There should be an easier way to look at a specific vc commit

From: Juri Linkov <[email-masked]>
Date: Sat, 23 Nov 2019 20:50:10 +0200

> Here's an alternative proposal.  It seems like almost all VCS backends
> we support provide a variant of a "log" command that shows the diffs
> together with the usual meta-data shown by "log".  Only RCS and CVS
> don't have such an option of "log", all the rest do (most of them via
> "log -p").
>
> So we could make this a subcommand of vc-log, more accurately
> vc-print-root-log, such that "C-u C-u C-x v L" will prompt for a
> revision ID, and display the information produced by such a "log -p"
> command (and fall back to displaying just the diffs for RCS and CVS).
>
> Does this sound better?

This is fine.  Here's a new patch that implements 'M-1 C-x v L'
to limit the log to one revision expanded with diff:

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index ca4c66a06d..3b977aa1f4 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1160,7 +1159,9 @@ vc-git-print-log
                       (list (concat start-revision ".." (if (equal limit "")
                                                             "HEAD"
                                                           limit)))
-                    (list start-revision)))
+                    (if (eq limit 1)
+                        (list "-p" start-revision)
+                      (list start-revision))))
 		'("--")))))))
 
 (defun vc-git-log-outgoing (buffer remote-location)
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 0d29c80d02..90603541b5 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -2475,13 +2475,26 @@ vc-print-log
     (vc-print-log-internal backend files working-revision nil limit)))
 
 ;;;###autoload
-(defun vc-print-root-log (&optional limit)
+(defun vc-print-root-log (&optional limit revision)
   "List the change log for the current VC controlled tree in a window.
 If LIMIT is non-nil, it should be a number specifying the maximum
 number of revisions to show; the default is `vc-log-show-limit'.
-When called interactively with a prefix argument, prompt for LIMIT."
+When called interactively with a prefix argument, prompt for LIMIT.
+When the prefix argument is a number, use it as LIMIT.
+A special case is when the prefix argument is 1, in this case
+it asks for the revision and shows it with its diff."
   (interactive
    (cond
+    ((eq current-prefix-arg 1)
+     (let* ((default (thing-at-point 'word))
+	    (revision (vc-read-revision
+		       (if default
+			   (format "Revision to show (default %s): " default)
+			 "Revision to show: ")
+		       nil nil default)))
+       (list 1 revision)))
+    ((numberp current-prefix-arg)
+     (list current-prefix-arg))
     (current-prefix-arg
      (let ((lim (string-to-number
 		 (read-from-minibuffer
@@ -2494,6 +2507,8 @@ vc-print-root-log
      (list (when (> vc-log-show-limit 0) vc-log-show-limit)))))
   (let ((backend (vc-deduce-backend))
 	(default-directory default-directory)
+	(vc-log-short-style (unless (and (eq limit 1) revision)
+                              vc-log-short-style))
 	rootdir)
     (if backend
 	(setq rootdir (vc-call-backend backend 'root default-directory))
@@ -2502,7 +2517,9 @@ vc-print-root-log
       (unless backend
         (error "Directory is not version controlled")))
     (setq default-directory rootdir)
-    (vc-print-log-internal backend (list rootdir) nil nil limit)))
+    (vc-print-log-internal backend (list rootdir) revision revision limit)
+    (when (and (eq limit 1) revision)
+      (vc-git-region-history-mode))))
 
 ;;;###autoload
 (defun vc-print-branch-log (branch)