Mercurial > emacs
annotate lisp/vc-mcvs.el @ 50914:26edd9033fca
Use the original buffer-name as `base' in place of the
nondirectory part of the file name.
(uniquify-rationalize-file-buffer-names):
Split the `newbuffile' arg into `base' and `dirname'.
Reuse old uniquify-items to avoid recomputing their base&dirname.
(uniquify-buffer-file-name): Only return the directory part.
(uniquify-rerationalize-w/o-cb): Don't bother reseting proposed names.
(rename-buffer): Use the `newname' arg as base.
(create-file-buffer): Split the file name into base and dirname.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 09 May 2003 13:19:15 +0000 |
parents | d3bb1d77a4b1 |
children | 15bfd674106a |
rev | line source |
---|---|
50646 | 1 ;;; vc-mcvs.el --- VC backend for the Meta-CVS version-control system |
2 | |
3 ;; Copyright (C) 1995,98,99,2000,01,02,2003 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: FSF (see vc.el for full credits) | |
6 ;; Maintainer: Stefan Monnier <monnier@gnu.org> | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
50779
02455099d549
Add a link to Meta-CVS home page.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50667
diff
changeset
|
27 ;; The home page of the Meta-CVS version control system is at |
02455099d549
Add a link to Meta-CVS home page.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50667
diff
changeset
|
28 ;; |
02455099d549
Add a link to Meta-CVS home page.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50667
diff
changeset
|
29 ;; http://users.footprints.net/~kaz/mcvs.html |
02455099d549
Add a link to Meta-CVS home page.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50667
diff
changeset
|
30 ;; |
50646 | 31 ;; This is derived from vc-cvs.el as follows: |
32 ;; - cp vc-cvs.el vc-mcvs.el | |
33 ;; - Replace CVS/ with MCVS/CVS/ | |
34 ;; - Replace 'CVS with 'MCVS | |
35 ;; - Replace -cvs- with -mcvs- | |
36 ;; - Replace most of the rest of CVS to Meta-CVS | |
37 ;; | |
38 ;; Then of course started the hacking. Only a small part of the code | |
39 ;; has been touched and not much more than that was tested, so if | |
40 ;; you bump into a bug, don't be surprised: just report it to me. | |
41 ;; | |
42 ;; What has been partly tested: | |
43 ;; - C-x v v to start editing a file that was checked out with CVSREAD on. | |
44 ;; - C-x v v to commit a file | |
45 ;; - C-x v = | |
46 ;; - C-x v l | |
47 ;; - C-x v i | |
48 ;; - C-x v g | |
50808
5a0d0a9219f3
(vc-mcvs-mode-line-string): Fix thinko.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50779
diff
changeset
|
49 ;; - M-x vc-rename-file RET |
50646 | 50 |
51 ;;; Bugs: | |
52 | |
53 ;; - VC-dired doesn't work. | |
54 | |
55 ;;; Code: | |
56 | |
57 (eval-when-compile (require 'vc)) | |
58 (require 'vc-cvs) | |
59 | |
60 ;;; | |
61 ;;; Customization options | |
62 ;;; | |
63 | |
64 (defcustom vc-mcvs-global-switches nil | |
65 "*Global switches to pass to any Meta-CVS command." | |
66 :type '(choice (const :tag "None" nil) | |
67 (string :tag "Argument String") | |
68 (repeat :tag "Argument List" | |
69 :value ("") | |
70 string)) | |
71 :version "21.4" | |
72 :group 'vc) | |
73 | |
74 (defcustom vc-mcvs-register-switches nil | |
75 "*Extra switches for registering a file into Meta-CVS. | |
76 A string or list of strings passed to the checkin program by | |
77 \\[vc-register]." | |
78 :type '(choice (const :tag "None" nil) | |
79 (string :tag "Argument String") | |
80 (repeat :tag "Argument List" | |
81 :value ("") | |
82 string)) | |
83 :version "21.4" | |
84 :group 'vc) | |
85 | |
86 (defcustom vc-mcvs-diff-switches nil | |
87 "*A string or list of strings specifying extra switches for cvs diff under VC." | |
88 :type '(choice (const :tag "None" nil) | |
89 (string :tag "Argument String") | |
90 (repeat :tag "Argument List" | |
91 :value ("") | |
92 string)) | |
93 :version "21.4" | |
94 :group 'vc) | |
95 | |
96 (defcustom vc-mcvs-header (or (cdr (assoc 'MCVS vc-header-alist)) | |
97 vc-cvs-header) | |
98 "*Header keywords to be inserted by `vc-insert-headers'." | |
99 :version "21.4" | |
100 :type '(repeat string) | |
101 :group 'vc) | |
102 | |
103 (defcustom vc-mcvs-use-edit vc-cvs-use-edit | |
104 "*Non-nil means to use `cvs edit' to \"check out\" a file. | |
105 This is only meaningful if you don't use the implicit checkout model | |
106 \(i.e. if you have $CVSREAD set)." | |
107 :type 'boolean | |
108 :version "21.4" | |
109 :group 'vc) | |
110 | |
111 (defcustom vc-mcvs-stay-local vc-cvs-stay-local | |
112 "*Non-nil means use local operations when possible for remote repositories. | |
113 This avoids slow queries over the network and instead uses heuristics | |
114 and past information to determine the current status of a file. | |
115 The value can also be a regular expression to match against the host name | |
116 of a repository; then VC only stays local for hosts that match it." | |
117 :type '(choice (const :tag "Always stay local" t) | |
118 (string :tag "Host regexp") | |
119 (const :tag "Don't stay local" nil)) | |
120 :version "21.4" | |
121 :group 'vc) | |
122 | |
123 ;;; | |
124 ;;; State-querying functions | |
125 ;;; | |
126 | |
127 ;;;###autoload (defun vc-mcvs-registered (file) | |
128 ;;;###autoload (let ((dir file)) | |
129 ;;;###autoload (while (and (stringp dir) | |
130 ;;;###autoload (not (equal dir (setq dir (file-name-directory dir))))) | |
131 ;;;###autoload (setq dir (if (file-directory-p | |
132 ;;;###autoload (expand-file-name "MCVS/CVS" dir)) | |
133 ;;;###autoload t (directory-file-name dir)))) | |
134 ;;;###autoload (if (eq dir t) | |
135 ;;;###autoload (progn | |
136 ;;;###autoload (load "vc-mcvs") | |
137 ;;;###autoload (vc-mcvs-registered file))))) | |
138 | |
139 (defun vc-mcvs-root (file) | |
140 "Return the root directory of a Meta-CVS project, if any." | |
50667
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
141 (or (vc-file-getprop file 'mcvs-root) |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
142 (vc-file-setprop |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
143 file 'mcvs-root |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
144 (let ((root nil)) |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
145 (while (not (or root |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
146 (equal file (setq file (file-name-directory file))))) |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
147 (if (file-directory-p (expand-file-name "MCVS/CVS" file)) |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
148 (setq root file) |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
149 (setq file (directory-file-name file)))) |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
150 root)))) |
50646 | 151 |
152 (defun vc-mcvs-read (file) | |
50899
6b9cefee3eee
(vc-mcvs-read): Don't require `file' to exist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50808
diff
changeset
|
153 (if (file-readable-p file) |
6b9cefee3eee
(vc-mcvs-read): Don't require `file' to exist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50808
diff
changeset
|
154 (with-temp-buffer |
6b9cefee3eee
(vc-mcvs-read): Don't require `file' to exist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50808
diff
changeset
|
155 (insert-file-contents file) |
6b9cefee3eee
(vc-mcvs-read): Don't require `file' to exist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50808
diff
changeset
|
156 (goto-char (point-min)) |
6b9cefee3eee
(vc-mcvs-read): Don't require `file' to exist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50808
diff
changeset
|
157 (read (current-buffer))))) |
50646 | 158 |
159 (defun vc-mcvs-map-file (dir file) | |
160 (let ((map (vc-mcvs-read (expand-file-name "MCVS/MAP" dir))) | |
161 inode) | |
162 (dolist (x map inode) | |
163 (if (equal (nth 2 x) file) (setq inode (nth 1 x)))))) | |
164 | |
165 (defun vc-mcvs-registered (file) | |
166 (let (root inode cvsfile) | |
167 (when (and (setq root (vc-mcvs-root file)) | |
168 (setq inode (vc-mcvs-map-file | |
50667
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
169 root (file-relative-name file root)))) |
50646 | 170 (vc-file-setprop file 'mcvs-inode inode) |
171 ;; Avoid calling `mcvs diff' in vc-workfile-unchanged-p. | |
172 (vc-file-setprop file 'vc-checkout-time | |
173 (if (vc-cvs-registered | |
174 (setq cvsfile (expand-file-name inode root))) | |
175 (vc-file-getprop cvsfile 'vc-checkout-time) | |
176 ;; The file might not be registered yet because | |
177 ;; of lazy-adding. | |
178 0)) | |
179 t))) | |
180 | |
181 (defmacro vc-mcvs-cvs (op file &rest args) | |
182 (declare (debug t)) | |
183 `(,(intern (concat "vc-cvs-" (symbol-name op))) | |
184 (expand-file-name (vc-file-getprop ,file 'mcvs-inode) | |
185 (vc-file-getprop ,file 'mcvs-root)) | |
186 ,@args)) | |
187 | |
188 (defun vc-mcvs-state (file) | |
189 ;; This would assume the Meta-CVS sandbox is synchronized. | |
190 ;; (vc-mcvs-cvs state file)) | |
191 "Meta-CVS-specific version of `vc-state'." | |
192 (if (vc-mcvs-stay-local-p file) | |
193 (let ((state (vc-file-getprop file 'vc-state))) | |
194 ;; If we should stay local, use the heuristic but only if | |
195 ;; we don't have a more precise state already available. | |
196 (if (memq state '(up-to-date edited)) | |
197 (vc-mcvs-state-heuristic file) | |
198 state)) | |
199 (with-temp-buffer | |
200 (cd (file-name-directory file)) | |
201 (vc-mcvs-command t 0 file "status") | |
202 (vc-cvs-parse-status t)))) | |
203 | |
204 | |
205 (defalias 'vc-mcvs-state-heuristic 'vc-cvs-state-heuristic) | |
206 | |
207 (defun vc-mcvs-dir-state (dir) | |
208 "Find the Meta-CVS state of all files in DIR." | |
209 ;; if DIR is not under Meta-CVS control, don't do anything. | |
210 (when (file-readable-p (expand-file-name "MCVS/CVS/Entries" dir)) | |
211 (if (vc-mcvs-stay-local-p dir) | |
212 (vc-mcvs-dir-state-heuristic dir) | |
213 (let ((default-directory dir)) | |
214 ;; Don't specify DIR in this command, the default-directory is | |
215 ;; enough. Otherwise it might fail with remote repositories. | |
216 (with-temp-buffer | |
217 (vc-mcvs-command t 0 nil "status" "-l") | |
218 (goto-char (point-min)) | |
219 (while (re-search-forward "^=+\n\\([^=\n].*\n\\|\n\\)+" nil t) | |
220 (narrow-to-region (match-beginning 0) (match-end 0)) | |
221 (vc-cvs-parse-status) | |
222 (goto-char (point-max)) | |
223 (widen))))))) | |
224 | |
225 (defun vc-mcvs-workfile-version (file) (vc-mcvs-cvs workfile-version file)) | |
226 | |
227 (defalias 'vc-mcvs-checkout-model 'vc-cvs-checkout-model) | |
228 | |
50808
5a0d0a9219f3
(vc-mcvs-mode-line-string): Fix thinko.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50779
diff
changeset
|
229 (defun vc-mcvs-mode-line-string (file) |
5a0d0a9219f3
(vc-mcvs-mode-line-string): Fix thinko.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50779
diff
changeset
|
230 (let ((s (vc-mcvs-cvs mode-line-string file))) |
5a0d0a9219f3
(vc-mcvs-mode-line-string): Fix thinko.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50779
diff
changeset
|
231 (if s (concat "M" s)))) |
50646 | 232 |
233 ;;; | |
234 ;;; State-changing functions | |
235 ;;; | |
236 | |
237 (defun vc-mcvs-register (file &optional rev comment) | |
238 "Register FILE into the Meta-CVS version-control system. | |
239 COMMENT can be used to provide an initial description of FILE. | |
240 | |
241 `vc-register-switches' and `vc-mcvs-register-switches' are passed to | |
242 the Meta-CVS command (in that order)." | |
243 (let* ((filename (file-name-nondirectory file)) | |
244 (extpos (string-match "\\." filename)) | |
245 (ext (if extpos (substring filename (1+ extpos)))) | |
246 (root (vc-mcvs-root file)) | |
247 (types-file (expand-file-name "MCVS/TYPES" root)) | |
248 (map-file (expand-file-name "MCVS/MAP" root)) | |
249 (types (vc-mcvs-read types-file))) | |
250 ;; Make sure meta files like MCVS/MAP are not read-only (happens with | |
251 ;; CVSREAD) since Meta-CVS doesn't pay attention to it at all and goes | |
252 ;; belly-up. | |
253 (unless (file-writable-p map-file) | |
254 (vc-checkout map-file t)) | |
50667
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
255 (unless (or (file-writable-p types-file) (not (file-exists-p types-file))) |
50646 | 256 (vc-checkout types-file t)) |
257 ;; Make sure the `mcvs add' will not fire up the CVSEDITOR | |
258 ;; to add a rule for the given file's extension. | |
259 (when (and ext (not (assoc ext types))) | |
260 (let ((type (completing-read "Type to use [default]: " | |
261 '("default" "name-only" "keep-old" | |
262 "binary" "value-only") | |
263 nil t nil nil "default"))) | |
264 (push (list ext (make-symbol (upcase (concat ":" type)))) types) | |
265 (setq types (sort types (lambda (x y) (string< (car x) (car y))))) | |
266 (with-current-buffer (find-file-noselect types-file) | |
267 (erase-buffer) | |
268 (pp types (current-buffer)) | |
269 (save-buffer) | |
270 (unless (get-buffer-window (current-buffer) t) | |
271 (kill-buffer (current-buffer))))))) | |
272 ;; Now do the ADD. | |
50901
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
273 (prog1 (apply 'vc-mcvs-command nil 0 file |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
274 "add" |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
275 (and comment (string-match "[^\t\n ]" comment) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
276 (concat "-m" comment)) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
277 (vc-switches 'MCVS 'register)) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
278 ;; I'm not sure exactly why, but if we don't setup the inode and root |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
279 ;; prop of the file, things break later on in vc-mode-line that |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
280 ;; ends up calling vc-mcvs-workfile-version. |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
281 ;; We also need to set vc-checkout-time so that vc-workfile-unchanged-p |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
282 ;; doesn't try to call `mcvs diff' on the file. |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
283 (vc-mcvs-registered file))) |
50646 | 284 |
285 (defalias 'vc-mcvs-responsible-p 'vc-mcvs-root | |
286 "Return non-nil if CVS thinks it is responsible for FILE.") | |
287 | |
288 (defalias 'vc-cvs-could-register 'vc-cvs-responsible-p | |
289 "Return non-nil if FILE could be registered in Meta-CVS. | |
290 This is only possible if Meta-CVS is responsible for FILE's directory.") | |
291 | |
292 (defun vc-mcvs-checkin (file rev comment) | |
293 "Meta-CVS-specific version of `vc-backend-checkin'." | |
50901
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
294 (unless (or (not rev) (vc-mcvs-valid-version-number-p rev)) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
295 (if (not (vc-mcvs-valid-symbolic-tag-name-p rev)) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
296 (error "%s is not a valid symbolic tag name" rev) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
297 ;; If the input revison is a valid symbolic tag name, we create it |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
298 ;; as a branch, commit and switch to it. |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
299 (apply 'vc-mcvs-command nil 0 file "tag" "-b" (list rev)) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
300 (apply 'vc-mcvs-command nil 0 file "update" "-r" (list rev)) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
301 (vc-file-setprop file 'vc-mcvs-sticky-tag rev) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
302 (setq rev nil))) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
303 (let ((status (apply 'vc-mcvs-command nil 1 file |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
304 "ci" (if rev (concat "-r" rev)) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
305 "-m" comment |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
306 (vc-switches 'MCVS 'checkin)))) |
50646 | 307 (set-buffer "*vc*") |
308 (goto-char (point-min)) | |
309 (when (not (zerop status)) | |
310 ;; Check checkin problem. | |
311 (cond | |
312 ((re-search-forward "Up-to-date check failed" nil t) | |
313 (vc-file-setprop file 'vc-state 'needs-merge) | |
314 (error (substitute-command-keys | |
315 (concat "Up-to-date check failed: " | |
316 "type \\[vc-next-action] to merge in changes")))) | |
317 (t | |
318 (pop-to-buffer (current-buffer)) | |
319 (goto-char (point-min)) | |
320 (shrink-window-if-larger-than-buffer) | |
321 (error "Check-in failed")))) | |
322 ;; Update file properties | |
323 (vc-file-setprop | |
324 file 'vc-workfile-version | |
325 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2)) | |
326 ;; Forget the checkout model of the file, because we might have | |
327 ;; guessed wrong when we found the file. After commit, we can | |
328 ;; tell it from the permissions of the file (see | |
329 ;; vc-mcvs-checkout-model). | |
330 (vc-file-setprop file 'vc-checkout-model nil) | |
331 | |
332 ;; if this was an explicit check-in (does not include creation of | |
333 ;; a branch), remove the sticky tag. | |
334 (if (and rev (not (vc-mcvs-valid-symbolic-tag-name-p rev))) | |
335 (vc-mcvs-command nil 0 file "update" "-A")))) | |
336 | |
337 (defun vc-mcvs-find-version (file rev buffer) | |
338 (apply 'vc-mcvs-command | |
339 buffer 0 file | |
340 "-Q" ; suppress diagnostic output | |
341 "update" | |
342 (and rev (not (string= rev "")) | |
343 (concat "-r" rev)) | |
344 "-p" | |
50901
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
345 (vc-switches 'MCVS 'checkout))) |
50646 | 346 |
347 (defun vc-mcvs-checkout (file &optional editable rev) | |
348 (message "Checking out %s..." file) | |
349 (with-current-buffer (or (get-file-buffer file) (current-buffer)) | |
50901
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
350 (vc-call update file editable rev (vc-switches 'MCVS 'checkout))) |
50646 | 351 (vc-mode-line file) |
352 (message "Checking out %s...done" file)) | |
353 | |
354 (defun vc-mcvs-update (file editable rev switches) | |
355 (if (and (file-exists-p file) (not rev)) | |
356 ;; If no revision was specified, just make the file writable | |
357 ;; if necessary (using `cvs-edit' if requested). | |
358 (and editable (not (eq (vc-mcvs-checkout-model file) 'implicit)) | |
359 (if vc-mcvs-use-edit | |
360 (vc-mcvs-command nil 0 file "edit") | |
361 (set-file-modes file (logior (file-modes file) 128)) | |
362 (if (equal file buffer-file-name) (toggle-read-only -1)))) | |
363 ;; Check out a particular version (or recreate the file). | |
364 (vc-file-setprop file 'vc-workfile-version nil) | |
365 (apply 'vc-mcvs-command nil 0 file | |
366 (if editable "-w") | |
367 "update" | |
368 ;; default for verbose checkout: clear the sticky tag so | |
369 ;; that the actual update will get the head of the trunk | |
370 (if (or (not rev) (string= rev "")) | |
371 "-A" | |
372 (concat "-r" rev)) | |
373 switches))) | |
374 | |
50808
5a0d0a9219f3
(vc-mcvs-mode-line-string): Fix thinko.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50779
diff
changeset
|
375 (defun vc-mcvs-rename-file (old new) |
5a0d0a9219f3
(vc-mcvs-mode-line-string): Fix thinko.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50779
diff
changeset
|
376 (vc-mcvs-command nil 0 new "move" (file-relative-name old))) |
5a0d0a9219f3
(vc-mcvs-mode-line-string): Fix thinko.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50779
diff
changeset
|
377 |
50646 | 378 (defun vc-mcvs-revert (file &optional contents-done) |
379 "Revert FILE to the version it was based on." | |
380 (vc-default-revert file contents-done) | |
381 (unless (eq (vc-checkout-model file) 'implicit) | |
382 (if vc-mcvs-use-edit | |
383 (vc-mcvs-command nil 0 file "unedit") | |
384 ;; Make the file read-only by switching off all w-bits | |
385 (set-file-modes file (logand (file-modes file) 3950))))) | |
386 | |
387 (defun vc-mcvs-merge (file first-version &optional second-version) | |
388 "Merge changes into current working copy of FILE. | |
389 The changes are between FIRST-VERSION and SECOND-VERSION." | |
390 (vc-mcvs-command nil 0 file | |
391 "update" "-kk" | |
392 (concat "-j" first-version) | |
393 (concat "-j" second-version)) | |
394 (vc-file-setprop file 'vc-state 'edited) | |
395 (with-current-buffer (get-buffer "*vc*") | |
396 (goto-char (point-min)) | |
397 (if (re-search-forward "conflicts during merge" nil t) | |
398 1 ; signal error | |
399 0))) ; signal success | |
400 | |
401 (defun vc-mcvs-merge-news (file) | |
402 "Merge in any new changes made to FILE." | |
403 (message "Merging changes into %s..." file) | |
404 ;; (vc-file-setprop file 'vc-workfile-version nil) | |
405 (vc-file-setprop file 'vc-checkout-time 0) | |
406 (vc-mcvs-command nil 0 file "update") | |
407 ;; Analyze the merge result reported by Meta-CVS, and set | |
408 ;; file properties accordingly. | |
409 (with-current-buffer (get-buffer "*vc*") | |
410 (goto-char (point-min)) | |
411 ;; get new workfile version | |
412 (if (re-search-forward | |
413 "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t) | |
414 (vc-file-setprop file 'vc-workfile-version (match-string 1)) | |
415 (vc-file-setprop file 'vc-workfile-version nil)) | |
416 ;; get file status | |
417 (prog1 | |
418 (if (eq (buffer-size) 0) | |
419 0 ;; there were no news; indicate success | |
420 (if (re-search-forward | |
421 (concat "^\\([CMUP] \\)?" | |
422 ".*" | |
423 "\\( already contains the differences between \\)?") | |
424 nil t) | |
425 (cond | |
426 ;; Merge successful, we are in sync with repository now | |
427 ((or (match-string 2) | |
428 (string= (match-string 1) "U ") | |
429 (string= (match-string 1) "P ")) | |
430 (vc-file-setprop file 'vc-state 'up-to-date) | |
431 (vc-file-setprop file 'vc-checkout-time | |
432 (nth 5 (file-attributes file))) | |
433 0);; indicate success to the caller | |
434 ;; Merge successful, but our own changes are still in the file | |
435 ((string= (match-string 1) "M ") | |
436 (vc-file-setprop file 'vc-state 'edited) | |
437 0);; indicate success to the caller | |
438 ;; Conflicts detected! | |
439 (t | |
440 (vc-file-setprop file 'vc-state 'edited) | |
441 1);; signal the error to the caller | |
442 ) | |
443 (pop-to-buffer "*vc*") | |
444 (error "Couldn't analyze mcvs update result"))) | |
445 (message "Merging changes into %s...done" file)))) | |
446 | |
447 ;;; | |
448 ;;; History functions | |
449 ;;; | |
450 | |
451 (defun vc-mcvs-print-log (file) | |
452 "Get change log associated with FILE." | |
453 (vc-mcvs-command | |
454 nil | |
455 (if (and (vc-mcvs-stay-local-p file) (fboundp 'start-process)) 'async 0) | |
456 file "log")) | |
457 | |
458 (defun vc-mcvs-diff (file &optional oldvers newvers) | |
459 "Get a difference report using Meta-CVS between two versions of FILE." | |
50901
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
460 (if (string= (vc-workfile-version file) "0") |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
461 ;; This file is added but not yet committed; there is no master file. |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
462 (if (or oldvers newvers) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
463 (error "No revisions of %s exist" file) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
464 ;; We regard this as "changed". |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
465 ;; Diff it against /dev/null. |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
466 ;; Note: this is NOT a "mcvs diff". |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
467 (apply 'vc-do-command "*vc-diff*" |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
468 1 "diff" file |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
469 (append (vc-switches nil 'diff) '("/dev/null"))) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
470 ;; Even if it's empty, it's locally modified. |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
471 1) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
472 (let* ((async (and (vc-mcvs-stay-local-p file) (fboundp 'start-process))) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
473 (status |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
474 (apply 'vc-mcvs-command "*vc-diff*" |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
475 (if async 'async 1) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
476 file "diff" |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
477 (and oldvers (concat "-r" oldvers)) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
478 (and newvers (concat "-r" newvers)) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
479 (vc-switches 'MCVS 'diff)))) |
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
480 (if async 1 status)))) ; async diff, pessimistic assumption. |
50646 | 481 |
482 (defun vc-mcvs-diff-tree (dir &optional rev1 rev2) | |
483 "Diff all files at and below DIR." | |
484 (with-current-buffer "*vc-diff*" | |
485 (setq default-directory dir) | |
486 (if (vc-mcvs-stay-local-p dir) | |
487 ;; local diff: do it filewise, and only for files that are modified | |
488 (vc-file-tree-walk | |
489 dir | |
490 (lambda (f) | |
491 (vc-exec-after | |
492 `(let ((coding-system-for-read (vc-coding-system-for-diff ',f))) | |
493 ;; possible optimization: fetch the state of all files | |
494 ;; in the tree via vc-mcvs-dir-state-heuristic | |
495 (unless (vc-up-to-date-p ',f) | |
496 (message "Looking at %s" ',f) | |
497 (vc-diff-internal ',f ',rev1 ',rev2)))))) | |
498 ;; cvs diff: use a single call for the entire tree | |
499 (let ((coding-system-for-read | |
500 (or coding-system-for-read 'undecided))) | |
501 (apply 'vc-mcvs-command "*vc-diff*" 1 nil "diff" | |
502 (and rev1 (concat "-r" rev1)) | |
503 (and rev2 (concat "-r" rev2)) | |
50901
d3bb1d77a4b1
(vc-mcvs-register, vc-mcvs-checkin, vc-mcvs-find-version)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50899
diff
changeset
|
504 (vc-switches 'MCVS 'diff)))))) |
50646 | 505 |
506 (defun vc-mcvs-annotate-command (file buffer &optional version) | |
507 "Execute \"mcvs annotate\" on FILE, inserting the contents in BUFFER. | |
508 Optional arg VERSION is a version to annotate from." | |
509 (vc-mcvs-command | |
510 buffer | |
511 (if (and (vc-mcvs-stay-local-p file) (fboundp 'start-process)) 'async 0) | |
512 file "annotate" (if version (concat "-r" version)))) | |
513 | |
514 (defalias 'vc-mcvs-annotate-current-time 'vc-cvs-annotate-current-time) | |
515 (defalias 'vc-mcvs-annotate-time 'vc-cvs-annotate-time) | |
516 | |
517 ;;; | |
518 ;;; Snapshot system | |
519 ;;; | |
520 | |
521 (defun vc-mcvs-create-snapshot (dir name branchp) | |
522 "Assign to DIR's current version a given NAME. | |
523 If BRANCHP is non-nil, the name is created as a branch (and the current | |
524 workspace is immediately moved to that new branch)." | |
525 (vc-mcvs-command nil 0 dir "tag" "-c" (if branchp "-b") name) | |
526 (when branchp (vc-mcvs-command nil 0 dir "update" "-r" name))) | |
527 | |
528 (defun vc-mcvs-retrieve-snapshot (dir name update) | |
529 "Retrieve a snapshot at and below DIR. | |
530 NAME is the name of the snapshot; if it is empty, do a `cvs update'. | |
531 If UPDATE is non-nil, then update (resynch) any affected buffers." | |
532 (with-current-buffer (get-buffer-create "*vc*") | |
533 (let ((default-directory dir) | |
534 (sticky-tag)) | |
535 (erase-buffer) | |
536 (if (or (not name) (string= name "")) | |
537 (vc-mcvs-command t 0 nil "update") | |
538 (vc-mcvs-command t 0 nil "update" "-r" name) | |
539 (setq sticky-tag name)) | |
540 (when update | |
541 (goto-char (point-min)) | |
542 (while (not (eobp)) | |
543 (if (looking-at "\\([CMUP]\\) \\(.*\\)") | |
544 (let* ((file (expand-file-name (match-string 2) dir)) | |
545 (state (match-string 1)) | |
546 (buffer (find-buffer-visiting file))) | |
547 (when buffer | |
548 (cond | |
549 ((or (string= state "U") | |
550 (string= state "P")) | |
551 (vc-file-setprop file 'vc-state 'up-to-date) | |
552 (vc-file-setprop file 'vc-workfile-version nil) | |
553 (vc-file-setprop file 'vc-checkout-time | |
554 (nth 5 (file-attributes file)))) | |
555 ((or (string= state "M") | |
556 (string= state "C")) | |
557 (vc-file-setprop file 'vc-state 'edited) | |
558 (vc-file-setprop file 'vc-workfile-version nil) | |
559 (vc-file-setprop file 'vc-checkout-time 0))) | |
560 (vc-file-setprop file 'vc-mcvs-sticky-tag sticky-tag) | |
561 (vc-resynch-buffer file t t)))) | |
562 (forward-line 1)))))) | |
563 | |
564 | |
565 ;;; | |
566 ;;; Miscellaneous | |
567 ;;; | |
568 | |
569 (defalias 'vc-mcvs-make-version-backups-p 'vc-mcvs-stay-local-p | |
570 "Return non-nil if version backups should be made for FILE.") | |
571 (defalias 'vc-mcvs-check-headers 'vc-cvs-check-headers) | |
572 | |
573 | |
574 ;;; | |
575 ;;; Internal functions | |
576 ;;; | |
577 | |
578 (defun vc-mcvs-command (buffer okstatus file &rest flags) | |
579 "A wrapper around `vc-do-command' for use in vc-mcvs.el. | |
580 The difference to vc-do-command is that this function always invokes `mcvs', | |
581 and that it passes `vc-mcvs-global-switches' to it before FLAGS." | |
50667
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
582 (let ((args (append '("--error-continue") |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
583 (if (stringp vc-mcvs-global-switches) |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
584 (cons vc-mcvs-global-switches flags) |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
585 (append vc-mcvs-global-switches |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
586 flags))))) |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
587 (if (member (car flags) '("diff" "log")) |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
588 ;; We need to filter the output. |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
589 (vc-do-command buffer okstatus "sh" nil "-c" |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
590 (concat "mcvs " |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
591 (mapconcat |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
592 'shell-quote-argument |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
593 (append (remq nil args) |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
594 (if file (list (file-relative-name file)))) |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
595 " ") |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
596 " | mcvs filt")) |
c475369e6995
(vc-mcvs-root): Cache the result.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50646
diff
changeset
|
597 (apply 'vc-do-command buffer okstatus "mcvs" file args)))) |
50646 | 598 |
599 (defun vc-mcvs-stay-local-p (file) (vc-mcvs-cvs stay-local-p file)) | |
600 | |
601 (defun vc-mcvs-dir-state-heuristic (dir) | |
602 "Find the Meta-CVS state of all files in DIR, using only local information." | |
603 (with-temp-buffer | |
604 (vc-cvs-get-entries dir) | |
605 (goto-char (point-min)) | |
606 (while (not (eobp)) | |
607 ;; Meta-MCVS-removed files are not taken under VC control. | |
608 (when (looking-at "/\\([^/]*\\)/[^/-]") | |
609 (let ((file (expand-file-name (match-string 1) dir))) | |
610 (unless (vc-file-getprop file 'vc-state) | |
611 (vc-cvs-parse-entry file t)))) | |
612 (forward-line 1)))) | |
613 | |
614 (defalias 'vc-mcvs-valid-symbolic-tag-name-p 'vc-cvs-valid-symbolic-tag-name-p) | |
615 (defalias 'vc-mcvs-valid-version-number-p 'vc-cvs-valid-version-number-p) | |
616 | |
617 (provide 'vc-mcvs) | |
618 ;;; vc-mcvs.el ends here |