comparison lisp/vc.el @ 31810:495ca3bd372d

(vc-index-of, vc-transfer-file, vc-default-receive-file): New functions. (vc-next-action-on-file): Call vc-transfer-file at appropriate places. (vc-switch-backend): New function. (vc-prefix-map): Bind `vc-switch-backend' to `b'. (vc-register): Fix prompt. (vc-unregister, vc-default-unregister): New functions. (vc-version-diff): Handle empty buffer in sentinel.
author André Spiegel <spiegel@gnu.org>
date Thu, 21 Sep 2000 13:27:08 +0000
parents a42f956dd8ad
children 69ccb7fbb1c1
comparison
equal deleted inserted replaced
31809:a2c432c6b343 31810:495ca3bd372d
71 ;;; Code: 71 ;;; Code:
72 72
73 ;;;;;;;;;;;;;;;;; Backend-specific functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 73 ;;;;;;;;;;;;;;;;; Backend-specific functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
74 ;; 74 ;;
75 ;; for each operation FUN, the backend should provide a function vc-BACKEND-FUN. 75 ;; for each operation FUN, the backend should provide a function vc-BACKEND-FUN.
76 ;; Operations marked with a `-' instead of a `*' have a sensible default 76 ;; Operations marked with a `-' instead of a `*' are optional.
77 ;; behavior.
78 77
79 ;; * registered (file) 78 ;; * registered (file)
80 ;; * state (file) 79 ;; * state (file)
81 ;; - state-heuristic (file) 80 ;; - state-heuristic (file)
82 ;; The default behavior delegates to `state'. 81 ;; The default behavior delegates to `state'.
89 ;; Only needed if state `needs-merge' is possible. 88 ;; Only needed if state `needs-merge' is possible.
90 ;; - merge (file rev1 rev2) 89 ;; - merge (file rev1 rev2)
91 ;; - steal-lock (file &optional version) 90 ;; - steal-lock (file &optional version)
92 ;; Only required if files can be locked by somebody else. 91 ;; Only required if files can be locked by somebody else.
93 ;; * register (file rev comment) 92 ;; * register (file rev comment)
93 ;; * unregister (file backend)
94 ;; - receive-file (file move)
94 ;; - responsible-p (file) 95 ;; - responsible-p (file)
95 ;; Should also work if FILE is a directory (ends with a slash). 96 ;; Should also work if FILE is a directory (ends with a slash).
96 ;; - could-register (file) 97 ;; - could-register (file)
97 ;; * checkout (file writable &optional rev destfile) 98 ;; * checkout (file writable &optional rev destfile)
98 ;; Checkout revision REV of FILE into DESTFILE. 99 ;; Checkout revision REV of FILE into DESTFILE.
133 ;; If UPDATE is non-nil, then update buffers of any files in the snapshot 134 ;; If UPDATE is non-nil, then update buffers of any files in the snapshot
134 ;; that are currently visited. 135 ;; that are currently visited.
135 ;; * print-log (file) 136 ;; * print-log (file)
136 ;; Insert the revision log of FILE into the current buffer. 137 ;; Insert the revision log of FILE into the current buffer.
137 ;; - show-log-entry (version) 138 ;; - show-log-entry (version)
139 ;; - comment-history (file)
138 ;; - update-changelog (files) 140 ;; - update-changelog (files)
139 ;; Find changelog entries for FILES, or for all files at or below 141 ;; Find changelog entries for FILES, or for all files at or below
140 ;; the default-directory if FILES is nil. 142 ;; the default-directory if FILES is nil.
141 ;; * latest-on-branch-p (file) 143 ;; * latest-on-branch-p (file)
142 ;; - cancel-version (file writable) 144 ;; - cancel-version (file writable)
370 ;;; The main keymap 372 ;;; The main keymap
371 373
372 (defvar vc-prefix-map 374 (defvar vc-prefix-map
373 (let ((map (make-sparse-keymap))) 375 (let ((map (make-sparse-keymap)))
374 (define-key map "a" 'vc-update-change-log) 376 (define-key map "a" 'vc-update-change-log)
377 (define-key map "b" 'vc-switch-backend)
375 (define-key map "c" 'vc-cancel-version) 378 (define-key map "c" 'vc-cancel-version)
376 (define-key map "d" 'vc-directory) 379 (define-key map "d" 'vc-directory)
377 (define-key map "g" 'vc-annotate) 380 (define-key map "g" 'vc-annotate)
378 (define-key map "h" 'vc-insert-headers) 381 (define-key map "h" 'vc-insert-headers)
379 (define-key map "i" 'vc-register) 382 (define-key map "i" 'vc-register)
831 834
832 ;; Do the right thing 835 ;; Do the right thing
833 (if (not (vc-registered file)) 836 (if (not (vc-registered file))
834 (vc-register verbose comment) 837 (vc-register verbose comment)
835 (vc-recompute-state file) 838 (vc-recompute-state file)
839 (vc-mode-line file)
836 (setq state (vc-state file)) 840 (setq state (vc-state file))
837 (cond 841 (cond
838 ;; up-to-date 842 ;; up-to-date
839 ((or (eq state 'up-to-date) 843 ((or (eq state 'up-to-date)
840 (and verbose (eq state 'needs-patch))) 844 (and verbose (eq state 'needs-patch)))
841 (cond 845 (cond
842 (verbose 846 (verbose
843 ;; go to a different version 847 ;; go to a different version
844 (setq version (read-string "Branch or version to move to: ")) 848 (setq version
845 (vc-checkout file (eq (vc-checkout-model file) 'implicit) version)) 849 (read-string "Branch, version, or backend to move to: "))
850 (let ((vsym (intern (upcase version))))
851 (if (member vsym vc-handled-backends)
852 (vc-transfer-file file vsym)
853 (vc-checkout file (eq (vc-checkout-model file) 'implicit)
854 version))))
846 ((not (eq (vc-checkout-model file) 'implicit)) 855 ((not (eq (vc-checkout-model file) 'implicit))
847 ;; check the file out 856 ;; check the file out
848 (vc-checkout file t)) 857 (vc-checkout file t))
849 (t 858 (t
850 ;; do nothing 859 ;; do nothing
874 ;; DO NOT revert the file without asking the user! 883 ;; DO NOT revert the file without asking the user!
875 (if (not visited) (find-file-other-window file)) 884 (if (not visited) (find-file-other-window file))
876 (if (yes-or-no-p "Revert to master version? ") 885 (if (yes-or-no-p "Revert to master version? ")
877 (vc-revert-buffer))) 886 (vc-revert-buffer)))
878 (t ;; normal action 887 (t ;; normal action
879 (if verbose (setq version (read-string "New version: "))) 888 (if (not verbose)
880 (vc-checkin file version comment)))) 889 (vc-checkin file nil comment)
890 (setq version (read-string "New version or backend: "))
891 (let ((vsym (intern (upcase version))))
892 (if (member vsym vc-handled-backends)
893 (vc-transfer-file file vsym)
894 (vc-checkin file version comment)))))))
881 895
882 ;; locked by somebody else 896 ;; locked by somebody else
883 ((stringp state) 897 ((stringp state)
884 (if comment 898 (if comment
885 (error "Sorry, you can't steal the lock on %s this way" 899 (error "Sorry, you can't steal the lock on %s this way"
1042 (set-buffer-modified-p t)) 1056 (set-buffer-modified-p t))
1043 (vc-buffer-sync) 1057 (vc-buffer-sync)
1044 1058
1045 (vc-start-entry buffer-file-name 1059 (vc-start-entry buffer-file-name
1046 (if set-version 1060 (if set-version
1047 (read-string "Initial version level for %s: " 1061 (read-string (format "Initial version level for %s: "
1048 (buffer-name)) 1062 (buffer-name)))
1049 ;; TODO: Use backend-specific init version. 1063 ;; TODO: Use backend-specific init version.
1050 vc-default-init-version) 1064 vc-default-init-version)
1051 (or comment (not vc-initial-comment)) 1065 (or comment (not vc-initial-comment))
1052 "Enter initial comment." 1066 "Enter initial comment."
1053 (lambda (file rev comment) 1067 (lambda (file rev comment)
1090 1104
1091 (defun vc-default-could-register (backend file) 1105 (defun vc-default-could-register (backend file)
1092 "Return non-nil if BACKEND could be used to register FILE. 1106 "Return non-nil if BACKEND could be used to register FILE.
1093 The default implementation returns t for all files." 1107 The default implementation returns t for all files."
1094 t) 1108 t)
1109
1110 (defun vc-unregister (file backend)
1111 "Unregister FILE from version control system BACKEND."
1112 (vc-call-backend backend 'unregister file)
1113 (vc-file-clearprops file))
1114
1115 (defun vc-default-unregister (backend file)
1116 "Default implementation of vc-unregister, signals an error."
1117 (error "Unregistering files is not supported for %s" backend))
1095 1118
1096 (defun vc-resynch-window (file &optional keep noquery) 1119 (defun vc-resynch-window (file &optional keep noquery)
1097 "If FILE is in the current buffer, either revert or unvisit it. 1120 "If FILE is in the current buffer, either revert or unvisit it.
1098 The choice between revert (to see expanded keywords) and unvisit depends on 1121 The choice between revert (to see expanded keywords) and unvisit depends on
1099 `vc-keep-workfiles'. NOQUERY if non-nil inhibits confirmation for 1122 `vc-keep-workfiles'. NOQUERY if non-nil inhibits confirmation for
1486 nil) 1509 nil)
1487 (pop-to-buffer (current-buffer)) 1510 (pop-to-buffer (current-buffer))
1488 ;; Gnus-5.8.5 sets up an autoload for diff-mode, even if it's 1511 ;; Gnus-5.8.5 sets up an autoload for diff-mode, even if it's
1489 ;; not available. Work around that. 1512 ;; not available. Work around that.
1490 (if (require 'diff-mode nil t) (diff-mode)) 1513 (if (require 'diff-mode nil t) (diff-mode))
1491 (vc-exec-after '(progn (goto-char (point-min)) 1514 (vc-exec-after '(progn (if (eq (buffer-size) 0)
1515 (insert "No differences found.\n"))
1516 (goto-char (point-min))
1492 (shrink-window-if-larger-than-buffer))) 1517 (shrink-window-if-larger-than-buffer)))
1493 t)) 1518 t))
1494 1519
1495 ;;;###autoload 1520 ;;;###autoload
1496 (defun vc-version-other-window (rev) 1521 (defun vc-version-other-window (rev)
2153 (vc-dired-resynch-file file)) 2178 (vc-dired-resynch-file file))
2154 (t ;; revert buffer to file on disk 2179 (t ;; revert buffer to file on disk
2155 (vc-resynch-buffer file t t))) 2180 (vc-resynch-buffer file t t)))
2156 (message "Version %s has been removed from the master" target)))) 2181 (message "Version %s has been removed from the master" target))))
2157 2182
2183 ;;;autoload
2184 (defun vc-switch-backend (file backend)
2185 "Make BACKEND the current version control system for FILE.
2186 FILE must already be registered in BACKEND. The change is not
2187 permanent, only for the current session. This function only changes
2188 VC's perspective on FILE, it does not register or unregister it."
2189 (interactive
2190 (list
2191 buffer-file-name
2192 (intern (upcase (read-string "Switch to backend: ")))))
2193 (vc-file-clearprops file)
2194 (vc-file-setprop file 'vc-backend backend)
2195 (vc-resynch-buffer file t t))
2196
2197 (defun vc-index-of (backend)
2198 "Return the index of BACKEND in vc-handled-backends."
2199 (- (length vc-handled-backends)
2200 (length (memq backend vc-handled-backends))))
2201
2202 ;;;autoload
2203 (defun vc-transfer-file (file new-backend)
2204 "Transfer FILE to another version control system NEW-BACKEND.
2205 If NEW-BACKEND has a higher precedence than FILE's current backend
2206 \(i.e. it comes earlier in vc-handled-backends), then register FILE in
2207 NEW-BACKEND, using the version number from the current backend as the
2208 base level. If NEW-BACKEND has a lower precedence than the current
2209 backend, then commit all changes that were made under the current
2210 backend to NEW-BACKEND, and unregister FILE from the current backend.
2211 \(If FILE is not yet registered under NEW-BACKEND, register it.)"
2212 (let ((old-backend (vc-backend file)))
2213 (if (eq old-backend new-backend)
2214 (error "%s is the current backend of %s"
2215 new-backend file)
2216 (with-vc-properties
2217 file
2218 (vc-call-backend new-backend 'receive-file file
2219 (< (vc-index-of old-backend)
2220 (vc-index-of new-backend)))
2221 `((vc-backend ,new-backend))))
2222 (vc-resynch-buffer file t t)))
2223
2224 (defun vc-default-receive-file (backend file move)
2225 "Let BACKEND receive FILE from another version control system.
2226 If MOVE is non-nil, then FILE is unregistered from the old
2227 backend and its comment history is used as the initial contents
2228 of the log entry buffer."
2229 (let ((old-backend (vc-backend file))
2230 (rev (vc-workfile-version file))
2231 (state (vc-state file))
2232 (comment (and move
2233 (vc-find-backend-function old-backend 'comment-history)
2234 (vc-call 'comment-history file))))
2235 (if move (vc-unregister file old-backend))
2236 (vc-file-clearprops file)
2237 (if (not (vc-call-backend backend 'registered file))
2238 (with-vc-properties
2239 file
2240 ;; TODO: If the file was 'edited under the old backend,
2241 ;; this should actually register the version
2242 ;; it was based on.
2243 (vc-call-backend backend 'register file rev "")
2244 `((vc-backend ,backend)))
2245 (vc-file-setprop file 'vc-backend backend)
2246 (vc-file-setprop file 'vc-state 'edited)
2247 (set-file-modes file
2248 (logior (file-modes file) 128)))
2249 (when (or move (eq state 'edited))
2250 (vc-file-setprop file 'vc-state 'edited)
2251 ;; TODO: The comment history should actually become the
2252 ;; initial contents of the log entry buffer.
2253 (and comment (ring-insert vc-comment-ring comment))
2254 (vc-checkin file))))
2255
2158 (defun vc-rename-master (oldmaster newfile templates) 2256 (defun vc-rename-master (oldmaster newfile templates)
2159 "Rename OLDMASTER to be the master file for NEWFILE based on TEMPLATES." 2257 "Rename OLDMASTER to be the master file for NEWFILE based on TEMPLATES."
2160 (let* ((dir (file-name-directory (expand-file-name oldmaster))) 2258 (let* ((dir (file-name-directory (expand-file-name oldmaster)))
2161 (newdir (or (file-name-directory newfile) "")) 2259 (newdir (or (file-name-directory newfile) ""))
2162 (newbase (file-name-nondirectory newfile)) 2260 (newbase (file-name-nondirectory newfile))