1 ;;; vc-cvs.el --- non-resident support for CVS version-control
3 ;; Copyright (C) 1995,98,99,2000,2001,02,2003 Free Software Foundation, Inc.
5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
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.
89 The value can also be a regular expression or list of regular
90 expressions to match against the host name of a repository; then VC
91 only stays local for hosts that match it. Alternatively, the value
92 can be a list of regular expressions where the first element is the
93 symbol `except'; then VC always stays local except for hosts matched
94 by these regular expressions."
95 :type
'(choice (const :tag
"Always stay local" t
)
96 (const :tag
"Don't stay local" nil
)
97 (list :format
"\nExamine hostname and %v" :tag
"Examine hostname ..."
98 (set :format
"%v" :inline t
(const :format
"%t" :tag
"don't" except
))
99 (regexp :format
" stay local,\n%t: %v" :tag
"if it matches")
100 (repeat :format
"%v%i\n" :inline t
(regexp :tag
"or"))))
104 (defcustom vc-cvs-sticky-date-format-string
"%c"
105 "*Format string for mode-line display of sticky date.
106 Format is according to `format-time-string'. Only used if
107 `vc-cvs-sticky-tag-display' is t."
112 (defcustom vc-cvs-sticky-tag-display t
113 "*Specify the mode-line display of sticky tags.
114 Value t means default display, nil means no display at all. If the
115 value is a function or macro, it is called with the sticky tag and
116 its' type as parameters, in that order. TYPE can have three different
117 values: `symbolic-name' (TAG is a string), `revision-number' (TAG is a
118 string) and `date' (TAG is a date as returned by `encode-time'). The
119 return value of the function or macro will be displayed as a string.
121 Here's an example that will display the formatted date for sticky
122 dates and the word \"Sticky\" for sticky tag names and revisions.
125 (cond ((eq type 'date) (format-time-string
126 vc-cvs-sticky-date-format-string tag))
127 ((eq type 'revision-number) \"Sticky\")
128 ((eq type 'symbolic-name) \"Sticky\")))
130 Here's an example that will abbreviate to the first character only,
131 any text before the first occurrence of `-' for sticky symbolic tags.
132 If the sticky tag is a revision number, the word \"Sticky\" is
133 displayed. Date and time is displayed for sticky dates.
136 (cond ((eq type 'date) (format-time-string \"%Y%m%d %H:%M\" tag))
137 ((eq type 'revision-number) \"Sticky\")
138 ((eq type 'symbolic-name)
141 (string-match \"\\\\([^-]*\\\\)\\\\(.*\\\\)\" tag)
142 (concat (substring (match-string 1 tag) 0 1) \":\"
143 (substring (match-string 2 tag) 1 nil)))
144 (error tag))))) ; Fall-back to given tag name.
146 See also variable `vc-cvs-sticky-date-format-string'."
147 :type
'(choice boolean function
)
152 ;;; Internal variables
157 ;;; State-querying functions
160 ;;;###autoload (defun vc-cvs-registered (f)
161 ;;;###autoload (when (file-readable-p (expand-file-name
162 ;;;###autoload "CVS/Entries" (file-name-directory f)))
163 ;;;###autoload (load "vc-cvs")
164 ;;;###autoload (vc-cvs-registered f)))
166 (defun vc-cvs-registered (file)
167 "Check if FILE is CVS registered."
168 (let ((dirname (or (file-name-directory file
) ""))
169 (basename (file-name-nondirectory file
))
170 ;; make sure that the file name is searched case-sensitively
171 (case-fold-search nil
))
172 (if (file-readable-p (expand-file-name "CVS/Entries" dirname
))
174 (vc-cvs-get-entries dirname
)
175 (goto-char (point-min))
178 ;; CVS-removed files are not taken under VC control.
179 (concat "^/" (regexp-quote basename
) "/[^/-]") nil t
)
181 (vc-cvs-parse-entry file
)
186 (defun vc-cvs-state (file)
187 "CVS-specific version of `vc-state'."
188 (if (vc-stay-local-p file
)
189 (let ((state (vc-file-getprop file
'vc-state
)))
190 ;; If we should stay local, use the heuristic but only if
191 ;; we don't have a more precise state already available.
192 (if (memq state
'(up-to-date edited
))
193 (vc-cvs-state-heuristic file
)
196 (cd (file-name-directory file
))
197 (vc-cvs-command t
0 file
"status")
198 (vc-cvs-parse-status t
))))
200 (defun vc-cvs-state-heuristic (file)
201 "CVS-specific state heuristic."
202 ;; If the file has not changed since checkout, consider it `up-to-date'.
203 ;; Otherwise consider it `edited'.
204 (let ((checkout-time (vc-file-getprop file
'vc-checkout-time
))
205 (lastmod (nth 5 (file-attributes file
))))
206 (if (equal checkout-time lastmod
)
210 (defun vc-cvs-dir-state (dir)
211 "Find the CVS state of all files in DIR."
212 ;; if DIR is not under CVS control, don't do anything.
213 (when (file-readable-p (expand-file-name "CVS/Entries" dir
))
214 (if (vc-stay-local-p dir
)
215 (vc-cvs-dir-state-heuristic dir
)
216 (let ((default-directory dir
))
217 ;; Don't specify DIR in this command, the default-directory is
218 ;; enough. Otherwise it might fail with remote repositories.
220 (vc-cvs-command t
0 nil
"status" "-l")
221 (goto-char (point-min))
222 (while (re-search-forward "^=+\n\\([^=\n].*\n\\|\n\\)+" nil t
)
223 (narrow-to-region (match-beginning 0) (match-end 0))
224 (vc-cvs-parse-status)
225 (goto-char (point-max))
228 (defun vc-cvs-workfile-version (file)
229 "CVS-specific version of `vc-workfile-version'."
230 ;; There is no need to consult RCS headers under CVS, because we
231 ;; get the workfile version for free when we recognize that a file
232 ;; is registered in CVS.
233 (vc-cvs-registered file
)
234 (vc-file-getprop file
'vc-workfile-version
))
236 (defun vc-cvs-checkout-model (file)
237 "CVS-specific version of `vc-checkout-model'."
238 (if (or (getenv "CVSREAD")
239 ;; If the file is not writable (despite CVSREAD being
240 ;; undefined), this is probably because the file is being
241 ;; "watched" by other developers.
242 ;; (If vc-mistrust-permissions was t, we actually shouldn't
243 ;; trust this, but there is no other way to learn this from CVS
244 ;; at the moment (version 1.9).)
245 (string-match "r-..-..-." (nth 8 (file-attributes file
))))
249 (defun vc-cvs-mode-line-string (file)
250 "Return string for placement into the modeline for FILE.
251 Compared to the default implementation, this function does two things:
252 Handle the special case of a CVS file that is added but not yet
253 committed and support display of sticky tags."
254 (let ((sticky-tag (vc-file-getprop file
'vc-cvs-sticky-tag
))
255 (string (if (string= (vc-workfile-version file
) "0")
256 ;; A file that is added but not yet committed.
258 (vc-default-mode-line-string 'CVS file
))))
259 (if (zerop (length sticky-tag
))
261 (concat string
"[" sticky-tag
"]"))))
263 (defun vc-cvs-dired-state-info (file)
264 "CVS-specific version of `vc-dired-state-info'."
265 (let ((cvs-state (vc-state file
)))
266 (cond ((eq cvs-state
'edited
)
267 (if (equal (vc-workfile-version file
) "0")
268 "(added)" "(modified)"))
269 ((eq cvs-state
'needs-patch
) "(patch)")
270 ((eq cvs-state
'needs-merge
) "(merge)"))))
274 ;;; State-changing functions
277 (defun vc-cvs-register (file &optional rev comment
)
278 "Register FILE into the CVS version-control system.
279 COMMENT can be used to provide an initial description of FILE.
281 `vc-register-switches' and `vc-cvs-register-switches' are passed to
282 the CVS command (in that order)."
283 (when (and (not (vc-cvs-responsible-p file
))
284 (vc-cvs-could-register file
))
285 ;; Register the directory if needed.
286 (vc-cvs-register (directory-file-name (file-name-directory file
))))
287 (apply 'vc-cvs-command nil
0 file
289 (and comment
(string-match "[^\t\n ]" comment
)
290 (concat "-m" comment
))
291 (vc-switches 'CVS
'register
)))
293 (defun vc-cvs-responsible-p (file)
294 "Return non-nil if CVS thinks it is responsible for FILE."
295 (file-directory-p (expand-file-name "CVS"
296 (if (file-directory-p file
)
298 (file-name-directory file
)))))
300 (defun vc-cvs-could-register (file)
301 "Return non-nil if FILE could be registered in CVS.
302 This is only possible if CVS is managing FILE's directory or one of
305 (while (and (stringp dir
)
306 (not (equal dir
(setq dir
(file-name-directory dir
))))
308 (setq dir
(if (file-directory-p
309 (expand-file-name "CVS/Entries" dir
))
310 t
(directory-file-name dir
))))
313 (defun vc-cvs-checkin (file rev comment
)
314 "CVS-specific version of `vc-backend-checkin'."
315 (unless (or (not rev
) (vc-cvs-valid-version-number-p rev
))
316 (if (not (vc-cvs-valid-symbolic-tag-name-p rev
))
317 (error "%s is not a valid symbolic tag name" rev
)
318 ;; If the input revison is a valid symbolic tag name, we create it
319 ;; as a branch, commit and switch to it.
320 (apply 'vc-cvs-command nil
0 file
"tag" "-b" (list rev
))
321 (apply 'vc-cvs-command nil
0 file
"update" "-r" (list rev
))
322 (vc-file-setprop file
'vc-cvs-sticky-tag rev
)))
323 (let ((status (apply 'vc-cvs-command nil
1 file
324 "ci" (if rev
(concat "-r" rev
))
325 (concat "-m" comment
)
326 (vc-switches 'CVS
'checkin
))))
328 (goto-char (point-min))
329 (when (not (zerop status
))
330 ;; Check checkin problem.
332 ((re-search-forward "Up-to-date check failed" nil t
)
333 (vc-file-setprop file
'vc-state
'needs-merge
)
334 (error (substitute-command-keys
335 (concat "Up-to-date check failed: "
336 "type \\[vc-next-action] to merge in changes"))))
338 (pop-to-buffer (current-buffer))
339 (goto-char (point-min))
340 (shrink-window-if-larger-than-buffer)
341 (error "Check-in failed"))))
342 ;; Update file properties
344 file
'vc-workfile-version
345 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
346 ;; Forget the checkout model of the file, because we might have
347 ;; guessed wrong when we found the file. After commit, we can
348 ;; tell it from the permissions of the file (see
349 ;; vc-cvs-checkout-model).
350 (vc-file-setprop file
'vc-checkout-model nil
)
352 ;; if this was an explicit check-in (does not include creation of
353 ;; a branch), remove the sticky tag.
354 (if (and rev
(not (vc-cvs-valid-symbolic-tag-name-p rev
)))
355 (vc-cvs-command nil
0 file
"update" "-A"))))
357 (defun vc-cvs-find-version (file rev buffer
)
358 (apply 'vc-cvs-command
360 "-Q" ; suppress diagnostic output
362 (and rev
(not (string= rev
""))
365 (vc-switches 'CVS
'checkout
)))
367 (defun vc-cvs-checkout (file &optional editable rev workfile
)
368 "Retrieve a revision of FILE into a WORKFILE.
369 EDITABLE non-nil means that the file should be writable.
370 REV is the revision to check out into WORKFILE."
371 (let ((filename (or workfile file
))
372 (file-buffer (get-file-buffer file
))
374 (message "Checking out %s..." filename
)
376 ;; Change buffers to get local value of vc-checkout-switches.
377 (if file-buffer
(set-buffer file-buffer
))
378 (setq switches
(vc-switches 'CVS
'checkout
))
379 ;; Save this buffer's default-directory
380 ;; and use save-excursion to make sure it is restored
381 ;; in the same buffer it was saved in.
382 (let ((default-directory default-directory
))
384 ;; Adjust the default-directory so that the check-out creates
385 ;; the file in the right place.
386 (setq default-directory
(file-name-directory filename
))
389 (backup-name (if (string= file workfile
)
390 (car (find-backup-file-name filename
)))))
392 (copy-file filename backup-name
393 'ok-if-already-exists
'keep-date
)
394 (unless (file-writable-p filename
)
395 (set-file-modes filename
396 (logior (file-modes filename
) 128))))
399 (let ((coding-system-for-read 'no-conversion
)
400 (coding-system-for-write 'no-conversion
))
401 (with-temp-file filename
402 (apply 'vc-cvs-command
403 (current-buffer) 0 file
404 "-Q" ; suppress diagnostic output
407 (not (string= rev
""))
414 (rename-file backup-name filename
415 'ok-if-already-exists
)
416 (if (file-exists-p filename
)
417 (delete-file filename
)))
419 (not vc-make-backup-files
)
420 (delete-file backup-name
)))))
421 (if (and (file-exists-p file
) (not rev
))
422 ;; If no revision was specified, just make the file writable
423 ;; if necessary (using `cvs-edit' if requested).
424 (and editable
(not (eq (vc-cvs-checkout-model file
) 'implicit
))
426 (vc-cvs-command nil
0 file
"edit")
427 (set-file-modes file
(logior (file-modes file
) 128))
428 (if file-buffer
(toggle-read-only -
1))))
429 ;; Check out a particular version (or recreate the file).
430 (vc-file-setprop file
'vc-workfile-version nil
)
431 (apply 'vc-cvs-command nil
0 file
433 (or (not (file-exists-p file
))
434 (not (eq (vc-cvs-checkout-model file
)
440 ;; default for verbose checkout: clear the
441 ;; sticky tag so that the actual update will
442 ;; get the head of the trunk
448 (message "Checking out %s...done" filename
)))))
450 (defun vc-cvs-delete-file (file)
451 (vc-cvs-command nil
0 file
"remove" "-f"))
453 (defun vc-cvs-revert (file &optional contents-done
)
454 "Revert FILE to the version it was based on."
455 (unless contents-done
456 ;; Check out via standard output (caused by the final argument
457 ;; FILE below), so that no sticky tag is set.
458 (vc-cvs-checkout file nil
(vc-workfile-version file
) file
))
459 (unless (eq (vc-checkout-model file
) 'implicit
)
461 (vc-cvs-command nil
0 file
"unedit")
462 ;; Make the file read-only by switching off all w-bits
463 (set-file-modes file
(logand (file-modes file
) 3950)))))
465 (defun vc-cvs-merge (file first-version
&optional second-version
)
466 "Merge changes into current working copy of FILE.
467 The changes are between FIRST-VERSION and SECOND-VERSION."
468 (vc-cvs-command nil
0 file
470 (concat "-j" first-version
)
471 (concat "-j" second-version
))
472 (vc-file-setprop file
'vc-state
'edited
)
473 (with-current-buffer (get-buffer "*vc*")
474 (goto-char (point-min))
475 (if (re-search-forward "conflicts during merge" nil t
)
477 0))) ; signal success
479 (defun vc-cvs-merge-news (file)
480 "Merge in any new changes made to FILE."
481 (message "Merging changes into %s..." file
)
482 ;; (vc-file-setprop file 'vc-workfile-version nil)
483 (vc-file-setprop file
'vc-checkout-time
0)
484 (vc-cvs-command nil
0 file
"update")
485 ;; Analyze the merge result reported by CVS, and set
486 ;; file properties accordingly.
487 (with-current-buffer (get-buffer "*vc*")
488 (goto-char (point-min))
489 ;; get new workfile version
490 (if (re-search-forward
491 "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t
)
492 (vc-file-setprop file
'vc-workfile-version
(match-string 1))
493 (vc-file-setprop file
'vc-workfile-version nil
))
496 (if (eq (buffer-size) 0)
497 0 ;; there were no news; indicate success
498 (if (re-search-forward
499 (concat "^\\([CMUP] \\)?"
500 (regexp-quote (file-name-nondirectory file
))
501 "\\( already contains the differences between \\)?")
504 ;; Merge successful, we are in sync with repository now
505 ((or (match-string 2)
506 (string= (match-string 1) "U ")
507 (string= (match-string 1) "P "))
508 (vc-file-setprop file
'vc-state
'up-to-date
)
509 (vc-file-setprop file
'vc-checkout-time
510 (nth 5 (file-attributes file
)))
511 0);; indicate success to the caller
512 ;; Merge successful, but our own changes are still in the file
513 ((string= (match-string 1) "M ")
514 (vc-file-setprop file
'vc-state
'edited
)
515 0);; indicate success to the caller
516 ;; Conflicts detected!
518 (vc-file-setprop file
'vc-state
'edited
)
519 1);; signal the error to the caller
521 (pop-to-buffer "*vc*")
522 (error "Couldn't analyze cvs update result")))
523 (message "Merging changes into %s...done" file
))))
527 ;;; History functions
530 (defun vc-cvs-print-log (file &optional buffer
)
531 "Get change log associated with FILE."
534 (if (and (vc-stay-local-p file
) (fboundp 'start-process
)) 'async
0)
537 (defun vc-cvs-diff (file &optional oldvers newvers buffer
)
538 "Get a difference report using CVS between two versions of FILE."
539 (if (string= (vc-workfile-version file
) "0")
540 ;; This file is added but not yet committed; there is no master file.
541 (if (or oldvers newvers
)
542 (error "No revisions of %s exist" file
)
543 ;; We regard this as "changed".
544 ;; Diff it against /dev/null.
545 ;; Note: this is NOT a "cvs diff".
546 (apply 'vc-do-command
(or buffer
"*vc-diff*")
548 (append (vc-switches nil
'diff
) '("/dev/null")))
549 ;; Even if it's empty, it's locally modified.
551 (let* ((async (and (vc-stay-local-p file
) (fboundp 'start-process
)))
552 (status (apply 'vc-cvs-command
(or buffer
"*vc-diff*")
555 (and oldvers
(concat "-r" oldvers
))
556 (and newvers
(concat "-r" newvers
))
557 (vc-switches 'CVS
'diff
))))
558 (if async
1 status
)))) ; async diff, pessimistic assumption
560 (defun vc-cvs-diff-tree (dir &optional rev1 rev2
)
561 "Diff all files at and below DIR."
562 (with-current-buffer "*vc-diff*"
563 (setq default-directory dir
)
564 (if (vc-stay-local-p dir
)
565 ;; local diff: do it filewise, and only for files that are modified
570 `(let ((coding-system-for-read (vc-coding-system-for-diff ',f
)))
571 ;; possible optimization: fetch the state of all files
572 ;; in the tree via vc-cvs-dir-state-heuristic
573 (unless (vc-up-to-date-p ',f
)
574 (message "Looking at %s" ',f
)
575 (vc-diff-internal ',f
',rev1
',rev2
))))))
576 ;; cvs diff: use a single call for the entire tree
577 (let ((coding-system-for-read
578 (or coding-system-for-read
'undecided
)))
579 (apply 'vc-cvs-command
"*vc-diff*" 1 nil
"diff"
580 (and rev1
(concat "-r" rev1
))
581 (and rev2
(concat "-r" rev2
))
582 (vc-switches 'CVS
'diff
))))))
584 (defun vc-cvs-annotate-command (file buffer
&optional version
)
585 "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER.
586 Optional arg VERSION is a version to annotate from."
587 (vc-cvs-command buffer
0 file
"annotate" (if version
(concat "-r" version
)))
588 (with-current-buffer buffer
589 (goto-char (point-min))
590 (re-search-forward "^[0-9]")
591 (delete-region (point-min) (1- (point)))))
593 (defun vc-cvs-annotate-current-time ()
594 "Return the current time, based at midnight of the current day, and
595 encoded as fractional days."
596 (vc-annotate-convert-time
597 (apply 'encode-time
0 0 0 (nthcdr 3 (decode-time (current-time))))))
599 (defun vc-cvs-annotate-time ()
600 "Return the time of the next annotation (as fraction of days)
601 systime, or nil if there is none."
603 (cache (get-text-property bol
'vc-cvs-annotate-time
))
608 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): ")
609 (let ((day (string-to-number (match-string 1)))
610 (month (cdr (assq (intern (match-string 2))
611 '((Jan .
1) (Feb .
2) (Mar .
3)
612 (Apr .
4) (May .
5) (Jun .
6)
613 (Jul .
7) (Aug .
8) (Sep .
9)
614 (Oct .
10) (Nov .
11) (Dec .
12)))))
615 (year (let ((tmp (string-to-number (match-string 3))))
616 ;; Years 0..68 are 2000..2068.
617 ;; Years 69..99 are 1969..1999.
618 (+ (cond ((> 69 tmp
) 2000)
623 bol
(1+ bol
) 'vc-cvs-annotate-time
625 ;; Position at end makes for nicer overlay result.
627 (vc-annotate-convert-time
628 (encode-time 0 0 0 day month year
))))))))
630 (goto-char (car cache
)) ; fontify from here to eol
631 (cdr cache
)))) ; days (float)
633 (defun vc-cvs-annotate-extract-revision-at-line ()
636 (if (re-search-forward "^\\([0-9]+\\.[0-9]+\\(\\.[0-9]+\\)*\\) +("
637 (line-end-position) t
)
638 (match-string-no-properties 1)
645 (defun vc-cvs-create-snapshot (dir name branchp
)
646 "Assign to DIR's current version a given NAME.
647 If BRANCHP is non-nil, the name is created as a branch (and the current
648 workspace is immediately moved to that new branch)."
649 (vc-cvs-command nil
0 dir
"tag" "-c" (if branchp
"-b") name
)
650 (when branchp
(vc-cvs-command nil
0 dir
"update" "-r" name
)))
652 (defun vc-cvs-retrieve-snapshot (dir name update
)
653 "Retrieve a snapshot at and below DIR.
654 NAME is the name of the snapshot; if it is empty, do a `cvs update'.
655 If UPDATE is non-nil, then update (resynch) any affected buffers."
656 (with-current-buffer (get-buffer-create "*vc*")
657 (let ((default-directory dir
)
660 (if (or (not name
) (string= name
""))
661 (vc-cvs-command t
0 nil
"update")
662 (vc-cvs-command t
0 nil
"update" "-r" name
)
663 (setq sticky-tag name
))
665 (goto-char (point-min))
667 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
668 (let* ((file (expand-file-name (match-string 2) dir
))
669 (state (match-string 1))
670 (buffer (find-buffer-visiting file
)))
673 ((or (string= state
"U")
675 (vc-file-setprop file
'vc-state
'up-to-date
)
676 (vc-file-setprop file
'vc-workfile-version nil
)
677 (vc-file-setprop file
'vc-checkout-time
678 (nth 5 (file-attributes file
))))
679 ((or (string= state
"M")
681 (vc-file-setprop file
'vc-state
'edited
)
682 (vc-file-setprop file
'vc-workfile-version nil
)
683 (vc-file-setprop file
'vc-checkout-time
0)))
684 (vc-file-setprop file
'vc-cvs-sticky-tag sticky-tag
)
685 (vc-resynch-buffer file t t
))))
686 (forward-line 1))))))
693 (defalias 'vc-cvs-make-version-backups-p
'vc-stay-local-p
694 "Return non-nil if version backups should be made for FILE.")
696 (defun vc-cvs-check-headers ()
697 "Check if the current file has any headers in it."
699 (goto-char (point-min))
700 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
701 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
705 ;;; Internal functions
708 (defun vc-cvs-command (buffer okstatus file
&rest flags
)
709 "A wrapper around `vc-do-command' for use in vc-cvs.el.
710 The difference to vc-do-command is that this function always invokes `cvs',
711 and that it passes `vc-cvs-global-switches' to it before FLAGS."
712 (apply 'vc-do-command buffer okstatus
"cvs" file
713 (if (stringp vc-cvs-global-switches
)
714 (cons vc-cvs-global-switches flags
)
715 (append vc-cvs-global-switches
718 (defalias 'vc-cvs-stay-local-p
'vc-stay-local-p
) ;Back-compatibility.
720 (defun vc-cvs-repository-hostname (dirname)
721 "Hostname of the CVS server associated to workarea DIRNAME."
722 (let ((rootname (expand-file-name "CVS/Root" dirname
)))
723 (when (file-readable-p rootname
)
725 (let ((coding-system-for-read
726 (or file-name-coding-system
727 default-file-name-coding-system
)))
728 (vc-insert-file rootname
))
729 (goto-char (point-min))
730 (nth 2 (vc-cvs-parse-root
731 (buffer-substring (point)
732 (line-end-position))))))))
734 (defun vc-cvs-parse-root (root)
735 "Split CVS ROOT specification string into a list of fields.
736 A CVS root specification of the form
737 [:METHOD:][[USER@]HOSTNAME:]/path/to/repository
738 is converted to a normalized record with the following structure:
739 \(METHOD USER HOSTNAME CVS-ROOT).
740 The default METHOD for a CVS root of the form
743 The default METHOD for a CVS root of the form
744 [USER@]HOSTNAME:/path/to/repository
746 For an empty string, nil is returned (illegal CVS root)."
747 ;; Split CVS root into colon separated fields (0-4).
748 ;; The `x:' makes sure, that leading colons are not lost;
749 ;; `HOST:/PATH' is then different from `:METHOD:/PATH'.
750 (let* ((root-list (cdr (split-string (concat "x:" root
) ":")))
751 (len (length root-list
))
752 ;; All syntactic varieties will get a proper METHOD.
759 ;; Simple PATH => method `local'
761 (cons nil root-list
)))
763 ;; [USER@]HOST:PATH => method `ext'
764 (and (not (equal (car root-list
) ""))
765 (cons "ext" root-list
)))
768 (cons (cadr root-list
)
769 (cons nil
(cddr root-list
))))
771 ;; :METHOD:[USER@]HOST:PATH
774 (let ((method (car root-list
))
775 (uhost (or (cadr root-list
) ""))
776 (root (nth 2 root-list
))
779 (if (string-match "\\(.*\\)@\\(.*\\)" uhost
)
780 (setq user
(match-string 1 uhost
)
781 host
(match-string 2 uhost
))
786 ;; Fix windows style CVS root `:local:C:\\project\\cvs\\some\\dir'
788 (equal method
"local")
789 (setq root
(concat host
":" root
) host
))
790 ;; Normalize CVS root record
791 (list method user host root
)))))
793 (defun vc-cvs-parse-status (&optional full
)
794 "Parse output of \"cvs status\" command in the current buffer.
795 Set file properties accordingly. Unless FULL is t, parse only
796 essential information."
798 (goto-char (point-min))
799 (if (re-search-forward "^File: " nil t
)
801 ((looking-at "no file") nil
)
802 ((re-search-forward "\\=\\([^ \t]+\\)" nil t
)
803 (setq file
(expand-file-name (match-string 1)))
804 (vc-file-setprop file
'vc-backend
'CVS
)
805 (if (not (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t
))
806 (setq status
"Unknown")
807 (setq status
(match-string 1)))
810 "\\(RCS Version\\|RCS Revision\\|Repository revision\\):\
811 \[\t ]+\\([0-9.]+\\)"
813 (vc-file-setprop file
'vc-latest-version
(match-string 2)))
817 ((string-match "Up-to-date" status
)
818 (vc-file-setprop file
'vc-checkout-time
819 (nth 5 (file-attributes file
)))
821 ((string-match "Locally Modified" status
) 'edited
)
822 ((string-match "Needs Merge" status
) 'needs-merge
)
823 ((string-match "Needs \\(Checkout\\|Patch\\)" status
) 'needs-patch
)
826 (defun vc-cvs-dir-state-heuristic (dir)
827 "Find the CVS state of all files in DIR, using only local information."
829 (vc-cvs-get-entries dir
)
830 (goto-char (point-min))
832 ;; CVS-removed files are not taken under VC control.
833 (when (looking-at "/\\([^/]*\\)/[^/-]")
834 (let ((file (expand-file-name (match-string 1) dir
)))
835 (unless (vc-file-getprop file
'vc-state
)
836 (vc-cvs-parse-entry file t
))))
839 (defun vc-cvs-get-entries (dir)
840 "Insert the CVS/Entries file from below DIR into the current buffer.
841 This function ensures that the correct coding system is used for that,
842 which may not be the one that is used for the files' contents.
843 CVS/Entries should only be accessed through this function."
844 (let ((coding-system-for-read (or file-name-coding-system
845 default-file-name-coding-system
)))
846 (vc-insert-file (expand-file-name "CVS/Entries" dir
))))
848 (defun vc-cvs-valid-symbolic-tag-name-p (tag)
849 "Return non-nil if TAG is a valid symbolic tag name."
850 ;; According to the CVS manual, a valid symbolic tag must start with
851 ;; an uppercase or lowercase letter and can contain uppercase and
852 ;; lowercase letters, digits, `-', and `_'.
853 (and (string-match "^[a-zA-Z]" tag
)
854 (not (string-match "[^a-z0-9A-Z-_]" tag
))))
856 (defun vc-cvs-valid-version-number-p (tag)
857 "Return non-nil if TAG is a valid version number."
858 (and (string-match "^[0-9]" tag
)
859 (not (string-match "[^0-9.]" tag
))))
861 (defun vc-cvs-parse-sticky-tag (match-type match-tag
)
862 "Parse and return the sticky tag as a string.
863 `match-data' is protected."
864 (let ((data (match-data))
866 (type (cond ((string= match-type
"D") 'date
)
867 ((string= match-type
"T")
868 (if (vc-cvs-valid-symbolic-tag-name-p match-tag
)
875 ;; Sticky Date tag. Convert to a proper date value (`encode-time')
878 "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)"
880 (let* ((year-tmp (string-to-number (match-string 1 match-tag
)))
881 (month (string-to-number (match-string 2 match-tag
)))
882 (day (string-to-number (match-string 3 match-tag
)))
883 (hour (string-to-number (match-string 4 match-tag
)))
884 (min (string-to-number (match-string 5 match-tag
)))
885 (sec (string-to-number (match-string 6 match-tag
)))
886 ;; Years 0..68 are 2000..2068.
887 ;; Years 69..99 are 1969..1999.
888 (year (+ (cond ((> 69 year-tmp
) 2000)
889 ((> 100 year-tmp
) 1900)
892 (setq tag
(encode-time sec min hour day month year
))))
893 ;; Sticky Tag name or revision number
894 ((eq type
'symbolic-name
) (setq tag match-tag
))
895 ((eq type
'revision-number
) (setq tag match-tag
))
896 ;; Default is no sticky tag at all
898 (cond ((eq vc-cvs-sticky-tag-display nil
) nil
)
899 ((eq vc-cvs-sticky-tag-display t
)
900 (cond ((eq type
'date
) (format-time-string
901 vc-cvs-sticky-date-format-string
903 ((eq type
'symbolic-name
) tag
)
904 ((eq type
'revision-number
) tag
)
906 ((functionp vc-cvs-sticky-tag-display
)
907 (funcall vc-cvs-sticky-tag-display tag type
))
910 (set-match-data data
))))
912 (defun vc-cvs-parse-entry (file &optional set-state
)
913 "Parse a line from CVS/Entries.
914 Compare modification time to that of the FILE, set file properties
915 accordingly. However, `vc-state' is set only if optional arg SET-STATE
918 ;; entry for a "locally added" file (not yet committed)
919 ((looking-at "/[^/]+/0/")
920 (vc-file-setprop file
'vc-checkout-time
0)
921 (vc-file-setprop file
'vc-workfile-version
"0")
922 (if set-state
(vc-file-setprop file
'vc-state
'edited
)))
928 ;; timestamp and optional conflict field
933 "\\(.\\|\\)" ;Sticky tag type (date or tag name, could be empty)
934 "\\(.*\\)")) ;Sticky tag
935 (vc-file-setprop file
'vc-workfile-version
(match-string 1))
936 (vc-file-setprop file
'vc-cvs-sticky-tag
937 (vc-cvs-parse-sticky-tag (match-string 4)
939 ;; Compare checkout time and modification time.
940 ;; This is intentionally different from the algorithm that CVS uses
941 ;; (which is based on textual comparison), because there can be problems
942 ;; generating a time string that looks exactly like the one from CVS.
943 (let ((mtime (nth 5 (file-attributes file
))))
944 (require 'parse-time
)
946 (parse-time-string (concat (match-string 2) " +0000"))))
947 (cond ((and (not (string-match "\\+" (match-string 2)))
949 (equal mtime
(apply 'encode-time parsed-time
)))
950 (vc-file-setprop file
'vc-checkout-time mtime
)
951 (if set-state
(vc-file-setprop file
'vc-state
'up-to-date
)))
953 (vc-file-setprop file
'vc-checkout-time
0)
954 (if set-state
(vc-file-setprop file
'vc-state
'edited
)))))))))
958 ;;; arch-tag: 60e1402a-aa53-4607-927a-cf74f144b432
959 ;;; vc-cvs.el ends here