comparison lisp/vc.el @ 54618:7cd50dab9d3d

(vc-version-diff, vc-default-diff-tree): Change `rel' -> `rev'. (vc-diff-label): New fun. (vc-diff-internal): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 28 Mar 2004 22:00:19 +0000
parents c3043c1faed3
children 494d96bf5f98 7f60e040ccfc
comparison
equal deleted inserted replaced
54617:9049edac1117 54618:7cd50dab9d3d
5 5
6 ;; Author: FSF (see below for full credits) 6 ;; Author: FSF (see below for full credits)
7 ;; Maintainer: Andre Spiegel <spiegel@gnu.org> 7 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
8 ;; Keywords: tools 8 ;; Keywords: tools
9 9
10 ;; $Id: vc.el,v 1.372 2004/03/26 06:07:55 spiegel Exp $ 10 ;; $Id: vc.el,v 1.373 2004/03/26 16:17:12 monnier Exp $
11 11
12 ;; This file is part of GNU Emacs. 12 ;; This file is part of GNU Emacs.
13 13
14 ;; GNU Emacs is free software; you can redistribute it and/or modify 14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by 15 ;; it under the terms of the GNU General Public License as published by
1675 (vc-buffer-sync not-urgent) 1675 (vc-buffer-sync not-urgent)
1676 (if (vc-workfile-unchanged-p buffer-file-name) 1676 (if (vc-workfile-unchanged-p buffer-file-name)
1677 (message "No changes to %s since latest version" file) 1677 (message "No changes to %s since latest version" file)
1678 (vc-version-diff file nil nil))))) 1678 (vc-version-diff file nil nil)))))
1679 1679
1680 (defun vc-version-diff (file rel1 rel2) 1680 (defun vc-version-diff (file rev1 rev2)
1681 "List the differences between FILE's versions REL1 and REL2. 1681 "List the differences between FILE's versions REV1 and REV2.
1682 If REL1 is empty or nil it means to use the current workfile version; 1682 If REV1 is empty or nil it means to use the current workfile version;
1683 REL2 empty or nil means the current file contents. FILE may also be 1683 REV2 empty or nil means the current file contents. FILE may also be
1684 a directory, in that case, generate diffs between the correponding 1684 a directory, in that case, generate diffs between the correponding
1685 versions of all registered files in or below it." 1685 versions of all registered files in or below it."
1686 (interactive 1686 (interactive
1687 (let ((file (expand-file-name 1687 (let ((file (expand-file-name
1688 (read-file-name (if buffer-file-name 1688 (read-file-name (if buffer-file-name
1689 "File or dir to diff: (default visited file) " 1689 "File or dir to diff: (default visited file) "
1690 "File or dir to diff: ") 1690 "File or dir to diff: ")
1691 default-directory buffer-file-name t))) 1691 default-directory buffer-file-name t)))
1692 (rel1-default nil) (rel2-default nil)) 1692 (rev1-default nil) (rev2-default nil))
1693 ;; compute default versions based on the file state 1693 ;; compute default versions based on the file state
1694 (cond 1694 (cond
1695 ;; if it's a directory, don't supply any version default 1695 ;; if it's a directory, don't supply any version default
1696 ((file-directory-p file) 1696 ((file-directory-p file)
1697 nil) 1697 nil)
1698 ;; if the file is not up-to-date, use current version as older version 1698 ;; if the file is not up-to-date, use current version as older version
1699 ((not (vc-up-to-date-p file)) 1699 ((not (vc-up-to-date-p file))
1700 (setq rel1-default (vc-workfile-version file))) 1700 (setq rev1-default (vc-workfile-version file)))
1701 ;; if the file is not locked, use last and previous version as default 1701 ;; if the file is not locked, use last and previous version as default
1702 (t 1702 (t
1703 (setq rel1-default (vc-call previous-version file 1703 (setq rev1-default (vc-call previous-version file
1704 (vc-workfile-version file))) 1704 (vc-workfile-version file)))
1705 (if (string= rel1-default "") (setq rel1-default nil)) 1705 (if (string= rev1-default "") (setq rev1-default nil))
1706 (setq rel2-default (vc-workfile-version file)))) 1706 (setq rev2-default (vc-workfile-version file))))
1707 ;; construct argument list 1707 ;; construct argument list
1708 (list file 1708 (list file
1709 (read-string (if rel1-default 1709 (read-string (if rev1-default
1710 (concat "Older version: (default " 1710 (concat "Older version: (default "
1711 rel1-default ") ") 1711 rev1-default ") ")
1712 "Older version: ") 1712 "Older version: ")
1713 nil nil rel1-default) 1713 nil nil rev1-default)
1714 (read-string (if rel2-default 1714 (read-string (if rev2-default
1715 (concat "Newer version: (default " 1715 (concat "Newer version: (default "
1716 rel2-default ") ") 1716 rev2-default ") ")
1717 "Newer version (default: current source): ") 1717 "Newer version (default: current source): ")
1718 nil nil rel2-default)))) 1718 nil nil rev2-default))))
1719 (if (file-directory-p file) 1719 (if (file-directory-p file)
1720 ;; recursive directory diff 1720 ;; recursive directory diff
1721 (progn 1721 (progn
1722 (vc-setup-buffer "*vc-diff*") 1722 (vc-setup-buffer "*vc-diff*")
1723 (if (string-equal rel1 "") (setq rel1 nil)) 1723 (if (string-equal rev1 "") (setq rev1 nil))
1724 (if (string-equal rel2 "") (setq rel2 nil)) 1724 (if (string-equal rev2 "") (setq rev2 nil))
1725 (let ((inhibit-read-only t)) 1725 (let ((inhibit-read-only t))
1726 (insert "Diffs between " 1726 (insert "Diffs between "
1727 (or rel1 "last version checked in") 1727 (or rev1 "last version checked in")
1728 " and " 1728 " and "
1729 (or rel2 "current workfile(s)") 1729 (or rev2 "current workfile(s)")
1730 ":\n\n")) 1730 ":\n\n"))
1731 (let ((dir (file-name-as-directory file))) 1731 (let ((dir (file-name-as-directory file)))
1732 (vc-call-backend (vc-responsible-backend dir) 1732 (vc-call-backend (vc-responsible-backend dir)
1733 'diff-tree dir rel1 rel2)) 1733 'diff-tree dir rev1 rev2))
1734 (vc-exec-after `(let ((inhibit-read-only t)) 1734 (vc-exec-after `(let ((inhibit-read-only t))
1735 (insert "\nEnd of diffs.\n")))) 1735 (insert "\nEnd of diffs.\n"))))
1736 ;; Single file diff. It is important that the vc-controlled buffer 1736 ;; Single file diff. It is important that the vc-controlled buffer
1737 ;; is still current at this time, because any local settings in that 1737 ;; is still current at this time, because any local settings in that
1738 ;; buffer should affect the diff command. 1738 ;; buffer should affect the diff command.
1739 (vc-diff-internal file rel1 rel2)) 1739 (vc-diff-internal file rev1 rev2))
1740 (set-buffer "*vc-diff*") 1740 (set-buffer "*vc-diff*")
1741 (if (and (zerop (buffer-size)) 1741 (if (and (zerop (buffer-size))
1742 (not (get-buffer-process (current-buffer)))) 1742 (not (get-buffer-process (current-buffer))))
1743 (progn 1743 (progn
1744 (if rel1 1744 (if rev1
1745 (if rel2 1745 (if rev2
1746 (message "No changes to %s between %s and %s" file rel1 rel2) 1746 (message "No changes to %s between %s and %s" file rev1 rev2)
1747 (message "No changes to %s since %s" file rel1)) 1747 (message "No changes to %s since %s" file rev1))
1748 (message "No changes to %s since latest version" file)) 1748 (message "No changes to %s since latest version" file))
1749 nil) 1749 nil)
1750 (pop-to-buffer (current-buffer)) 1750 (pop-to-buffer (current-buffer))
1751 ;; Gnus-5.8.5 sets up an autoload for diff-mode, even if it's 1751 ;; Gnus-5.8.5 sets up an autoload for diff-mode, even if it's
1752 ;; not available. Work around that. 1752 ;; not available. Work around that.
1756 (insert "No differences found.\n")) 1756 (insert "No differences found.\n"))
1757 (goto-char (point-min)) 1757 (goto-char (point-min))
1758 (shrink-window-if-larger-than-buffer))) 1758 (shrink-window-if-larger-than-buffer)))
1759 t)) 1759 t))
1760 1760
1761 (defun vc-diff-internal (file rel1 rel2) 1761 (defun vc-diff-label (file file-rev rev)
1762 "Run diff to compare FILE's revisions REL1 and REL2. 1762 (concat (file-relative-name file)
1763 (format-time-string "\t%d %b %Y %T %z\t"
1764 (nth 5 (file-attributes file-rev)))
1765 rev))
1766
1767 (defun vc-diff-internal (file rev1 rev2)
1768 "Run diff to compare FILE's revisions REV1 and REV2.
1763 Diff output goes to the *vc-diff* buffer. The exit status of the diff 1769 Diff output goes to the *vc-diff* buffer. The exit status of the diff
1764 command is returned. 1770 command is returned.
1765 1771
1766 This function takes care to set up a proper coding system for diff output. 1772 This function takes care to set up a proper coding system for diff output.
1767 If both revisions are available as local files, then it also does not 1773 If both revisions are available as local files, then it also does not
1768 actually call the backend, but performs a local diff." 1774 actually call the backend, but performs a local diff."
1769 (if (or (not rel1) (string-equal rel1 "")) 1775 (if (or (not rev1) (string-equal rev1 ""))
1770 (setq rel1 (vc-workfile-version file))) 1776 (setq rev1 (vc-workfile-version file)))
1771 (if (string-equal rel2 "") 1777 (if (string-equal rev2 "")
1772 (setq rel2 nil)) 1778 (setq rev2 nil))
1773 (let ((file-rel1 (vc-version-backup-file file rel1)) 1779 (let ((file-rev1 (vc-version-backup-file file rev1))
1774 (file-rel2 (if (not rel2) 1780 (file-rev2 (if (not rev2)
1775 file 1781 file
1776 (vc-version-backup-file file rel2))) 1782 (vc-version-backup-file file rev2)))
1777 (coding-system-for-read (vc-coding-system-for-diff file))) 1783 (coding-system-for-read (vc-coding-system-for-diff file)))
1778 (if (and file-rel1 file-rel2) 1784 (if (and file-rev1 file-rev2)
1779 (apply 'vc-do-command "*vc-diff*" 1 "diff" nil 1785 (apply 'vc-do-command "*vc-diff*" 1 "diff" nil
1780 (append (vc-switches nil 'diff) 1786 (append (vc-switches nil 'diff)
1781 (list (file-relative-name file-rel1) 1787 ;; Provide explicit labels like RCS or CVS would do
1782 (file-relative-name file-rel2)))) 1788 ;; so diff-mode refers to `file' rather than to
1783 (vc-call diff file rel1 rel2)))) 1789 ;; `file-rev1' when trying to find/apply/undo hunks.
1790 (list "-L" (vc-diff-label file file-rev1 rev1)
1791 "-L" (vc-diff-label file file-rev2 rev2)
1792 (file-relative-name file-rev1)
1793 (file-relative-name file-rev2))))
1794 (vc-call diff file rev1 rev2))))
1784 1795
1785 1796
1786 (defun vc-switches (backend op) 1797 (defun vc-switches (backend op)
1787 (let ((switches 1798 (let ((switches
1788 (or (if backend 1799 (or (if backend
1802 1813
1803 ;; Old def for compatibility with Emacs-21.[123]. 1814 ;; Old def for compatibility with Emacs-21.[123].
1804 (defmacro vc-diff-switches-list (backend) `(vc-switches ',backend 'diff)) 1815 (defmacro vc-diff-switches-list (backend) `(vc-switches ',backend 'diff))
1805 (make-obsolete 'vc-diff-switches-list 'vc-switches "21.4") 1816 (make-obsolete 'vc-diff-switches-list 'vc-switches "21.4")
1806 1817
1807 (defun vc-default-diff-tree (backend dir rel1 rel2) 1818 (defun vc-default-diff-tree (backend dir rev1 rev2)
1808 "List differences for all registered files at and below DIR. 1819 "List differences for all registered files at and below DIR.
1809 The meaning of REL1 and REL2 is the same as for `vc-version-diff'." 1820 The meaning of REV1 and REV2 is the same as for `vc-version-diff'."
1810 ;; This implementation does an explicit tree walk, and calls 1821 ;; This implementation does an explicit tree walk, and calls
1811 ;; vc-BACKEND-diff directly for each file. An optimization 1822 ;; vc-BACKEND-diff directly for each file. An optimization
1812 ;; would be to use `vc-diff-internal', so that diffs can be local, 1823 ;; would be to use `vc-diff-internal', so that diffs can be local,
1813 ;; and to call it only for files that are actually changed. 1824 ;; and to call it only for files that are actually changed.
1814 ;; However, this is expensive for some backends, and so it is left 1825 ;; However, this is expensive for some backends, and so it is left
1819 (lambda (f) 1830 (lambda (f)
1820 (vc-exec-after 1831 (vc-exec-after
1821 `(let ((coding-system-for-read (vc-coding-system-for-diff ',f))) 1832 `(let ((coding-system-for-read (vc-coding-system-for-diff ',f)))
1822 (message "Looking at %s" ',f) 1833 (message "Looking at %s" ',f)
1823 (vc-call-backend ',(vc-backend f) 1834 (vc-call-backend ',(vc-backend f)
1824 'diff ',f ',rel1 ',rel2)))))) 1835 'diff ',f ',rev1 ',rev2))))))
1825 1836
1826 (defun vc-coding-system-for-diff (file) 1837 (defun vc-coding-system-for-diff (file)
1827 "Return the coding system for reading diff output for FILE." 1838 "Return the coding system for reading diff output for FILE."
1828 (or coding-system-for-read 1839 (or coding-system-for-read
1829 ;; if we already have this file open, 1840 ;; if we already have this file open,