diff options
| author | Stefan Monnier | 2003-05-09 16:33:10 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2003-05-09 16:33:10 +0000 |
| commit | a36319a462218494e4c81fc8fbe629fb34caccbb (patch) | |
| tree | 50be935da1d54e4f84d0a8873d084d3453a8b0cc | |
| parent | 7b33268a39471c028962523cd30da880af5d3ab8 (diff) | |
| download | emacs-a36319a462218494e4c81fc8fbe629fb34caccbb.tar.gz emacs-a36319a462218494e4c81fc8fbe629fb34caccbb.zip | |
New backend functions `delete-file' and `repository-hostname'.
(vc-stay-local): New var. Mostly taken from vc-cvs-stay-local.
(vc-stay-local-p): New fun. Adapted from vc-cvs-stay-local-p.
(vc-diff-switches-list): Revert to the Emacs-21.[123] semantics.
Mark as obsolete.
(vc-delete-file): New command.
(vc-default-rename-file): New function.
(vc-rename-file): Use it.
Be careful to disallow renaming if the file is locked or out-of-date.
(vc-ensure-vc-buffer, vc-next-action-on-file, vc-insert-headers)
(vc-cancel-version, vc-annotate): Use buffer-file-name variable.
| -rw-r--r-- | lisp/vc.el | 134 |
1 files changed, 113 insertions, 21 deletions
diff --git a/lisp/vc.el b/lisp/vc.el index c0d94a683ae..43580f8decb 100644 --- a/lisp/vc.el +++ b/lisp/vc.el | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | ;; Maintainer: Andre Spiegel <spiegel@gnu.org> | 6 | ;; Maintainer: Andre Spiegel <spiegel@gnu.org> |
| 7 | ;; Keywords: tools | 7 | ;; Keywords: tools |
| 8 | 8 | ||
| 9 | ;; $Id: vc.el,v 1.350 2003/02/19 18:56:38 spiegel Exp $ | 9 | ;; $Id: vc.el,v 1.351 2003/05/08 17:41:16 monnier Exp $ |
| 10 | 10 | ||
| 11 | ;; This file is part of GNU Emacs. | 11 | ;; This file is part of GNU Emacs. |
| 12 | 12 | ||
| @@ -305,7 +305,7 @@ | |||
| 305 | ;; is nil, use the current workfile version (as found in the | 305 | ;; is nil, use the current workfile version (as found in the |
| 306 | ;; repository) as the older version; if REV2 is nil, use the current | 306 | ;; repository) as the older version; if REV2 is nil, use the current |
| 307 | ;; workfile contents as the newer version. This function should | 307 | ;; workfile contents as the newer version. This function should |
| 308 | ;; pass the value of (vc-diff-switches-list BACKEND) to the backend | 308 | ;; pass the value of (vc-switches BACKEND 'diff) to the backend |
| 309 | ;; command. It should return a status of either 0 (no differences | 309 | ;; command. It should return a status of either 0 (no differences |
| 310 | ;; found), or 1 (either non-empty diff or the diff is run | 310 | ;; found), or 1 (either non-empty diff or the diff is run |
| 311 | ;; asynchronously). | 311 | ;; asynchronously). |
| @@ -379,6 +379,14 @@ | |||
| 379 | ;; `revert' operations itself, without calling the backend system. The | 379 | ;; `revert' operations itself, without calling the backend system. The |
| 380 | ;; default implementation always returns nil. | 380 | ;; default implementation always returns nil. |
| 381 | ;; | 381 | ;; |
| 382 | ;; - repository-hostname (dirname) | ||
| 383 | ;; | ||
| 384 | ;; Return the hostname that the backend will have to contact | ||
| 385 | ;; in order to operate on a file in DIRNAME. If the return value | ||
| 386 | ;; is nil, it is means that the repository is local. | ||
| 387 | ;; This function is used in `vc-stay-local-p' which backends can use | ||
| 388 | ;; for their convenience. | ||
| 389 | ;; | ||
| 382 | ;; - previous-version (file rev) | 390 | ;; - previous-version (file rev) |
| 383 | ;; | 391 | ;; |
| 384 | ;; Return the version number that precedes REV for FILE. | 392 | ;; Return the version number that precedes REV for FILE. |
| @@ -396,11 +404,18 @@ | |||
| 396 | ;; version control state in such a way that the headers would give | 404 | ;; version control state in such a way that the headers would give |
| 397 | ;; wrong information. | 405 | ;; wrong information. |
| 398 | ;; | 406 | ;; |
| 407 | ;; - delete-file (file) | ||
| 408 | ;; | ||
| 409 | ;; Delete FILE and mark it as deleted in the repository. If this | ||
| 410 | ;; function is not provided, the command `vc-delete-file' will | ||
| 411 | ;; signal an error. | ||
| 412 | ;; | ||
| 399 | ;; - rename-file (old new) | 413 | ;; - rename-file (old new) |
| 400 | ;; | 414 | ;; |
| 401 | ;; Rename file OLD to NEW, both in the working area and in the | 415 | ;; Rename file OLD to NEW, both in the working area and in the |
| 402 | ;; repository. If this function is not provided, the command | 416 | ;; repository. If this function is not provided, the renaming |
| 403 | ;; `vc-rename-file' will signal an error. | 417 | ;; will be done by (vc-delete-file old) and (vc-register new). |
| 418 | ;; | ||
| 404 | 419 | ||
| 405 | ;;; Code: | 420 | ;;; Code: |
| 406 | 421 | ||
| @@ -811,10 +826,10 @@ However, before executing BODY, find FILE, and after BODY, save buffer." | |||
| 811 | (set-buffer (find-file-noselect (dired-get-filename))) | 826 | (set-buffer (find-file-noselect (dired-get-filename))) |
| 812 | (while vc-parent-buffer | 827 | (while vc-parent-buffer |
| 813 | (pop-to-buffer vc-parent-buffer)) | 828 | (pop-to-buffer vc-parent-buffer)) |
| 814 | (if (not (buffer-file-name)) | 829 | (if (not buffer-file-name) |
| 815 | (error "Buffer %s is not associated with a file" (buffer-name)) | 830 | (error "Buffer %s is not associated with a file" (buffer-name)) |
| 816 | (if (not (vc-backend (buffer-file-name))) | 831 | (if (not (vc-backend buffer-file-name)) |
| 817 | (error "File %s is not under version control" (buffer-file-name)))))) | 832 | (error "File %s is not under version control" buffer-file-name))))) |
| 818 | 833 | ||
| 819 | (defun vc-process-filter (p s) | 834 | (defun vc-process-filter (p s) |
| 820 | "An alternative output filter for async process P. | 835 | "An alternative output filter for async process P. |
| @@ -1101,7 +1116,7 @@ If VERBOSE is non-nil, query the user rather than using default parameters." | |||
| 1101 | (find-file-noselect file nil find-file-literally)) | 1116 | (find-file-noselect file nil find-file-literally)) |
| 1102 | (if (not (verify-visited-file-modtime (current-buffer))) | 1117 | (if (not (verify-visited-file-modtime (current-buffer))) |
| 1103 | (if (yes-or-no-p "Replace file on disk with buffer contents? ") | 1118 | (if (yes-or-no-p "Replace file on disk with buffer contents? ") |
| 1104 | (write-file (buffer-file-name)) | 1119 | (write-file buffer-file-name) |
| 1105 | (error "Aborted")) | 1120 | (error "Aborted")) |
| 1106 | ;; Now, check if we have unsaved changes. | 1121 | ;; Now, check if we have unsaved changes. |
| 1107 | (vc-buffer-sync t) | 1122 | (vc-buffer-sync t) |
| @@ -1217,7 +1232,7 @@ If VERBOSE is non-nil, query the user rather than using default parameters." | |||
| 1217 | ;; Must clear any headers here because they wouldn't | 1232 | ;; Must clear any headers here because they wouldn't |
| 1218 | ;; show that the file is locked now. | 1233 | ;; show that the file is locked now. |
| 1219 | (vc-clear-headers file) | 1234 | (vc-clear-headers file) |
| 1220 | (write-file (buffer-file-name)) | 1235 | (write-file buffer-file-name) |
| 1221 | (vc-mode-line file)) | 1236 | (vc-mode-line file)) |
| 1222 | (if (not (yes-or-no-p | 1237 | (if (not (yes-or-no-p |
| 1223 | "Revert to checked-in version, instead? ")) | 1238 | "Revert to checked-in version, instead? ")) |
| @@ -1858,6 +1873,55 @@ actually call the backend, but performs a local diff." | |||
| 1858 | (vc-call diff file rel1 rel2)))) | 1873 | (vc-call diff file rel1 rel2)))) |
| 1859 | 1874 | ||
| 1860 | 1875 | ||
| 1876 | (defcustom vc-stay-local t | ||
| 1877 | "*Non-nil means use local operations when possible for remote repositories. | ||
| 1878 | This avoids slow queries over the network and instead uses heuristics | ||
| 1879 | and past information to determine the current status of a file. | ||
| 1880 | |||
| 1881 | The value can also be a regular expression or list of regular | ||
| 1882 | expressions to match against the host name of a repository; then VC | ||
| 1883 | only stays local for hosts that match it. Alternatively, the value | ||
| 1884 | can be a list of regular expressions where the first element is the | ||
| 1885 | symbol `except'; then VC always stays local except for hosts matched | ||
| 1886 | by these regular expressions." | ||
| 1887 | :type '(choice (const :tag "Always stay local" t) | ||
| 1888 | (const :tag "Don't stay local" nil) | ||
| 1889 | (list :format "\nExamine hostname and %v" :tag "Examine hostname ..." | ||
| 1890 | (set :format "%v" :inline t (const :format "%t" :tag "don't" except)) | ||
| 1891 | (regexp :format " stay local,\n%t: %v" :tag "if it matches") | ||
| 1892 | (repeat :format "%v%i\n" :inline t (regexp :tag "or")))) | ||
| 1893 | :version "21.4" | ||
| 1894 | :group 'vc) | ||
| 1895 | |||
| 1896 | (defun vc-stay-local-p (file) | ||
| 1897 | "Return non-nil if VC should stay local when handling FILE. | ||
| 1898 | This uses the `repository-hostname' backend operation." | ||
| 1899 | (let* ((backend (vc-backend file)) | ||
| 1900 | (sym (vc-make-backend-sym backend 'stay-local)) | ||
| 1901 | (stay-local (if (boundp sym) (symbol-value sym) t))) | ||
| 1902 | (if (eq stay-local t) (setq stay-local vc-stay-local)) | ||
| 1903 | (if (symbolp stay-local) stay-local | ||
| 1904 | (let ((dirname (if (file-directory-p file) | ||
| 1905 | (directory-file-name file) | ||
| 1906 | (file-name-directory file)))) | ||
| 1907 | (eq 'yes | ||
| 1908 | (or (vc-file-getprop dirname 'vc-stay-local-p) | ||
| 1909 | (vc-file-setprop | ||
| 1910 | dirname 'vc-stay-local-p | ||
| 1911 | (let ((hostname (vc-call-backend | ||
| 1912 | backend 'repository-hostname dirname))) | ||
| 1913 | (if (not hostname) | ||
| 1914 | 'no | ||
| 1915 | (let ((default t)) | ||
| 1916 | (if (eq (car-safe stay-local) 'except) | ||
| 1917 | (setq default nil stay-local (cdr stay-local))) | ||
| 1918 | (when (consp stay-local) | ||
| 1919 | (setq stay-local | ||
| 1920 | (mapconcat 'identity stay-local "\\|"))) | ||
| 1921 | (if (if (string-match stay-local hostname) | ||
| 1922 | default (not default)) | ||
| 1923 | 'yes 'no))))))))))) | ||
| 1924 | |||
| 1861 | (defun vc-switches (backend op) | 1925 | (defun vc-switches (backend op) |
| 1862 | (let ((switches | 1926 | (let ((switches |
| 1863 | (or (if backend | 1927 | (or (if backend |
| @@ -1875,8 +1939,9 @@ actually call the backend, but performs a local diff." | |||
| 1875 | ;; any switches in diff-switches. | 1939 | ;; any switches in diff-switches. |
| 1876 | (if (listp switches) switches)))) | 1940 | (if (listp switches) switches)))) |
| 1877 | 1941 | ||
| 1878 | (defun vc-diff-switches-list (backend) (vc-switches backend 'diff)) | 1942 | ;; Old def for compatibility with Emacs-21.[123]. |
| 1879 | ;; (defmacro vc-diff-switches-list (backend) `(vc-switches ',backend 'diff)) | 1943 | (defmacro vc-diff-switches-list (backend) `(vc-switches ',backend 'diff)) |
| 1944 | (make-obsolete 'vc-diff-switches-list 'vc-switches "21.4") | ||
| 1880 | 1945 | ||
| 1881 | (defun vc-default-diff-tree (backend dir rel1 rel2) | 1946 | (defun vc-default-diff-tree (backend dir rel1 rel2) |
| 1882 | "List differences for all registered files at and below DIR. | 1947 | "List differences for all registered files at and below DIR. |
| @@ -1980,7 +2045,7 @@ the variable `vc-BACKEND-header'." | |||
| 1980 | (let* ((delims (cdr (assq major-mode vc-comment-alist))) | 2045 | (let* ((delims (cdr (assq major-mode vc-comment-alist))) |
| 1981 | (comment-start-vc (or (car delims) comment-start "#")) | 2046 | (comment-start-vc (or (car delims) comment-start "#")) |
| 1982 | (comment-end-vc (or (car (cdr delims)) comment-end "")) | 2047 | (comment-end-vc (or (car (cdr delims)) comment-end "")) |
| 1983 | (hdsym (vc-make-backend-sym (vc-backend (buffer-file-name)) | 2048 | (hdsym (vc-make-backend-sym (vc-backend buffer-file-name) |
| 1984 | 'header)) | 2049 | 'header)) |
| 1985 | (hdstrings (and (boundp hdsym) (symbol-value hdsym)))) | 2050 | (hdstrings (and (boundp hdsym) (symbol-value hdsym)))) |
| 1986 | (mapcar (lambda (s) | 2051 | (mapcar (lambda (s) |
| @@ -2561,7 +2626,7 @@ return its name; otherwise return nil." | |||
| 2561 | A prefix argument NOREVERT means do not revert the buffer afterwards." | 2626 | A prefix argument NOREVERT means do not revert the buffer afterwards." |
| 2562 | (interactive "P") | 2627 | (interactive "P") |
| 2563 | (vc-ensure-vc-buffer) | 2628 | (vc-ensure-vc-buffer) |
| 2564 | (let* ((file (buffer-file-name)) | 2629 | (let* ((file buffer-file-name) |
| 2565 | (backend (vc-backend file)) | 2630 | (backend (vc-backend file)) |
| 2566 | (target (vc-workfile-version file))) | 2631 | (target (vc-workfile-version file))) |
| 2567 | (cond | 2632 | (cond |
| @@ -2734,25 +2799,52 @@ backend to NEW-BACKEND, and unregister FILE from the current backend. | |||
| 2734 | (throw 'found f))) | 2799 | (throw 'found f))) |
| 2735 | (error "New file lacks a version control directory"))))) | 2800 | (error "New file lacks a version control directory"))))) |
| 2736 | 2801 | ||
| 2802 | (defun vc-delete-file (file) | ||
| 2803 | "Delete file and mark it as such in the version control system." | ||
| 2804 | (interactive "fVC delete file: ") | ||
| 2805 | (let ((buf (get-file-buffer file))) | ||
| 2806 | (unless (vc-find-backend-function backend 'delete-file) | ||
| 2807 | (error "Renaming files under %s is not supported in VC" backend)) | ||
| 2808 | (if (and buf (buffer-modified-p buf)) | ||
| 2809 | (error "Please save files before deleting them")) | ||
| 2810 | (unless (y-or-n-p (format "Really want to delete %s ? " | ||
| 2811 | (file-name-nondirectory file))) | ||
| 2812 | (error "Abort!")) | ||
| 2813 | (unless (or (file-directory-p file) (null make-backup-files)) | ||
| 2814 | (with-current-buffer (or buf (find-file-noselect file)) | ||
| 2815 | (let ((backup-inhibited nil)) | ||
| 2816 | (backup-buffer)))) | ||
| 2817 | (vc-call delete-file file) | ||
| 2818 | ;; If the backend hasn't deleted the file itself, let's do it for him. | ||
| 2819 | (if (file-exists-p file) (delete-file file)))) | ||
| 2820 | |||
| 2821 | (defun vc-default-rename-file (backend old new) | ||
| 2822 | (condition-case nil | ||
| 2823 | (add-name-to-file old new) | ||
| 2824 | (error (rename-file old new))) | ||
| 2825 | (vc-delete-file old) | ||
| 2826 | (with-current-buffer (find-file-noselect new) | ||
| 2827 | (vc-register))) | ||
| 2828 | |||
| 2737 | ;;;###autoload | 2829 | ;;;###autoload |
| 2738 | (defun vc-rename-file (old new) | 2830 | (defun vc-rename-file (old new) |
| 2739 | "Rename file OLD to NEW, and rename its master file likewise." | 2831 | "Rename file OLD to NEW, and rename its master file likewise." |
| 2740 | (interactive "fVC rename file: \nFRename to: ") | 2832 | (interactive "fVC rename file: \nFRename to: ") |
| 2741 | (let ((oldbuf (get-file-buffer old)) | 2833 | (let ((oldbuf (get-file-buffer old))) |
| 2742 | (backend (vc-backend old))) | ||
| 2743 | (unless (vc-find-backend-function backend 'rename-file) | ||
| 2744 | (error "Renaming files under %s is not supported in VC" backend)) | ||
| 2745 | (if (and oldbuf (buffer-modified-p oldbuf)) | 2834 | (if (and oldbuf (buffer-modified-p oldbuf)) |
| 2746 | (error "Please save files before moving them")) | 2835 | (error "Please save files before moving them")) |
| 2747 | (if (get-file-buffer new) | 2836 | (if (get-file-buffer new) |
| 2748 | (error "Already editing new file name")) | 2837 | (error "Already editing new file name")) |
| 2749 | (if (file-exists-p new) | 2838 | (if (file-exists-p new) |
| 2750 | (error "New file already exists")) | 2839 | (error "New file already exists")) |
| 2751 | (vc-call-backend backend 'rename-file old new) | 2840 | (let ((state (vc-state file))) |
| 2841 | (unless (memq state '(up-to-date edited)) | ||
| 2842 | (error "Please %s files before moving them" | ||
| 2843 | (if (stringp state) "check in" "update")))) | ||
| 2844 | (vc-call rename-file old new) | ||
| 2752 | (vc-file-clearprops old) | 2845 | (vc-file-clearprops old) |
| 2753 | ;; Move the actual file (unless the backend did it already) | 2846 | ;; Move the actual file (unless the backend did it already) |
| 2754 | (if (or (not backend) (file-exists-p old)) | 2847 | (if (file-exists-p old) (rename-file old new)) |
| 2755 | (rename-file old new)) | ||
| 2756 | ;; ?? Renaming a file might change its contents due to keyword expansion. | 2848 | ;; ?? Renaming a file might change its contents due to keyword expansion. |
| 2757 | ;; We should really check out a new copy if the old copy was precisely equal | 2849 | ;; We should really check out a new copy if the old copy was precisely equal |
| 2758 | ;; to some checked in version. However, testing for this is tricky.... | 2850 | ;; to some checked in version. However, testing for this is tricky.... |
| @@ -3037,7 +3129,7 @@ colors. `vc-annotate-background' specifies the background color." | |||
| 3037 | (vc-ensure-vc-buffer) | 3129 | (vc-ensure-vc-buffer) |
| 3038 | (let* ((temp-buffer-name (concat "*Annotate " (buffer-name) "*")) | 3130 | (let* ((temp-buffer-name (concat "*Annotate " (buffer-name) "*")) |
| 3039 | (temp-buffer-show-function 'vc-annotate-display-select) | 3131 | (temp-buffer-show-function 'vc-annotate-display-select) |
| 3040 | (rev (vc-workfile-version (buffer-file-name))) | 3132 | (rev (vc-workfile-version buffer-file-name)) |
| 3041 | (vc-annotate-version | 3133 | (vc-annotate-version |
| 3042 | (if prefix (read-string | 3134 | (if prefix (read-string |
| 3043 | (format "Annotate from version: (default %s) " rev) | 3135 | (format "Annotate from version: (default %s) " rev) |