emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r104726: New option for showing a dif


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r104726: New option for showing a diff in vc-revert (Bug#8927).
Date: Sun, 26 Jun 2011 00:05:39 -0400
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 104726
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Sun 2011-06-26 00:05:39 -0400
message:
  New option for showing a diff in vc-revert (Bug#8927).
  
  * vc/vc.el (vc-revert-show-diff): New defcustom.
  (vc-diff-internal): New arg specifying diff buffer.
  (vc-revert): Obey vc-revert-show-diff.  If we show a diff, don't
  reuse an existing *vc-diff* buffer.
modified:
  etc/NEWS
  lisp/ChangeLog
  lisp/vc/vc.el
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2011-06-26 01:25:53 +0000
+++ b/etc/NEWS  2011-06-26 04:05:39 +0000
@@ -787,6 +787,9 @@
 
 **** Currently supported for Bzr, Git, and Mercurial.
 
+*** New option `vc-revert-show-diff' controls whether `vc-revert'
+shows a diff while querying the user.  It defaults to nil.
+
 *** Log entries in some Log View buffers can be toggled to display a
 longer description by typing RET (log-view-toggle-entry-display).
 In the Log View buffers made by `C-x v L' (vc-print-root-log), you can

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-06-26 03:42:22 +0000
+++ b/lisp/ChangeLog    2011-06-26 04:05:39 +0000
@@ -1,5 +1,10 @@
 2011-06-26  Chong Yidong  <address@hidden>
 
+       * vc/vc.el (vc-revert-show-diff): New defcustom.
+       (vc-diff-internal): New arg specifying diff buffer.
+       (vc-revert): Obey vc-revert-show-diff.  If we show a diff, don't
+       reuse an existing *vc-diff* buffer (Bug#8927).
+
        * progmodes/cperl-mode.el (cperl-mode): Derive from prog-mode.
 
 2011-06-26  Glenn Morris  <address@hidden>

=== modified file 'lisp/vc/vc.el'
--- a/lisp/vc/vc.el     2011-04-20 23:34:00 +0000
+++ b/lisp/vc/vc.el     2011-06-26 04:05:39 +0000
@@ -775,6 +775,12 @@
   :type 'hook
   :group 'vc)
 
+(defcustom vc-revert-show-diff nil
+  "If non-nil, `vc-revert' shows a `vc-diff' buffer before querying."
+  :type 'boolean
+  :group 'vc
+  :version "24.1")
+
 ;; Header-insertion hair
 
 (defcustom vc-static-header-alist
@@ -1534,10 +1540,13 @@
 (defvar vc-diff-added-files nil
   "If non-nil, diff added files by comparing them to /dev/null.")
 
-(defun vc-diff-internal (async vc-fileset rev1 rev2 &optional verbose)
+(defun vc-diff-internal (async vc-fileset rev1 rev2 &optional verbose buffer)
   "Report diffs between two revisions of a fileset.
-Diff output goes to the *vc-diff* buffer.  The function
-returns t if the buffer had changes, nil otherwise."
+Output goes to the buffer BUFFER, which defaults to *vc-diff*.
+BUFFER, if non-nil, should be a buffer or a buffer name.
+Return t if the buffer had changes, nil otherwise."
+  (unless buffer
+    (setq buffer "*vc-diff*"))
   (let* ((files (cadr vc-fileset))
         (messages (cons (format "Finding changes in %s..."
                                  (vc-delistify files))
@@ -1549,7 +1558,7 @@
         ;; be to call the back end separately for each file.
         (coding-system-for-read
          (if files (vc-coding-system-for-diff (car files)) 'undecided)))
-    (vc-setup-buffer "*vc-diff*")
+    (vc-setup-buffer buffer)
     (message "%s" (car messages))
     ;; Many backends don't handle well the case of a file that has been
     ;; added but not yet committed to the repo (notably CVS and Subversion).
@@ -1574,13 +1583,13 @@
                 (error "No revisions of %s exist" file)
               ;; We regard this as "changed".
               ;; Diff it against /dev/null.
-              (apply 'vc-do-command "*vc-diff*"
+              (apply 'vc-do-command buffer
                      1 "diff" file
                      (append (vc-switches nil 'diff) '("/dev/null"))))))
         (setq files (nreverse filtered))))
     (let ((vc-disable-async-diff (not async)))
-      (vc-call-backend (car vc-fileset) 'diff files rev1 rev2 "*vc-diff*"))
-    (set-buffer "*vc-diff*")
+      (vc-call-backend (car vc-fileset) 'diff files rev1 rev2 buffer))
+    (set-buffer buffer)
     (if (and (zerop (buffer-size))
              (not (get-buffer-process (current-buffer))))
         ;; Treat this case specially so as not to pop the buffer.
@@ -2256,11 +2265,12 @@
 to the working revision (except for keyword expansion)."
   (interactive)
   (let* ((vc-fileset (vc-deduce-fileset))
-        (files (cadr vc-fileset)))
-    ;; If any of the files is visited by the current buffer, make
-    ;; sure buffer is saved.  If the user says `no', abort since
-    ;; we cannot show the changes and ask for confirmation to
-    ;; discard them.
+        (files (cadr vc-fileset))
+        (queried nil)
+        diff-buffer)
+    ;; If any of the files is visited by the current buffer, make sure
+    ;; buffer is saved.  If the user says `no', abort since we cannot
+    ;; show the changes and ask for confirmation to discard them.
     (when (or (not files) (memq (buffer-file-name) files))
       (vc-buffer-sync nil))
     (dolist (file files)
@@ -2268,20 +2278,29 @@
        (when (and buf (buffer-modified-p buf))
          (error "Please kill or save all modified buffers before reverting")))
       (when (vc-up-to-date-p file)
-       (unless (yes-or-no-p (format "%s seems up-to-date.  Revert anyway? " 
file))
+       (if (yes-or-no-p (format "%s seems up-to-date.  Revert anyway? " file))
+           (setq queried t)
          (error "Revert canceled"))))
-    (when (vc-diff-internal vc-allow-async-revert vc-fileset nil nil)
-      (unless (yes-or-no-p
-              (format "Discard changes in %s? "
-                      (let ((str (vc-delistify files))
-                            (nfiles (length files)))
-                        (if (< (length str) 50)
-                            str
-                          (format "%d file%s" nfiles
-                                  (if (= nfiles 1) "" "s"))))))
-       (error "Revert canceled"))
-      (delete-windows-on "*vc-diff*")
-      (kill-buffer "*vc-diff*"))
+    (unwind-protect
+       (when (if vc-revert-show-diff
+                 (progn
+                   (setq diff-buffer (generate-new-buffer-name "*vc-diff*"))
+                   (vc-diff-internal vc-allow-async-revert vc-fileset
+                                     nil nil nil diff-buffer))
+               ;; Avoid querying the user again.
+               (null queried))
+         (unless (yes-or-no-p
+                  (format "Discard changes in %s? "
+                          (let ((str (vc-delistify files))
+                                (nfiles (length files)))
+                            (if (< (length str) 50)
+                                str
+                              (format "%d file%s" nfiles
+                                      (if (= nfiles 1) "" "s"))))))
+           (error "Revert canceled")))
+      (when diff-buffer
+       (delete-windows-on diff-buffer)
+       (kill-buffer diff-buffer)))
     (dolist (file files)
       (message "Reverting %s..." (vc-delistify files))
       (vc-revert-file file)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]