Merge from emacs--rel--22
[bpt/emacs.git] / lisp / vc-mcvs.el
CommitLineData
3928b9a6
SM
1;;; vc-mcvs.el --- VC backend for the Meta-CVS version-control system
2
409cc4a3 3;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
3928b9a6
SM
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
b4aa6026 12;; the Free Software Foundation; either version 3, or (at your option)
3928b9a6
SM
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
086add15
LK
22;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23;; Boston, MA 02110-1301, USA.
3928b9a6
SM
24
25;;; Commentary:
26
51241d96 27;; The home page of the Meta-CVS version control system is at
cd227df3 28;;
51241d96 29;; http://users.footprints.net/~kaz/mcvs.html
cd227df3 30;;
3928b9a6
SM
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
4a97caca 49;; - M-x vc-rename-file RET
3928b9a6
SM
50
51;;; Bugs:
52
6dbeb3d8
SM
53;; - Retrieving snapshots doesn't filter `cvs update' output and thus
54;; parses bogus filenames. Don't know if it harms.
3928b9a6
SM
55
56;;; Code:
57
58(eval-when-compile (require 'vc))
59(require 'vc-cvs)
60
61;;;
62;;; Customization options
63;;;
64
65(defcustom vc-mcvs-global-switches nil
66 "*Global switches to pass to any Meta-CVS command."
67 :type '(choice (const :tag "None" nil)
68 (string :tag "Argument String")
69 (repeat :tag "Argument List"
70 :value ("")
71 string))
bf247b6e 72 :version "22.1"
3928b9a6
SM
73 :group 'vc)
74
75(defcustom vc-mcvs-register-switches nil
76 "*Extra switches for registering a file into Meta-CVS.
77A string or list of strings passed to the checkin program by
78\\[vc-register]."
79 :type '(choice (const :tag "None" nil)
80 (string :tag "Argument String")
81 (repeat :tag "Argument List"
82 :value ("")
83 string))
bf247b6e 84 :version "22.1"
3928b9a6
SM
85 :group 'vc)
86
87(defcustom vc-mcvs-diff-switches nil
88 "*A string or list of strings specifying extra switches for cvs diff under VC."
89 :type '(choice (const :tag "None" nil)
90 (string :tag "Argument String")
91 (repeat :tag "Argument List"
92 :value ("")
93 string))
bf247b6e 94 :version "22.1"
3928b9a6
SM
95 :group 'vc)
96
97(defcustom vc-mcvs-header (or (cdr (assoc 'MCVS vc-header-alist))
98 vc-cvs-header)
99 "*Header keywords to be inserted by `vc-insert-headers'."
bf247b6e 100 :version "22.1"
3928b9a6
SM
101 :type '(repeat string)
102 :group 'vc)
103
104(defcustom vc-mcvs-use-edit vc-cvs-use-edit
105 "*Non-nil means to use `cvs edit' to \"check out\" a file.
106This is only meaningful if you don't use the implicit checkout model
107\(i.e. if you have $CVSREAD set)."
108 :type 'boolean
bf247b6e 109 :version "22.1"
3928b9a6
SM
110 :group 'vc)
111
8cdd17b4
ER
112;;; Properties of the backend
113
114(defun vc-mcvs-revision-granularity ()
115 'file)
116
3928b9a6
SM
117;;;
118;;; State-querying functions
119;;;
120
121;;;###autoload (defun vc-mcvs-registered (file)
58913dd3
SM
122;;;###autoload (if (vc-find-root file "MCVS/CVS")
123;;;###autoload (progn
124;;;###autoload (load "vc-mcvs")
125;;;###autoload (vc-mcvs-registered file))))
3928b9a6
SM
126
127(defun vc-mcvs-root (file)
128 "Return the root directory of a Meta-CVS project, if any."
15a45706 129 (or (vc-file-getprop file 'mcvs-root)
58913dd3 130 (vc-file-setprop file 'mcvs-root (vc-find-root file "MCVS/CVS"))))
3928b9a6
SM
131
132(defun vc-mcvs-read (file)
1207c9d2
SM
133 (if (file-readable-p file)
134 (with-temp-buffer
135 (insert-file-contents file)
136 (goto-char (point-min))
137 (read (current-buffer)))))
3928b9a6
SM
138
139(defun vc-mcvs-map-file (dir file)
140 (let ((map (vc-mcvs-read (expand-file-name "MCVS/MAP" dir)))
141 inode)
142 (dolist (x map inode)
143 (if (equal (nth 2 x) file) (setq inode (nth 1 x))))))
144
145(defun vc-mcvs-registered (file)
146 (let (root inode cvsfile)
147 (when (and (setq root (vc-mcvs-root file))
148 (setq inode (vc-mcvs-map-file
15a45706 149 root (file-relative-name file root))))
3928b9a6 150 (vc-file-setprop file 'mcvs-inode inode)
3928b9a6
SM
151 ;; Avoid calling `mcvs diff' in vc-workfile-unchanged-p.
152 (vc-file-setprop file 'vc-checkout-time
153 (if (vc-cvs-registered
154 (setq cvsfile (expand-file-name inode root)))
155 (vc-file-getprop cvsfile 'vc-checkout-time)
156 ;; The file might not be registered yet because
157 ;; of lazy-adding.
158 0))
159 t)))
160
3928b9a6
SM
161(defun vc-mcvs-state (file)
162 ;; This would assume the Meta-CVS sandbox is synchronized.
163 ;; (vc-mcvs-cvs state file))
164 "Meta-CVS-specific version of `vc-state'."
d699c8e2 165 (if (vc-stay-local-p file)
3928b9a6
SM
166 (let ((state (vc-file-getprop file 'vc-state)))
167 ;; If we should stay local, use the heuristic but only if
168 ;; we don't have a more precise state already available.
169 (if (memq state '(up-to-date edited))
170 (vc-mcvs-state-heuristic file)
171 state))
172 (with-temp-buffer
6dbeb3d8 173 (setq default-directory (vc-mcvs-root file))
3928b9a6
SM
174 (vc-mcvs-command t 0 file "status")
175 (vc-cvs-parse-status t))))
176
177
178(defalias 'vc-mcvs-state-heuristic 'vc-cvs-state-heuristic)
179
180(defun vc-mcvs-dir-state (dir)
cdce374a 181 "Find the Meta-CVS state of all files in DIR and subdirectories."
3928b9a6
SM
182 ;; if DIR is not under Meta-CVS control, don't do anything.
183 (when (file-readable-p (expand-file-name "MCVS/CVS/Entries" dir))
d699c8e2 184 (if (vc-stay-local-p dir)
3928b9a6
SM
185 (vc-mcvs-dir-state-heuristic dir)
186 (let ((default-directory dir))
187 ;; Don't specify DIR in this command, the default-directory is
188 ;; enough. Otherwise it might fail with remote repositories.
189 (with-temp-buffer
18e1f249 190 (buffer-disable-undo) ;; Because these buffers can get huge
6dbeb3d8 191 (setq default-directory (vc-mcvs-root dir))
cdce374a 192 (vc-mcvs-command t 0 nil "status")
3928b9a6
SM
193 (goto-char (point-min))
194 (while (re-search-forward "^=+\n\\([^=\n].*\n\\|\n\\)+" nil t)
195 (narrow-to-region (match-beginning 0) (match-end 0))
196 (vc-cvs-parse-status)
197 (goto-char (point-max))
198 (widen)))))))
199
ac3f4c6f
ER
200(defun vc-mcvs-working-revision (file)
201 (vc-cvs-working-revision
b6c4e4e0
SM
202 (expand-file-name (vc-file-getprop file 'mcvs-inode)
203 (vc-file-getprop file 'mcvs-root))))
3928b9a6
SM
204
205(defalias 'vc-mcvs-checkout-model 'vc-cvs-checkout-model)
206
3928b9a6
SM
207;;;
208;;; State-changing functions
209;;;
210
8cdd17b4
ER
211(defun vc-mcvs-register (files &optional rev comment)
212 "Register FILES into the Meta-CVS version-control system.
3928b9a6
SM
213COMMENT can be used to provide an initial description of FILE.
214
215`vc-register-switches' and `vc-mcvs-register-switches' are passed to
216the Meta-CVS command (in that order)."
8cdd17b4
ER
217 ;; FIXME: multiple-file case should be made to work
218 (if (> (length files) 1) (error "Registering filesets is not yet supported."))
219 (let* ((file (car files))
220 (filename (file-name-nondirectory file))
3928b9a6
SM
221 (extpos (string-match "\\." filename))
222 (ext (if extpos (substring filename (1+ extpos))))
223 (root (vc-mcvs-root file))
224 (types-file (expand-file-name "MCVS/TYPES" root))
225 (map-file (expand-file-name "MCVS/MAP" root))
226 (types (vc-mcvs-read types-file)))
227 ;; Make sure meta files like MCVS/MAP are not read-only (happens with
228 ;; CVSREAD) since Meta-CVS doesn't pay attention to it at all and goes
229 ;; belly-up.
230 (unless (file-writable-p map-file)
231 (vc-checkout map-file t))
15a45706 232 (unless (or (file-writable-p types-file) (not (file-exists-p types-file)))
3928b9a6
SM
233 (vc-checkout types-file t))
234 ;; Make sure the `mcvs add' will not fire up the CVSEDITOR
235 ;; to add a rule for the given file's extension.
236 (when (and ext (not (assoc ext types)))
5b76833f 237 (let ((type (completing-read "Type to use (default): "
3928b9a6
SM
238 '("default" "name-only" "keep-old"
239 "binary" "value-only")
240 nil t nil nil "default")))
241 (push (list ext (make-symbol (upcase (concat ":" type)))) types)
242 (setq types (sort types (lambda (x y) (string< (car x) (car y)))))
243 (with-current-buffer (find-file-noselect types-file)
3928b9a6
SM
244 (erase-buffer)
245 (pp types (current-buffer))
246 (save-buffer)
247 (unless (get-buffer-window (current-buffer) t)
248 (kill-buffer (current-buffer)))))))
249 ;; Now do the ADD.
d011ca0f
SM
250 (prog1 (apply 'vc-mcvs-command nil 0 file
251 "add"
252 (and comment (string-match "[^\t\n ]" comment)
253 (concat "-m" comment))
254 (vc-switches 'MCVS 'register))
255 ;; I'm not sure exactly why, but if we don't setup the inode and root
256 ;; prop of the file, things break later on in vc-mode-line that
ac3f4c6f 257 ;; ends up calling vc-mcvs-working-revision.
d011ca0f
SM
258 ;; We also need to set vc-checkout-time so that vc-workfile-unchanged-p
259 ;; doesn't try to call `mcvs diff' on the file.
260 (vc-mcvs-registered file)))
3928b9a6
SM
261
262(defalias 'vc-mcvs-responsible-p 'vc-mcvs-root
263 "Return non-nil if CVS thinks it is responsible for FILE.")
264
265(defalias 'vc-cvs-could-register 'vc-cvs-responsible-p
266 "Return non-nil if FILE could be registered in Meta-CVS.
267This is only possible if Meta-CVS is responsible for FILE's directory.")
268
8cdd17b4 269(defun vc-mcvs-checkin (files rev comment)
3928b9a6 270 "Meta-CVS-specific version of `vc-backend-checkin'."
5b5afd50 271 (unless (or (not rev) (vc-mcvs-valid-revision-number-p rev))
d011ca0f
SM
272 (if (not (vc-mcvs-valid-symbolic-tag-name-p rev))
273 (error "%s is not a valid symbolic tag name" rev)
d699c8e2 274 ;; If the input revision is a valid symbolic tag name, we create it
d011ca0f 275 ;; as a branch, commit and switch to it.
6dbeb3d8
SM
276 ;; This file-specific form of branching is deprecated.
277 ;; We can't use `mcvs branch' and `mcvs switch' because they cannot
278 ;; be applied just to this one file.
8cdd17b4
ER
279 (apply 'vc-mcvs-command nil 0 files "tag" "-b" (list rev))
280 (apply 'vc-mcvs-command nil 0 files "update" "-r" (list rev))
3d1726ad
GM
281 (mapc (lambda (file) (vc-file-setprop file 'vc-mcvs-sticky-tag rev))
282 files)
d011ca0f 283 (setq rev nil)))
d699c8e2
SM
284 ;; This commit might cvs-commit several files (e.g. MAP and TYPES)
285 ;; so using numbered revs here is dangerous and somewhat meaningless.
286 (when rev (error "Cannot commit to a specific revision number"))
8cdd17b4 287 (let ((status (apply 'vc-mcvs-command nil 1 files
d699c8e2 288 "ci" "-m" comment
d011ca0f 289 (vc-switches 'MCVS 'checkin))))
3928b9a6
SM
290 (set-buffer "*vc*")
291 (goto-char (point-min))
292 (when (not (zerop status))
293 ;; Check checkin problem.
294 (cond
295 ((re-search-forward "Up-to-date check failed" nil t)
3d1726ad 296 (mapc (lambda (file) (vc-file-setprop file 'vc-state 'needs-merge))
8cdd17b4 297 files)
8c16bd8c 298 (error "%s" (substitute-command-keys
3928b9a6
SM
299 (concat "Up-to-date check failed: "
300 "type \\[vc-next-action] to merge in changes"))))
301 (t
302 (pop-to-buffer (current-buffer))
303 (goto-char (point-min))
304 (shrink-window-if-larger-than-buffer)
305 (error "Check-in failed"))))
5b5afd50 306 ;; Single-file commit? Then update the revision by parsing the buffer.
8cdd17b4
ER
307 ;; Otherwise we can't necessarily tell what goes with what; clear
308 ;; its properties so they have to be refetched.
309 (if (= (length files) 1)
310 (vc-file-setprop
ac3f4c6f 311 (car files) 'vc-working-revision
8cdd17b4
ER
312 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
313 (mapc (lambda (file) (vc-file-clearprops file)) files))
314 ;; Anyway, forget the checkout model of the file, because we might have
3928b9a6
SM
315 ;; guessed wrong when we found the file. After commit, we can
316 ;; tell it from the permissions of the file (see
317 ;; vc-mcvs-checkout-model).
8cdd17b4
ER
318 (mapc (lambda (file) (vc-file-setprop file 'vc-checkout-model nil))
319 files)
3928b9a6
SM
320
321 ;; if this was an explicit check-in (does not include creation of
322 ;; a branch), remove the sticky tag.
323 (if (and rev (not (vc-mcvs-valid-symbolic-tag-name-p rev)))
8cdd17b4 324 (vc-mcvs-command nil 0 files "update" "-A"))))
3928b9a6 325
ac3f4c6f 326(defun vc-mcvs-find-revision (file rev buffer)
3928b9a6
SM
327 (apply 'vc-mcvs-command
328 buffer 0 file
329 "-Q" ; suppress diagnostic output
330 "update"
331 (and rev (not (string= rev ""))
332 (concat "-r" rev))
333 "-p"
d011ca0f 334 (vc-switches 'MCVS 'checkout)))
3928b9a6
SM
335
336(defun vc-mcvs-checkout (file &optional editable rev)
337 (message "Checking out %s..." file)
338 (with-current-buffer (or (get-file-buffer file) (current-buffer))
d011ca0f 339 (vc-call update file editable rev (vc-switches 'MCVS 'checkout)))
3928b9a6
SM
340 (vc-mode-line file)
341 (message "Checking out %s...done" file))
342
343(defun vc-mcvs-update (file editable rev switches)
344 (if (and (file-exists-p file) (not rev))
345 ;; If no revision was specified, just make the file writable
346 ;; if necessary (using `cvs-edit' if requested).
347 (and editable (not (eq (vc-mcvs-checkout-model file) 'implicit))
348 (if vc-mcvs-use-edit
349 (vc-mcvs-command nil 0 file "edit")
350 (set-file-modes file (logior (file-modes file) 128))
351 (if (equal file buffer-file-name) (toggle-read-only -1))))
5b5afd50 352 ;; Check out a particular revision (or recreate the file).
ac3f4c6f 353 (vc-file-setprop file 'vc-working-revision nil)
3928b9a6
SM
354 (apply 'vc-mcvs-command nil 0 file
355 (if editable "-w")
356 "update"
357 ;; default for verbose checkout: clear the sticky tag so
358 ;; that the actual update will get the head of the trunk
359 (if (or (not rev) (string= rev ""))
360 "-A"
361 (concat "-r" rev))
362 switches)))
363
4a97caca
SM
364(defun vc-mcvs-rename-file (old new)
365 (vc-mcvs-command nil 0 new "move" (file-relative-name old)))
366
3928b9a6 367(defun vc-mcvs-revert (file &optional contents-done)
5b5afd50 368 "Revert FILE to the working revision it was based on."
de387896 369 (vc-default-revert 'MCVS file contents-done)
3928b9a6
SM
370 (unless (eq (vc-checkout-model file) 'implicit)
371 (if vc-mcvs-use-edit
372 (vc-mcvs-command nil 0 file "unedit")
373 ;; Make the file read-only by switching off all w-bits
374 (set-file-modes file (logand (file-modes file) 3950)))))
375
5b5afd50 376(defun vc-mcvs-merge (file first-revision &optional second-revision)
3928b9a6 377 "Merge changes into current working copy of FILE.
5b5afd50 378The changes are between FIRST-REVISION and SECOND-REVISION."
3928b9a6
SM
379 (vc-mcvs-command nil 0 file
380 "update" "-kk"
5b5afd50
ER
381 (concat "-j" first-revision)
382 (concat "-j" second-revision))
3928b9a6
SM
383 (vc-file-setprop file 'vc-state 'edited)
384 (with-current-buffer (get-buffer "*vc*")
385 (goto-char (point-min))
386 (if (re-search-forward "conflicts during merge" nil t)
387 1 ; signal error
388 0))) ; signal success
389
390(defun vc-mcvs-merge-news (file)
391 "Merge in any new changes made to FILE."
392 (message "Merging changes into %s..." file)
ac3f4c6f 393 ;; (vc-file-setprop file 'vc-working-revision nil)
3928b9a6
SM
394 (vc-file-setprop file 'vc-checkout-time 0)
395 (vc-mcvs-command nil 0 file "update")
396 ;; Analyze the merge result reported by Meta-CVS, and set
397 ;; file properties accordingly.
398 (with-current-buffer (get-buffer "*vc*")
399 (goto-char (point-min))
5b5afd50 400 ;; get new working revision
3928b9a6
SM
401 (if (re-search-forward
402 "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t)
ac3f4c6f
ER
403 (vc-file-setprop file 'vc-working-revision (match-string 1))
404 (vc-file-setprop file 'vc-working-revision nil))
3928b9a6
SM
405 ;; get file status
406 (prog1
407 (if (eq (buffer-size) 0)
408 0 ;; there were no news; indicate success
409 (if (re-search-forward
410 (concat "^\\([CMUP] \\)?"
411 ".*"
412 "\\( already contains the differences between \\)?")
413 nil t)
414 (cond
415 ;; Merge successful, we are in sync with repository now
416 ((or (match-string 2)
417 (string= (match-string 1) "U ")
418 (string= (match-string 1) "P "))
419 (vc-file-setprop file 'vc-state 'up-to-date)
420 (vc-file-setprop file 'vc-checkout-time
421 (nth 5 (file-attributes file)))
422 0);; indicate success to the caller
423 ;; Merge successful, but our own changes are still in the file
424 ((string= (match-string 1) "M ")
425 (vc-file-setprop file 'vc-state 'edited)
426 0);; indicate success to the caller
427 ;; Conflicts detected!
428 (t
429 (vc-file-setprop file 'vc-state 'edited)
430 1);; signal the error to the caller
431 )
432 (pop-to-buffer "*vc*")
433 (error "Couldn't analyze mcvs update result")))
434 (message "Merging changes into %s...done" file))))
435
9b64a7f0
ER
436(defun vc-mcvs-modify-change-comment (files rev comment)
437 "Modify the change comments for FILES on a specified REV.
438Will fail unless you have administrative privileges on the repo."
439 (vc-mcvs-command nil 0 files "rcs" (concat "-m" comment ":" rev)))
440
441
3928b9a6
SM
442;;;
443;;; History functions
444;;;
445
8cdd17b4
ER
446(defun vc-mcvs-print-log (files &optional buffer)
447 "Get change log associated with FILES."
448 (let ((default-directory (vc-mcvs-root (car files))))
6dbeb3d8
SM
449 ;; Run the command from the root dir so that `mcvs filt' returns
450 ;; valid relative names.
451 (vc-mcvs-command
138c4b3d 452 buffer
fe1919ab 453 (if (vc-stay-local-p files) 'async 0)
8cdd17b4
ER
454 files "log")))
455
456(defun vc-mcvs-diff (files &optional oldvers newvers buffer)
5b5afd50 457 "Get a difference report using Meta-CVS between two revisions of FILES."
fb7454e8 458 (let* ((async (and (not vc-disable-async-diff)
fe1919ab 459 (vc-stay-local-p files)))
6dbeb3d8
SM
460 ;; Run the command from the root dir so that `mcvs filt' returns
461 ;; valid relative names.
8cdd17b4 462 (default-directory (vc-mcvs-root (car files)))
d011ca0f 463 (status
138c4b3d 464 (apply 'vc-mcvs-command (or buffer "*vc-diff*")
d011ca0f 465 (if async 'async 1)
8cdd17b4 466 files "diff"
d011ca0f
SM
467 (and oldvers (concat "-r" oldvers))
468 (and newvers (concat "-r" newvers))
469 (vc-switches 'MCVS 'diff))))
8cdd17b4 470 (if async 1 status))) ; async diff, pessimistic assumption.
3928b9a6 471
5b5afd50 472(defun vc-mcvs-annotate-command (file buffer &optional revision)
3928b9a6 473 "Execute \"mcvs annotate\" on FILE, inserting the contents in BUFFER.
5b5afd50 474Optional arg REVISION is a revision to annotate from."
3928b9a6
SM
475 (vc-mcvs-command
476 buffer
fe1919ab 477 (if (vc-stay-local-p file) 'async 0)
5b5afd50 478 file "annotate" (if revision (concat "-r" revision)))
cd227df3
TTN
479 (with-current-buffer buffer
480 (goto-char (point-min))
481 (re-search-forward "^[0-9]")
482 (delete-region (point-min) (1- (point)))))
3928b9a6
SM
483
484(defalias 'vc-mcvs-annotate-current-time 'vc-cvs-annotate-current-time)
485(defalias 'vc-mcvs-annotate-time 'vc-cvs-annotate-time)
486
487;;;
488;;; Snapshot system
489;;;
490
491(defun vc-mcvs-create-snapshot (dir name branchp)
5b5afd50 492 "Assign to DIR's current revision a given NAME.
3928b9a6
SM
493If BRANCHP is non-nil, the name is created as a branch (and the current
494workspace is immediately moved to that new branch)."
6dbeb3d8
SM
495 (if (not branchp)
496 (vc-mcvs-command nil 0 dir "tag" "-c" name)
497 (vc-mcvs-command nil 0 dir "branch" name)
498 (vc-mcvs-command nil 0 dir "switch" name)))
3928b9a6
SM
499
500(defun vc-mcvs-retrieve-snapshot (dir name update)
501 "Retrieve a snapshot at and below DIR.
502NAME is the name of the snapshot; if it is empty, do a `cvs update'.
503If UPDATE is non-nil, then update (resynch) any affected buffers."
504 (with-current-buffer (get-buffer-create "*vc*")
505 (let ((default-directory dir)
506 (sticky-tag))
507 (erase-buffer)
508 (if (or (not name) (string= name ""))
509 (vc-mcvs-command t 0 nil "update")
510 (vc-mcvs-command t 0 nil "update" "-r" name)
511 (setq sticky-tag name))
512 (when update
513 (goto-char (point-min))
514 (while (not (eobp))
515 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
516 (let* ((file (expand-file-name (match-string 2) dir))
517 (state (match-string 1))
518 (buffer (find-buffer-visiting file)))
519 (when buffer
520 (cond
521 ((or (string= state "U")
522 (string= state "P"))
523 (vc-file-setprop file 'vc-state 'up-to-date)
ac3f4c6f 524 (vc-file-setprop file 'vc-working-revision nil)
3928b9a6
SM
525 (vc-file-setprop file 'vc-checkout-time
526 (nth 5 (file-attributes file))))
527 ((or (string= state "M")
528 (string= state "C"))
529 (vc-file-setprop file 'vc-state 'edited)
ac3f4c6f 530 (vc-file-setprop file 'vc-working-revision nil)
3928b9a6
SM
531 (vc-file-setprop file 'vc-checkout-time 0)))
532 (vc-file-setprop file 'vc-mcvs-sticky-tag sticky-tag)
533 (vc-resynch-buffer file t t))))
534 (forward-line 1))))))
535
536
537;;;
538;;; Miscellaneous
539;;;
540
d699c8e2 541(defalias 'vc-mcvs-make-version-backups-p 'vc-stay-local-p
3928b9a6
SM
542 "Return non-nil if version backups should be made for FILE.")
543(defalias 'vc-mcvs-check-headers 'vc-cvs-check-headers)
544
545
546;;;
547;;; Internal functions
548;;;
549
550(defun vc-mcvs-command (buffer okstatus file &rest flags)
551 "A wrapper around `vc-do-command' for use in vc-mcvs.el.
552The difference to vc-do-command is that this function always invokes `mcvs',
553and that it passes `vc-mcvs-global-switches' to it before FLAGS."
6dbeb3d8 554 (let ((args (append '("--error-terminate")
15a45706
SM
555 (if (stringp vc-mcvs-global-switches)
556 (cons vc-mcvs-global-switches flags)
6dbeb3d8
SM
557 (append vc-mcvs-global-switches flags)))))
558 (if (not (member (car flags) '("diff" "log" "status")))
559 ;; No need to filter: do it the easy way.
560 (apply 'vc-do-command buffer okstatus "mcvs" file args)
561 ;; We need to filter the output.
562 ;; The output of the filter uses filenames relative to the root,
563 ;; so we need to change the default-directory.
b6c4e4e0 564 ;; (assert (equal default-directory (vc-mcvs-root file)))
6dbeb3d8
SM
565 (vc-do-command
566 buffer okstatus "sh" nil "-c"
567 (concat "mcvs "
568 (mapconcat
569 'shell-quote-argument
570 (append (remq nil args)
571 (if file (list (file-relative-name file))))
572 " ")
573 " | mcvs filt")))))
3928b9a6 574
d699c8e2
SM
575(defun vc-mcvs-repository-hostname (dirname)
576 (vc-cvs-repository-hostname (vc-mcvs-root dirname)))
3928b9a6
SM
577
578(defun vc-mcvs-dir-state-heuristic (dir)
579 "Find the Meta-CVS state of all files in DIR, using only local information."
580 (with-temp-buffer
581 (vc-cvs-get-entries dir)
582 (goto-char (point-min))
583 (while (not (eobp))
584 ;; Meta-MCVS-removed files are not taken under VC control.
585 (when (looking-at "/\\([^/]*\\)/[^/-]")
586 (let ((file (expand-file-name (match-string 1) dir)))
587 (unless (vc-file-getprop file 'vc-state)
588 (vc-cvs-parse-entry file t))))
589 (forward-line 1))))
590
591(defalias 'vc-mcvs-valid-symbolic-tag-name-p 'vc-cvs-valid-symbolic-tag-name-p)
5b5afd50 592(defalias 'vc-mcvs-valid-revision-number-p 'vc-cvs-valid-revision-number-p)
3928b9a6
SM
593
594(provide 'vc-mcvs)
ab5796a9 595
58913dd3 596;; arch-tag: a39c7c1c-5247-429d-88df-dd7187d2e704
3928b9a6 597;;; vc-mcvs.el ends here