From: Juri Linkov Date: Wed, 27 Nov 2019 22:14:46 +0000 (+0200) Subject: 'C-1 C-x v L' asks for revision and shows its log entry with diff (bug#38044) X-Git-Tag: emacs-27.0.90~501 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f655967b83378b56390904a503ec0f1a19a1a7e9;p=emacs.git '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. --- diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi index 33a1ec0be07..c1f7aed114f 100644 --- a/doc/emacs/maintaining.texi +++ b/doc/emacs/maintaining.texi @@ -991,7 +991,10 @@ file listed on the current line. @file{*vc-change-log*} buffer showing the history of the entire version-controlled directory tree (RCS, SCCS, CVS, and SRC do not support this feature). With a prefix argument, the command prompts -for the maximum number of revisions to display. +for the maximum number of revisions to display. A numeric prefix +argument specifies the maximum number of revisions without prompting. +When the numeric prefix argument is @kbd{M-1}, the command prompts +for the revision ID, and displays its log entry with a diff of changes. The @kbd{C-x v L} history is shown in a compact form, usually showing only the first line of each log entry. However, you can type diff --git a/etc/NEWS b/etc/NEWS index db304508886..f3f9f2f2c65 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -993,6 +993,9 @@ With a prefix argument asks for a command, so for example, 'C-u M-x vc-log-search RET git log -1 f302475 RET' will display just one log entry found by its revision number. ++++ +*** 'C-1 C-x v L' asks for a revision and shows its log entry with diff. + *** 'C-x v =' can now mimic Magit's diff format. Set the new user option 'diff-font-lock-prettify' to t for that, see below under "Diff mode". diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index ca4c66a06dc..71307cdffda 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -708,7 +708,7 @@ or an empty string if none." '(menu-item "Snapshot Stash" vc-git-stash-snapshot :help "Snapshot stash")) (define-key map [cr] - '(menu-item "Create Samed Stash" vc-git-stash + '(menu-item "Create Named Stash" vc-git-stash :help "Create named stash")) (define-key map [de] '(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." ;; If the buffer exists from a previous invocation it might be ;; read-only. (let ((inhibit-read-only t)) - (with-current-buffer - buffer + (with-current-buffer buffer (apply 'vc-git-command buffer 'async files (append @@ -1161,6 +1160,8 @@ If LIMIT is a revision string, use it as an end-revision." "HEAD" limit))) (list start-revision))) + (when (eq vc-log-view-type 'with-diff) + (list "-p")) '("--"))))))) (defun vc-git-log-outgoing (buffer remote-location) @@ -1226,7 +1227,7 @@ log entries." (set (make-local-variable 'log-view-file-re) regexp-unmatchable) (set (make-local-variable 'log-view-per-file-logs) nil) (set (make-local-variable 'log-view-message-re) - (if (not (memq vc-log-view-type '(long log-search))) + (if (not (memq vc-log-view-type '(long log-search with-diff))) (cadr vc-git-root-log-format) "^commit *\\([0-9a-z]+\\)")) ;; Allow expanding short log entries. @@ -1235,7 +1236,7 @@ log entries." (set (make-local-variable 'log-view-expanded-log-entry-function) 'vc-git-expanded-log-entry)) (set (make-local-variable 'log-view-font-lock-keywords) - (if (not (memq vc-log-view-type '(long log-search))) + (if (not (memq vc-log-view-type '(long log-search with-diff))) (list (cons (nth 1 vc-git-root-log-format) (nth 2 vc-git-root-log-format))) (append diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 0d29c80d026..d0d2c39ac3d 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -2361,7 +2361,7 @@ or if PL-RETURN is `limit-unsupported'." 'help-echo "Show the log again, including all entries"))) (defun vc-print-log-internal (backend files working-revision - &optional is-start-revision limit) + &optional is-start-revision limit type) "For specified BACKEND and FILES, show the VC log. Leave point at WORKING-REVISION, if it is non-nil. 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)." (shortlog (not (null (memq (if dir-present 'directory 'file) vc-log-short-style)))) (buffer-name "*vc-change-log*") - (type (if shortlog 'short 'long))) + (type (or type (if shortlog 'short 'long)))) (vc-log-internal-common backend buffer-name files type (lambda (bk buf _type-arg files-arg) @@ -2393,7 +2393,7 @@ earlier revisions. Show up to LIMIT entries (non-nil means unlimited)." (vc-call-backend bk 'show-log-entry working-revision))) (lambda (_ignore-auto _noconfirm) (vc-print-log-internal backend files working-revision - is-start-revision limit))))) + is-start-revision limit type))))) (defvar vc-log-view-type nil "Set this to differentiate the different types of logs.") @@ -2416,7 +2416,12 @@ earlier revisions. Show up to LIMIT entries (non-nil means unlimited)." (let ((inhibit-read-only t)) ;; log-view-mode used to be called with inhibit-read-only bound ;; to t, so let's keep doing it, just in case. - (vc-call-backend backend 'log-view-mode) + (vc-call-backend backend + (if (and (eq type 'with-diff) + (vc-find-backend-function + backend 'region-history-mode)) + 'region-history-mode + 'log-view-mode)) (set (make-local-variable 'log-view-vc-backend) backend) (set (make-local-variable 'log-view-vc-fileset) files) (set (make-local-variable 'revert-buffer-function) @@ -2475,13 +2480,26 @@ WORKING-REVISION and LIMIT." (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 (read-string + (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 @@ -2492,9 +2510,11 @@ When called interactively with a prefix argument, prompt for LIMIT." (list lim))) (t (list (when (> vc-log-show-limit 0) vc-log-show-limit))))) - (let ((backend (vc-deduce-backend)) - (default-directory default-directory) - rootdir) + (let* ((backend (vc-deduce-backend)) + (default-directory default-directory) + (with-diff (and (eq limit 1) revision)) + (vc-log-short-style (unless with-diff vc-log-short-style)) + rootdir) (if backend (setq rootdir (vc-call-backend backend 'root default-directory)) (setq rootdir (read-directory-name "Directory for VC root-log: ")) @@ -2502,7 +2522,8 @@ When called interactively with a prefix argument, prompt for LIMIT." (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 with-diff 'with-diff)))) ;;;###autoload (defun vc-print-branch-log (branch)