Skip to content

Commit f655967

Browse files
committed
'C-1 C-x v L' asks for revision and shows its log entry with diff (bug#38044)
* doc/emacs/maintaining.texi (VC Change Log): Explain the numeric prefix arg of 'C-x v L' (vc-print-root-log). * lisp/vc/vc-git.el (vc-git-print-log): Add command line option "-p" when vc-log-view-type is 'with-diff'. (vc-git-log-view-mode): Use long style when vc-log-view-type is 'with-diff'. * lisp/vc/vc.el (vc-print-log-internal): Add optional arg 'type'. (vc-log-internal-common): Use 'region-history-mode' when type is 'with-diff' and backend supports 'region-history-mode'. (vc-print-root-log): Add optional arg 'revision'. In interactive spec read a revision when current-prefix-arg is 1. Use current-prefix-arg "as is" when it is a number. Show revision in long style with diff when limit is 1 and revision is non-nil.
1 parent b31a966 commit f655967

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

doc/emacs/maintaining.texi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,10 @@ file listed on the current line.
991991
@file{*vc-change-log*} buffer showing the history of the entire
992992
version-controlled directory tree (RCS, SCCS, CVS, and SRC do not
993993
support this feature). With a prefix argument, the command prompts
994-
for the maximum number of revisions to display.
994+
for the maximum number of revisions to display. A numeric prefix
995+
argument specifies the maximum number of revisions without prompting.
996+
When the numeric prefix argument is @kbd{M-1}, the command prompts
997+
for the revision ID, and displays its log entry with a diff of changes.
995998

996999
The @kbd{C-x v L} history is shown in a compact form, usually
9971000
showing only the first line of each log entry. However, you can type

etc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,9 @@ With a prefix argument asks for a command, so for example,
993993
'C-u M-x vc-log-search RET git log -1 f302475 RET' will display
994994
just one log entry found by its revision number.
995995

996+
+++
997+
*** 'C-1 C-x v L' asks for a revision and shows its log entry with diff.
998+
996999
*** 'C-x v =' can now mimic Magit's diff format.
9971000
Set the new user option 'diff-font-lock-prettify' to t for that, see
9981001
below under "Diff mode".

lisp/vc/vc-git.el

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ or an empty string if none."
708708
'(menu-item "Snapshot Stash" vc-git-stash-snapshot
709709
:help "Snapshot stash"))
710710
(define-key map [cr]
711-
'(menu-item "Create Samed Stash" vc-git-stash
711+
'(menu-item "Create Named Stash" vc-git-stash
712712
:help "Create named stash"))
713713
(define-key map [de]
714714
'(menu-item "Delete Stash" vc-git-stash-delete-at-point
@@ -1134,8 +1134,7 @@ If LIMIT is a revision string, use it as an end-revision."
11341134
;; If the buffer exists from a previous invocation it might be
11351135
;; read-only.
11361136
(let ((inhibit-read-only t))
1137-
(with-current-buffer
1138-
buffer
1137+
(with-current-buffer buffer
11391138
(apply 'vc-git-command buffer
11401139
'async files
11411140
(append
@@ -1161,6 +1160,8 @@ If LIMIT is a revision string, use it as an end-revision."
11611160
"HEAD"
11621161
limit)))
11631162
(list start-revision)))
1163+
(when (eq vc-log-view-type 'with-diff)
1164+
(list "-p"))
11641165
'("--")))))))
11651166

11661167
(defun vc-git-log-outgoing (buffer remote-location)
@@ -1226,7 +1227,7 @@ log entries."
12261227
(set (make-local-variable 'log-view-file-re) regexp-unmatchable)
12271228
(set (make-local-variable 'log-view-per-file-logs) nil)
12281229
(set (make-local-variable 'log-view-message-re)
1229-
(if (not (memq vc-log-view-type '(long log-search)))
1230+
(if (not (memq vc-log-view-type '(long log-search with-diff)))
12301231
(cadr vc-git-root-log-format)
12311232
"^commit *\\([0-9a-z]+\\)"))
12321233
;; Allow expanding short log entries.
@@ -1235,7 +1236,7 @@ log entries."
12351236
(set (make-local-variable 'log-view-expanded-log-entry-function)
12361237
'vc-git-expanded-log-entry))
12371238
(set (make-local-variable 'log-view-font-lock-keywords)
1238-
(if (not (memq vc-log-view-type '(long log-search)))
1239+
(if (not (memq vc-log-view-type '(long log-search with-diff)))
12391240
(list (cons (nth 1 vc-git-root-log-format)
12401241
(nth 2 vc-git-root-log-format)))
12411242
(append

lisp/vc/vc.el

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,7 +2361,7 @@ or if PL-RETURN is `limit-unsupported'."
23612361
'help-echo "Show the log again, including all entries")))
23622362

23632363
(defun vc-print-log-internal (backend files working-revision
2364-
&optional is-start-revision limit)
2364+
&optional is-start-revision limit type)
23652365
"For specified BACKEND and FILES, show the VC log.
23662366
Leave point at WORKING-REVISION, if it is non-nil.
23672367
If IS-START-REVISION is non-nil, start the log from WORKING-REVISION
@@ -2377,7 +2377,7 @@ earlier revisions. Show up to LIMIT entries (non-nil means unlimited)."
23772377
(shortlog (not (null (memq (if dir-present 'directory 'file)
23782378
vc-log-short-style))))
23792379
(buffer-name "*vc-change-log*")
2380-
(type (if shortlog 'short 'long)))
2380+
(type (or type (if shortlog 'short 'long))))
23812381
(vc-log-internal-common
23822382
backend buffer-name files type
23832383
(lambda (bk buf _type-arg files-arg)
@@ -2393,7 +2393,7 @@ earlier revisions. Show up to LIMIT entries (non-nil means unlimited)."
23932393
(vc-call-backend bk 'show-log-entry working-revision)))
23942394
(lambda (_ignore-auto _noconfirm)
23952395
(vc-print-log-internal backend files working-revision
2396-
is-start-revision limit)))))
2396+
is-start-revision limit type)))))
23972397

23982398
(defvar vc-log-view-type nil
23992399
"Set this to differentiate the different types of logs.")
@@ -2416,7 +2416,12 @@ earlier revisions. Show up to LIMIT entries (non-nil means unlimited)."
24162416
(let ((inhibit-read-only t))
24172417
;; log-view-mode used to be called with inhibit-read-only bound
24182418
;; to t, so let's keep doing it, just in case.
2419-
(vc-call-backend backend 'log-view-mode)
2419+
(vc-call-backend backend
2420+
(if (and (eq type 'with-diff)
2421+
(vc-find-backend-function
2422+
backend 'region-history-mode))
2423+
'region-history-mode
2424+
'log-view-mode))
24202425
(set (make-local-variable 'log-view-vc-backend) backend)
24212426
(set (make-local-variable 'log-view-vc-fileset) files)
24222427
(set (make-local-variable 'revert-buffer-function)
@@ -2475,13 +2480,26 @@ WORKING-REVISION and LIMIT."
24752480
(vc-print-log-internal backend files working-revision nil limit)))
24762481

24772482
;;;###autoload
2478-
(defun vc-print-root-log (&optional limit)
2483+
(defun vc-print-root-log (&optional limit revision)
24792484
"List the change log for the current VC controlled tree in a window.
24802485
If LIMIT is non-nil, it should be a number specifying the maximum
24812486
number of revisions to show; the default is `vc-log-show-limit'.
2482-
When called interactively with a prefix argument, prompt for LIMIT."
2487+
When called interactively with a prefix argument, prompt for LIMIT.
2488+
When the prefix argument is a number, use it as LIMIT.
2489+
A special case is when the prefix argument is 1, in this case
2490+
it asks for the revision and shows it with its diff."
24832491
(interactive
24842492
(cond
2493+
((eq current-prefix-arg 1)
2494+
(let* ((default (thing-at-point 'word))
2495+
(revision (read-string
2496+
(if default
2497+
(format "Revision to show (default %s): " default)
2498+
"Revision to show: ")
2499+
nil nil default)))
2500+
(list 1 revision)))
2501+
((numberp current-prefix-arg)
2502+
(list current-prefix-arg))
24852503
(current-prefix-arg
24862504
(let ((lim (string-to-number
24872505
(read-from-minibuffer
@@ -2492,17 +2510,20 @@ When called interactively with a prefix argument, prompt for LIMIT."
24922510
(list lim)))
24932511
(t
24942512
(list (when (> vc-log-show-limit 0) vc-log-show-limit)))))
2495-
(let ((backend (vc-deduce-backend))
2496-
(default-directory default-directory)
2497-
rootdir)
2513+
(let* ((backend (vc-deduce-backend))
2514+
(default-directory default-directory)
2515+
(with-diff (and (eq limit 1) revision))
2516+
(vc-log-short-style (unless with-diff vc-log-short-style))
2517+
rootdir)
24982518
(if backend
24992519
(setq rootdir (vc-call-backend backend 'root default-directory))
25002520
(setq rootdir (read-directory-name "Directory for VC root-log: "))
25012521
(setq backend (vc-responsible-backend rootdir))
25022522
(unless backend
25032523
(error "Directory is not version controlled")))
25042524
(setq default-directory rootdir)
2505-
(vc-print-log-internal backend (list rootdir) nil nil limit)))
2525+
(vc-print-log-internal backend (list rootdir) revision revision limit
2526+
(when with-diff 'with-diff))))
25062527

25072528
;;;###autoload
25082529
(defun vc-print-branch-log (branch)

0 commit comments

Comments
 (0)