aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2011-06-26 00:05:39 -0400
committerChong Yidong2011-06-26 00:05:39 -0400
commit2afef60a03c32cd6a9db697f12d6284b2b41415a (patch)
tree4aa579ee89fca6ec9eca71d31e66128effb1f274
parent5fdd4046b937d06b695fb8794ec1cdeb46bdfd8f (diff)
downloademacs-2afef60a03c32cd6a9db697f12d6284b2b41415a.tar.gz
emacs-2afef60a03c32cd6a9db697f12d6284b2b41415a.zip
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.
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/vc/vc.el69
3 files changed, 52 insertions, 25 deletions
diff --git a/etc/NEWS b/etc/NEWS
index ac9a49af864..5fcd8927cf1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -787,6 +787,9 @@ the user for specifics, e.g. a merge source.
787 787
788**** Currently supported for Bzr, Git, and Mercurial. 788**** Currently supported for Bzr, Git, and Mercurial.
789 789
790*** New option `vc-revert-show-diff' controls whether `vc-revert'
791shows a diff while querying the user. It defaults to nil.
792
790*** Log entries in some Log View buffers can be toggled to display a 793*** Log entries in some Log View buffers can be toggled to display a
791longer description by typing RET (log-view-toggle-entry-display). 794longer description by typing RET (log-view-toggle-entry-display).
792In the Log View buffers made by `C-x v L' (vc-print-root-log), you can 795In the Log View buffers made by `C-x v L' (vc-print-root-log), you can
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index dd0c187759e..81f0eaa723a 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,10 @@
12011-06-26 Chong Yidong <cyd@stupidchicken.com> 12011-06-26 Chong Yidong <cyd@stupidchicken.com>
2 2
3 * vc/vc.el (vc-revert-show-diff): New defcustom.
4 (vc-diff-internal): New arg specifying diff buffer.
5 (vc-revert): Obey vc-revert-show-diff. If we show a diff, don't
6 reuse an existing *vc-diff* buffer (Bug#8927).
7
3 * progmodes/cperl-mode.el (cperl-mode): Derive from prog-mode. 8 * progmodes/cperl-mode.el (cperl-mode): Derive from prog-mode.
4 9
52011-06-26 Glenn Morris <rgm@gnu.org> 102011-06-26 Glenn Morris <rgm@gnu.org>
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 3809b5b4293..5e4347d2fe8 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -775,6 +775,12 @@ See `run-hooks'."
775 :type 'hook 775 :type 'hook
776 :group 'vc) 776 :group 'vc)
777 777
778(defcustom vc-revert-show-diff nil
779 "If non-nil, `vc-revert' shows a `vc-diff' buffer before querying."
780 :type 'boolean
781 :group 'vc
782 :version "24.1")
783
778;; Header-insertion hair 784;; Header-insertion hair
779 785
780(defcustom vc-static-header-alist 786(defcustom vc-static-header-alist
@@ -1534,10 +1540,13 @@ to override the value of `vc-diff-switches' and `diff-switches'."
1534(defvar vc-diff-added-files nil 1540(defvar vc-diff-added-files nil
1535 "If non-nil, diff added files by comparing them to /dev/null.") 1541 "If non-nil, diff added files by comparing them to /dev/null.")
1536 1542
1537(defun vc-diff-internal (async vc-fileset rev1 rev2 &optional verbose) 1543(defun vc-diff-internal (async vc-fileset rev1 rev2 &optional verbose buffer)
1538 "Report diffs between two revisions of a fileset. 1544 "Report diffs between two revisions of a fileset.
1539Diff output goes to the *vc-diff* buffer. The function 1545Output goes to the buffer BUFFER, which defaults to *vc-diff*.
1540returns t if the buffer had changes, nil otherwise." 1546BUFFER, if non-nil, should be a buffer or a buffer name.
1547Return t if the buffer had changes, nil otherwise."
1548 (unless buffer
1549 (setq buffer "*vc-diff*"))
1541 (let* ((files (cadr vc-fileset)) 1550 (let* ((files (cadr vc-fileset))
1542 (messages (cons (format "Finding changes in %s..." 1551 (messages (cons (format "Finding changes in %s..."
1543 (vc-delistify files)) 1552 (vc-delistify files))
@@ -1549,7 +1558,7 @@ returns t if the buffer had changes, nil otherwise."
1549 ;; be to call the back end separately for each file. 1558 ;; be to call the back end separately for each file.
1550 (coding-system-for-read 1559 (coding-system-for-read
1551 (if files (vc-coding-system-for-diff (car files)) 'undecided))) 1560 (if files (vc-coding-system-for-diff (car files)) 'undecided)))
1552 (vc-setup-buffer "*vc-diff*") 1561 (vc-setup-buffer buffer)
1553 (message "%s" (car messages)) 1562 (message "%s" (car messages))
1554 ;; Many backends don't handle well the case of a file that has been 1563 ;; Many backends don't handle well the case of a file that has been
1555 ;; added but not yet committed to the repo (notably CVS and Subversion). 1564 ;; added but not yet committed to the repo (notably CVS and Subversion).
@@ -1574,13 +1583,13 @@ returns t if the buffer had changes, nil otherwise."
1574 (error "No revisions of %s exist" file) 1583 (error "No revisions of %s exist" file)
1575 ;; We regard this as "changed". 1584 ;; We regard this as "changed".
1576 ;; Diff it against /dev/null. 1585 ;; Diff it against /dev/null.
1577 (apply 'vc-do-command "*vc-diff*" 1586 (apply 'vc-do-command buffer
1578 1 "diff" file 1587 1 "diff" file
1579 (append (vc-switches nil 'diff) '("/dev/null")))))) 1588 (append (vc-switches nil 'diff) '("/dev/null"))))))
1580 (setq files (nreverse filtered)))) 1589 (setq files (nreverse filtered))))
1581 (let ((vc-disable-async-diff (not async))) 1590 (let ((vc-disable-async-diff (not async)))
1582 (vc-call-backend (car vc-fileset) 'diff files rev1 rev2 "*vc-diff*")) 1591 (vc-call-backend (car vc-fileset) 'diff files rev1 rev2 buffer))
1583 (set-buffer "*vc-diff*") 1592 (set-buffer buffer)
1584 (if (and (zerop (buffer-size)) 1593 (if (and (zerop (buffer-size))
1585 (not (get-buffer-process (current-buffer)))) 1594 (not (get-buffer-process (current-buffer))))
1586 ;; Treat this case specially so as not to pop the buffer. 1595 ;; Treat this case specially so as not to pop the buffer.
@@ -2256,11 +2265,12 @@ This asks for confirmation if the buffer contents are not identical
2256to the working revision (except for keyword expansion)." 2265to the working revision (except for keyword expansion)."
2257 (interactive) 2266 (interactive)
2258 (let* ((vc-fileset (vc-deduce-fileset)) 2267 (let* ((vc-fileset (vc-deduce-fileset))
2259 (files (cadr vc-fileset))) 2268 (files (cadr vc-fileset))
2260 ;; If any of the files is visited by the current buffer, make 2269 (queried nil)
2261 ;; sure buffer is saved. If the user says `no', abort since 2270 diff-buffer)
2262 ;; we cannot show the changes and ask for confirmation to 2271 ;; If any of the files is visited by the current buffer, make sure
2263 ;; discard them. 2272 ;; buffer is saved. If the user says `no', abort since we cannot
2273 ;; show the changes and ask for confirmation to discard them.
2264 (when (or (not files) (memq (buffer-file-name) files)) 2274 (when (or (not files) (memq (buffer-file-name) files))
2265 (vc-buffer-sync nil)) 2275 (vc-buffer-sync nil))
2266 (dolist (file files) 2276 (dolist (file files)
@@ -2268,20 +2278,29 @@ to the working revision (except for keyword expansion)."
2268 (when (and buf (buffer-modified-p buf)) 2278 (when (and buf (buffer-modified-p buf))
2269 (error "Please kill or save all modified buffers before reverting"))) 2279 (error "Please kill or save all modified buffers before reverting")))
2270 (when (vc-up-to-date-p file) 2280 (when (vc-up-to-date-p file)
2271 (unless (yes-or-no-p (format "%s seems up-to-date. Revert anyway? " file)) 2281 (if (yes-or-no-p (format "%s seems up-to-date. Revert anyway? " file))
2282 (setq queried t)
2272 (error "Revert canceled")))) 2283 (error "Revert canceled"))))
2273 (when (vc-diff-internal vc-allow-async-revert vc-fileset nil nil) 2284 (unwind-protect
2274 (unless (yes-or-no-p 2285 (when (if vc-revert-show-diff
2275 (format "Discard changes in %s? " 2286 (progn
2276 (let ((str (vc-delistify files)) 2287 (setq diff-buffer (generate-new-buffer-name "*vc-diff*"))
2277 (nfiles (length files))) 2288 (vc-diff-internal vc-allow-async-revert vc-fileset
2278 (if (< (length str) 50) 2289 nil nil nil diff-buffer))
2279 str 2290 ;; Avoid querying the user again.
2280 (format "%d file%s" nfiles 2291 (null queried))
2281 (if (= nfiles 1) "" "s")))))) 2292 (unless (yes-or-no-p
2282 (error "Revert canceled")) 2293 (format "Discard changes in %s? "
2283 (delete-windows-on "*vc-diff*") 2294 (let ((str (vc-delistify files))
2284 (kill-buffer "*vc-diff*")) 2295 (nfiles (length files)))
2296 (if (< (length str) 50)
2297 str
2298 (format "%d file%s" nfiles
2299 (if (= nfiles 1) "" "s"))))))
2300 (error "Revert canceled")))
2301 (when diff-buffer
2302 (delete-windows-on diff-buffer)
2303 (kill-buffer diff-buffer)))
2285 (dolist (file files) 2304 (dolist (file files)
2286 (message "Reverting %s..." (vc-delistify files)) 2305 (message "Reverting %s..." (vc-delistify files))
2287 (vc-revert-file file) 2306 (vc-revert-file file)