1 ;;; vc-mcvs.el --- VC backend for the Meta-CVS version-control system
3 ;; Copyright (C) 2003-2011 Free Software Foundation, Inc.
5 ;; Author: FSF (see vc.el for full credits)
8 ;; This file is part of GNU Emacs.
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 3 of the License, or
13 ;; (at your option) any later version.
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; ********** READ THIS! **********
27 ;; This file apparently does not work with the new (as of Emacs 23)
28 ;; VC code. Use at your own risk. Please contact emacs-devel if you
29 ;; can maintain this file and update it to work correctly.
31 ;; ********** READ THIS! **********
33 ;; This file has been obsolete and unsupported since Emacs 23.1.
36 ;; The home page of the Meta-CVS version control system is at
38 ;; http://users.footprints.net/~kaz/mcvs.html
40 ;; This is derived from vc-cvs.el as follows:
41 ;; - cp vc-cvs.el vc-mcvs.el
42 ;; - Replace CVS/ with MCVS/CVS/
43 ;; - Replace 'CVS with 'MCVS
44 ;; - Replace -cvs- with -mcvs-
45 ;; - Replace most of the rest of CVS to Meta-CVS
47 ;; Then of course started the hacking. Only a small part of the code
48 ;; has been touched and not much more than that was tested, so if
49 ;; you bump into a bug, don't be surprised: just report it to me.
51 ;; What has been partly tested:
52 ;; - C-x v v to start editing a file that was checked out with CVSREAD on.
53 ;; - C-x v v to commit a file
58 ;; - M-x vc-rename-file RET
62 ;; - Retrieving tags doesn't filter `cvs update' output and thus
63 ;; parses bogus filenames. Don't know if it harms.
67 (eval-when-compile (require 'vc
))
71 ;;; Customization options
74 (defcustom vc-mcvs-global-switches nil
75 "Global switches to pass to any Meta-CVS command."
76 :type
'(choice (const :tag
"None" nil
)
77 (string :tag
"Argument String")
78 (repeat :tag
"Argument List" :value
("") string
))
82 (defcustom vc-mcvs-register-switches nil
83 "Switches for registering a file into Meta-CVS.
84 A string or list of strings passed to the checkin program by
85 \\[vc-register]. If nil, use the value of `vc-register-switches'.
86 If t, use no switches."
87 :type
'(choice (const :tag
"Unspecified" nil
)
89 (string :tag
"Argument String")
90 (repeat :tag
"Argument List" :value
("") string
))
94 (defcustom vc-mcvs-diff-switches nil
95 "String or list of strings specifying switches for Meta-CVS diff under VC.
96 If nil, use the value of `vc-diff-switches'. If t, use no switches."
97 :type
'(choice (const :tag
"Unspecified" nil
)
99 (string :tag
"Argument String")
100 (repeat :tag
"Argument List" :value
("") string
))
104 (defcustom vc-mcvs-header vc-cvs-header
105 "Header keywords to be inserted by `vc-insert-headers'."
106 :version
"24.1" ; no longer consult the obsolete vc-header-alist
107 :type
'(repeat string
)
110 (defcustom vc-mcvs-use-edit vc-cvs-use-edit
111 "Non-nil means to use `cvs edit' to \"check out\" a file.
112 This is only meaningful if you don't use the implicit checkout model
113 \(i.e. if you have $CVSREAD set)."
118 ;;; Properties of the backend
120 (defalias 'vc-mcvs-revision-granularity
'vc-cvs-revision-granularity
)
121 (defalias 'vc-mcvs-checkout-model
'vc-cvs-checkout-model
)
124 ;;; State-querying functions
127 ;;;###autoload (defun vc-mcvs-registered (file)
128 ;;;###autoload (if (vc-find-root file "MCVS/CVS")
129 ;;;###autoload (progn
130 ;;;###autoload (load "vc-mcvs")
131 ;;;###autoload (vc-mcvs-registered file))))
133 (defun vc-mcvs-root (file)
134 "Return the root directory of a Meta-CVS project, if any."
135 (or (vc-file-getprop file
'mcvs-root
)
136 (vc-file-setprop file
'mcvs-root
(vc-find-root file
"MCVS/CVS"))))
138 (defun vc-mcvs-read (file)
139 (if (file-readable-p file
)
141 (insert-file-contents file
)
142 (goto-char (point-min))
143 (read (current-buffer)))))
145 (defun vc-mcvs-map-file (dir file
)
146 (let ((map (vc-mcvs-read (expand-file-name "MCVS/MAP" dir
)))
148 (dolist (x map inode
)
149 (if (equal (nth 2 x
) file
) (setq inode
(nth 1 x
))))))
151 (defun vc-mcvs-registered (file)
152 (let (root inode cvsfile
)
153 (when (and (setq root
(vc-mcvs-root file
))
154 (setq inode
(vc-mcvs-map-file
155 root
(file-relative-name file root
))))
156 (vc-file-setprop file
'mcvs-inode inode
)
157 ;; Avoid calling `mcvs diff' in vc-workfile-unchanged-p.
158 (vc-file-setprop file
'vc-checkout-time
159 (if (vc-cvs-registered
160 (setq cvsfile
(expand-file-name inode root
)))
161 (vc-file-getprop cvsfile
'vc-checkout-time
)
162 ;; The file might not be registered yet because
167 (defun vc-mcvs-state (file)
168 ;; This would assume the Meta-CVS sandbox is synchronized.
169 ;; (vc-mcvs-cvs state file))
170 "Meta-CVS-specific version of `vc-state'."
171 (if (vc-stay-local-p file
)
172 (let ((state (vc-file-getprop file
'vc-state
)))
173 ;; If we should stay local, use the heuristic but only if
174 ;; we don't have a more precise state already available.
175 (if (memq state
'(up-to-date edited
))
176 (vc-mcvs-state-heuristic file
)
179 (setq default-directory
(vc-mcvs-root file
))
180 (vc-mcvs-command t
0 file
"status")
181 (vc-cvs-parse-status t
))))
184 (defalias 'vc-mcvs-state-heuristic
'vc-cvs-state-heuristic
)
186 (defun vc-mcvs-working-revision (file)
187 (vc-cvs-working-revision
188 (expand-file-name (vc-file-getprop file
'mcvs-inode
)
189 (vc-file-getprop file
'mcvs-root
))))
192 ;;; State-changing functions
195 (defun vc-mcvs-register (files &optional rev comment
)
196 "Register FILES into the Meta-CVS version-control system.
197 COMMENT can be used to provide an initial description of FILE.
198 Passes either `vc-mcvs-register-switches' or `vc-register-switches'
199 to the Meta-CVS command."
200 ;; FIXME: multiple-file case should be made to work.
201 (if (> (length files
) 1) (error "Registering filesets is not yet supported"))
202 (let* ((file (car files
))
203 (filename (file-name-nondirectory file
))
204 (extpos (string-match "\\." filename
))
205 (ext (if extpos
(substring filename
(1+ extpos
))))
206 (root (vc-mcvs-root file
))
207 (types-file (expand-file-name "MCVS/TYPES" root
))
208 (map-file (expand-file-name "MCVS/MAP" root
))
209 (types (vc-mcvs-read types-file
)))
210 ;; Make sure meta files like MCVS/MAP are not read-only (happens with
211 ;; CVSREAD) since Meta-CVS doesn't pay attention to it at all and goes
213 (unless (file-writable-p map-file
)
214 (vc-checkout map-file t
))
215 (unless (or (file-writable-p types-file
) (not (file-exists-p types-file
)))
216 (vc-checkout types-file t
))
217 ;; Make sure the `mcvs add' will not fire up the CVSEDITOR
218 ;; to add a rule for the given file's extension.
219 (when (and ext
(not (assoc ext types
)))
220 (let ((type (completing-read "Type to use (default): "
221 '("default" "name-only" "keep-old"
222 "binary" "value-only")
223 nil t nil nil
"default")))
224 (push (list ext
(make-symbol (upcase (concat ":" type
)))) types
)
225 (setq types
(sort types
(lambda (x y
) (string< (car x
) (car y
)))))
226 (with-current-buffer (find-file-noselect types-file
)
228 (pp types
(current-buffer))
230 (unless (get-buffer-window (current-buffer) t
)
231 (kill-buffer (current-buffer))))))
233 (prog1 (apply 'vc-mcvs-command nil
0 file
235 (and comment
(string-match "[^\t\n ]" comment
)
236 (concat "-m" comment
))
237 (vc-switches 'MCVS
'register
))
238 ;; I'm not sure exactly why, but if we don't setup the inode and root
239 ;; prop of the file, things break later on in vc-mode-line that
240 ;; ends up calling vc-mcvs-working-revision.
241 ;; We also need to set vc-checkout-time so that vc-workfile-unchanged-p
242 ;; doesn't try to call `mcvs diff' on the file.
243 (vc-mcvs-registered file
))))
245 (defalias 'vc-mcvs-responsible-p
'vc-mcvs-root
246 "Return non-nil if CVS thinks it is responsible for FILE.")
248 (defalias 'vc-cvs-could-register
'vc-cvs-responsible-p
249 "Return non-nil if FILE could be registered in Meta-CVS.
250 This is only possible if Meta-CVS is responsible for FILE's directory.")
252 (defun vc-mcvs-checkin (files rev comment
)
253 "Meta-CVS-specific version of `vc-backend-checkin'."
254 (unless (or (not rev
) (vc-mcvs-valid-revision-number-p rev
))
255 (if (not (vc-mcvs-valid-symbolic-tag-name-p rev
))
256 (error "%s is not a valid symbolic tag name" rev
)
257 ;; If the input revision is a valid symbolic tag name, we create it
258 ;; as a branch, commit and switch to it.
259 ;; This file-specific form of branching is deprecated.
260 ;; We can't use `mcvs branch' and `mcvs switch' because they cannot
261 ;; be applied just to this one file.
262 (apply 'vc-mcvs-command nil
0 files
"tag" "-b" (list rev
))
263 (apply 'vc-mcvs-command nil
0 files
"update" "-r" (list rev
))
264 (mapc (lambda (file) (vc-file-setprop file
'vc-mcvs-sticky-tag rev
))
267 ;; This commit might cvs-commit several files (e.g. MAP and TYPES)
268 ;; so using numbered revs here is dangerous and somewhat meaningless.
269 (when rev
(error "Cannot commit to a specific revision number"))
270 (let ((status (apply 'vc-mcvs-command nil
1 files
272 (vc-switches 'MCVS
'checkin
))))
274 (goto-char (point-min))
275 (when (not (zerop status
))
276 ;; Check checkin problem.
278 ((re-search-forward "Up-to-date check failed" nil t
)
279 (mapc (lambda (file) (vc-file-setprop file
'vc-state
'needs-merge
))
281 (error "%s" (substitute-command-keys
282 (concat "Up-to-date check failed: "
283 "type \\[vc-next-action] to merge in changes"))))
285 (pop-to-buffer (current-buffer))
286 (goto-char (point-min))
287 (shrink-window-if-larger-than-buffer)
288 (error "Check-in failed"))))
289 ;; Single-file commit? Then update the revision by parsing the buffer.
290 ;; Otherwise we can't necessarily tell what goes with what; clear
291 ;; its properties so they have to be refetched.
292 (if (= (length files
) 1)
294 (car files
) 'vc-working-revision
295 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
296 (mapc (lambda (file) (vc-file-clearprops file
)) files
))
297 ;; Anyway, forget the checkout model of the file, because we might have
298 ;; guessed wrong when we found the file. After commit, we can
299 ;; tell it from the permissions of the file (see
300 ;; vc-mcvs-checkout-model).
301 (mapc (lambda (file) (vc-file-setprop file
'vc-checkout-model nil
))
304 ;; if this was an explicit check-in (does not include creation of
305 ;; a branch), remove the sticky tag.
306 (if (and rev
(not (vc-mcvs-valid-symbolic-tag-name-p rev
)))
307 (vc-mcvs-command nil
0 files
"update" "-A"))))
309 (defun vc-mcvs-find-revision (file rev buffer
)
310 (apply 'vc-mcvs-command
312 "-Q" ; suppress diagnostic output
314 (and rev
(not (string= rev
""))
317 (vc-switches 'MCVS
'checkout
)))
319 (defun vc-mcvs-checkout (file &optional editable rev
)
320 (message "Checking out %s..." file
)
321 (with-current-buffer (or (get-file-buffer file
) (current-buffer))
322 (vc-mcvs-update file editable rev
(vc-switches 'MCVS
'checkout
)))
324 (message "Checking out %s...done" file
))
326 (defun vc-mcvs-update (file editable rev switches
)
327 (if (and (file-exists-p file
) (not rev
))
328 ;; If no revision was specified, just make the file writable
329 ;; if necessary (using `cvs-edit' if requested).
330 (and editable
(not (eq (vc-mcvs-checkout-model (list file
)) 'implicit
))
332 (vc-mcvs-command nil
0 file
"edit")
333 (set-file-modes file
(logior (file-modes file
) 128))
334 (if (equal file buffer-file-name
) (toggle-read-only -
1))))
335 ;; Check out a particular revision (or recreate the file).
336 (vc-file-setprop file
'vc-working-revision nil
)
337 (apply 'vc-mcvs-command nil
0 file
340 ;; default for verbose checkout: clear the sticky tag so
341 ;; that the actual update will get the head of the trunk
342 (if (or (not rev
) (string= rev
""))
347 (defun vc-mcvs-rename-file (old new
)
348 (vc-mcvs-command nil
0 new
"move" (file-relative-name old
)))
350 (defun vc-mcvs-revert (file &optional contents-done
)
351 "Revert FILE to the working revision it was based on."
352 (vc-default-revert 'MCVS file contents-done
)
353 (unless (eq (vc-mcvs-checkout-model (list file
)) 'implicit
)
355 (vc-mcvs-command nil
0 file
"unedit")
356 ;; Make the file read-only by switching off all w-bits
357 (set-file-modes file
(logand (file-modes file
) 3950)))))
359 (defun vc-mcvs-merge (file first-revision
&optional second-revision
)
360 "Merge changes into current working copy of FILE.
361 The changes are between FIRST-REVISION and SECOND-REVISION."
362 (vc-mcvs-command nil
0 file
364 (concat "-j" first-revision
)
365 (concat "-j" second-revision
))
366 (vc-file-setprop file
'vc-state
'edited
)
367 (with-current-buffer (get-buffer "*vc*")
368 (goto-char (point-min))
369 (if (re-search-forward "conflicts during merge" nil t
)
371 0))) ; signal success
373 (defun vc-mcvs-merge-news (file)
374 "Merge in any new changes made to FILE."
375 (message "Merging changes into %s..." file
)
376 ;; (vc-file-setprop file 'vc-working-revision nil)
377 (vc-file-setprop file
'vc-checkout-time
0)
378 (vc-mcvs-command nil
0 file
"update")
379 ;; Analyze the merge result reported by Meta-CVS, and set
380 ;; file properties accordingly.
381 (with-current-buffer (get-buffer "*vc*")
382 (goto-char (point-min))
383 ;; get new working revision
384 (if (re-search-forward
385 "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t
)
386 (vc-file-setprop file
'vc-working-revision
(match-string 1))
387 (vc-file-setprop file
'vc-working-revision nil
))
390 (if (eq (buffer-size) 0)
391 0 ;; there were no news; indicate success
392 (if (re-search-forward
393 (concat "^\\([CMUP] \\)?"
395 "\\( already contains the differences between \\)?")
398 ;; Merge successful, we are in sync with repository now
399 ((or (match-string 2)
400 (string= (match-string 1) "U ")
401 (string= (match-string 1) "P "))
402 (vc-file-setprop file
'vc-state
'up-to-date
)
403 (vc-file-setprop file
'vc-checkout-time
404 (nth 5 (file-attributes file
)))
405 0);; indicate success to the caller
406 ;; Merge successful, but our own changes are still in the file
407 ((string= (match-string 1) "M ")
408 (vc-file-setprop file
'vc-state
'edited
)
409 0);; indicate success to the caller
410 ;; Conflicts detected!
412 (vc-file-setprop file
'vc-state
'edited
)
413 1);; signal the error to the caller
415 (pop-to-buffer "*vc*")
416 (error "Couldn't analyze mcvs update result")))
417 (message "Merging changes into %s...done" file
))))
419 (defun vc-mcvs-modify-change-comment (files rev comment
)
420 "Modify the change comments for FILES on a specified REV.
421 Will fail unless you have administrative privileges on the repo."
422 (vc-mcvs-command nil
0 files
"rcs" (concat "-m" comment
":" rev
)))
426 ;;; History functions
429 (defun vc-mcvs-print-log (files &optional buffer
)
430 "Get change log associated with FILES."
431 (let ((default-directory (vc-mcvs-root (car files
))))
432 ;; Run the command from the root dir so that `mcvs filt' returns
433 ;; valid relative names.
436 (if (vc-stay-local-p files
) 'async
0)
439 (defun vc-mcvs-diff (files &optional oldvers newvers buffer
)
440 "Get a difference report using Meta-CVS between two revisions of FILES."
441 (let* ((async (and (not vc-disable-async-diff
)
442 (vc-stay-local-p files
)))
443 ;; Run the command from the root dir so that `mcvs filt' returns
444 ;; valid relative names.
445 (default-directory (vc-mcvs-root (car files
)))
447 (apply 'vc-mcvs-command
(or buffer
"*vc-diff*")
450 (and oldvers
(concat "-r" oldvers
))
451 (and newvers
(concat "-r" newvers
))
452 (vc-switches 'MCVS
'diff
))))
453 (if async
1 status
))) ; async diff, pessimistic assumption.
455 (defun vc-mcvs-annotate-command (file buffer
&optional revision
)
456 "Execute \"mcvs annotate\" on FILE, inserting the contents in BUFFER.
457 Optional arg REVISION is a revision to annotate from."
460 (if (vc-stay-local-p file
) 'async
0)
461 file
"annotate" (if revision
(concat "-r" revision
)))
462 (with-current-buffer buffer
463 (goto-char (point-min))
464 (re-search-forward "^[0-9]")
465 (delete-region (point-min) (1- (point)))))
467 (defalias 'vc-mcvs-annotate-current-time
'vc-cvs-annotate-current-time
)
468 (defalias 'vc-mcvs-annotate-time
'vc-cvs-annotate-time
)
474 (defun vc-mcvs-create-tag (dir name branchp
)
475 "Assign to DIR's current revision a given NAME.
476 If BRANCHP is non-nil, the name is created as a branch (and the current
477 workspace is immediately moved to that new branch)."
479 (vc-mcvs-command nil
0 dir
"tag" "-c" name
)
480 (vc-mcvs-command nil
0 dir
"branch" name
)
481 (vc-mcvs-command nil
0 dir
"switch" name
)))
483 (defun vc-mcvs-retrieve-tag (dir name update
)
484 "Retrieve a tag at and below DIR.
485 NAME is the name of the tag; if it is empty, do a `cvs update'.
486 If UPDATE is non-nil, then update (resynch) any affected buffers."
487 (with-current-buffer (get-buffer-create "*vc*")
488 (let ((default-directory dir
)
491 (if (or (not name
) (string= name
""))
492 (vc-mcvs-command t
0 nil
"update")
493 (vc-mcvs-command t
0 nil
"update" "-r" name
)
494 (setq sticky-tag name
))
496 (goto-char (point-min))
498 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
499 (let* ((file (expand-file-name (match-string 2) dir
))
500 (state (match-string 1))
501 (buffer (find-buffer-visiting file
)))
504 ((or (string= state
"U")
506 (vc-file-setprop file
'vc-state
'up-to-date
)
507 (vc-file-setprop file
'vc-working-revision nil
)
508 (vc-file-setprop file
'vc-checkout-time
509 (nth 5 (file-attributes file
))))
510 ((or (string= state
"M")
512 (vc-file-setprop file
'vc-state
'edited
)
513 (vc-file-setprop file
'vc-working-revision nil
)
514 (vc-file-setprop file
'vc-checkout-time
0)))
515 (vc-file-setprop file
'vc-mcvs-sticky-tag sticky-tag
)
516 (vc-resynch-buffer file t t
))))
517 (forward-line 1))))))
524 (defalias 'vc-mcvs-make-version-backups-p
'vc-stay-local-p
525 "Return non-nil if version backups should be made for FILE.")
526 (defalias 'vc-mcvs-check-headers
'vc-cvs-check-headers
)
530 ;;; Internal functions
533 (defun vc-mcvs-command (buffer okstatus file
&rest flags
)
534 "A wrapper around `vc-do-command' for use in vc-mcvs.el.
535 The difference to vc-do-command is that this function always invokes `mcvs',
536 and that it passes `vc-mcvs-global-switches' to it before FLAGS."
537 (let ((args (append '("--error-terminate")
538 (if (stringp vc-mcvs-global-switches
)
539 (cons vc-mcvs-global-switches flags
)
540 (append vc-mcvs-global-switches flags
)))))
541 (if (not (member (car flags
) '("diff" "log" "status")))
542 ;; No need to filter: do it the easy way.
543 (apply 'vc-do-command
(or buffer
"*vc*") okstatus
"mcvs" file args
)
544 ;; We need to filter the output.
545 ;; The output of the filter uses filenames relative to the root,
546 ;; so we need to change the default-directory.
547 ;; (assert (equal default-directory (vc-mcvs-root file)))
549 (or buffer
"*vc*") okstatus
"sh" nil
"-c"
552 'shell-quote-argument
553 (append (remq nil args
)
554 (if file
(list (file-relative-name file
))))
558 (defun vc-mcvs-repository-hostname (dirname)
559 (vc-cvs-repository-hostname (vc-mcvs-root dirname
)))
561 (defun vc-mcvs-dir-state-heuristic (dir)
562 "Find the Meta-CVS state of all files in DIR, using only local information."
564 (vc-cvs-get-entries dir
)
565 (goto-char (point-min))
567 ;; Meta-MCVS-removed files are not taken under VC control.
568 (when (looking-at "/\\([^/]*\\)/[^/-]")
569 (let ((file (expand-file-name (match-string 1) dir
)))
570 (unless (vc-file-getprop file
'vc-state
)
571 (vc-cvs-parse-entry file t
))))
574 (defalias 'vc-mcvs-valid-symbolic-tag-name-p
'vc-cvs-valid-symbolic-tag-name-p
)
575 (defalias 'vc-mcvs-valid-revision-number-p
'vc-cvs-valid-revision-number-p
)
579 ;; ********** READ THIS! **********
581 ;; This file apparently does not work with the new (as of Emacs 23)
582 ;; VC code. Use at your own risk. Please contact emacs-devel if you
583 ;; can maintain this file and update it to work correctly.
585 ;; ********** READ THIS! **********
587 ;;; vc-mcvs.el ends here