comparison lisp/vc.el @ 36710:66e9d0506b71

(vc-do-command): If the destination buffer is already current, don't set it up and don't erase it. Updated doc string to reflect that. (vc-version-diff): When doing a single file diff, don't switch to the *vc-diff* buffer before the command. This is to preserve local variable bindings that might affect the diff command. (vc-print-log): Don't switch to the *vc* buffer before the command, so that local variable bindings are preserved.
author André Spiegel <spiegel@gnu.org>
date Sat, 10 Mar 2001 10:44:35 +0000
parents 20a768ca0cf8
children 94c0503d3f2d
comparison
equal deleted inserted replaced
36709:9566f100bdd3 36710:66e9d0506b71
3 ;; Copyright (C) 1992,93,94,95,96,97,98,2000,2001 Free Software Foundation, Inc. 3 ;; Copyright (C) 1992,93,94,95,96,97,98,2000,2001 Free Software Foundation, Inc.
4 4
5 ;; Author: FSF (see below for full credits) 5 ;; Author: FSF (see below for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org> 6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
7 7
8 ;; $Id: vc.el,v 1.296 2001/02/01 17:41:06 fx Exp $ 8 ;; $Id: vc.el,v 1.297 2001/02/26 13:45:06 spiegel Exp $
9 9
10 ;; This file is part of GNU Emacs. 10 ;; This file is part of GNU Emacs.
11 11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify 12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by 13 ;; it under the terms of the GNU General Public License as published by
238 ;; 238 ;;
239 ;; HISTORY FUNCTIONS 239 ;; HISTORY FUNCTIONS
240 ;; 240 ;;
241 ;; * print-log (file) 241 ;; * print-log (file)
242 ;; 242 ;;
243 ;; Insert the revision log of FILE into the current buffer. 243 ;; Insert the revision log of FILE into the *vc* buffer.
244 ;; 244 ;;
245 ;; - show-log-entry (version) 245 ;; - show-log-entry (version)
246 ;; 246 ;;
247 ;; If provided, search the log entry for VERSION in the current buffer, 247 ;; If provided, search the log entry for VERSION in the current buffer,
248 ;; and make sure it is displayed in the buffer's window. The default 248 ;; and make sure it is displayed in the buffer's window. The default
275 ;; default implementation runs rcs2log, which handles RCS- and 275 ;; default implementation runs rcs2log, which handles RCS- and
276 ;; CVS-style logs. 276 ;; CVS-style logs.
277 ;; 277 ;;
278 ;; * diff (file &optional rev1 rev2) 278 ;; * diff (file &optional rev1 rev2)
279 ;; 279 ;;
280 ;; Insert the diff for FILE into the current buffer. If REV1 and REV2 280 ;; Insert the diff for FILE into the *vc-diff* buffer. If REV1 and REV2
281 ;; are non-nil, report differences from REV1 to REV2. If REV1 is nil, 281 ;; are non-nil, report differences from REV1 to REV2. If REV1 is nil,
282 ;; use the current workfile version (as found in the repository) as the 282 ;; use the current workfile version (as found in the repository) as the
283 ;; older version; if REV2 is nil, use the current workfile contents as 283 ;; older version; if REV2 is nil, use the current workfile contents as
284 ;; the newer version. This function should return a status of either 0 284 ;; the newer version. This function should return a status of either 0
285 ;; (no differences found), or 1 (either non-empty diff or the diff is 285 ;; (no differences found), or 1 (either non-empty diff or the diff is
824 Each function is called inside the buffer in which the command was run 824 Each function is called inside the buffer in which the command was run
825 and is passed 3 argument: the COMMAND, the FILE and the FLAGS.") 825 and is passed 3 argument: the COMMAND, the FILE and the FLAGS.")
826 826
827 (defun vc-do-command (buffer okstatus command file &rest flags) 827 (defun vc-do-command (buffer okstatus command file &rest flags)
828 "Execute a version control command, notifying user and checking for errors. 828 "Execute a version control command, notifying user and checking for errors.
829 Output from COMMAND goes to BUFFER, or *vc* if BUFFER is nil or the current 829 Output from COMMAND goes to BUFFER, or *vc* if BUFFER is nil or the
830 buffer (which is assumed to be properly setup) if BUFFER is t. The 830 current buffer if BUFFER is t. If the destination buffer is not
831 command is considered successful if its exit status does not exceed 831 already current, set it up properly and erase it. The command is
832 OKSTATUS (if OKSTATUS is nil, that means to ignore errors, if it is 'async, 832 considered successful if its exit status does not exceed OKSTATUS (if
833 that means not to wait for termination of the subprocess). FILE is 833 OKSTATUS is nil, that means to ignore errors, if it is 'async, that
834 the name of the working file (may also be nil, to execute commands 834 means not to wait for termination of the subprocess). FILE is the
835 that don't expect a file name). If an optional list of FLAGS is present, 835 name of the working file (may also be nil, to execute commands that
836 don't expect a file name). If an optional list of FLAGS is present,
836 that is inserted into the command line before the filename." 837 that is inserted into the command line before the filename."
837 (and file (setq file (expand-file-name file))) 838 (and file (setq file (expand-file-name file)))
838 (if vc-command-messages 839 (if vc-command-messages
839 (message "Running %s on %s..." command file)) 840 (message "Running %s on %s..." command file))
840 (save-current-buffer 841 (save-current-buffer
841 (unless (eq buffer t) (vc-setup-buffer buffer)) 842 (unless (or (eq buffer t)
843 (and (stringp buffer)
844 (string= (buffer-name) buffer))
845 (eq buffer (current-buffer)))
846 (vc-setup-buffer buffer))
842 (let ((squeezed nil) 847 (let ((squeezed nil)
843 (inhibit-read-only t) 848 (inhibit-read-only t)
844 (status 0)) 849 (status 0))
845 (setq squeezed (delq nil (copy-sequence flags))) 850 (setq squeezed (delq nil (copy-sequence flags)))
846 (when file 851 (when file
1725 (read-string (if rel2-default 1730 (read-string (if rel2-default
1726 (concat "Newer version: (default " 1731 (concat "Newer version: (default "
1727 rel2-default ") ") 1732 rel2-default ") ")
1728 "Newer version (default: current source): ") 1733 "Newer version (default: current source): ")
1729 nil nil rel2-default)))) 1734 nil nil rel2-default))))
1730 (vc-setup-buffer "*vc-diff*")
1731 (if (file-directory-p file) 1735 (if (file-directory-p file)
1732 ;; recursive directory diff 1736 ;; recursive directory diff
1733 (let ((inhibit-read-only t)) 1737 (progn
1738 (vc-setup-buffer "*vc-diff*")
1734 (if (string-equal rel1 "") (setq rel1 nil)) 1739 (if (string-equal rel1 "") (setq rel1 nil))
1735 (if (string-equal rel2 "") (setq rel2 nil)) 1740 (if (string-equal rel2 "") (setq rel2 nil))
1736 (insert "Diffs between " 1741 (let ((inhibit-read-only t))
1737 (or rel1 "last version checked in") 1742 (insert "Diffs between "
1738 " and " 1743 (or rel1 "last version checked in")
1739 (or rel2 "current workfile(s)") 1744 " and "
1740 ":\n\n") 1745 (or rel2 "current workfile(s)")
1746 ":\n\n"))
1741 (setq default-directory (file-name-as-directory file)) 1747 (setq default-directory (file-name-as-directory file))
1742 ;; FIXME: this should do a single exec in CVS. 1748 ;; FIXME: this should do a single exec in CVS.
1743 (vc-file-tree-walk 1749 (vc-file-tree-walk
1744 default-directory 1750 default-directory
1745 (lambda (f) 1751 (lambda (f)
1757 (let ((file-rel1 (vc-version-backup-file file rel1)) 1763 (let ((file-rel1 (vc-version-backup-file file rel1))
1758 (file-rel2 (if (not rel2) 1764 (file-rel2 (if (not rel2)
1759 file 1765 file
1760 (vc-version-backup-file file rel2)))) 1766 (vc-version-backup-file file rel2))))
1761 (if (and file-rel1 file-rel2) 1767 (if (and file-rel1 file-rel2)
1762 (apply 'vc-do-command t 1 "diff" nil 1768 (apply 'vc-do-command "*vc-diff*" 1 "diff" nil
1763 (append (if (listp diff-switches) 1769 (append (if (listp diff-switches)
1764 diff-switches 1770 diff-switches
1765 (list diff-switches)) 1771 (list diff-switches))
1766 (if (listp vc-diff-switches) 1772 (if (listp vc-diff-switches)
1767 vc-diff-switches 1773 vc-diff-switches
1768 (list vc-diff-switches)) 1774 (list vc-diff-switches))
1769 (list (file-relative-name file-rel1) 1775 (list (file-relative-name file-rel1)
1770 (file-relative-name file-rel2)))) 1776 (file-relative-name file-rel2))))
1771 (cd (file-name-directory file))
1772 (vc-call diff file rel1 rel2)))) 1777 (vc-call diff file rel1 rel2))))
1778 (set-buffer "*vc-diff*")
1773 (if (and (zerop (buffer-size)) 1779 (if (and (zerop (buffer-size))
1774 (not (get-buffer-process (current-buffer)))) 1780 (not (get-buffer-process (current-buffer))))
1775 (progn 1781 (progn
1776 (if rel1 1782 (if rel1
1777 (if rel2 1783 (if rel2
2361 (defun vc-print-log () 2367 (defun vc-print-log ()
2362 "List the change log of the current buffer in a window." 2368 "List the change log of the current buffer in a window."
2363 (interactive) 2369 (interactive)
2364 (vc-ensure-vc-buffer) 2370 (vc-ensure-vc-buffer)
2365 (let ((file buffer-file-name)) 2371 (let ((file buffer-file-name))
2366 (vc-setup-buffer nil)
2367 (setq default-directory (file-name-directory file))
2368 (vc-call print-log file) 2372 (vc-call print-log file)
2373 (set-buffer "*vc*")
2369 (pop-to-buffer (current-buffer)) 2374 (pop-to-buffer (current-buffer))
2370 (if (fboundp 'log-view-mode) (log-view-mode)) 2375 (if (fboundp 'log-view-mode) (log-view-mode))
2371 (vc-exec-after 2376 (vc-exec-after
2372 `(progn 2377 `(progn
2373 (goto-char (point-max)) (forward-line -1) 2378 (goto-char (point-max)) (forward-line -1)