1 ;;; vc-cvs.el --- non-resident support for CVS version-control
3 ;; Copyright (C) 1995,98,99,2000,2001 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.33 2002/02/21 20:16:47 spiegel 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-register-switches nil
39 "*Extra switches for registering a file into CVS.
40 A string or list of strings passed to the checkin program by
42 :type
'(choice (const :tag
"None" nil
)
43 (string :tag
"Argument String")
44 (repeat :tag
"Argument List"
50 (defcustom vc-cvs-diff-switches nil
51 "*A string or list of strings specifying extra switches for cvs diff under VC."
52 :type
'(choice (const :tag
"None" nil
)
53 (string :tag
"Argument String")
54 (repeat :tag
"Argument List"
60 (defcustom vc-cvs-header
(or (cdr (assoc 'CVS vc-header-alist
)) '("\$Id\$"))
61 "*Header keywords to be inserted by `vc-insert-headers'."
63 :type
'(repeat string
)
66 (defcustom vc-cvs-use-edit t
67 "*Non-nil means to use `cvs edit' to \"check out\" a file.
68 This is only meaningful if you don't use the implicit checkout model
69 \(i.e. if you have $CVSREAD set)."
74 (defcustom vc-cvs-stay-local t
75 "*Non-nil means use local operations when possible for remote repositories.
76 This avoids slow queries over the network and instead uses heuristics
77 and past information to determine the current status of a file.
78 The value can also be a regular expression to match against the host name
79 of a repository; then VC only stays local for hosts that match it."
80 :type
'(choice (const :tag
"Always stay local" t
)
81 (string :tag
"Host regexp")
82 (const :tag
"Don't stay local" nil
))
86 (defcustom vc-cvs-sticky-date-format-string
"%c"
87 "*Format string for mode-line display of sticky date.
88 Format is according to `format-time-string'. Only used if
89 `vc-cvs-sticky-tag-display' is t."
94 (defcustom vc-cvs-sticky-tag-display t
95 "*Specify the mode-line display of sticky tags.
96 Value t means default display, nil means no display at all. If the
97 value is a function or macro, it is called with the sticky tag and
98 its' type as parameters, in that order. TYPE can have three different
99 values: `symbolic-name' (TAG is a string), `revision-number' (TAG is a
100 string) and `date' (TAG is a date as returned by `encode-time'). The
101 return value of the function or macro will be displayed as a string.
103 Here's an example that will display the formatted date for sticky
104 dates and the word \"Sticky\" for sticky tag names and revisions.
107 (cond ((eq type 'date) (format-time-string
108 vc-cvs-sticky-date-format-string tag))
109 ((eq type 'revision-number) \"Sticky\")
110 ((eq type 'symbolic-name) \"Sticky\")))
112 Here's an example that will abbreviate to the first character only,
113 any text before the first occurence of `-' for sticky symbolic tags.
114 If the sticky tag is a revision number, the word \"Sticky\" is
115 displayed. Date and time is displayed for sticky dates.
118 (cond ((eq type 'date) (format-time-string \"%Y%m%d %H:%M\" tag))
119 ((eq type 'revision-number) \"Sticky\")
120 ((eq type 'symbolic-name)
123 (string-match \"\\\\([^-]*\\\\)\\\\(.*\\\\)\" tag)
124 (concat (substring (match-string 1 tag) 0 1) \":\"
125 (substring (match-string 2 tag) 1 nil)))
126 (error tag))))) ; Fall-back to given tag name.
128 See also variable `vc-cvs-sticky-date-format-string'."
129 :type
'(choice boolean function
)
134 ;;; Internal variables
137 (defvar vc-cvs-local-month-numbers
138 '(("Jan" .
1) ("Feb" .
2) ("Mar" .
3) ("Apr" .
4)
139 ("May" .
5) ("Jun" .
6) ("Jul" .
7) ("Aug" .
8)
140 ("Sep" .
9) ("Oct" .
10) ("Nov" .
11) ("Dec" .
12))
141 "Local association list of month numbers.")
145 ;;; State-querying functions
148 ;;;###autoload (defun vc-cvs-registered (f)
149 ;;;###autoload (when (file-readable-p (expand-file-name
150 ;;;###autoload "CVS/Entries" (file-name-directory f)))
151 ;;;###autoload (require 'vc-cvs)
152 ;;;###autoload (vc-cvs-registered f)))
154 (defun vc-cvs-registered (file)
155 "Check if FILE is CVS registered."
156 (let ((dirname (or (file-name-directory file
) ""))
157 (basename (file-name-nondirectory file
))
158 ;; make sure that the file name is searched case-sensitively
159 (case-fold-search nil
))
160 (if (file-readable-p (expand-file-name "CVS/Entries" dirname
))
162 (vc-insert-file (expand-file-name "CVS/Entries" dirname
))
163 (goto-char (point-min))
166 (concat "^/" (regexp-quote basename
) "/") nil t
)
168 (vc-cvs-parse-entry file
)
173 (defun vc-cvs-state (file)
174 "CVS-specific version of `vc-state'."
175 (if (vc-cvs-stay-local-p file
)
176 (let ((state (vc-file-getprop file
'vc-state
)))
177 ;; If we should stay local, use the heuristic but only if
178 ;; we don't have a more precise state already available.
179 (if (memq state
'(up-to-date edited
))
180 (vc-cvs-state-heuristic file
)
183 (cd (file-name-directory file
))
184 (vc-do-command t
0 "cvs" file
"status")
185 (vc-cvs-parse-status t
))))
187 (defun vc-cvs-state-heuristic (file)
188 "CVS-specific state heuristic."
189 ;; If the file has not changed since checkout, consider it `up-to-date'.
190 ;; Otherwise consider it `edited'.
191 (let ((checkout-time (vc-file-getprop file
'vc-checkout-time
))
192 (lastmod (nth 5 (file-attributes file
))))
193 (if (equal checkout-time lastmod
)
197 (defun vc-cvs-dir-state (dir)
198 "Find the CVS state of all files in DIR."
199 (if (vc-cvs-stay-local-p dir
)
200 (vc-cvs-dir-state-heuristic dir
)
201 (let ((default-directory dir
))
202 ;; Don't specify DIR in this command, the default-directory is
203 ;; enough. Otherwise it might fail with remote repositories.
205 (vc-do-command t
0 "cvs" nil
"status" "-l")
206 (goto-char (point-min))
207 (while (re-search-forward "^=+\n\\([^=\n].*\n\\|\n\\)+" nil t
)
208 (narrow-to-region (match-beginning 0) (match-end 0))
209 (vc-cvs-parse-status)
210 (goto-char (point-max))
213 (defun vc-cvs-workfile-version (file)
214 "CVS-specific version of `vc-workfile-version'."
215 ;; There is no need to consult RCS headers under CVS, because we
216 ;; get the workfile version for free when we recognize that a file
217 ;; is registered in CVS.
218 (vc-cvs-registered file
)
219 (vc-file-getprop file
'vc-workfile-version
))
221 (defun vc-cvs-checkout-model (file)
222 "CVS-specific version of `vc-checkout-model'."
223 (if (or (getenv "CVSREAD")
224 ;; If the file is not writable (despite CVSREAD being
225 ;; undefined), this is probably because the file is being
226 ;; "watched" by other developers.
227 ;; (If vc-mistrust-permissions was t, we actually shouldn't
228 ;; trust this, but there is no other way to learn this from CVS
229 ;; at the moment (version 1.9).)
230 (string-match "r-..-..-." (nth 8 (file-attributes file
))))
234 (defun vc-cvs-mode-line-string (file)
235 "Return string for placement into the modeline for FILE.
236 Compared to the default implementation, this function does two things:
237 Handle the special case of a CVS file that is added but not yet
238 committed and support display of sticky tags."
239 (let* ((state (vc-state file
))
240 (rev (vc-workfile-version file
))
241 (sticky-tag (vc-file-getprop file
'vc-cvs-sticky-tag
))
242 (sticky-tag-printable (and sticky-tag
243 (not (string= sticky-tag
""))
244 (concat "[" sticky-tag
"]"))))
245 (cond ((string= rev
"0")
246 ;; A file that is added but not yet committed.
248 ((or (eq state
'up-to-date
)
249 (eq state
'needs-patch
))
250 (concat "CVS-" rev sticky-tag-printable
))
252 (concat "CVS:" state
":" rev sticky-tag-printable
))
254 ;; Not just for the 'edited state, but also a fallback
255 ;; for all other states. Think about different symbols
256 ;; for 'needs-patch and 'needs-merge.
257 (concat "CVS:" rev sticky-tag-printable
)))))
259 (defun vc-cvs-dired-state-info (file)
260 "CVS-specific version of `vc-dired-state-info'."
261 (let* ((cvs-state (vc-state file
))
262 (state (cond ((eq cvs-state
'edited
) "modified")
263 ((eq cvs-state
'needs-patch
) "patch")
264 ((eq cvs-state
'needs-merge
) "merge")
265 ;; FIXME: those two states cannot occur right now
266 ((eq cvs-state
'unlocked-changes
) "conflict")
267 ((eq cvs-state
'locally-added
) "added")
269 (if state
(concat "(" state
")"))))
273 ;;; State-changing functions
276 (defun vc-cvs-register (file &optional rev comment
)
277 "Register FILE into the CVS version-control system.
278 COMMENT can be used to provide an initial description of FILE.
280 `vc-register-switches' and `vc-cvs-register-switches' are passed to
281 the CVS command (in that order)."
282 (let ((switches (list
283 (if (stringp vc-register-switches
)
284 (list vc-register-switches
)
285 vc-register-switches
)
286 (if (stringp vc-cvs-register-switches
)
287 (list vc-cvs-register-switches
)
288 vc-cvs-register-switches
))))
290 (apply 'vc-do-command nil
0 "cvs" file
292 (and comment
(string-match "[^\t\n ]" comment
)
293 (concat "-m" comment
))
296 (defun vc-cvs-responsible-p (file)
297 "Return non-nil if CVS thinks it is responsible for FILE."
298 (file-directory-p (expand-file-name "CVS"
299 (if (file-directory-p file
)
301 (file-name-directory file
)))))
303 (defun vc-cvs-could-register (file)
304 "Return non-nil if FILE could be registered in CVS.
305 This is only possible if CVS is responsible for FILE's directory."
306 (vc-cvs-responsible-p file
))
308 (defun vc-cvs-checkin (file rev comment
)
309 "CVS-specific version of `vc-backend-checkin'."
310 (let ((switches (if (stringp vc-checkin-switches
)
311 (list vc-checkin-switches
)
312 vc-checkin-switches
))
315 (setq status
(apply 'vc-do-command nil
1 "cvs" file
316 "ci" (if rev
(concat "-r" rev
))
317 (concat "-m" comment
)
319 (if (not (vc-cvs-valid-symbolic-tag-name-p rev
))
320 (error "%s is not a valid symbolic tag name")
321 ;; If the input revison is a valid symbolic tag name, we create it
322 ;; as a branch, commit and switch to it.
323 (apply 'vc-do-command nil
0 "cvs" file
"tag" "-b" (list rev
))
324 (apply 'vc-do-command nil
0 "cvs" file
"update" "-r" (list rev
))
325 (setq status
(apply 'vc-do-command nil
1 "cvs" file
327 (concat "-m" comment
)
329 (vc-file-setprop file
'vc-cvs-sticky-tag rev
)))
331 (goto-char (point-min))
332 (when (not (zerop status
))
333 ;; Check checkin problem.
335 ((re-search-forward "Up-to-date check failed" nil t
)
336 (vc-file-setprop file
'vc-state
'needs-merge
)
337 (error (substitute-command-keys
338 (concat "Up-to-date check failed: "
339 "type \\[vc-next-action] to merge in changes"))))
341 (pop-to-buffer (current-buffer))
342 (goto-char (point-min))
343 (shrink-window-if-larger-than-buffer)
344 (error "Check-in failed"))))
345 ;; Update file properties
347 file
'vc-workfile-version
348 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
349 ;; Forget the checkout model of the file, because we might have
350 ;; guessed wrong when we found the file. After commit, we can
351 ;; tell it from the permissions of the file (see
352 ;; vc-cvs-checkout-model).
353 (vc-file-setprop file
'vc-checkout-model nil
)
355 ;; if this was an explicit check-in (does not include creation of
356 ;; a branch), remove the sticky tag.
357 (if (and rev
(not (vc-cvs-valid-symbolic-tag-name-p rev
)))
358 (vc-do-command nil
0 "cvs" file
"update" "-A"))))
360 (defun vc-cvs-checkout (file &optional editable rev workfile
)
361 "Retrieve a revision of FILE into a WORKFILE.
362 EDITABLE non-nil means that the file should be writable.
363 REV is the revision to check out into WORKFILE."
364 (let ((filename (or workfile file
))
365 (file-buffer (get-file-buffer file
))
367 (message "Checking out %s..." filename
)
369 ;; Change buffers to get local value of vc-checkout-switches.
370 (if file-buffer
(set-buffer file-buffer
))
371 (setq switches
(if (stringp vc-checkout-switches
)
372 (list vc-checkout-switches
)
373 vc-checkout-switches
))
374 ;; Save this buffer's default-directory
375 ;; and use save-excursion to make sure it is restored
376 ;; in the same buffer it was saved in.
377 (let ((default-directory default-directory
))
379 ;; Adjust the default-directory so that the check-out creates
380 ;; the file in the right place.
381 (setq default-directory
(file-name-directory filename
))
384 (backup-name (if (string= file workfile
)
385 (car (find-backup-file-name filename
)))))
387 (copy-file filename backup-name
388 'ok-if-already-exists
'keep-date
)
389 (unless (file-writable-p filename
)
390 (set-file-modes filename
391 (logior (file-modes filename
) 128))))
394 (let ((coding-system-for-read 'no-conversion
)
395 (coding-system-for-write 'no-conversion
))
396 (with-temp-file filename
397 (apply 'vc-do-command
398 (current-buffer) 0 "cvs" file
399 "-Q" ; suppress diagnostic output
401 (and rev
(not (string= rev
""))
408 (rename-file backup-name filename
409 'ok-if-already-exists
)
410 (if (file-exists-p filename
)
411 (delete-file filename
)))
413 (not vc-make-backup-files
)
414 (delete-file backup-name
)))))
415 (if (and (file-exists-p file
) (not rev
))
416 ;; If no revision was specified, just make the file writable
417 ;; if necessary (using `cvs-edit' if requested).
418 (and editable
(not (eq (vc-cvs-checkout-model file
) 'implicit
))
420 (vc-do-command nil
0 "cvs" file
"edit")
421 (set-file-modes file
(logior (file-modes file
) 128))
422 (if file-buffer
(toggle-read-only -
1))))
423 ;; Check out a particular version (or recreate the file).
424 (vc-file-setprop file
'vc-workfile-version nil
)
425 (apply 'vc-do-command nil
0 "cvs" file
427 (or (not (file-exists-p file
))
428 (not (eq (vc-cvs-checkout-model file
)
432 ;; default for verbose checkout: clear the sticky tag so
433 ;; that the actual update will get the head of the trunk
434 (if (or (not rev
) (string= rev
""))
439 (message "Checking out %s...done" filename
)))))
441 (defun vc-cvs-revert (file &optional contents-done
)
442 "Revert FILE to the version it was based on."
443 (unless contents-done
444 ;; Check out via standard output (caused by the final argument
445 ;; FILE below), so that no sticky tag is set.
446 (vc-cvs-checkout file nil
(vc-workfile-version file
) file
))
447 (unless (eq (vc-checkout-model file
) 'implicit
)
449 (vc-do-command nil
0 "cvs" file
"unedit")
450 ;; Make the file read-only by switching off all w-bits
451 (set-file-modes file
(logand (file-modes file
) 3950)))))
453 (defun vc-cvs-merge (file first-version
&optional second-version
)
454 "Merge changes into current working copy of FILE.
455 The changes are between FIRST-VERSION and SECOND-VERSION."
456 (vc-do-command nil
0 "cvs" file
458 (concat "-j" first-version
)
459 (concat "-j" second-version
))
460 (vc-file-setprop file
'vc-state
'edited
)
462 (set-buffer (get-buffer "*vc*"))
463 (goto-char (point-min))
464 (if (re-search-forward "conflicts during merge" nil t
)
466 0))) ; signal success
468 (defun vc-cvs-merge-news (file)
469 "Merge in any new changes made to FILE."
470 (message "Merging changes into %s..." file
)
472 ;; (vc-file-setprop file 'vc-workfile-version nil)
473 (vc-file-setprop file
'vc-checkout-time
0)
474 (vc-do-command nil
0 "cvs" file
"update")
475 ;; Analyze the merge result reported by CVS, and set
476 ;; file properties accordingly.
477 (set-buffer (get-buffer "*vc*"))
478 (goto-char (point-min))
479 ;; get new workfile version
480 (if (re-search-forward (concat "^Merging differences between "
481 "[01234567890.]* and "
482 "\\([01234567890.]*\\) into")
484 (vc-file-setprop file
'vc-workfile-version
(match-string 1))
485 (vc-file-setprop file
'vc-workfile-version nil
))
488 (if (eq (buffer-size) 0)
489 0 ;; there were no news; indicate success
490 (if (re-search-forward
491 (concat "^\\([CMUP] \\)?"
492 (regexp-quote (file-name-nondirectory file
))
493 "\\( already contains the differences between \\)?")
496 ;; Merge successful, we are in sync with repository now
497 ((or (match-string 2)
498 (string= (match-string 1) "U ")
499 (string= (match-string 1) "P "))
500 (vc-file-setprop file
'vc-state
'up-to-date
)
501 (vc-file-setprop file
'vc-checkout-time
502 (nth 5 (file-attributes file
)))
503 0);; indicate success to the caller
504 ;; Merge successful, but our own changes are still in the file
505 ((string= (match-string 1) "M ")
506 (vc-file-setprop file
'vc-state
'edited
)
507 0);; indicate success to the caller
508 ;; Conflicts detected!
510 (vc-file-setprop file
'vc-state
'edited
)
511 1);; signal the error to the caller
513 (pop-to-buffer "*vc*")
514 (error "Couldn't analyze cvs update result")))
515 (message "Merging changes into %s...done" file
))))
519 ;;; History functions
522 (defun vc-cvs-print-log (file)
523 "Get change log associated with FILE."
526 (if (and (vc-cvs-stay-local-p file
) (fboundp 'start-process
)) 'async
0)
529 (defun vc-cvs-show-log-entry (version)
530 (when (re-search-forward
531 ;; also match some context, for safety
532 (concat "----\nrevision " version
533 "\\(\tlocked by:.*\n\\|\n\\)date: ") nil t
)
534 ;; set the display window so that
535 ;; the whole log entry is displayed
536 (let (start end lines
)
537 (beginning-of-line) (forward-line -
1) (setq start
(point))
538 (if (not (re-search-forward "^----*\nrevision" nil t
))
539 (setq end
(point-max))
540 (beginning-of-line) (forward-line -
1) (setq end
(point)))
541 (setq lines
(count-lines start end
))
543 ;; if the global information and this log entry fit
544 ;; into the window, display from the beginning
545 ((< (count-lines (point-min) end
) (window-height))
546 (goto-char (point-min))
549 ;; if the whole entry fits into the window,
550 ;; display it centered
551 ((< (1+ lines
) (window-height))
553 (recenter (1- (- (/ (window-height) 2) (/ lines
2)))))
554 ;; otherwise (the entry is too large for the window),
555 ;; display from the start
560 (defun vc-cvs-diff (file &optional oldvers newvers
)
561 "Get a difference report using CVS between two versions of FILE."
562 (let (options status
(diff-switches-list (vc-diff-switches-list 'CVS
)))
563 (if (string= (vc-workfile-version file
) "0")
564 ;; This file is added but not yet committed; there is no master file.
565 (if (or oldvers newvers
)
566 (error "No revisions of %s exist" file
)
567 ;; we regard this as "changed".
568 ;; diff it against /dev/null.
569 (apply 'vc-do-command
"*vc-diff*"
571 (append diff-switches-list
'("/dev/null"))))
573 (apply 'vc-do-command
"*vc-diff*"
574 (if (and (vc-cvs-stay-local-p file
)
575 (fboundp 'start-process
))
579 (and oldvers
(concat "-r" oldvers
))
580 (and newvers
(concat "-r" newvers
))
582 (if (vc-cvs-stay-local-p file
)
583 1 ;; async diff, pessimistic assumption
586 (defun vc-cvs-diff-tree (dir &optional rev1 rev2
)
587 "Diff all files at and below DIR."
588 (with-current-buffer "*vc-diff*"
589 (setq default-directory dir
)
590 (if (vc-cvs-stay-local-p dir
)
591 ;; local diff: do it filewise, and only for files that are modified
596 `(let ((coding-system-for-read (vc-coding-system-for-diff ',f
)))
597 ;; possible optimization: fetch the state of all files
598 ;; in the tree via vc-cvs-dir-state-heuristic
599 (unless (vc-up-to-date-p ',f
)
600 (message "Looking at %s" ',f
)
601 (vc-diff-internal ',f
',rel1
',rel2
))))))
602 ;; cvs diff: use a single call for the entire tree
603 (let ((coding-system-for-read
604 (or coding-system-for-read
'undecided
)))
605 (apply 'vc-do-command
"*vc-diff*" 1 "cvs" nil
"diff"
606 (and rel1
(concat "-r" rel1
))
607 (and rel2
(concat "-r" rel2
))
608 (vc-diff-switches-list 'CVS
))))))
610 (defun vc-cvs-annotate-command (file buffer
&optional version
)
611 "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER.
612 Optional arg VERSION is a version to annotate from."
613 (vc-do-command buffer
0 "cvs" file
"annotate" (if version
614 (concat "-r" version
))))
616 (defun vc-cvs-annotate-current-time ()
617 "Return the current time, based at midnight of the current day, and
618 encoded as fractional days."
619 (vc-annotate-convert-time
620 (apply 'encode-time
0 0 0 (nthcdr 3 (decode-time (current-time))))))
622 (defun vc-cvs-annotate-time ()
623 "Return the time of the next annotation (as fraction of days)
624 systime, or nil if there is none."
626 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): "))
627 (if (looking-at time-stamp
)
629 (let* ((day (string-to-number (match-string 1)))
630 (month (cdr (assoc (match-string 2)
631 vc-cvs-local-month-numbers
)))
632 (year-tmp (string-to-number (match-string 3)))
633 ;; Years 0..68 are 2000..2068.
634 ;; Years 69..99 are 1969..1999.
635 (year (+ (cond ((> 69 year-tmp
) 2000)
636 ((> 100 year-tmp
) 1900)
639 (goto-char (match-end 0)) ; Position at end makes for nicer overlay result
640 (vc-annotate-convert-time (encode-time 0 0 0 day month year
))))
641 ;; If we did not look directly at an annotation, there might be
642 ;; some further down. This is the case if we are positioned at
643 ;; the very top of the buffer, for instance.
644 (if (re-search-forward time-stamp nil t
)
646 (beginning-of-line nil
)
647 (vc-cvs-annotate-time))))))
653 (defun vc-cvs-create-snapshot (dir name branchp
)
654 "Assign to DIR's current version a given NAME.
655 If BRANCHP is non-nil, the name is created as a branch (and the current
656 workspace is immediately moved to that new branch)."
657 (vc-do-command nil
0 "cvs" dir
"tag" "-c" (if branchp
"-b") name
)
658 (when branchp
(vc-do-command nil
0 "cvs" dir
"update" "-r" name
)))
660 (defun vc-cvs-retrieve-snapshot (dir name update
)
661 "Retrieve a snapshot at and below DIR.
662 NAME is the name of the snapshot; if it is empty, do a `cvs update'.
663 If UPDATE is non-nil, then update (resynch) any affected buffers."
664 (with-current-buffer (get-buffer-create "*vc*")
665 (let ((default-directory dir
)
668 (if (or (not name
) (string= name
""))
669 (vc-do-command t
0 "cvs" nil
"update")
670 (vc-do-command t
0 "cvs" nil
"update" "-r" name
)
671 (setq sticky-tag name
))
673 (goto-char (point-min))
675 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
676 (let* ((file (expand-file-name (match-string 2) dir
))
677 (state (match-string 1))
678 (buffer (find-buffer-visiting file
)))
681 ((or (string= state
"U")
683 (vc-file-setprop file
'vc-state
'up-to-date
)
684 (vc-file-setprop file
'vc-workfile-version nil
)
685 (vc-file-setprop file
'vc-checkout-time
686 (nth 5 (file-attributes file
))))
687 ((or (string= state
"M")
689 (vc-file-setprop file
'vc-state
'edited
)
690 (vc-file-setprop file
'vc-workfile-version nil
)
691 (vc-file-setprop file
'vc-checkout-time
0)))
692 (vc-file-setprop file
'vc-cvs-sticky-tag sticky-tag
)
693 (vc-resynch-buffer file t t
))))
694 (forward-line 1))))))
701 (defun vc-cvs-make-version-backups-p (file)
702 "Return non-nil if version backups should be made for FILE."
703 (vc-cvs-stay-local-p file
))
705 (defun vc-cvs-check-headers ()
706 "Check if the current file has any headers in it."
708 (goto-char (point-min))
709 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
710 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
714 ;;; Internal functions
717 (defun vc-cvs-stay-local-p (file)
718 "Return non-nil if VC should stay local when handling FILE."
719 (if vc-cvs-stay-local
720 (let* ((dirname (if (file-directory-p file
)
721 (directory-file-name file
)
722 (file-name-directory file
)))
724 (or (vc-file-getprop dirname
'vc-cvs-stay-local-p
)
725 (let ((rootname (expand-file-name "CVS/Root" dirname
)))
727 dirname
'vc-cvs-stay-local-p
728 (when (file-readable-p rootname
)
730 (vc-insert-file rootname
)
731 (goto-char (point-min))
732 (if (looking-at "\\([^:]*\\):")
733 (if (not (stringp vc-cvs-stay-local
))
735 (let ((hostname (match-string 1)))
736 (if (string-match vc-cvs-stay-local hostname
)
740 (if (eq prop
'yes
) t nil
))))
742 (defun vc-cvs-parse-status (&optional full
)
743 "Parse output of \"cvs status\" command in the current buffer.
744 Set file properties accordingly. Unless FULL is t, parse only
745 essential information."
747 (goto-char (point-min))
748 (if (re-search-forward "^File: " nil t
)
750 ((looking-at "no file") nil
)
751 ((re-search-forward "\\=\\([^ \t]+\\)" nil t
)
752 (setq file
(expand-file-name (match-string 1)))
753 (vc-file-setprop file
'vc-backend
'CVS
)
754 (if (not (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t
))
755 (setq status
"Unknown")
756 (setq status
(match-string 1)))
759 "\\(RCS Version\\|RCS Revision\\|Repository revision\\):\
760 \[\t ]+\\([0-9.]+\\)"
762 (vc-file-setprop file
'vc-latest-version
(match-string 2)))
766 ((string-match "Up-to-date" status
)
767 (vc-file-setprop file
'vc-checkout-time
768 (nth 5 (file-attributes file
)))
770 ((string-match "Locally Modified" status
) 'edited
)
771 ((string-match "Needs Merge" status
) 'needs-merge
)
772 ((string-match "Needs \\(Checkout\\|Patch\\)" status
) 'needs-patch
)
775 (defun vc-cvs-dir-state-heuristic (dir)
776 "Find the CVS state of all files in DIR, using only local information."
778 (vc-insert-file (expand-file-name "CVS/Entries" dir
))
779 (goto-char (point-min))
781 (when (looking-at "/\\([^/]*\\)/")
782 (let ((file (expand-file-name (match-string 1) dir
)))
783 (unless (vc-file-getprop file
'vc-state
)
784 (vc-cvs-parse-entry file t
))))
788 (defun vc-cvs-valid-symbolic-tag-name-p (tag)
789 "Return non-nil if TAG is a valid symbolic tag name."
790 ;; According to the CVS manual, a valid symbolic tag must start with
791 ;; an uppercase or lowercase letter and can contain uppercase and
792 ;; lowercase letters, digits, `-', and `_'.
793 (and (string-match "^[a-zA-Z]" tag
)
794 (not (string-match "[^a-z0-9A-Z-_]" tag
))))
797 (defun vc-cvs-parse-sticky-tag (match-type match-tag
)
798 "Parse and return the sticky tag as a string.
799 `match-data' is protected."
800 (let ((data (match-data))
802 (type (cond ((string= match-type
"D") 'date
)
803 ((string= match-type
"T")
804 (if (vc-cvs-valid-symbolic-tag-name-p match-tag
)
811 ;; Sticky Date tag. Convert to to a proper date value (`encode-time')
814 "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)"
816 (let* ((year-tmp (string-to-number (match-string 1 match-tag
)))
817 (month (string-to-number (match-string 2 match-tag
)))
818 (day (string-to-number (match-string 3 match-tag
)))
819 (hour (string-to-number (match-string 4 match-tag
)))
820 (min (string-to-number (match-string 5 match-tag
)))
821 (sec (string-to-number (match-string 6 match-tag
)))
822 ;; Years 0..68 are 2000..2068.
823 ;; Years 69..99 are 1969..1999.
824 (year (+ (cond ((> 69 year-tmp
) 2000)
825 ((> 100 year-tmp
) 1900)
828 (setq tag
(encode-time sec min hour day month year
))))
829 ;; Sticky Tag name or revision number
830 ((eq type
'symbolic-name
) (setq tag match-tag
))
831 ((eq type
'revision-number
) (setq tag match-tag
))
832 ;; Default is no sticky tag at all
834 (cond ((eq vc-cvs-sticky-tag-display nil
) nil
)
835 ((eq vc-cvs-sticky-tag-display t
)
836 (cond ((eq type
'date
) (format-time-string
837 vc-cvs-sticky-date-format-string
839 ((eq type
'symbolic-name
) tag
)
840 ((eq type
'revision-number
) tag
)
842 ((functionp vc-cvs-sticky-tag-display
)
843 (funcall vc-cvs-sticky-tag-display tag type
))
846 (set-match-data data
))))
848 (defun vc-cvs-parse-entry (file &optional set-state
)
849 "Parse a line from CVS/Entries.
850 Compare modification time to that of the FILE, set file properties
851 accordingly. However, `vc-state' is set only if optional arg SET-STATE
854 ;; entry for a "locally added" file (not yet committed)
855 ((looking-at "/[^/]+/0/")
856 (vc-file-setprop file
'vc-checkout-time
0)
857 (vc-file-setprop file
'vc-workfile-version
"0")
858 (if set-state
(vc-file-setprop file
'vc-state
'edited
)))
866 ;; optional conflict field
871 "\\(.\\|\\)" ;Sticky tag type (date or tag name, could be empty)
872 "\\(.*\\)")) ;Sticky tag
873 (vc-file-setprop file
'vc-workfile-version
(match-string 1))
874 (vc-file-setprop file
'vc-cvs-sticky-tag
875 (vc-cvs-parse-sticky-tag (match-string 5) (match-string 6)))
876 ;; compare checkout time and modification time
877 (let ((mtime (nth 5 (file-attributes file
)))
878 (system-time-locale "C"))
879 (cond ((equal (format-time-string "%c" mtime
'utc
) (match-string 2))
880 (vc-file-setprop file
'vc-checkout-time mtime
)
881 (if set-state
(vc-file-setprop file
'vc-state
'up-to-date
)))
883 (vc-file-setprop file
'vc-checkout-time
0)
884 (if set-state
(vc-file-setprop file
'vc-state
'edited
))))))))
888 ;;; vc-cvs.el ends here