(gdb-invalidate-assembler): Update assembler buffer
[bpt/emacs.git] / lisp / vc-mcvs.el
CommitLineData
3928b9a6
SM
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
51241d96
SM
27;; The home page of the Meta-CVS version control system is at
28;;
29;; http://users.footprints.net/~kaz/mcvs.html
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))
72 :version "21.4"
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))
84 :version "21.4"
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))
94 :version "21.4"
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'."
100 :version "21.4"
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
109 :version "21.4"
110 :group 'vc)
111
3928b9a6
SM
112;;;
113;;; State-querying functions
114;;;
115
116;;;###autoload (defun vc-mcvs-registered (file)
117;;;###autoload (let ((dir file))
118;;;###autoload (while (and (stringp dir)
119;;;###autoload (not (equal dir (setq dir (file-name-directory dir)))))
120;;;###autoload (setq dir (if (file-directory-p
121;;;###autoload (expand-file-name "MCVS/CVS" dir))
122;;;###autoload t (directory-file-name dir))))
123;;;###autoload (if (eq dir t)
124;;;###autoload (progn
125;;;###autoload (load "vc-mcvs")
126;;;###autoload (vc-mcvs-registered file)))))
127
128(defun vc-mcvs-root (file)
129 "Return the root directory of a Meta-CVS project, if any."
15a45706
SM
130 (or (vc-file-getprop file 'mcvs-root)
131 (vc-file-setprop
132 file 'mcvs-root
133 (let ((root nil))
134 (while (not (or root
135 (equal file (setq file (file-name-directory file)))))
136 (if (file-directory-p (expand-file-name "MCVS/CVS" file))
137 (setq root file)
138 (setq file (directory-file-name file))))
139 root))))
3928b9a6
SM
140
141(defun vc-mcvs-read (file)
1207c9d2
SM
142 (if (file-readable-p file)
143 (with-temp-buffer
144 (insert-file-contents file)
145 (goto-char (point-min))
146 (read (current-buffer)))))
3928b9a6
SM
147
148(defun vc-mcvs-map-file (dir file)
149 (let ((map (vc-mcvs-read (expand-file-name "MCVS/MAP" dir)))
150 inode)
151 (dolist (x map inode)
152 (if (equal (nth 2 x) file) (setq inode (nth 1 x))))))
153
154(defun vc-mcvs-registered (file)
155 (let (root inode cvsfile)
156 (when (and (setq root (vc-mcvs-root file))
157 (setq inode (vc-mcvs-map-file
15a45706 158 root (file-relative-name file root))))
3928b9a6 159 (vc-file-setprop file 'mcvs-inode inode)
3928b9a6
SM
160 ;; Avoid calling `mcvs diff' in vc-workfile-unchanged-p.
161 (vc-file-setprop file 'vc-checkout-time
162 (if (vc-cvs-registered
163 (setq cvsfile (expand-file-name inode root)))
164 (vc-file-getprop cvsfile 'vc-checkout-time)
165 ;; The file might not be registered yet because
166 ;; of lazy-adding.
167 0))
168 t)))
169
170(defmacro vc-mcvs-cvs (op file &rest args)
171 (declare (debug t))
172 `(,(intern (concat "vc-cvs-" (symbol-name op)))
173 (expand-file-name (vc-file-getprop ,file 'mcvs-inode)
174 (vc-file-getprop ,file 'mcvs-root))
175 ,@args))
176
177(defun vc-mcvs-state (file)
178 ;; This would assume the Meta-CVS sandbox is synchronized.
179 ;; (vc-mcvs-cvs state file))
180 "Meta-CVS-specific version of `vc-state'."
d699c8e2 181 (if (vc-stay-local-p file)
3928b9a6
SM
182 (let ((state (vc-file-getprop file 'vc-state)))
183 ;; If we should stay local, use the heuristic but only if
184 ;; we don't have a more precise state already available.
185 (if (memq state '(up-to-date edited))
186 (vc-mcvs-state-heuristic file)
187 state))
188 (with-temp-buffer
6dbeb3d8 189 (setq default-directory (vc-mcvs-root file))
3928b9a6
SM
190 (vc-mcvs-command t 0 file "status")
191 (vc-cvs-parse-status t))))
192
193
194(defalias 'vc-mcvs-state-heuristic 'vc-cvs-state-heuristic)
195
196(defun vc-mcvs-dir-state (dir)
197 "Find the Meta-CVS state of all files in DIR."
198 ;; if DIR is not under Meta-CVS control, don't do anything.
199 (when (file-readable-p (expand-file-name "MCVS/CVS/Entries" dir))
d699c8e2 200 (if (vc-stay-local-p dir)
3928b9a6
SM
201 (vc-mcvs-dir-state-heuristic dir)
202 (let ((default-directory dir))
203 ;; Don't specify DIR in this command, the default-directory is
204 ;; enough. Otherwise it might fail with remote repositories.
205 (with-temp-buffer
6dbeb3d8 206 (setq default-directory (vc-mcvs-root dir))
3928b9a6
SM
207 (vc-mcvs-command t 0 nil "status" "-l")
208 (goto-char (point-min))
209 (while (re-search-forward "^=+\n\\([^=\n].*\n\\|\n\\)+" nil t)
210 (narrow-to-region (match-beginning 0) (match-end 0))
211 (vc-cvs-parse-status)
212 (goto-char (point-max))
213 (widen)))))))
214
215(defun vc-mcvs-workfile-version (file) (vc-mcvs-cvs workfile-version file))
216
217(defalias 'vc-mcvs-checkout-model 'vc-cvs-checkout-model)
218
4a97caca
SM
219(defun vc-mcvs-mode-line-string (file)
220 (let ((s (vc-mcvs-cvs mode-line-string file)))
6dbeb3d8
SM
221 (when s
222 (if (and (not (memq (vc-state file) '(up-to-date needs-patch)))
223 (string-match "\\`CVS-" s))
224 ;; The CVS file is not in sync, so we need to adjust the state.
225 (concat "MCVS:" (substring s 4))
226 (concat "M" s)))))
3928b9a6
SM
227
228;;;
229;;; State-changing functions
230;;;
231
232(defun vc-mcvs-register (file &optional rev comment)
233 "Register FILE into the Meta-CVS version-control system.
234COMMENT can be used to provide an initial description of FILE.
235
236`vc-register-switches' and `vc-mcvs-register-switches' are passed to
237the Meta-CVS command (in that order)."
238 (let* ((filename (file-name-nondirectory file))
239 (extpos (string-match "\\." filename))
240 (ext (if extpos (substring filename (1+ extpos))))
241 (root (vc-mcvs-root file))
242 (types-file (expand-file-name "MCVS/TYPES" root))
243 (map-file (expand-file-name "MCVS/MAP" root))
244 (types (vc-mcvs-read types-file)))
245 ;; Make sure meta files like MCVS/MAP are not read-only (happens with
246 ;; CVSREAD) since Meta-CVS doesn't pay attention to it at all and goes
247 ;; belly-up.
248 (unless (file-writable-p map-file)
249 (vc-checkout map-file t))
15a45706 250 (unless (or (file-writable-p types-file) (not (file-exists-p types-file)))
3928b9a6
SM
251 (vc-checkout types-file t))
252 ;; Make sure the `mcvs add' will not fire up the CVSEDITOR
253 ;; to add a rule for the given file's extension.
254 (when (and ext (not (assoc ext types)))
255 (let ((type (completing-read "Type to use [default]: "
256 '("default" "name-only" "keep-old"
257 "binary" "value-only")
258 nil t nil nil "default")))
259 (push (list ext (make-symbol (upcase (concat ":" type)))) types)
260 (setq types (sort types (lambda (x y) (string< (car x) (car y)))))
261 (with-current-buffer (find-file-noselect types-file)
3928b9a6
SM
262 (erase-buffer)
263 (pp types (current-buffer))
264 (save-buffer)
265 (unless (get-buffer-window (current-buffer) t)
266 (kill-buffer (current-buffer)))))))
267 ;; Now do the ADD.
d011ca0f
SM
268 (prog1 (apply 'vc-mcvs-command nil 0 file
269 "add"
270 (and comment (string-match "[^\t\n ]" comment)
271 (concat "-m" comment))
272 (vc-switches 'MCVS 'register))
273 ;; I'm not sure exactly why, but if we don't setup the inode and root
274 ;; prop of the file, things break later on in vc-mode-line that
275 ;; ends up calling vc-mcvs-workfile-version.
276 ;; We also need to set vc-checkout-time so that vc-workfile-unchanged-p
277 ;; doesn't try to call `mcvs diff' on the file.
278 (vc-mcvs-registered file)))
3928b9a6
SM
279
280(defalias 'vc-mcvs-responsible-p 'vc-mcvs-root
281 "Return non-nil if CVS thinks it is responsible for FILE.")
282
283(defalias 'vc-cvs-could-register 'vc-cvs-responsible-p
284 "Return non-nil if FILE could be registered in Meta-CVS.
285This is only possible if Meta-CVS is responsible for FILE's directory.")
286
287(defun vc-mcvs-checkin (file rev comment)
288 "Meta-CVS-specific version of `vc-backend-checkin'."
d011ca0f
SM
289 (unless (or (not rev) (vc-mcvs-valid-version-number-p rev))
290 (if (not (vc-mcvs-valid-symbolic-tag-name-p rev))
291 (error "%s is not a valid symbolic tag name" rev)
d699c8e2 292 ;; If the input revision is a valid symbolic tag name, we create it
d011ca0f 293 ;; as a branch, commit and switch to it.
6dbeb3d8
SM
294 ;; This file-specific form of branching is deprecated.
295 ;; We can't use `mcvs branch' and `mcvs switch' because they cannot
296 ;; be applied just to this one file.
d011ca0f
SM
297 (apply 'vc-mcvs-command nil 0 file "tag" "-b" (list rev))
298 (apply 'vc-mcvs-command nil 0 file "update" "-r" (list rev))
299 (vc-file-setprop file 'vc-mcvs-sticky-tag rev)
300 (setq rev nil)))
d699c8e2
SM
301 ;; This commit might cvs-commit several files (e.g. MAP and TYPES)
302 ;; so using numbered revs here is dangerous and somewhat meaningless.
303 (when rev (error "Cannot commit to a specific revision number"))
d011ca0f 304 (let ((status (apply 'vc-mcvs-command nil 1 file
d699c8e2 305 "ci" "-m" comment
d011ca0f 306 (vc-switches 'MCVS 'checkin))))
3928b9a6
SM
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"
d011ca0f 345 (vc-switches 'MCVS 'checkout)))
3928b9a6
SM
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))
d011ca0f 350 (vc-call update file editable rev (vc-switches 'MCVS 'checkout)))
3928b9a6
SM
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
4a97caca
SM
375(defun vc-mcvs-rename-file (old new)
376 (vc-mcvs-command nil 0 new "move" (file-relative-name old)))
377
3928b9a6
SM
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.
389The 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."
6dbeb3d8
SM
453 (let ((default-directory (vc-mcvs-root file)))
454 ;; Run the command from the root dir so that `mcvs filt' returns
455 ;; valid relative names.
456 (vc-mcvs-command
457 nil
458 (if (and (vc-stay-local-p file) (fboundp 'start-process)) 'async 0)
459 file "log")))
3928b9a6
SM
460
461(defun vc-mcvs-diff (file &optional oldvers newvers)
462 "Get a difference report using Meta-CVS between two versions of FILE."
d011ca0f
SM
463 (if (string= (vc-workfile-version file) "0")
464 ;; This file is added but not yet committed; there is no master file.
465 (if (or oldvers newvers)
466 (error "No revisions of %s exist" file)
467 ;; We regard this as "changed".
468 ;; Diff it against /dev/null.
469 ;; Note: this is NOT a "mcvs diff".
470 (apply 'vc-do-command "*vc-diff*"
471 1 "diff" file
472 (append (vc-switches nil 'diff) '("/dev/null")))
473 ;; Even if it's empty, it's locally modified.
474 1)
d699c8e2 475 (let* ((async (and (vc-stay-local-p file) (fboundp 'start-process)))
6dbeb3d8
SM
476 ;; Run the command from the root dir so that `mcvs filt' returns
477 ;; valid relative names.
478 (default-directory (vc-mcvs-root file))
d011ca0f
SM
479 (status
480 (apply 'vc-mcvs-command "*vc-diff*"
481 (if async 'async 1)
482 file "diff"
483 (and oldvers (concat "-r" oldvers))
484 (and newvers (concat "-r" newvers))
485 (vc-switches 'MCVS 'diff))))
486 (if async 1 status)))) ; async diff, pessimistic assumption.
3928b9a6
SM
487
488(defun vc-mcvs-diff-tree (dir &optional rev1 rev2)
489 "Diff all files at and below DIR."
490 (with-current-buffer "*vc-diff*"
6dbeb3d8
SM
491 ;; Run the command from the root dir so that `mcvs filt' returns
492 ;; valid relative names.
493 (setq default-directory (vc-mcvs-root dir))
494 ;; cvs diff: use a single call for the entire tree
495 (let ((coding-system-for-read (or coding-system-for-read 'undecided)))
496 (apply 'vc-mcvs-command "*vc-diff*" 1 dir "diff"
497 (and rev1 (concat "-r" rev1))
498 (and rev2 (concat "-r" rev2))
499 (vc-switches 'MCVS 'diff)))))
3928b9a6
SM
500
501(defun vc-mcvs-annotate-command (file buffer &optional version)
502 "Execute \"mcvs annotate\" on FILE, inserting the contents in BUFFER.
503Optional arg VERSION is a version to annotate from."
504 (vc-mcvs-command
505 buffer
d699c8e2 506 (if (and (vc-stay-local-p file) (fboundp 'start-process)) 'async 0)
3928b9a6
SM
507 file "annotate" (if version (concat "-r" version))))
508
509(defalias 'vc-mcvs-annotate-current-time 'vc-cvs-annotate-current-time)
510(defalias 'vc-mcvs-annotate-time 'vc-cvs-annotate-time)
511
512;;;
513;;; Snapshot system
514;;;
515
516(defun vc-mcvs-create-snapshot (dir name branchp)
517 "Assign to DIR's current version a given NAME.
518If BRANCHP is non-nil, the name is created as a branch (and the current
519workspace is immediately moved to that new branch)."
6dbeb3d8
SM
520 (if (not branchp)
521 (vc-mcvs-command nil 0 dir "tag" "-c" name)
522 (vc-mcvs-command nil 0 dir "branch" name)
523 (vc-mcvs-command nil 0 dir "switch" name)))
3928b9a6
SM
524
525(defun vc-mcvs-retrieve-snapshot (dir name update)
526 "Retrieve a snapshot at and below DIR.
527NAME is the name of the snapshot; if it is empty, do a `cvs update'.
528If UPDATE is non-nil, then update (resynch) any affected buffers."
529 (with-current-buffer (get-buffer-create "*vc*")
530 (let ((default-directory dir)
531 (sticky-tag))
532 (erase-buffer)
533 (if (or (not name) (string= name ""))
534 (vc-mcvs-command t 0 nil "update")
535 (vc-mcvs-command t 0 nil "update" "-r" name)
536 (setq sticky-tag name))
537 (when update
538 (goto-char (point-min))
539 (while (not (eobp))
540 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
541 (let* ((file (expand-file-name (match-string 2) dir))
542 (state (match-string 1))
543 (buffer (find-buffer-visiting file)))
544 (when buffer
545 (cond
546 ((or (string= state "U")
547 (string= state "P"))
548 (vc-file-setprop file 'vc-state 'up-to-date)
549 (vc-file-setprop file 'vc-workfile-version nil)
550 (vc-file-setprop file 'vc-checkout-time
551 (nth 5 (file-attributes file))))
552 ((or (string= state "M")
553 (string= state "C"))
554 (vc-file-setprop file 'vc-state 'edited)
555 (vc-file-setprop file 'vc-workfile-version nil)
556 (vc-file-setprop file 'vc-checkout-time 0)))
557 (vc-file-setprop file 'vc-mcvs-sticky-tag sticky-tag)
558 (vc-resynch-buffer file t t))))
559 (forward-line 1))))))
560
561
562;;;
563;;; Miscellaneous
564;;;
565
d699c8e2 566(defalias 'vc-mcvs-make-version-backups-p 'vc-stay-local-p
3928b9a6
SM
567 "Return non-nil if version backups should be made for FILE.")
568(defalias 'vc-mcvs-check-headers 'vc-cvs-check-headers)
569
570
571;;;
572;;; Internal functions
573;;;
574
575(defun vc-mcvs-command (buffer okstatus file &rest flags)
576 "A wrapper around `vc-do-command' for use in vc-mcvs.el.
577The difference to vc-do-command is that this function always invokes `mcvs',
578and that it passes `vc-mcvs-global-switches' to it before FLAGS."
6dbeb3d8 579 (let ((args (append '("--error-terminate")
15a45706
SM
580 (if (stringp vc-mcvs-global-switches)
581 (cons vc-mcvs-global-switches flags)
6dbeb3d8
SM
582 (append vc-mcvs-global-switches flags)))))
583 (if (not (member (car flags) '("diff" "log" "status")))
584 ;; No need to filter: do it the easy way.
585 (apply 'vc-do-command buffer okstatus "mcvs" file args)
586 ;; We need to filter the output.
587 ;; The output of the filter uses filenames relative to the root,
588 ;; so we need to change the default-directory.
589 (assert (equal default-directory (vc-mcvs-root file)))
590 (vc-do-command
591 buffer okstatus "sh" nil "-c"
592 (concat "mcvs "
593 (mapconcat
594 'shell-quote-argument
595 (append (remq nil args)
596 (if file (list (file-relative-name file))))
597 " ")
598 " | mcvs filt")))))
3928b9a6 599
d699c8e2
SM
600(defun vc-mcvs-repository-hostname (dirname)
601 (vc-cvs-repository-hostname (vc-mcvs-root dirname)))
3928b9a6
SM
602
603(defun vc-mcvs-dir-state-heuristic (dir)
604 "Find the Meta-CVS state of all files in DIR, using only local information."
605 (with-temp-buffer
606 (vc-cvs-get-entries dir)
607 (goto-char (point-min))
608 (while (not (eobp))
609 ;; Meta-MCVS-removed files are not taken under VC control.
610 (when (looking-at "/\\([^/]*\\)/[^/-]")
611 (let ((file (expand-file-name (match-string 1) dir)))
612 (unless (vc-file-getprop file 'vc-state)
613 (vc-cvs-parse-entry file t))))
614 (forward-line 1))))
615
616(defalias 'vc-mcvs-valid-symbolic-tag-name-p 'vc-cvs-valid-symbolic-tag-name-p)
617(defalias 'vc-mcvs-valid-version-number-p 'vc-cvs-valid-version-number-p)
618
619(provide 'vc-mcvs)
620;;; vc-mcvs.el ends here