1 ;;; vc-cvs.el --- non-resident support for CVS version-control
3 ;; Copyright (C) 1995,98,99,2000,2001,2002 Free Software Foundation, Inc.
5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
8 ;; $Id: vc-cvs.el,v 1.52 2003/03/27 22:38:38 schwab Exp $
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
35 ;;; Customization options
38 (defcustom vc-cvs-global-switches nil
39 "*Global switches to pass to any CVS command."
40 :type
'(choice (const :tag
"None" nil
)
41 (string :tag
"Argument String")
42 (repeat :tag
"Argument List"
48 (defcustom vc-cvs-register-switches nil
49 "*Extra switches for registering a file into CVS.
50 A string or list of strings passed to the checkin program by
52 :type
'(choice (const :tag
"None" nil
)
53 (string :tag
"Argument String")
54 (repeat :tag
"Argument List"
60 (defcustom vc-cvs-diff-switches nil
61 "*A string or list of strings specifying extra switches for cvs diff under VC."
62 :type
'(choice (const :tag
"None" nil
)
63 (string :tag
"Argument String")
64 (repeat :tag
"Argument List"
70 (defcustom vc-cvs-header
(or (cdr (assoc 'CVS vc-header-alist
)) '("\$Id\$"))
71 "*Header keywords to be inserted by `vc-insert-headers'."
73 :type
'(repeat string
)
76 (defcustom vc-cvs-use-edit t
77 "*Non-nil means to use `cvs edit' to \"check out\" a file.
78 This is only meaningful if you don't use the implicit checkout model
79 \(i.e. if you have $CVSREAD set)."
84 (defcustom vc-cvs-stay-local t
85 "*Non-nil means use local operations when possible for remote repositories.
86 This avoids slow queries over the network and instead uses heuristics
87 and past information to determine the current status of a file.
88 The value can also be a regular expression to match against the host name
89 of a repository; then VC only stays local for hosts that match it."
90 :type
'(choice (const :tag
"Always stay local" t
)
91 (string :tag
"Host regexp")
92 (const :tag
"Don't stay local" nil
))
96 (defcustom vc-cvs-sticky-date-format-string
"%c"
97 "*Format string for mode-line display of sticky date.
98 Format is according to `format-time-string'. Only used if
99 `vc-cvs-sticky-tag-display' is t."
104 (defcustom vc-cvs-sticky-tag-display t
105 "*Specify the mode-line display of sticky tags.
106 Value t means default display, nil means no display at all. If the
107 value is a function or macro, it is called with the sticky tag and
108 its' type as parameters, in that order. TYPE can have three different
109 values: `symbolic-name' (TAG is a string), `revision-number' (TAG is a
110 string) and `date' (TAG is a date as returned by `encode-time'). The
111 return value of the function or macro will be displayed as a string.
113 Here's an example that will display the formatted date for sticky
114 dates and the word \"Sticky\" for sticky tag names and revisions.
117 (cond ((eq type 'date) (format-time-string
118 vc-cvs-sticky-date-format-string tag))
119 ((eq type 'revision-number) \"Sticky\")
120 ((eq type 'symbolic-name) \"Sticky\")))
122 Here's an example that will abbreviate to the first character only,
123 any text before the first occurrence of `-' for sticky symbolic tags.
124 If the sticky tag is a revision number, the word \"Sticky\" is
125 displayed. Date and time is displayed for sticky dates.
128 (cond ((eq type 'date) (format-time-string \"%Y%m%d %H:%M\" tag))
129 ((eq type 'revision-number) \"Sticky\")
130 ((eq type 'symbolic-name)
133 (string-match \"\\\\([^-]*\\\\)\\\\(.*\\\\)\" tag)
134 (concat (substring (match-string 1 tag) 0 1) \":\"
135 (substring (match-string 2 tag) 1 nil)))
136 (error tag))))) ; Fall-back to given tag name.
138 See also variable `vc-cvs-sticky-date-format-string'."
139 :type
'(choice boolean function
)
144 ;;; Internal variables
147 (defvar vc-cvs-local-month-numbers
148 '(("Jan" .
1) ("Feb" .
2) ("Mar" .
3) ("Apr" .
4)
149 ("May" .
5) ("Jun" .
6) ("Jul" .
7) ("Aug" .
8)
150 ("Sep" .
9) ("Oct" .
10) ("Nov" .
11) ("Dec" .
12))
151 "Local association list of month numbers.")
155 ;;; State-querying functions
158 ;;;###autoload (defun vc-cvs-registered (f)
159 ;;;###autoload (when (file-readable-p (expand-file-name
160 ;;;###autoload "CVS/Entries" (file-name-directory f)))
161 ;;;###autoload (load "vc-cvs")
162 ;;;###autoload (vc-cvs-registered f)))
164 (defun vc-cvs-registered (file)
165 "Check if FILE is CVS registered."
166 (let ((dirname (or (file-name-directory file
) ""))
167 (basename (file-name-nondirectory file
))
168 ;; make sure that the file name is searched case-sensitively
169 (case-fold-search nil
))
170 (if (file-readable-p (expand-file-name "CVS/Entries" dirname
))
172 (vc-cvs-get-entries dirname
)
173 (goto-char (point-min))
176 ;; CVS-removed files are not taken under VC control.
177 (concat "^/" (regexp-quote basename
) "/[^/-]") nil t
)
179 (vc-cvs-parse-entry file
)
184 (defun vc-cvs-state (file)
185 "CVS-specific version of `vc-state'."
186 (if (vc-cvs-stay-local-p file
)
187 (let ((state (vc-file-getprop file
'vc-state
)))
188 ;; If we should stay local, use the heuristic but only if
189 ;; we don't have a more precise state already available.
190 (if (memq state
'(up-to-date edited
))
191 (vc-cvs-state-heuristic file
)
194 (cd (file-name-directory file
))
195 (vc-cvs-command t
0 file
"status")
196 (vc-cvs-parse-status t
))))
198 (defun vc-cvs-state-heuristic (file)
199 "CVS-specific state heuristic."
200 ;; If the file has not changed since checkout, consider it `up-to-date'.
201 ;; Otherwise consider it `edited'.
202 (let ((checkout-time (vc-file-getprop file
'vc-checkout-time
))
203 (lastmod (nth 5 (file-attributes file
))))
204 (if (equal checkout-time lastmod
)
208 (defun vc-cvs-dir-state (dir)
209 "Find the CVS state of all files in DIR."
210 ;; if DIR is not under CVS control, don't do anything
211 (if (file-readable-p (expand-file-name "CVS/Entries" dir
))
212 (if (vc-cvs-stay-local-p dir
)
213 (vc-cvs-dir-state-heuristic dir
)
214 (let ((default-directory dir
))
215 ;; Don't specify DIR in this command, the default-directory is
216 ;; enough. Otherwise it might fail with remote repositories.
218 (vc-do-command t
0 "cvs" nil
"status" "-l")
219 (goto-char (point-min))
220 (while (re-search-forward "^=+\n\\([^=\n].*\n\\|\n\\)+" nil t
)
221 (narrow-to-region (match-beginning 0) (match-end 0))
222 (vc-cvs-parse-status)
223 (goto-char (point-max))
226 (defun vc-cvs-workfile-version (file)
227 "CVS-specific version of `vc-workfile-version'."
228 ;; There is no need to consult RCS headers under CVS, because we
229 ;; get the workfile version for free when we recognize that a file
230 ;; is registered in CVS.
231 (vc-cvs-registered file
)
232 (vc-file-getprop file
'vc-workfile-version
))
234 (defun vc-cvs-checkout-model (file)
235 "CVS-specific version of `vc-checkout-model'."
236 (if (or (getenv "CVSREAD")
237 ;; If the file is not writable (despite CVSREAD being
238 ;; undefined), this is probably because the file is being
239 ;; "watched" by other developers.
240 ;; (If vc-mistrust-permissions was t, we actually shouldn't
241 ;; trust this, but there is no other way to learn this from CVS
242 ;; at the moment (version 1.9).)
243 (string-match "r-..-..-." (nth 8 (file-attributes file
))))
247 (defun vc-cvs-mode-line-string (file)
248 "Return string for placement into the modeline for FILE.
249 Compared to the default implementation, this function does two things:
250 Handle the special case of a CVS file that is added but not yet
251 committed and support display of sticky tags."
252 (let* ((state (vc-state file
))
253 (rev (vc-workfile-version file
))
254 (sticky-tag (vc-file-getprop file
'vc-cvs-sticky-tag
))
255 (sticky-tag-printable (and sticky-tag
256 (not (string= sticky-tag
""))
257 (concat "[" sticky-tag
"]"))))
258 (cond ((string= rev
"0")
259 ;; A file that is added but not yet committed.
261 ((or (eq state
'up-to-date
)
262 (eq state
'needs-patch
))
263 (concat "CVS-" rev sticky-tag-printable
))
265 (concat "CVS:" state
":" rev sticky-tag-printable
))
267 ;; Not just for the 'edited state, but also a fallback
268 ;; for all other states. Think about different symbols
269 ;; for 'needs-patch and 'needs-merge.
270 (concat "CVS:" rev sticky-tag-printable
)))))
272 (defun vc-cvs-dired-state-info (file)
273 "CVS-specific version of `vc-dired-state-info'."
274 (let* ((cvs-state (vc-state file
))
275 (state (cond ((eq cvs-state
'edited
) "modified")
276 ((eq cvs-state
'needs-patch
) "patch")
277 ((eq cvs-state
'needs-merge
) "merge")
278 ;; FIXME: those two states cannot occur right now
279 ((eq cvs-state
'unlocked-changes
) "conflict")
280 ((eq cvs-state
'locally-added
) "added")
282 (if state
(concat "(" state
")"))))
286 ;;; State-changing functions
289 (defun vc-cvs-register (file &optional rev comment
)
290 "Register FILE into the CVS version-control system.
291 COMMENT can be used to provide an initial description of FILE.
293 `vc-register-switches' and `vc-cvs-register-switches' are passed to
294 the CVS command (in that order)."
295 (let ((switches (append
296 (if (stringp vc-register-switches
)
297 (list vc-register-switches
)
298 vc-register-switches
)
299 (if (stringp vc-cvs-register-switches
)
300 (list vc-cvs-register-switches
)
301 vc-cvs-register-switches
))))
303 (apply 'vc-cvs-command nil
0 file
305 (and comment
(string-match "[^\t\n ]" comment
)
306 (concat "-m" comment
))
309 (defun vc-cvs-responsible-p (file)
310 "Return non-nil if CVS thinks it is responsible for FILE."
311 (file-directory-p (expand-file-name "CVS"
312 (if (file-directory-p file
)
314 (file-name-directory file
)))))
316 (defun vc-cvs-could-register (file)
317 "Return non-nil if FILE could be registered in CVS.
318 This is only possible if CVS is responsible for FILE's directory."
319 (vc-cvs-responsible-p file
))
321 (defun vc-cvs-checkin (file rev comment
)
322 "CVS-specific version of `vc-backend-checkin'."
323 (let ((switches (if (stringp vc-checkin-switches
)
324 (list vc-checkin-switches
)
325 vc-checkin-switches
))
327 (if (or (not rev
) (vc-cvs-valid-version-number-p rev
))
328 (setq status
(apply 'vc-cvs-command nil
1 file
329 "ci" (if rev
(concat "-r" rev
))
330 (concat "-m" comment
)
332 (if (not (vc-cvs-valid-symbolic-tag-name-p rev
))
333 (error "%s is not a valid symbolic tag name" rev
)
334 ;; If the input revison is a valid symbolic tag name, we create it
335 ;; as a branch, commit and switch to it.
336 (apply 'vc-cvs-command nil
0 file
"tag" "-b" (list rev
))
337 (apply 'vc-cvs-command nil
0 file
"update" "-r" (list rev
))
338 (setq status
(apply 'vc-cvs-command nil
1 file
340 (concat "-m" comment
)
342 (vc-file-setprop file
'vc-cvs-sticky-tag rev
)))
344 (goto-char (point-min))
345 (when (not (zerop status
))
346 ;; Check checkin problem.
348 ((re-search-forward "Up-to-date check failed" nil t
)
349 (vc-file-setprop file
'vc-state
'needs-merge
)
350 (error (substitute-command-keys
351 (concat "Up-to-date check failed: "
352 "type \\[vc-next-action] to merge in changes"))))
354 (pop-to-buffer (current-buffer))
355 (goto-char (point-min))
356 (shrink-window-if-larger-than-buffer)
357 (error "Check-in failed"))))
358 ;; Update file properties
360 file
'vc-workfile-version
361 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
362 ;; Forget the checkout model of the file, because we might have
363 ;; guessed wrong when we found the file. After commit, we can
364 ;; tell it from the permissions of the file (see
365 ;; vc-cvs-checkout-model).
366 (vc-file-setprop file
'vc-checkout-model nil
)
368 ;; if this was an explicit check-in (does not include creation of
369 ;; a branch), remove the sticky tag.
370 (if (and rev
(not (vc-cvs-valid-symbolic-tag-name-p rev
)))
371 (vc-cvs-command nil
0 file
"update" "-A"))))
373 (defun vc-cvs-find-version (file rev buffer
)
374 (apply 'vc-cvs-command
376 "-Q" ; suppress diagnostic output
378 (and rev
(not (string= rev
""))
381 (if (stringp vc-checkout-switches
)
382 (list vc-checkout-switches
)
383 vc-checkout-switches
)))
385 (defun vc-cvs-checkout (file &optional editable rev workfile
)
386 "Retrieve a revision of FILE into a WORKFILE.
387 EDITABLE non-nil means that the file should be writable.
388 REV is the revision to check out into WORKFILE."
389 (let ((filename (or workfile file
))
390 (file-buffer (get-file-buffer file
))
392 (message "Checking out %s..." filename
)
394 ;; Change buffers to get local value of vc-checkout-switches.
395 (if file-buffer
(set-buffer file-buffer
))
396 (setq switches
(if (stringp vc-checkout-switches
)
397 (list vc-checkout-switches
)
398 vc-checkout-switches
))
399 ;; Save this buffer's default-directory
400 ;; and use save-excursion to make sure it is restored
401 ;; in the same buffer it was saved in.
402 (let ((default-directory default-directory
))
404 ;; Adjust the default-directory so that the check-out creates
405 ;; the file in the right place.
406 (setq default-directory
(file-name-directory filename
))
409 (backup-name (if (string= file workfile
)
410 (car (find-backup-file-name filename
)))))
412 (copy-file filename backup-name
413 'ok-if-already-exists
'keep-date
)
414 (unless (file-writable-p filename
)
415 (set-file-modes filename
416 (logior (file-modes filename
) 128))))
419 (let ((coding-system-for-read 'no-conversion
)
420 (coding-system-for-write 'no-conversion
))
421 (with-temp-file filename
422 (apply 'vc-cvs-command
423 (current-buffer) 0 file
424 "-Q" ; suppress diagnostic output
427 (not (string= rev
""))
434 (rename-file backup-name filename
435 'ok-if-already-exists
)
436 (if (file-exists-p filename
)
437 (delete-file filename
)))
439 (not vc-make-backup-files
)
440 (delete-file backup-name
)))))
441 (if (and (file-exists-p file
) (not rev
))
442 ;; If no revision was specified, just make the file writable
443 ;; if necessary (using `cvs-edit' if requested).
444 (and editable
(not (eq (vc-cvs-checkout-model file
) 'implicit
))
446 (vc-cvs-command nil
0 file
"edit")
447 (set-file-modes file
(logior (file-modes file
) 128))
448 (if file-buffer
(toggle-read-only -
1))))
449 ;; Check out a particular version (or recreate the file).
450 (vc-file-setprop file
'vc-workfile-version nil
)
451 (apply 'vc-cvs-command nil
0 file
453 (or (not (file-exists-p file
))
454 (not (eq (vc-cvs-checkout-model file
)
458 ;; default for verbose checkout: clear the sticky tag so
459 ;; that the actual update will get the head of the trunk
460 (if (or (not rev
) (eq rev t
) (string= rev
""))
465 (message "Checking out %s...done" filename
)))))
467 (defun vc-cvs-revert (file &optional contents-done
)
468 "Revert FILE to the version it was based on."
469 (unless contents-done
470 ;; Check out via standard output (caused by the final argument
471 ;; FILE below), so that no sticky tag is set.
472 (vc-cvs-checkout file nil
(vc-workfile-version file
) file
))
473 (unless (eq (vc-checkout-model file
) 'implicit
)
475 (vc-cvs-command nil
0 file
"unedit")
476 ;; Make the file read-only by switching off all w-bits
477 (set-file-modes file
(logand (file-modes file
) 3950)))))
479 (defun vc-cvs-merge (file first-version
&optional second-version
)
480 "Merge changes into current working copy of FILE.
481 The changes are between FIRST-VERSION and SECOND-VERSION."
482 (vc-cvs-command nil
0 file
484 (concat "-j" first-version
)
485 (concat "-j" second-version
))
486 (vc-file-setprop file
'vc-state
'edited
)
488 (set-buffer (get-buffer "*vc*"))
489 (goto-char (point-min))
490 (if (re-search-forward "conflicts during merge" nil t
)
492 0))) ; signal success
494 (defun vc-cvs-merge-news (file)
495 "Merge in any new changes made to FILE."
496 (message "Merging changes into %s..." file
)
498 ;; (vc-file-setprop file 'vc-workfile-version nil)
499 (vc-file-setprop file
'vc-checkout-time
0)
500 (vc-cvs-command nil
0 file
"update")
501 ;; Analyze the merge result reported by CVS, and set
502 ;; file properties accordingly.
503 (set-buffer (get-buffer "*vc*"))
504 (goto-char (point-min))
505 ;; get new workfile version
506 (if (re-search-forward (concat "^Merging differences between "
507 "[01234567890.]* and "
508 "\\([01234567890.]*\\) into")
510 (vc-file-setprop file
'vc-workfile-version
(match-string 1))
511 (vc-file-setprop file
'vc-workfile-version nil
))
514 (if (eq (buffer-size) 0)
515 0 ;; there were no news; indicate success
516 (if (re-search-forward
517 (concat "^\\([CMUP] \\)?"
518 (regexp-quote (file-name-nondirectory file
))
519 "\\( already contains the differences between \\)?")
522 ;; Merge successful, we are in sync with repository now
523 ((or (match-string 2)
524 (string= (match-string 1) "U ")
525 (string= (match-string 1) "P "))
526 (vc-file-setprop file
'vc-state
'up-to-date
)
527 (vc-file-setprop file
'vc-checkout-time
528 (nth 5 (file-attributes file
)))
529 0);; indicate success to the caller
530 ;; Merge successful, but our own changes are still in the file
531 ((string= (match-string 1) "M ")
532 (vc-file-setprop file
'vc-state
'edited
)
533 0);; indicate success to the caller
534 ;; Conflicts detected!
536 (vc-file-setprop file
'vc-state
'edited
)
537 1);; signal the error to the caller
539 (pop-to-buffer "*vc*")
540 (error "Couldn't analyze cvs update result")))
541 (message "Merging changes into %s...done" file
))))
545 ;;; History functions
548 (defun vc-cvs-print-log (file)
549 "Get change log associated with FILE."
552 (if (and (vc-cvs-stay-local-p file
) (fboundp 'start-process
)) 'async
0)
555 (defun vc-cvs-diff (file &optional oldvers newvers
)
556 "Get a difference report using CVS between two versions of FILE."
557 (let (options status
(diff-switches-list (vc-diff-switches-list 'CVS
)))
558 (if (string= (vc-workfile-version file
) "0")
559 ;; This file is added but not yet committed; there is no master file.
560 (if (or oldvers newvers
)
561 (error "No revisions of %s exist" file
)
562 ;; We regard this as "changed".
563 ;; Diff it against /dev/null.
564 ;; Note: this is NOT a "cvs diff".
565 (apply 'vc-do-command
"*vc-diff*"
567 (append diff-switches-list
'("/dev/null"))))
569 (apply 'vc-cvs-command
"*vc-diff*"
570 (if (and (vc-cvs-stay-local-p file
)
571 (fboundp 'start-process
))
575 (and oldvers
(concat "-r" oldvers
))
576 (and newvers
(concat "-r" newvers
))
578 (if (vc-cvs-stay-local-p file
)
579 1 ;; async diff, pessimistic assumption
582 (defun vc-cvs-diff-tree (dir &optional rev1 rev2
)
583 "Diff all files at and below DIR."
584 (with-current-buffer "*vc-diff*"
585 (setq default-directory dir
)
586 (if (vc-cvs-stay-local-p dir
)
587 ;; local diff: do it filewise, and only for files that are modified
592 `(let ((coding-system-for-read (vc-coding-system-for-diff ',f
)))
593 ;; possible optimization: fetch the state of all files
594 ;; in the tree via vc-cvs-dir-state-heuristic
595 (unless (vc-up-to-date-p ',f
)
596 (message "Looking at %s" ',f
)
597 (vc-diff-internal ',f
',rev1
',rev2
))))))
598 ;; cvs diff: use a single call for the entire tree
599 (let ((coding-system-for-read
600 (or coding-system-for-read
'undecided
)))
601 (apply 'vc-cvs-command
"*vc-diff*" 1 nil
"diff"
602 (and rev1
(concat "-r" rev1
))
603 (and rev2
(concat "-r" rev2
))
604 (vc-diff-switches-list 'CVS
))))))
606 (defun vc-cvs-annotate-command (file buffer
&optional version
)
607 "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER.
608 Optional arg VERSION is a version to annotate from."
609 (vc-cvs-command buffer
0 file
"annotate" (if version
610 (concat "-r" version
))))
612 (defun vc-cvs-annotate-current-time ()
613 "Return the current time, based at midnight of the current day, and
614 encoded as fractional days."
615 (vc-annotate-convert-time
616 (apply 'encode-time
0 0 0 (nthcdr 3 (decode-time (current-time))))))
618 (defun vc-cvs-annotate-time ()
619 "Return the time of the next annotation (as fraction of days)
620 systime, or nil if there is none."
622 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): "))
623 (if (looking-at time-stamp
)
625 (let* ((day (string-to-number (match-string 1)))
626 (month (cdr (assoc (match-string 2)
627 vc-cvs-local-month-numbers
)))
628 (year-tmp (string-to-number (match-string 3)))
629 ;; Years 0..68 are 2000..2068.
630 ;; Years 69..99 are 1969..1999.
631 (year (+ (cond ((> 69 year-tmp
) 2000)
632 ((> 100 year-tmp
) 1900)
635 (goto-char (match-end 0)) ; Position at end makes for nicer overlay result
636 (vc-annotate-convert-time (encode-time 0 0 0 day month year
))))
637 ;; If we did not look directly at an annotation, there might be
638 ;; some further down. This is the case if we are positioned at
639 ;; the very top of the buffer, for instance.
640 (if (re-search-forward time-stamp nil t
)
642 (beginning-of-line nil
)
643 (vc-cvs-annotate-time))))))
649 (defun vc-cvs-create-snapshot (dir name branchp
)
650 "Assign to DIR's current version a given NAME.
651 If BRANCHP is non-nil, the name is created as a branch (and the current
652 workspace is immediately moved to that new branch)."
653 (vc-cvs-command nil
0 dir
"tag" "-c" (if branchp
"-b") name
)
654 (when branchp
(vc-cvs-command nil
0 dir
"update" "-r" name
)))
656 (defun vc-cvs-retrieve-snapshot (dir name update
)
657 "Retrieve a snapshot at and below DIR.
658 NAME is the name of the snapshot; if it is empty, do a `cvs update'.
659 If UPDATE is non-nil, then update (resynch) any affected buffers."
660 (with-current-buffer (get-buffer-create "*vc*")
661 (let ((default-directory dir
)
664 (if (or (not name
) (string= name
""))
665 (vc-cvs-command t
0 nil
"update")
666 (vc-cvs-command t
0 nil
"update" "-r" name
)
667 (setq sticky-tag name
))
669 (goto-char (point-min))
671 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
672 (let* ((file (expand-file-name (match-string 2) dir
))
673 (state (match-string 1))
674 (buffer (find-buffer-visiting file
)))
677 ((or (string= state
"U")
679 (vc-file-setprop file
'vc-state
'up-to-date
)
680 (vc-file-setprop file
'vc-workfile-version nil
)
681 (vc-file-setprop file
'vc-checkout-time
682 (nth 5 (file-attributes file
))))
683 ((or (string= state
"M")
685 (vc-file-setprop file
'vc-state
'edited
)
686 (vc-file-setprop file
'vc-workfile-version nil
)
687 (vc-file-setprop file
'vc-checkout-time
0)))
688 (vc-file-setprop file
'vc-cvs-sticky-tag sticky-tag
)
689 (vc-resynch-buffer file t t
))))
690 (forward-line 1))))))
697 (defun vc-cvs-make-version-backups-p (file)
698 "Return non-nil if version backups should be made for FILE."
699 (vc-cvs-stay-local-p file
))
701 (defun vc-cvs-check-headers ()
702 "Check if the current file has any headers in it."
704 (goto-char (point-min))
705 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
706 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
710 ;;; Internal functions
713 (defun vc-cvs-command (buffer okstatus file
&rest flags
)
714 "A wrapper around `vc-do-command' for use in vc-cvs.el.
715 The difference to vc-do-command is that this function always invokes `cvs',
716 and that it passes `vc-cvs-global-switches' to it before FLAGS."
717 (apply 'vc-do-command buffer okstatus
"cvs" file
718 (if (stringp vc-cvs-global-switches
)
719 (cons vc-cvs-global-switches flags
)
720 (append vc-cvs-global-switches
723 (defun vc-cvs-stay-local-p (file)
724 "Return non-nil if VC should stay local when handling FILE."
725 (if vc-cvs-stay-local
726 (let* ((dirname (if (file-directory-p file
)
727 (directory-file-name file
)
728 (file-name-directory file
)))
730 (or (vc-file-getprop dirname
'vc-cvs-stay-local-p
)
731 (let ((rootname (expand-file-name "CVS/Root" dirname
)))
733 dirname
'vc-cvs-stay-local-p
734 (when (file-readable-p rootname
)
736 (vc-insert-file rootname
)
737 (goto-char (point-min))
738 (if (looking-at "\\([^:]*\\):")
739 (if (not (stringp vc-cvs-stay-local
))
741 (let ((hostname (match-string 1)))
742 (if (string-match vc-cvs-stay-local hostname
)
746 (if (eq prop
'yes
) t nil
))))
748 (defun vc-cvs-parse-status (&optional full
)
749 "Parse output of \"cvs status\" command in the current buffer.
750 Set file properties accordingly. Unless FULL is t, parse only
751 essential information."
753 (goto-char (point-min))
754 (if (re-search-forward "^File: " nil t
)
756 ((looking-at "no file") nil
)
757 ((re-search-forward "\\=\\([^ \t]+\\)" nil t
)
758 (setq file
(expand-file-name (match-string 1)))
759 (vc-file-setprop file
'vc-backend
'CVS
)
760 (if (not (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t
))
761 (setq status
"Unknown")
762 (setq status
(match-string 1)))
765 "\\(RCS Version\\|RCS Revision\\|Repository revision\\):\
766 \[\t ]+\\([0-9.]+\\)"
768 (vc-file-setprop file
'vc-latest-version
(match-string 2)))
772 ((string-match "Up-to-date" status
)
773 (vc-file-setprop file
'vc-checkout-time
774 (nth 5 (file-attributes file
)))
776 ((string-match "Locally Modified" status
) 'edited
)
777 ((string-match "Needs Merge" status
) 'needs-merge
)
778 ((string-match "Needs \\(Checkout\\|Patch\\)" status
) 'needs-patch
)
781 (defun vc-cvs-dir-state-heuristic (dir)
782 "Find the CVS state of all files in DIR, using only local information."
784 (vc-cvs-get-entries dir
)
785 (goto-char (point-min))
787 ;; CVS-removed files are not taken under VC control.
788 (when (looking-at "/\\([^/]*\\)/[^/-]")
789 (let ((file (expand-file-name (match-string 1) dir
)))
790 (unless (vc-file-getprop file
'vc-state
)
791 (vc-cvs-parse-entry file t
))))
794 (defun vc-cvs-get-entries (dir)
795 "Insert the CVS/Entries file from below DIR into the current buffer.
796 This function ensures that the correct coding system is used for that,
797 which may not be the one that is used for the files' contents.
798 CVS/Entries should only be accessed through this function."
799 (let ((coding-system-for-read (or file-name-coding-system
800 default-file-name-coding-system
)))
801 (vc-insert-file (expand-file-name "CVS/Entries" dir
))))
803 (defun vc-cvs-valid-symbolic-tag-name-p (tag)
804 "Return non-nil if TAG is a valid symbolic tag name."
805 ;; According to the CVS manual, a valid symbolic tag must start with
806 ;; an uppercase or lowercase letter and can contain uppercase and
807 ;; lowercase letters, digits, `-', and `_'.
808 (and (string-match "^[a-zA-Z]" tag
)
809 (not (string-match "[^a-z0-9A-Z-_]" tag
))))
811 (defun vc-cvs-valid-version-number-p (tag)
812 "Return non-nil if TAG is a valid version number."
813 (and (string-match "^[0-9]" tag
)
814 (not (string-match "[^0-9.]" tag
))))
816 (defun vc-cvs-parse-sticky-tag (match-type match-tag
)
817 "Parse and return the sticky tag as a string.
818 `match-data' is protected."
819 (let ((data (match-data))
821 (type (cond ((string= match-type
"D") 'date
)
822 ((string= match-type
"T")
823 (if (vc-cvs-valid-symbolic-tag-name-p match-tag
)
830 ;; Sticky Date tag. Convert to a proper date value (`encode-time')
833 "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)"
835 (let* ((year-tmp (string-to-number (match-string 1 match-tag
)))
836 (month (string-to-number (match-string 2 match-tag
)))
837 (day (string-to-number (match-string 3 match-tag
)))
838 (hour (string-to-number (match-string 4 match-tag
)))
839 (min (string-to-number (match-string 5 match-tag
)))
840 (sec (string-to-number (match-string 6 match-tag
)))
841 ;; Years 0..68 are 2000..2068.
842 ;; Years 69..99 are 1969..1999.
843 (year (+ (cond ((> 69 year-tmp
) 2000)
844 ((> 100 year-tmp
) 1900)
847 (setq tag
(encode-time sec min hour day month year
))))
848 ;; Sticky Tag name or revision number
849 ((eq type
'symbolic-name
) (setq tag match-tag
))
850 ((eq type
'revision-number
) (setq tag match-tag
))
851 ;; Default is no sticky tag at all
853 (cond ((eq vc-cvs-sticky-tag-display nil
) nil
)
854 ((eq vc-cvs-sticky-tag-display t
)
855 (cond ((eq type
'date
) (format-time-string
856 vc-cvs-sticky-date-format-string
858 ((eq type
'symbolic-name
) tag
)
859 ((eq type
'revision-number
) tag
)
861 ((functionp vc-cvs-sticky-tag-display
)
862 (funcall vc-cvs-sticky-tag-display tag type
))
865 (set-match-data data
))))
867 (defun vc-cvs-parse-entry (file &optional set-state
)
868 "Parse a line from CVS/Entries.
869 Compare modification time to that of the FILE, set file properties
870 accordingly. However, `vc-state' is set only if optional arg SET-STATE
873 ;; entry for a "locally added" file (not yet committed)
874 ((looking-at "/[^/]+/0/")
875 (vc-file-setprop file
'vc-checkout-time
0)
876 (vc-file-setprop file
'vc-workfile-version
"0")
877 (if set-state
(vc-file-setprop file
'vc-state
'edited
)))
883 ;; timestamp and optional conflict field
888 "\\(.\\|\\)" ;Sticky tag type (date or tag name, could be empty)
889 "\\(.*\\)")) ;Sticky tag
890 (vc-file-setprop file
'vc-workfile-version
(match-string 1))
891 (vc-file-setprop file
'vc-cvs-sticky-tag
892 (vc-cvs-parse-sticky-tag (match-string 4) (match-string 5)))
893 ;; compare checkout time and modification time
894 (let ((mtime (nth 5 (file-attributes file
))))
895 (require 'parse-time
)
897 (parse-time-string (concat (match-string 2) " +0000"))))
898 (cond ((and (not (string-match "\\+" (match-string 2)))
900 (equal mtime
(apply 'encode-time parsed-time
)))
901 (vc-file-setprop file
'vc-checkout-time mtime
)
902 (if set-state
(vc-file-setprop file
'vc-state
'up-to-date
)))
904 (vc-file-setprop file
'vc-checkout-time
0)
905 (if set-state
(vc-file-setprop file
'vc-state
'edited
)))))))))
909 ;;; vc-cvs.el ends here