From: Juri Linkov Date: Wed, 14 Nov 2018 00:14:52 +0000 (+0200) Subject: Support VC revisions in diff-goto-source (bug#33319) X-Git-Tag: emacs-27.0.90~4166 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2ccfb4b5f43b7592af4efe943c24741370f3eb86;p=emacs.git Support VC revisions in diff-goto-source (bug#33319) * lisp/vc/diff-mode.el (diff-vc-revisions): New defvar. (diff-find-source-location): Call vc-find-revision for non-nil values of 'other', diff-vc-backend, diff-vc-revisions. * lisp/vc/vc.el (vc-diff-internal): Set buffer-local diff-vc-revisions to the list of used revisions. * doc/emacs/files.texi (Diff Mode): Update diff-goto-source for VC-related prefix argument. --- diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 649fa8bcb4d..b47be51e24c 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -1530,6 +1530,10 @@ default jumps to the ``old'' file, and the meaning of the prefix argument is reversed. If the prefix argument is a number greater than 8 (e.g., if you type @kbd{C-u C-u C-c C-c}), then this command also sets @code{diff-jump-to-old-file} for the next invocation. +If the source file is under version control (@pxref{Version Control}), +this jumps to the work file by default. With a prefix argument, jump +to the ``old'' revision of the file (@pxref{Old Revisions}), when +point is on the old line, or otherwise jump to the ``new'' revision. @item C-c C-e @findex diff-ediff-patch diff --git a/etc/NEWS b/etc/NEWS index 2f07abb4eb5..2a2010e9d36 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -368,6 +368,10 @@ To disable it, set the new defcustom 'diff-font-lock-refine' to nil. *** File headers can be shortened, mimicking Magit's diff format. To enable it, set the new defcustom 'diff-font-lock-prettify to t. +*** Prefix arg of 'diff-goto-source' means jump to the old revision +of the file under version control if point is on an old changed line, +or to the new revision of the file otherwise. + ** Browse-url *** The function 'browse-url-emacs' can now visit a URL in selected window. diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index cf523685086..8539423eed5 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -55,6 +55,7 @@ ;;; Code: (eval-when-compile (require 'cl-lib)) +(autoload 'vc-find-revision "vc") (defvar add-log-buffer-file-name-function) @@ -104,6 +105,9 @@ when editing big diffs)." (defvar diff-vc-backend nil "The VC backend that created the current Diff buffer, if any.") +(defvar diff-vc-revisions nil + "The VC revisions compared in the current Diff buffer, if any.") + (defvar diff-outline-regexp "\\([*+][*+][*+] [^0-9]\\|@@ ...\\|\\*\\*\\* [0-9].\\|--- [0-9]..\\)") @@ -1736,7 +1740,11 @@ NOPROMPT, if non-nil, means not to prompt the user." (match-string 1))))) (file (or (diff-find-file-name other noprompt) (error "Can't find the file"))) - (buf (find-file-noselect file))) + (revision (and other diff-vc-backend + (nth (if reverse 1 0) diff-vc-revisions))) + (buf (if revision + (vc-find-revision file revision diff-vc-backend) + (find-file-noselect file)))) ;; Update the user preference if he so wished. (when (> (prefix-numeric-value other-file) 8) (setq diff-jump-to-old-file other)) @@ -1862,7 +1870,11 @@ With a prefix argument, try to REVERSE the hunk." `diff-jump-to-old-file' (or its opposite if the OTHER-FILE prefix arg is given) determines whether to jump to the old or the new file. If the prefix arg is bigger than 8 (for example with \\[universal-argument] \\[universal-argument]) -then `diff-jump-to-old-file' is also set, for the next invocations." +then `diff-jump-to-old-file' is also set, for the next invocations. + +Under version control, the OTHER-FILE prefix arg means jump to the old +revision of the file if point is on an old changed line, or to the new +revision of the file otherwise." (interactive (list current-prefix-arg last-input-event)) ;; When pointing at a removal line, we probably want to jump to ;; the old location, and else to the new (i.e. as if reverting). diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index dcfbf26e867..6b7ca02440d 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -987,6 +987,7 @@ Within directories, only files already under version control are noticed." (defvar log-view-vc-backend) (defvar log-edit-vc-backend) (defvar diff-vc-backend) +(defvar diff-vc-revisions) (defun vc-deduce-backend () (cond ((derived-mode-p 'vc-dir-mode) vc-dir-backend) @@ -1728,6 +1729,7 @@ Return t if the buffer had changes, nil otherwise." (set-buffer buffer) (diff-mode) (set (make-local-variable 'diff-vc-backend) (car vc-fileset)) + (set (make-local-variable 'diff-vc-revisions) (list rev1 rev2)) (set (make-local-variable 'revert-buffer-function) (lambda (_ignore-auto _noconfirm) (vc-diff-internal async vc-fileset rev1 rev2 verbose)))