Mercurial > emacs
comparison lisp/vc.el @ 81619:86c056eb5d82
Add new VC operation `revision-completion-table'.
(vc-default-revision-completion-table): New function.
(vc-version-diff, vc-version-other-window): Use it to provide
completion of revision names if the backend provides it.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 26 Jun 2007 17:43:04 +0000 |
parents | 6eafc2a3843a |
children | e7f1f230ec0d |
comparison
equal
deleted
inserted
replaced
81618:42755149d51d | 81619:86c056eb5d82 |
---|---|
320 ;; REV2 is nil, use the current workfile contents as the newer | 320 ;; REV2 is nil, use the current workfile contents as the newer |
321 ;; version. This function should pass the value of (vc-switches | 321 ;; version. This function should pass the value of (vc-switches |
322 ;; BACKEND 'diff) to the backend command. It should return a status | 322 ;; BACKEND 'diff) to the backend command. It should return a status |
323 ;; of either 0 (no differences found), or 1 (either non-empty diff | 323 ;; of either 0 (no differences found), or 1 (either non-empty diff |
324 ;; or the diff is run asynchronously). | 324 ;; or the diff is run asynchronously). |
325 ;; | |
326 ;; - revision-completion-table (file) | |
327 ;; | |
328 ;; Return a completion table for existing revisions of FILE. | |
329 ;; The default is to not use any completion table. | |
325 ;; | 330 ;; |
326 ;; - diff-tree (dir &optional rev1 rev2) | 331 ;; - diff-tree (dir &optional rev1 rev2) |
327 ;; | 332 ;; |
328 ;; Insert the diff for all files at and below DIR into the *vc-diff* | 333 ;; Insert the diff for all files at and below DIR into the *vc-diff* |
329 ;; buffer. The meaning of REV1 and REV2 is the same as for | 334 ;; buffer. The meaning of REV1 and REV2 is the same as for |
1746 (vc-buffer-sync not-urgent) | 1751 (vc-buffer-sync not-urgent) |
1747 (if (vc-workfile-unchanged-p buffer-file-name) | 1752 (if (vc-workfile-unchanged-p buffer-file-name) |
1748 (message "No changes to %s since latest version" file) | 1753 (message "No changes to %s since latest version" file) |
1749 (vc-version-diff file nil nil))))) | 1754 (vc-version-diff file nil nil))))) |
1750 | 1755 |
1756 (defun vc-default-revision-completion-table (backend file) nil) | |
1757 | |
1751 (defun vc-version-diff (file rev1 rev2) | 1758 (defun vc-version-diff (file rev1 rev2) |
1752 "List the differences between FILE's versions REV1 and REV2. | 1759 "List the differences between FILE's versions REV1 and REV2. |
1753 If REV1 is empty or nil it means to use the current workfile version; | 1760 If REV1 is empty or nil it means to use the current workfile version; |
1754 REV2 empty or nil means the current file contents. FILE may also be | 1761 REV2 empty or nil means the current file contents. FILE may also be |
1755 a directory, in that case, generate diffs between the correponding | 1762 a directory, in that case, generate diffs between the correponding |
1756 versions of all registered files in or below it." | 1763 versions of all registered files in or below it." |
1757 (interactive | 1764 (interactive |
1758 (let ((file (expand-file-name | 1765 (let* ((file (expand-file-name |
1759 (read-file-name (if buffer-file-name | 1766 (read-file-name (if buffer-file-name |
1760 "File or dir to diff (default visited file): " | 1767 "File or dir to diff (default visited file): " |
1761 "File or dir to diff: ") | 1768 "File or dir to diff: ") |
1762 default-directory buffer-file-name t))) | 1769 default-directory buffer-file-name t))) |
1763 (rev1-default nil) (rev2-default nil)) | 1770 (rev1-default nil) (rev2-default nil) |
1771 (completion-table (vc-call revision-completion-table file))) | |
1764 ;; compute default versions based on the file state | 1772 ;; compute default versions based on the file state |
1765 (cond | 1773 (cond |
1766 ;; if it's a directory, don't supply any version default | 1774 ;; if it's a directory, don't supply any version default |
1767 ((file-directory-p file) | 1775 ((file-directory-p file) |
1768 nil) | 1776 nil) |
1770 ((not (vc-up-to-date-p file)) | 1778 ((not (vc-up-to-date-p file)) |
1771 (setq rev1-default (vc-workfile-version file))) | 1779 (setq rev1-default (vc-workfile-version file))) |
1772 ;; if the file is not locked, use last and previous version as default | 1780 ;; if the file is not locked, use last and previous version as default |
1773 (t | 1781 (t |
1774 (setq rev1-default (vc-call previous-version file | 1782 (setq rev1-default (vc-call previous-version file |
1775 (vc-workfile-version file))) | 1783 (vc-workfile-version file))) |
1776 (if (string= rev1-default "") (setq rev1-default nil)) | 1784 (if (string= rev1-default "") (setq rev1-default nil)) |
1777 (setq rev2-default (vc-workfile-version file)))) | 1785 (setq rev2-default (vc-workfile-version file)))) |
1778 ;; construct argument list | 1786 ;; construct argument list |
1779 (list file | 1787 (let* ((rev1-prompt (if rev1-default |
1780 (read-string (if rev1-default | 1788 (concat "Older version (default " |
1781 (concat "Older version (default " | 1789 rev1-default "): ") |
1782 rev1-default "): ") | 1790 "Older version: ")) |
1783 "Older version: ") | 1791 (rev2-prompt (concat "Newer version (default " |
1784 nil nil rev1-default) | 1792 (or rev2-default "current source") "): ")) |
1785 (read-string (if rev2-default | 1793 (rev1 (if completion-table |
1786 (concat "Newer version (default " | 1794 (completing-read rev1-prompt completion-table |
1787 rev2-default "): ") | 1795 nil nil nil nil rev1-default) |
1788 "Newer version (default current source): ") | 1796 (read-string rev1-prompt nil nil rev1-default))) |
1789 nil nil rev2-default)))) | 1797 (rev2 (if completion-table |
1798 (completing-read rev2-prompt completion-table | |
1799 nil nil nil nil rev2-default) | |
1800 (read-string rev2-prompt nil nil rev2-default)))) | |
1801 (list file rev1 rev2)))) | |
1790 (if (file-directory-p file) | 1802 (if (file-directory-p file) |
1791 ;; recursive directory diff | 1803 ;; recursive directory diff |
1792 (progn | 1804 (progn |
1793 (vc-setup-buffer "*vc-diff*") | 1805 (vc-setup-buffer "*vc-diff*") |
1794 (if (string-equal rev1 "") (setq rev1 nil)) | 1806 (if (string-equal rev1 "") (setq rev1 nil)) |
1939 ;;;###autoload | 1951 ;;;###autoload |
1940 (defun vc-version-other-window (rev) | 1952 (defun vc-version-other-window (rev) |
1941 "Visit version REV of the current file in another window. | 1953 "Visit version REV of the current file in another window. |
1942 If the current file is named `F', the version is named `F.~REV~'. | 1954 If the current file is named `F', the version is named `F.~REV~'. |
1943 If `F.~REV~' already exists, use it instead of checking it out again." | 1955 If `F.~REV~' already exists, use it instead of checking it out again." |
1944 (interactive "sVersion to visit (default is workfile version): ") | 1956 (interactive |
1957 (save-current-buffer | |
1958 (vc-ensure-vc-buffer) | |
1959 (let ((completion-table | |
1960 (vc-call revision-completion-table buffer-file-name)) | |
1961 (prompt "Version to visit (default is workfile version): ")) | |
1962 (list | |
1963 (if completion-table | |
1964 (completing-read prompt completion-table) | |
1965 (read-string prompt)))))) | |
1945 (vc-ensure-vc-buffer) | 1966 (vc-ensure-vc-buffer) |
1946 (let* ((file buffer-file-name) | 1967 (let* ((file buffer-file-name) |
1947 (version (if (string-equal rev "") | 1968 (version (if (string-equal rev "") |
1948 (vc-workfile-version file) | 1969 (vc-workfile-version file) |
1949 rev))) | 1970 rev))) |