all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: 33319@debbugs.gnu.org
Subject: bug#33319: Support revisions in diff-goto-source
Date: Thu, 08 Nov 2018 23:05:10 +0200	[thread overview]
Message-ID: <87lg63p9fd.fsf@mail.linkov.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 773 bytes --]

Severity: wishlist
Tags: patch

Currently diff-goto-source with no prefix arg jumps to the new file,
and with a prefix arg jumps to the old file.

It does nothing special when the diff buffer is created by
a version control system, because the same current file is
visited by old and new.  This is a useful default behavior
to visit the current file and continue making changes
at an approximate location of the difference.

However, often this fails to find the change in old revisions.

So the proposed feature is backward-compatible: in the diff buffer
created by a version control system, with a prefix arg it will jump
to an old revision of the file.

It is very useful to look at the context of changed lines 
of the file as it was at the time of that old revision.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: diff-goto-source.1.patch --]
[-- Type: text/x-diff, Size: 3093 bytes --]

diff --git a/etc/NEWS b/etc/NEWS
index 1020a2a0ea..36ad3d82df 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -353,6 +353,11 @@ 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.
 
+*** In the diff buffer created by a version control system, the prefix
+arg of diff-goto-source means it jumps to the old revision of the file
+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/vc.el b/lisp/vc/vc.el
index dcfbf26e86..6b7ca02440 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1728,6 +1729,7 @@ vc-diff-internal
     (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)))
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index cf52368508..b41206296d 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -104,6 +105,9 @@ diff-font-lock-prettify
 (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 @@ diff-find-source-location
 		       (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 @@ diff-goto-source
 `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.
+
+In the diff buffer created by a version control system, the OTHER-FILE
+prefix arg means it jumps 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).

             reply	other threads:[~2018-11-08 21:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-08 21:05 Juri Linkov [this message]
2018-11-09  7:52 ` bug#33319: Support revisions in diff-goto-source Eli Zaretskii
2018-11-10 21:12   ` Juri Linkov
2018-11-11 15:40     ` Eli Zaretskii
2018-11-14  0:24       ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lg63p9fd.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=33319@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.