1 ;;; vc-mcvs.el --- VC backend for the Meta-CVS version-control system
3 ;; Copyright (C) 2003-2012 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
193 (defun vc-mcvs-register (files &optional rev comment
)
194 "Register FILES into the Meta-CVS version-control system.
195 COMMENT can be used to provide an initial description of FILE.
196 Passes either `vc-mcvs-register-switches' or `vc-register-switches'
197 to the Meta-CVS command."
198 ;; FIXME: multiple-file case should be made to work.
199 (if (> (length files
) 1) (error "Registering filesets is not yet supported"))
200 (let* ((file (car files
))
201 (filename (file-name-nondirectory file
))
202 (extpos (string-match "\\." filename
))
203 (ext (if extpos
(substring filename
(1+ extpos
))))
204 (root (vc-mcvs-root file
))
205 (types-file (expand-file-name "MCVS/TYPES" root
))
206 (map-file (expand-file-name "MCVS/MAP" root
))
207 (types (vc-mcvs-read types-file
)))
208 ;; Make sure meta files like MCVS/MAP are not read-only (happens with
209 ;; CVSREAD) since Meta-CVS doesn't pay attention to it at all and goes
211 (unless (file-writable-p map-file
)
212 (vc-checkout map-file t
))
213 (unless (or (file-writable-p types-file
) (not (file-exists-p types-file
)))
214 (vc-checkout types-file t
))
215 ;; Make sure the `mcvs add' will not fire up the CVSEDITOR
216 ;; to add a rule for the given file's extension.
217 (when (and ext
(not (assoc ext types
)))
218 (let ((type (completing-read "Type to use (default): "
219 '("default" "name-only" "keep-old"
220 "binary" "value-only")
221 nil t nil nil
"default")))
222 (push (list ext
(make-symbol (upcase (concat ":" type
)))) types
)
223 (setq types
(sort types
(lambda (x y
) (string< (car x
) (car y
)))))
224 (with-current-buffer (find-file-noselect types-file
)
226 (pp types
(current-buffer))
228 (unless (get-buffer-window (current-buffer) t
)
229 (kill-buffer (current-buffer))))))
231 (prog1 (apply 'vc-mcvs-command nil
0 file
233 (and comment
(string-match "[^\t\n ]" comment
)
234 (concat "-m" comment
))
235 (vc-switches 'MCVS
'register
))
236 ;; I'm not sure exactly why, but if we don't setup the inode and root
237 ;; prop of the file, things break later on in vc-mode-line that
238 ;; ends up calling vc-mcvs-working-revision.
239 ;; We also need to set vc-checkout-time so that vc-workfile-unchanged-p
240 ;; doesn't try to call `mcvs diff' on the file.
241 (vc-mcvs-registered file
))))
243 (defalias 'vc-mcvs-responsible-p
'vc-mcvs-root
244 "Return non-nil if CVS thinks it is responsible for FILE.")
246 (defalias 'vc-cvs-could-register
'vc-cvs-responsible-p
247 "Return non-nil if FILE could be registered in Meta-CVS.
248 This is only possible if Meta-CVS is responsible for FILE's directory.")
250 (defun vc-mcvs-checkin (files rev comment
)
251 "Meta-CVS-specific version of `vc-backend-checkin'."
252 (unless (or (not rev
) (vc-mcvs-valid-revision-number-p rev
))
253 (if (not (vc-mcvs-valid-symbolic-tag-name-p rev
))
254 (error "%s is not a valid symbolic tag name" rev
)
255 ;; If the input revision is a valid symbolic tag name, we create it
256 ;; as a branch, commit and switch to it.
257 ;; This file-specific form of branching is deprecated.
258 ;; We can't use `mcvs branch' and `mcvs switch' because they cannot
259 ;; be applied just to this one file.
260 (apply 'vc-mcvs-command nil
0 files
"tag" "-b" (list rev
))
261 (apply 'vc-mcvs-command nil
0 files
"update" "-r" (list rev
))
262 (mapc (lambda (file) (vc-file-setprop file
'vc-mcvs-sticky-tag rev
))
265 ;; This commit might cvs-commit several files (e.g. MAP and TYPES)
266 ;; so using numbered revs here is dangerous and somewhat meaningless.
267 (when rev
(error "Cannot commit to a specific revision number"))
268 (let ((status (apply 'vc-mcvs-command nil
1 files
270 (vc-switches 'MCVS
'checkin
))))
272 (goto-char (point-min))
273 (when (not (zerop status
))
274 ;; Check checkin problem.
276 ((re-search-forward "Up-to-date check failed" nil t
)
277 (mapc (lambda (file) (vc-file-setprop file
'vc-state
'needs-merge
))
279 (error "%s" (substitute-command-keys
280 (concat "Up-to-date check failed: "
281 "type \\[vc-next-action] to merge in changes"))))
283 (pop-to-buffer (current-buffer))
284 (goto-char (point-min))
285 (shrink-window-if-larger-than-buffer)
286 (error "Check-in failed"))))
287 ;; Single-file commit? Then update the revision by parsing the buffer.
288 ;; Otherwise we can't necessarily tell what goes with what; clear
289 ;; its properties so they have to be refetched.
290 (if (= (length files
) 1)
292 (car files
) 'vc-working-revision
293 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
294 (mapc (lambda (file) (vc-file-clearprops file
)) files
))
295 ;; Anyway, forget the checkout model of the file, because we might have
296 ;; guessed wrong when we found the file. After commit, we can
297 ;; tell it from the permissions of the file (see
298 ;; vc-mcvs-checkout-model).
299 (mapc (lambda (file) (vc-file-setprop file
'vc-checkout-model nil
))
302 ;; if this was an explicit check-in (does not include creation of
303 ;; a branch), remove the sticky tag.
304 (if (and rev
(not (vc-mcvs-valid-symbolic-tag-name-p rev
)))
305 (vc-mcvs-command nil
0 files
"update" "-A"))))
307 (defun vc-mcvs-find-revision (file rev buffer
)
308 (apply 'vc-mcvs-command
310 "-Q" ; suppress diagnostic output
312 (and rev
(not (string= rev
""))
315 (vc-switches 'MCVS
'checkout
)))
317 (defun vc-mcvs-checkout (file &optional editable rev
)
318 (message "Checking out %s..." file
)
319 (with-current-buffer (or (get-file-buffer file
) (current-buffer))
320 (vc-mcvs-update file editable rev
(vc-switches 'MCVS
'checkout
)))
322 (message "Checking out %s...done" file
))
324 (defun vc-mcvs-update (file editable rev switches
)
325 (if (and (file-exists-p file
) (not rev
))
326 ;; If no revision was specified, just make the file writable
327 ;; if necessary (using `cvs-edit' if requested).
328 (and editable
(not (eq (vc-mcvs-checkout-model (list file
)) 'implicit
))
330 (vc-mcvs-command nil
0 file
"edit")
331 (set-file-modes file
(logior (file-modes file
) 128))
332 (if (equal file buffer-file-name
) (read-only-mode -
1))))
333 ;; Check out a particular revision (or recreate the file).
334 (vc-file-setprop file
'vc-working-revision nil
)
335 (apply 'vc-mcvs-command nil
0 file
338 ;; default for verbose checkout: clear the sticky tag so
339 ;; that the actual update will get the head of the trunk
340 (if (or (not rev
) (string= rev
""))
345 (defun vc-mcvs-rename-file (old new
)
346 (vc-mcvs-command nil
0 new
"move" (file-relative-name old
)))
348 (defun vc-mcvs-revert (file &optional contents-done
)
349 "Revert FILE to the working revision it was based on."
350 (vc-default-revert 'MCVS file contents-done
)
351 (unless (eq (vc-mcvs-checkout-model (list file
)) 'implicit
)
353 (vc-mcvs-command nil
0 file
"unedit")
354 ;; Make the file read-only by switching off all w-bits
355 (set-file-modes file
(logand (file-modes file
) 3950)))))
357 (defun vc-mcvs-merge (file first-revision
&optional second-revision
)
358 "Merge changes into current working copy of FILE.
359 The changes are between FIRST-REVISION and SECOND-REVISION."
360 (vc-mcvs-command nil
0 file
362 (concat "-j" first-revision
)
363 (concat "-j" second-revision
))
364 (vc-file-setprop file
'vc-state
'edited
)
365 (with-current-buffer (get-buffer "*vc*")
366 (goto-char (point-min))
367 (if (re-search-forward "conflicts during merge" nil t
)
369 0))) ; signal success
371 (defun vc-mcvs-merge-news (file)
372 "Merge in any new changes made to FILE."
373 (message "Merging changes into %s..." file
)
374 ;; (vc-file-setprop file 'vc-working-revision nil)
375 (vc-file-setprop file
'vc-checkout-time
0)
376 (vc-mcvs-command nil
0 file
"update")
377 ;; Analyze the merge result reported by Meta-CVS, and set
378 ;; file properties accordingly.
379 (with-current-buffer (get-buffer "*vc*")
380 (goto-char (point-min))
381 ;; get new working revision
382 (if (re-search-forward
383 "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t
)
384 (vc-file-setprop file
'vc-working-revision
(match-string 1))
385 (vc-file-setprop file
'vc-working-revision nil
))
388 (if (eq (buffer-size) 0)
389 0 ;; there were no news; indicate success
390 (if (re-search-forward
391 (concat "^\\([CMUP] \\)?"
393 "\\( already contains the differences between \\)?")
396 ;; Merge successful, we are in sync with repository now
397 ((or (match-string 2)
398 (string= (match-string 1) "U ")
399 (string= (match-string 1) "P "))
400 (vc-file-setprop file
'vc-state
'up-to-date
)
401 (vc-file-setprop file
'vc-checkout-time
402 (nth 5 (file-attributes file
)))
403 0);; indicate success to the caller
404 ;; Merge successful, but our own changes are still in the file
405 ((string= (match-string 1) "M ")
406 (vc-file-setprop file
'vc-state
'edited
)
407 0);; indicate success to the caller
408 ;; Conflicts detected!
410 (vc-file-setprop file
'vc-state
'edited
)
411 1);; signal the error to the caller
413 (pop-to-buffer "*vc*")
414 (error "Couldn't analyze mcvs update result")))
415 (message "Merging changes into %s...done" file
))))
417 (defun vc-mcvs-modify-change-comment (files rev comment
)
418 "Modify the change comments for FILES on a specified REV.
419 Will fail unless you have administrative privileges on the repo."
420 (vc-mcvs-command nil
0 files
"rcs" (concat "-m" comment
":" rev
)))
424 ;;; History functions
427 (defun vc-mcvs-print-log (files &optional buffer
)
428 "Get change log associated with FILES."
429 (let ((default-directory (vc-mcvs-root (car files
))))
430 ;; Run the command from the root dir so that `mcvs filt' returns
431 ;; valid relative names.
434 (if (vc-stay-local-p files
) 'async
0)
437 (defun vc-mcvs-diff (files &optional oldvers newvers buffer
)
438 "Get a difference report using Meta-CVS between two revisions of FILES."
439 (let* ((async (and (not vc-disable-async-diff
)
440 (vc-stay-local-p files
)))
441 ;; Run the command from the root dir so that `mcvs filt' returns
442 ;; valid relative names.
443 (default-directory (vc-mcvs-root (car files
)))
445 (apply 'vc-mcvs-command
(or buffer
"*vc-diff*")
448 (and oldvers
(concat "-r" oldvers
))
449 (and newvers
(concat "-r" newvers
))
450 (vc-switches 'MCVS
'diff
))))
451 (if async
1 status
))) ; async diff, pessimistic assumption.
453 (defun vc-mcvs-annotate-command (file buffer
&optional revision
)
454 "Execute \"mcvs annotate\" on FILE, inserting the contents in BUFFER.
455 Optional arg REVISION is a revision to annotate from."
458 (if (vc-stay-local-p file
) 'async
0)
459 file
"annotate" (if revision
(concat "-r" revision
)))
460 (with-current-buffer buffer
461 (goto-char (point-min))
462 (re-search-forward "^[0-9]")
463 (delete-region (point-min) (1- (point)))))
465 (defalias 'vc-mcvs-annotate-current-time
'vc-cvs-annotate-current-time
)
466 (defalias 'vc-mcvs-annotate-time
'vc-cvs-annotate-time
)
472 (defun vc-mcvs-create-tag (dir name branchp
)
473 "Assign to DIR's current revision a given NAME.
474 If BRANCHP is non-nil, the name is created as a branch (and the current
475 workspace is immediately moved to that new branch)."
477 (vc-mcvs-command nil
0 dir
"tag" "-c" name
)
478 (vc-mcvs-command nil
0 dir
"branch" name
)
479 (vc-mcvs-command nil
0 dir
"switch" name
)))
481 (defun vc-mcvs-retrieve-tag (dir name update
)
482 "Retrieve a tag at and below DIR.
483 NAME is the name of the tag; if it is empty, do a `cvs update'.
484 If UPDATE is non-nil, then update (resynch) any affected buffers."
485 (with-current-buffer (get-buffer-create "*vc*")
486 (let ((default-directory dir
)
489 (if (or (not name
) (string= name
""))
490 (vc-mcvs-command t
0 nil
"update")
491 (vc-mcvs-command t
0 nil
"update" "-r" name
)
492 (setq sticky-tag name
))
494 (goto-char (point-min))
496 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
497 (let* ((file (expand-file-name (match-string 2) dir
))
498 (state (match-string 1))
499 (buffer (find-buffer-visiting file
)))
502 ((or (string= state
"U")
504 (vc-file-setprop file
'vc-state
'up-to-date
)
505 (vc-file-setprop file
'vc-working-revision nil
)
506 (vc-file-setprop file
'vc-checkout-time
507 (nth 5 (file-attributes file
))))
508 ((or (string= state
"M")
510 (vc-file-setprop file
'vc-state
'edited
)
511 (vc-file-setprop file
'vc-working-revision nil
)
512 (vc-file-setprop file
'vc-checkout-time
0)))
513 (vc-file-setprop file
'vc-mcvs-sticky-tag sticky-tag
)
514 (vc-resynch-buffer file t t
))))
515 (forward-line 1))))))
522 (defalias 'vc-mcvs-make-version-backups-p
'vc-stay-local-p
523 "Return non-nil if version backups should be made for FILE.")
524 (defalias 'vc-mcvs-check-headers
'vc-cvs-check-headers
)
528 ;;; Internal functions
531 (defun vc-mcvs-command (buffer okstatus file
&rest flags
)
532 "A wrapper around `vc-do-command' for use in vc-mcvs.el.
533 The difference to vc-do-command is that this function always invokes `mcvs',
534 and that it passes `vc-mcvs-global-switches' to it before FLAGS."
535 (let ((args (append '("--error-terminate")
536 (if (stringp vc-mcvs-global-switches
)
537 (cons vc-mcvs-global-switches flags
)
538 (append vc-mcvs-global-switches flags
)))))
539 (if (not (member (car flags
) '("diff" "log" "status")))
540 ;; No need to filter: do it the easy way.
541 (apply 'vc-do-command
(or buffer
"*vc*") okstatus
"mcvs" file args
)
542 ;; We need to filter the output.
543 ;; The output of the filter uses filenames relative to the root,
544 ;; so we need to change the default-directory.
545 ;; (assert (equal default-directory (vc-mcvs-root file)))
547 (or buffer
"*vc*") okstatus
"sh" nil
"-c"
550 'shell-quote-argument
551 (append (remq nil args
)
552 (if file
(list (file-relative-name file
))))
556 (defun vc-mcvs-repository-hostname (dirname)
557 (vc-cvs-repository-hostname (vc-mcvs-root dirname
)))
559 (defun vc-mcvs-dir-state-heuristic (dir)
560 "Find the Meta-CVS state of all files in DIR, using only local information."
562 (vc-cvs-get-entries dir
)
563 (goto-char (point-min))
565 ;; Meta-MCVS-removed files are not taken under VC control.
566 (when (looking-at "/\\([^/]*\\)/[^/-]")
567 (let ((file (expand-file-name (match-string 1) dir
)))
568 (unless (vc-file-getprop file
'vc-state
)
569 (vc-cvs-parse-entry file t
))))
572 (defalias 'vc-mcvs-valid-symbolic-tag-name-p
'vc-cvs-valid-symbolic-tag-name-p
)
573 (defalias 'vc-mcvs-valid-revision-number-p
'vc-cvs-valid-revision-number-p
)
577 ;; ********** READ THIS! **********
579 ;; This file apparently does not work with the new (as of Emacs 23)
580 ;; VC code. Use at your own risk. Please contact emacs-devel if you
581 ;; can maintain this file and update it to work correctly.
583 ;; ********** READ THIS! **********
585 ;;; vc-mcvs.el ends here