1 ;;; vc-mcvs.el --- VC backend for the Meta-CVS version-control system
3 ;; Copyright (C) 2003-2015 Free Software Foundation, Inc.
5 ;; Author: FSF (see vc.el for full credits)
7 ;; Obsolete-since: 23.1
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; ********** READ THIS! **********
28 ;; This file apparently does not work with the new (as of Emacs 23)
29 ;; VC code. Use at your own risk. Please contact emacs-devel if you
30 ;; can maintain this file and update it to work correctly.
32 ;; ********** READ THIS! **********
34 ;; The home page of the Meta-CVS version control system is at
36 ;; http://users.footprints.net/~kaz/mcvs.html
38 ;; This is derived from vc-cvs.el as follows:
39 ;; - cp vc-cvs.el vc-mcvs.el
40 ;; - Replace CVS/ with MCVS/CVS/
41 ;; - Replace 'CVS with 'MCVS
42 ;; - Replace -cvs- with -mcvs-
43 ;; - Replace most of the rest of CVS to Meta-CVS
45 ;; Then of course started the hacking. Only a small part of the code
46 ;; has been touched and not much more than that was tested, so if
47 ;; you bump into a bug, don't be surprised: just report it to me.
49 ;; What has been partly tested:
50 ;; - C-x v v to start editing a file that was checked out with CVSREAD on.
51 ;; - C-x v v to commit a file
56 ;; - M-x vc-rename-file RET
60 ;; - Retrieving tags doesn't filter `cvs update' output and thus
61 ;; parses bogus filenames. Don't know if it harms.
65 (eval-when-compile (require 'vc
))
69 ;;; Customization options
72 (defcustom vc-mcvs-global-switches nil
73 "Global switches to pass to any Meta-CVS command."
74 :type
'(choice (const :tag
"None" nil
)
75 (string :tag
"Argument String")
76 (repeat :tag
"Argument List" :value
("") string
))
80 (defcustom vc-mcvs-register-switches nil
81 "Switches for registering a file into Meta-CVS.
82 A string or list of strings passed to the checkin program by
83 \\[vc-register]. If nil, use the value of `vc-register-switches'.
84 If t, use no switches."
85 :type
'(choice (const :tag
"Unspecified" nil
)
87 (string :tag
"Argument String")
88 (repeat :tag
"Argument List" :value
("") string
))
92 (defcustom vc-mcvs-diff-switches nil
93 "String or list of strings specifying switches for Meta-CVS diff under VC.
94 If nil, use the value of `vc-diff-switches'. If t, use no switches."
95 :type
'(choice (const :tag
"Unspecified" nil
)
97 (string :tag
"Argument String")
98 (repeat :tag
"Argument List" :value
("") string
))
102 (defcustom vc-mcvs-header vc-cvs-header
103 "Header keywords to be inserted by `vc-insert-headers'."
104 :version
"24.1" ; no longer consult the obsolete vc-header-alist
105 :type
'(repeat string
)
108 (defcustom vc-mcvs-use-edit vc-cvs-use-edit
109 "Non-nil means to use `cvs edit' to \"check out\" a file.
110 This is only meaningful if you don't use the implicit checkout model
111 \(i.e. if you have $CVSREAD set)."
116 ;;; Properties of the backend
118 (defalias 'vc-mcvs-revision-granularity
'vc-cvs-revision-granularity
)
119 (defalias 'vc-mcvs-checkout-model
'vc-cvs-checkout-model
)
122 ;;; State-querying functions
125 ;;;###autoload (defun vc-mcvs-registered (file)
126 ;;;###autoload (if (vc-find-root file "MCVS/CVS")
127 ;;;###autoload (progn
128 ;;;###autoload (load "vc-mcvs")
129 ;;;###autoload (vc-mcvs-registered file))))
131 (defun vc-mcvs-root (file)
132 "Return the root directory of a Meta-CVS project, if any."
133 (or (vc-file-getprop file
'mcvs-root
)
134 (vc-file-setprop file
'mcvs-root
(vc-find-root file
"MCVS/CVS"))))
136 (defun vc-mcvs-read (file)
137 (if (file-readable-p file
)
139 (insert-file-contents file
)
140 (goto-char (point-min))
141 (read (current-buffer)))))
143 (defun vc-mcvs-map-file (dir file
)
144 (let ((map (vc-mcvs-read (expand-file-name "MCVS/MAP" dir
)))
146 (dolist (x map inode
)
147 (if (equal (nth 2 x
) file
) (setq inode
(nth 1 x
))))))
149 (defun vc-mcvs-registered (file)
150 (let (root inode cvsfile
)
151 (when (and (setq root
(vc-mcvs-root file
))
152 (setq inode
(vc-mcvs-map-file
153 root
(file-relative-name file root
))))
154 (vc-file-setprop file
'mcvs-inode inode
)
155 ;; Avoid calling `mcvs diff' in vc-workfile-unchanged-p.
156 (vc-file-setprop file
'vc-checkout-time
157 (if (vc-cvs-registered
158 (setq cvsfile
(expand-file-name inode root
)))
159 (vc-file-getprop cvsfile
'vc-checkout-time
)
160 ;; The file might not be registered yet because
165 (defun vc-mcvs-state (file)
166 ;; This would assume the Meta-CVS sandbox is synchronized.
167 ;; (vc-mcvs-cvs state file))
168 "Meta-CVS-specific version of `vc-state'."
169 (if (vc-stay-local-p file
)
170 (let ((state (vc-file-getprop file
'vc-state
)))
171 ;; If we should stay local, use the heuristic but only if
172 ;; we don't have a more precise state already available.
173 (if (memq state
'(up-to-date edited
))
174 (vc-mcvs-state-heuristic file
)
177 (setq default-directory
(vc-mcvs-root file
))
178 (vc-mcvs-command t
0 file
"status")
179 (vc-cvs-parse-status t
))))
182 (defalias 'vc-mcvs-state-heuristic
'vc-cvs-state-heuristic
)
184 (defun vc-mcvs-working-revision (file)
185 (vc-cvs-working-revision
186 (expand-file-name (vc-file-getprop file
'mcvs-inode
)
187 (vc-file-getprop file
'mcvs-root
))))
190 ;;; State-changing functions
192 (autoload 'vc-checkout
"vc")
193 (autoload 'vc-switches
"vc")
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
) (read-only-mode -
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 (autoload 'vc-default-revert
"vc")
352 (defun vc-mcvs-revert (file &optional contents-done
)
353 "Revert FILE to the working revision it was based on."
354 (vc-default-revert 'MCVS file contents-done
)
355 (unless (eq (vc-mcvs-checkout-model (list file
)) 'implicit
)
357 (vc-mcvs-command nil
0 file
"unedit")
358 ;; Make the file read-only by switching off all w-bits
359 (set-file-modes file
(logand (file-modes file
) 3950)))))
361 (defun vc-mcvs-merge (file first-revision
&optional second-revision
)
362 "Merge changes into current working copy of FILE.
363 The changes are between FIRST-REVISION and SECOND-REVISION."
364 (vc-mcvs-command nil
0 file
366 (concat "-j" first-revision
)
367 (concat "-j" second-revision
))
368 (vc-file-setprop file
'vc-state
'edited
)
369 (with-current-buffer (get-buffer "*vc*")
370 (goto-char (point-min))
371 (if (re-search-forward "conflicts during merge" nil t
)
373 0))) ; signal success
375 (defun vc-mcvs-merge-news (file)
376 "Merge in any new changes made to FILE."
377 (message "Merging changes into %s..." file
)
378 ;; (vc-file-setprop file 'vc-working-revision nil)
379 (vc-file-setprop file
'vc-checkout-time
0)
380 (vc-mcvs-command nil
0 file
"update")
381 ;; Analyze the merge result reported by Meta-CVS, and set
382 ;; file properties accordingly.
383 (with-current-buffer (get-buffer "*vc*")
384 (goto-char (point-min))
385 ;; get new working revision
386 (if (re-search-forward
387 "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t
)
388 (vc-file-setprop file
'vc-working-revision
(match-string 1))
389 (vc-file-setprop file
'vc-working-revision nil
))
392 (if (eq (buffer-size) 0)
393 0 ;; there were no news; indicate success
394 (if (re-search-forward
395 (concat "^\\([CMUP] \\)?"
397 "\\( already contains the differences between \\)?")
400 ;; Merge successful, we are in sync with repository now
401 ((or (match-string 2)
402 (string= (match-string 1) "U ")
403 (string= (match-string 1) "P "))
404 (vc-file-setprop file
'vc-state
'up-to-date
)
405 (vc-file-setprop file
'vc-checkout-time
406 (nth 5 (file-attributes file
)))
407 0);; indicate success to the caller
408 ;; Merge successful, but our own changes are still in the file
409 ((string= (match-string 1) "M ")
410 (vc-file-setprop file
'vc-state
'edited
)
411 0);; indicate success to the caller
412 ;; Conflicts detected!
414 (vc-file-setprop file
'vc-state
'edited
)
415 1);; signal the error to the caller
417 (pop-to-buffer "*vc*")
418 (error "Couldn't analyze mcvs update result")))
419 (message "Merging changes into %s...done" file
))))
421 (defun vc-mcvs-modify-change-comment (files rev comment
)
422 "Modify the change comments for FILES on a specified REV.
423 Will fail unless you have administrative privileges on the repo."
424 (vc-mcvs-command nil
0 files
"rcs" (concat "-m" comment
":" rev
)))
428 ;;; History functions
431 (defun vc-mcvs-print-log (files &optional buffer
)
432 "Get change log associated with FILES."
433 (let ((default-directory (vc-mcvs-root (car files
))))
434 ;; Run the command from the root dir so that `mcvs filt' returns
435 ;; valid relative names.
438 (if (vc-stay-local-p files
) 'async
0)
441 (defun vc-mcvs-diff (files &optional oldvers newvers buffer
)
442 "Get a difference report using Meta-CVS between two revisions of FILES."
443 (let* ((async (and (not vc-disable-async-diff
)
444 (vc-stay-local-p files
)))
445 ;; Run the command from the root dir so that `mcvs filt' returns
446 ;; valid relative names.
447 (default-directory (vc-mcvs-root (car files
)))
449 (apply 'vc-mcvs-command
(or buffer
"*vc-diff*")
452 (and oldvers
(concat "-r" oldvers
))
453 (and newvers
(concat "-r" newvers
))
454 (vc-switches 'MCVS
'diff
))))
455 (if async
1 status
))) ; async diff, pessimistic assumption.
457 (defun vc-mcvs-annotate-command (file buffer
&optional revision
)
458 "Execute \"mcvs annotate\" on FILE, inserting the contents in BUFFER.
459 Optional arg REVISION is a revision to annotate from."
462 (if (vc-stay-local-p file
) 'async
0)
463 file
"annotate" (if revision
(concat "-r" revision
)))
464 (with-current-buffer buffer
465 (goto-char (point-min))
466 (re-search-forward "^[0-9]")
467 (delete-region (point-min) (1- (point)))))
469 (defalias 'vc-mcvs-annotate-current-time
'vc-cvs-annotate-current-time
)
470 (defalias 'vc-mcvs-annotate-time
'vc-cvs-annotate-time
)
476 (defun vc-mcvs-create-tag (dir name branchp
)
477 "Assign to DIR's current revision a given NAME.
478 If BRANCHP is non-nil, the name is created as a branch (and the current
479 workspace is immediately moved to that new branch)."
481 (vc-mcvs-command nil
0 dir
"tag" "-c" name
)
482 (vc-mcvs-command nil
0 dir
"branch" name
)
483 (vc-mcvs-command nil
0 dir
"switch" name
)))
485 ;; vc-mcvs-command calls the autoloaded vc-do-command from vc-dispatcher.
486 (declare-function vc-resynch-buffer
"vc-dispatcher"
487 (file &optional keep noquery reset-vc-info
))
489 (defun vc-mcvs-retrieve-tag (dir name update
)
490 "Retrieve a tag at and below DIR.
491 NAME is the name of the tag; if it is empty, do a `cvs update'.
492 If UPDATE is non-nil, then update (resynch) any affected buffers."
493 (with-current-buffer (get-buffer-create "*vc*")
494 (let ((default-directory dir
)
497 (if (or (not name
) (string= name
""))
498 (vc-mcvs-command t
0 nil
"update")
499 (vc-mcvs-command t
0 nil
"update" "-r" name
)
500 (setq sticky-tag name
))
502 (goto-char (point-min))
504 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
505 (let* ((file (expand-file-name (match-string 2) dir
))
506 (state (match-string 1))
507 (buffer (find-buffer-visiting file
)))
510 ((or (string= state
"U")
512 (vc-file-setprop file
'vc-state
'up-to-date
)
513 (vc-file-setprop file
'vc-working-revision nil
)
514 (vc-file-setprop file
'vc-checkout-time
515 (nth 5 (file-attributes file
))))
516 ((or (string= state
"M")
518 (vc-file-setprop file
'vc-state
'edited
)
519 (vc-file-setprop file
'vc-working-revision nil
)
520 (vc-file-setprop file
'vc-checkout-time
0)))
521 (vc-file-setprop file
'vc-mcvs-sticky-tag sticky-tag
)
522 (vc-resynch-buffer file t t
))))
523 (forward-line 1))))))
530 (defalias 'vc-mcvs-make-version-backups-p
'vc-stay-local-p
531 "Return non-nil if version backups should be made for FILE.")
532 (defalias 'vc-mcvs-check-headers
'vc-cvs-check-headers
)
536 ;;; Internal functions
539 (defun vc-mcvs-command (buffer okstatus file
&rest flags
)
540 "A wrapper around `vc-do-command' for use in vc-mcvs.el.
541 The difference to vc-do-command is that this function always invokes `mcvs',
542 and that it passes `vc-mcvs-global-switches' to it before FLAGS."
543 (let ((args (append '("--error-terminate")
544 (if (stringp vc-mcvs-global-switches
)
545 (cons vc-mcvs-global-switches flags
)
546 (append vc-mcvs-global-switches flags
)))))
547 (if (not (member (car flags
) '("diff" "log" "status")))
548 ;; No need to filter: do it the easy way.
549 (apply 'vc-do-command
(or buffer
"*vc*") okstatus
"mcvs" file args
)
550 ;; We need to filter the output.
551 ;; The output of the filter uses filenames relative to the root,
552 ;; so we need to change the default-directory.
553 ;; (assert (equal default-directory (vc-mcvs-root file)))
555 (or buffer
"*vc*") okstatus
"sh" nil
"-c"
558 'shell-quote-argument
559 (append (remq nil args
)
560 (if file
(list (file-relative-name file
))))
564 (defun vc-mcvs-repository-hostname (dirname)
565 (vc-cvs-repository-hostname (vc-mcvs-root dirname
)))
567 (defun vc-mcvs-dir-state-heuristic (dir)
568 "Find the Meta-CVS state of all files in DIR, using only local information."
570 (vc-cvs-get-entries dir
)
571 (goto-char (point-min))
573 ;; Meta-MCVS-removed files are not taken under VC control.
574 (when (looking-at "/\\([^/]*\\)/[^/-]")
575 (let ((file (expand-file-name (match-string 1) dir
)))
576 (unless (vc-file-getprop file
'vc-state
)
577 (vc-cvs-parse-entry file t
))))
580 (defalias 'vc-mcvs-valid-symbolic-tag-name-p
'vc-cvs-valid-symbolic-tag-name-p
)
581 (defalias 'vc-mcvs-valid-revision-number-p
'vc-cvs-valid-revision-number-p
)
585 ;; ********** READ THIS! **********
587 ;; This file apparently does not work with the new (as of Emacs 23)
588 ;; VC code. Use at your own risk. Please contact emacs-devel if you
589 ;; can maintain this file and update it to work correctly.
591 ;; ********** READ THIS! **********
593 ;;; vc-mcvs.el ends here