all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nathan Moreau <nathan.moreau@m4x.org>
To: Dmitry Gutov <dgutov@yandex.ru>,
	40967@debbugs.gnu.org, Phil Sainty <psainty@orcon.net.nz>
Subject: bug#40967: 27.0.50; vc-diff in indirect buffers
Date: Wed, 1 Jul 2020 02:19:56 +0200	[thread overview]
Message-ID: <CADDcBWXjJTA92BsG9UGr24uLOQ6vBJc=Ks61ta2dcqp5CMUy8A@mail.gmail.com> (raw)
In-Reply-To: <77dd86b8-c5f8-5a91-a424-74feed90b037@yandex.ru>

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

Here is a new version of the patch, with support for most of the
commands defined in vc.el.

The support is not exhaustive as I was not able to make all commands work
I did not succeed in testing all the commands: vc-delete-file and
vc-rename-file are probably candidates next.

Feedback is very welcome, I am not used to the contribution process on Emacs.
Nathan

On Wed, 17 Jun 2020 at 00:37, Dmitry Gutov <dgutov@yandex.ru> wrote:
>
> On 16.06.2020 15:08, Phil Sainty wrote:
> > Personally I'd be ok with seeing piecemeal changes to commands
> > like these to enable certain common workflows to DTRT with
> > indirect buffers.
>
> All right then.
>
> > I think there will likely be a subset of
> > commands which are of higher value than others, and so there
> > might not be such a vast number of things which are very useful
> > to change in practice.
>
> IDK, seems like it wouldn't simplify the proposed patch. It's short
> already anywa.

[-- Attachment #2: vc-diff-indirect-buffers.diff --]
[-- Type: application/octet-stream, Size: 4667 bytes --]

commit 46841d828c6f1bc9504019266e78d7c565871700
Author: Nathan Moreau <nathan.moreau@m4x.org>
Date:   Wed Jul 1 02:02:25 2020 +0200

    Improve support for indirect buffers.
    
    * lisp/vc/vc.el (vc-deduce-fileset-1): new defun.
    (vc-deduce-fileset): adapt.
    (vc-maybe-buffer-sync): new defun.
    (vc-diff): adapt.
    (vc-ediff): adapt.
    (vc-root-diff): adapt.
    (vc-revision-other-window): adapt.

diff --git lisp/vc/vc.el lisp/vc/vc.el
index c640ba0420..291e10bc8a 100644
--- lisp/vc/vc.el
+++ lisp/vc/vc.el
@@ -1027,7 +1027,9 @@ vc-deduce-fileset
 list of marked files, or the current directory if no files are
 marked.
 Otherwise, if the current buffer is visiting a version-controlled
-file, FILESET is a single-file list containing that file's name.
+file or is an indirect buffer whose base buffer visits a
+version-controlled file, FILESET is a single-file list containing
+that file's name.
 Otherwise, if ALLOW-UNREGISTERED is non-nil and the visited file
 is unregistered, FILESET is a single-file list containing the
 name of the visited file.
@@ -1041,6 +1043,14 @@ vc-deduce-fileset
 the returned list.
 
 BEWARE: this function may change the current buffer."
+  (with-current-buffer (or (buffer-base-buffer) (current-buffer))
+    (vc-deduce-fileset-1 not-state-changing
+                         allow-unregistered
+                         state-model-only-files)))
+
+(defun vc-deduce-fileset-1 (not-state-changing
+                            allow-unregistered
+                            state-model-only-files)
   (let (backend)
     (cond
      ((derived-mode-p 'vc-dir-mode)
@@ -1062,7 +1072,7 @@ vc-deduce-fileset
 				      (derived-mode-p 'dired-mode)))))
       (progn                  ;FIXME: Why not `with-current-buffer'? --Stef.
 	(set-buffer vc-parent-buffer)
-	(vc-deduce-fileset not-state-changing allow-unregistered state-model-only-files)))
+	(vc-deduce-fileset-1 not-state-changing allow-unregistered state-model-only-files)))
      ((and (derived-mode-p 'log-view-mode)
 	   (setq backend (vc-responsible-backend default-directory)))
       (list backend nil))
@@ -1878,6 +1888,10 @@ vc-root-version-diff
        t (list backend (list rootdir)) rev1 rev2
        (called-interactively-p 'interactive)))))
 
+(defun vc-maybe-buffer-sync (not-urgent)
+  (with-current-buffer (or (buffer-base-buffer) (current-buffer))
+    (when buffer-file-name (vc-buffer-sync not-urgent))))
+
 ;;;###autoload
 (defun vc-diff (&optional historic not-urgent)
   "Display diffs between file revisions.
@@ -1890,7 +1904,7 @@ vc-diff
   (interactive (list current-prefix-arg t))
   (if historic
       (call-interactively 'vc-version-diff)
-    (when buffer-file-name (vc-buffer-sync not-urgent))
+    (vc-maybe-buffer-sync not-urgent)
     (vc-diff-internal t (vc-deduce-fileset t) nil nil
 		      (called-interactively-p 'interactive))))
 
@@ -1969,7 +1983,7 @@ vc-ediff
   (interactive (list current-prefix-arg t))
   (if historic
       (call-interactively 'vc-version-ediff)
-    (when buffer-file-name (vc-buffer-sync not-urgent))
+    (vc-maybe-buffer-sync not-urgent)
     (vc-version-ediff (cadr (vc-deduce-fileset t)) nil nil)))
 
 ;;;###autoload
@@ -1986,7 +2000,7 @@ vc-root-diff
   (if historic
       ;; We want the diff for the VC root dir.
       (call-interactively 'vc-root-version-diff)
-    (when buffer-file-name (vc-buffer-sync not-urgent))
+    (vc-maybe-buffer-sync not-urgent)
     (let ((backend (vc-deduce-backend))
 	  (default-directory default-directory)
 	  rootdir working-revision)
@@ -2026,17 +2040,18 @@ vc-revision-other-window
 If the current file is named `F', the revision is named `F.~REV~'.
 If `F.~REV~' already exists, use it instead of checking it out again."
   (interactive
-   (save-current-buffer
+   (with-current-buffer (or (buffer-base-buffer) (current-buffer))
      (vc-ensure-vc-buffer)
      (list
       (vc-read-revision "Revision to visit (default is working revision): "
                         (list buffer-file-name)))))
-  (vc-ensure-vc-buffer)
-  (let* ((file buffer-file-name)
-	 (revision (if (string-equal rev "")
-		      (vc-working-revision file)
-		    rev)))
-    (switch-to-buffer-other-window (vc-find-revision file revision))))
+  (with-current-buffer (or (buffer-base-buffer) (current-buffer))
+    (vc-ensure-vc-buffer)
+    (let* ((file buffer-file-name)
+	   (revision (if (string-equal rev "")
+		         (vc-working-revision file)
+		       rev)))
+      (switch-to-buffer-other-window (vc-find-revision file revision)))))
 
 (defun vc-find-revision (file revision &optional backend)
   "Read REVISION of FILE into a buffer and return the buffer.

  reply	other threads:[~2020-07-01  0:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-29 18:01 bug#40967: 27.0.50; vc-diff in indirect buffers Nathan Moreau
2020-04-29 18:13 ` Dmitry Gutov
2020-06-16 12:08   ` Phil Sainty
2020-06-16 22:37     ` Dmitry Gutov
2020-07-01  0:19       ` Nathan Moreau [this message]
2020-07-09 21:47         ` Nathan Moreau
2020-10-01 17:56           ` Lars Ingebrigtsen
2020-10-02  0:27             ` Nathan Moreau
2020-10-03 17:33               ` Lars Ingebrigtsen
2020-10-03 18:32                 ` Dmitry Gutov
2020-10-05  6:50                   ` Lars Ingebrigtsen
2020-10-15  8:08 ` Richard Copley

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='CADDcBWXjJTA92BsG9UGr24uLOQ6vBJc=Ks61ta2dcqp5CMUy8A@mail.gmail.com' \
    --to=nathan.moreau@m4x.org \
    --cc=40967@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=psainty@orcon.net.nz \
    /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.