(hi-lock-find-patterns): Don't activate font-lock-mode.
[emacs.git] / lisp / vc-cvs.el
blob2ca04b4f9cdd8baed230de4323235a929b8f4471
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.19 2001/02/01 15:10:16 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)
15 ;; any later version.
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.
27 ;;; Commentary:
29 ;;; Code:
31 (eval-when-compile
32 (require 'vc))
34 ;;;
35 ;;; Customization options
36 ;;;
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
41 \\[vc-register]."
42 :type '(choice (const :tag "None" nil)
43 (string :tag "Argument String")
44 (repeat :tag "Argument List"
45 :value ("")
46 string))
47 :version "21.1"
48 :group 'vc)
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"
55 :value ("")
56 string))
57 :version "21.1"
58 :group 'vc)
60 (defcustom vc-cvs-header (or (cdr (assoc 'CVS vc-header-alist)) '("\$Id\$"))
61 "*Header keywords to be inserted by `vc-insert-headers'."
62 :version "21.1"
63 :type '(repeat string)
64 :group 'vc)
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)."
70 :type 'boolean
71 :version "21.1"
72 :group 'vc)
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. Turning this option on
77 will instruct VC to use only heuristics and past information to
78 determine the current status of a file. The value can also be a
79 regular expression to match against the host name of a repository;
80 then VC only stays local for hosts that match it."
81 :type '(choice (const :tag "Always stay local" t)
82 (string :tag "Host regexp")
83 (const :tag "Don't stay local" nil))
84 :version "21.1"
85 :group 'vc)
88 ;;;
89 ;;; Internal variables
90 ;;;
92 (defvar vc-cvs-local-month-numbers
93 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4)
94 ("May" . 5) ("Jun" . 6) ("Jul" . 7) ("Aug" . 8)
95 ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12))
96 "Local association list of month numbers.")
99 ;;;
100 ;;; State-querying functions
103 ;;;###autoload (defun vc-cvs-registered (f)
104 ;;;###autoload (when (file-readable-p (expand-file-name
105 ;;;###autoload "CVS/Entries" (file-name-directory f)))
106 ;;;###autoload (require 'vc-cvs)
107 ;;;###autoload (vc-cvs-registered f)))
109 (defun vc-cvs-registered (file)
110 "Check if FILE is CVS registered."
111 (let ((dirname (or (file-name-directory file) ""))
112 (basename (file-name-nondirectory file))
113 ;; make sure that the file name is searched case-sensitively
114 (case-fold-search nil))
115 (if (file-readable-p (expand-file-name "CVS/Entries" dirname))
116 (with-temp-buffer
117 (vc-insert-file (expand-file-name "CVS/Entries" dirname))
118 (goto-char (point-min))
119 (cond
120 ((re-search-forward
121 (concat "^/" (regexp-quote basename) "/") nil t)
122 (beginning-of-line)
123 (vc-cvs-parse-entry file)
125 (t nil)))
126 nil)))
128 (defun vc-cvs-state (file)
129 "CVS-specific version of `vc-state'."
130 (if (vc-cvs-stay-local-p file)
131 (let ((state (vc-file-getprop file 'vc-state)))
132 ;; If we should stay local, use the heuristic but only if
133 ;; we don't have a more precise state already available.
134 (if (memq state '(up-to-date edited))
135 (vc-cvs-state-heuristic file)
136 state))
137 (with-temp-buffer
138 (cd (file-name-directory file))
139 (vc-do-command t 0 "cvs" file "status")
140 (vc-cvs-parse-status t))))
142 (defun vc-cvs-state-heuristic (file)
143 "CVS-specific state heuristic."
144 ;; If the file has not changed since checkout, consider it `up-to-date'.
145 ;; Otherwise consider it `edited'.
146 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time))
147 (lastmod (nth 5 (file-attributes file))))
148 (if (equal checkout-time lastmod)
149 'up-to-date
150 'edited)))
152 (defun vc-cvs-dir-state (dir)
153 "Find the CVS state of all files in DIR."
154 (if (vc-cvs-stay-local-p dir)
155 (vc-cvs-dir-state-heuristic dir)
156 (let ((default-directory dir))
157 ;; Don't specify DIR in this command, the default-directory is
158 ;; enough. Otherwise it might fail with remote repositories.
159 (with-temp-buffer
160 (vc-do-command t 0 "cvs" nil "status" "-l")
161 (goto-char (point-min))
162 (while (re-search-forward "^=+\n\\([^=\n].*\n\\|\n\\)+" nil t)
163 (narrow-to-region (match-beginning 0) (match-end 0))
164 (vc-cvs-parse-status)
165 (goto-char (point-max))
166 (widen))))))
168 (defun vc-cvs-workfile-version (file)
169 "CVS-specific version of `vc-workfile-version'."
170 ;; There is no need to consult RCS headers under CVS, because we
171 ;; get the workfile version for free when we recognize that a file
172 ;; is registered in CVS.
173 (vc-cvs-registered file)
174 (vc-file-getprop file 'vc-workfile-version))
176 (defun vc-cvs-checkout-model (file)
177 "CVS-specific version of `vc-checkout-model'."
178 (if (or (getenv "CVSREAD")
179 ;; If the file is not writable (despite CVSREAD being
180 ;; undefined), this is probably because the file is being
181 ;; "watched" by other developers.
182 ;; (If vc-mistrust-permissions was t, we actually shouldn't
183 ;; trust this, but there is no other way to learn this from CVS
184 ;; at the moment (version 1.9).)
185 (string-match "r-..-..-." (nth 8 (file-attributes file))))
186 'announce
187 'implicit))
189 (defun vc-cvs-mode-line-string (file)
190 "Return string for placement into the modeline for FILE.
191 Compared to the default implementation, this function handles the
192 special case of a CVS file that is added but not yet committed."
193 (let ((state (vc-state file))
194 (rev (vc-workfile-version file)))
195 (cond ((string= rev "0")
196 ;; A file that is added but not yet committed.
197 "CVS @@")
198 ((or (eq state 'up-to-date)
199 (eq state 'needs-patch))
200 (concat "CVS-" rev))
201 ((stringp state)
202 (concat "CVS:" state ":" rev))
204 ;; Not just for the 'edited state, but also a fallback
205 ;; for all other states. Think about different symbols
206 ;; for 'needs-patch and 'needs-merge.
207 (concat "CVS:" rev)))))
209 (defun vc-cvs-dired-state-info (file)
210 "CVS-specific version of `vc-dired-state-info'."
211 (let* ((cvs-state (vc-state file))
212 (state (cond ((eq cvs-state 'edited) "modified")
213 ((eq cvs-state 'needs-patch) "patch")
214 ((eq cvs-state 'needs-merge) "merge")
215 ;; FIXME: those two states cannot occur right now
216 ((eq cvs-state 'unlocked-changes) "conflict")
217 ((eq cvs-state 'locally-added) "added")
219 (if state (concat "(" state ")"))))
223 ;;; State-changing functions
226 (defun vc-cvs-register (file &optional rev comment)
227 "Register FILE into the CVS version-control system.
228 COMMENT can be used to provide an initial description of FILE.
230 `vc-register-switches' and `vc-cvs-register-switches' are passed to
231 the CVS command (in that order)."
232 (let ((switches (list
233 (if (stringp vc-register-switches)
234 (list vc-register-switches)
235 vc-register-switches)
236 (if (stringp vc-cvs-register-switches)
237 (list vc-cvs-register-switches)
238 vc-cvs-register-switches))))
240 (apply 'vc-do-command nil 0 "cvs" file
241 "add"
242 (and comment (string-match "[^\t\n ]" comment)
243 (concat "-m" comment))
244 switches)))
246 (defun vc-cvs-responsible-p (file)
247 "Return non-nil if CVS thinks it is responsible for FILE."
248 (file-directory-p (expand-file-name "CVS"
249 (if (file-directory-p file)
250 file
251 (file-name-directory file)))))
253 (defun vc-cvs-could-register (file)
254 "Return non-nil if FILE could be registered in CVS.
255 This is only possible if CVS is responsible for FILE's directory."
256 (vc-cvs-responsible-p file))
258 (defun vc-cvs-checkin (file rev comment)
259 "CVS-specific version of `vc-backend-checkin'."
260 (let ((switches (if (stringp vc-checkin-switches)
261 (list vc-checkin-switches)
262 vc-checkin-switches))
263 status)
264 ;; explicit check-in to the trunk requires a double check-in (first
265 ;; unexplicit) (CVS-1.3)
266 (if (and rev (vc-trunk-p rev))
267 (apply 'vc-do-command nil 1 "cvs" file
268 "ci" "-m" "intermediate"
269 switches))
270 (setq status (apply 'vc-do-command nil 1 "cvs" file
271 "ci" (if rev (concat "-r" rev))
272 (concat "-m" comment)
273 switches))
274 (set-buffer "*vc*")
275 (goto-char (point-min))
276 (when (not (zerop status))
277 ;; Check checkin problem.
278 (cond
279 ((re-search-forward "Up-to-date check failed" nil t)
280 (vc-file-setprop file 'vc-state 'needs-merge)
281 (error (substitute-command-keys
282 (concat "Up-to-date check failed: "
283 "type \\[vc-next-action] to merge in changes"))))
285 (pop-to-buffer (current-buffer))
286 (goto-char (point-min))
287 (shrink-window-if-larger-than-buffer)
288 (error "Check-in failed"))))
289 ;; Update file properties
290 (vc-file-setprop
291 file 'vc-workfile-version
292 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
293 ;; Forget the checkout model of the file, because we might have
294 ;; guessed wrong when we found the file. After commit, we can
295 ;; tell it from the permissions of the file (see
296 ;; vc-cvs-checkout-model).
297 (vc-file-setprop file 'vc-checkout-model nil)
298 ;; if this was an explicit check-in, remove the sticky tag
299 (if rev (vc-do-command t 0 "cvs" file "update" "-A"))))
301 (defun vc-cvs-checkout (file &optional editable rev workfile)
302 "Retrieve a revision of FILE into a WORKFILE.
303 EDITABLE non-nil means that the file should be writable.
304 REV is the revision to check out into WORKFILE."
305 (let ((filename (or workfile file))
306 (file-buffer (get-file-buffer file))
307 switches)
308 (message "Checking out %s..." filename)
309 (save-excursion
310 ;; Change buffers to get local value of vc-checkout-switches.
311 (if file-buffer (set-buffer file-buffer))
312 (setq switches (if (stringp vc-checkout-switches)
313 (list vc-checkout-switches)
314 vc-checkout-switches))
315 ;; Save this buffer's default-directory
316 ;; and use save-excursion to make sure it is restored
317 ;; in the same buffer it was saved in.
318 (let ((default-directory default-directory))
319 (save-excursion
320 ;; Adjust the default-directory so that the check-out creates
321 ;; the file in the right place.
322 (setq default-directory (file-name-directory filename))
323 (if workfile
324 (let ((failed t)
325 (backup-name (if (string= file workfile)
326 (car (find-backup-file-name filename)))))
327 (when backup-name
328 (copy-file filename backup-name
329 'ok-if-already-exists 'keep-date)
330 (unless (file-writable-p filename)
331 (set-file-modes filename
332 (logior (file-modes filename) 128))))
333 (unwind-protect
334 (progn
335 (let ((coding-system-for-read 'no-conversion)
336 (coding-system-for-write 'no-conversion))
337 (with-temp-file filename
338 (apply 'vc-do-command
339 (current-buffer) 0 "cvs" file
340 "-Q" ; suppress diagnostic output
341 "update"
342 (and rev (not (string= rev ""))
343 (concat "-r" rev))
344 "-p"
345 switches)))
346 (setq failed nil))
347 (if failed
348 (if backup-name
349 (rename-file backup-name filename
350 'ok-if-already-exists)
351 (if (file-exists-p filename)
352 (delete-file filename)))
353 (and backup-name
354 (not vc-make-backup-files)
355 (delete-file backup-name)))))
356 (if (and (file-exists-p file) (not rev))
357 ;; If no revision was specified, just make the file writable
358 ;; if necessary (using `cvs-edit' if requested).
359 (and editable (not (eq (vc-cvs-checkout-model file) 'implicit))
360 (if vc-cvs-use-edit
361 (vc-do-command nil 0 "cvs" file "edit")
362 (set-file-modes file (logior (file-modes file) 128))
363 (if file-buffer (toggle-read-only -1))))
364 ;; Check out a particular version (or recreate the file).
365 (vc-file-setprop file 'vc-workfile-version nil)
366 (apply 'vc-do-command nil 0 "cvs" file
367 (and editable
368 (or (not (file-exists-p file))
369 (not (eq (vc-cvs-checkout-model file)
370 'implicit)))
371 "-w")
372 "update"
373 ;; default for verbose checkout: clear the sticky tag so
374 ;; that the actual update will get the head of the trunk
375 (if (or (not rev) (string= rev ""))
376 "-A"
377 (concat "-r" rev))
378 switches))))
379 (vc-mode-line file)
380 (message "Checking out %s...done" filename)))))
382 (defun vc-cvs-revert (file)
383 "Revert FILE to the version it was based on."
384 ;; Check out via standard output (caused by the final argument
385 ;; FILE below), so that no sticky tag is set.
386 (vc-cvs-checkout file nil (vc-workfile-version file) file)
387 ;; If "cvs edit" was used to make the file writable,
388 ;; call "cvs unedit" now to undo that.
389 (if (and (not (eq (vc-cvs-checkout-model file) 'implicit))
390 vc-cvs-use-edit)
391 (vc-do-command nil 0 "cvs" file "unedit")))
393 (defun vc-cvs-merge (file first-version &optional second-version)
394 "Merge changes into current working copy of FILE.
395 The changes are between FIRST-VERSION and SECOND-VERSION."
396 (vc-do-command nil 0 "cvs" file
397 "update" "-kk"
398 (concat "-j" first-version)
399 (concat "-j" second-version))
400 (vc-file-setprop file 'vc-state 'edited)
401 (save-excursion
402 (set-buffer (get-buffer "*vc*"))
403 (goto-char (point-min))
404 (if (re-search-forward "conflicts during merge" nil t)
405 1 ; signal error
406 0))) ; signal success
408 (defun vc-cvs-merge-news (file)
409 "Merge in any new changes made to FILE."
410 (message "Merging changes into %s..." file)
411 (save-excursion
412 ;; (vc-file-setprop file 'vc-workfile-version nil)
413 (vc-file-setprop file 'vc-checkout-time 0)
414 (vc-do-command nil 0 "cvs" file "update")
415 ;; Analyze the merge result reported by CVS, and set
416 ;; file properties accordingly.
417 (set-buffer (get-buffer "*vc*"))
418 (goto-char (point-min))
419 ;; get new workfile version
420 (if (re-search-forward (concat "^Merging differences between "
421 "[01234567890.]* and "
422 "\\([01234567890.]*\\) into")
423 nil t)
424 (vc-file-setprop file 'vc-workfile-version (match-string 1))
425 (vc-file-setprop file 'vc-workfile-version nil))
426 ;; get file status
427 (prog1
428 (if (eq (buffer-size) 0)
429 0 ;; there were no news; indicate success
430 (if (re-search-forward
431 (concat "^\\([CMUP] \\)?"
432 (regexp-quote (file-name-nondirectory file))
433 "\\( already contains the differences between \\)?")
434 nil t)
435 (cond
436 ;; Merge successful, we are in sync with repository now
437 ((or (match-string 2)
438 (string= (match-string 1) "U ")
439 (string= (match-string 1) "P "))
440 (vc-file-setprop file 'vc-state 'up-to-date)
441 (vc-file-setprop file 'vc-checkout-time
442 (nth 5 (file-attributes file)))
443 0);; indicate success to the caller
444 ;; Merge successful, but our own changes are still in the file
445 ((string= (match-string 1) "M ")
446 (vc-file-setprop file 'vc-state 'edited)
447 0);; indicate success to the caller
448 ;; Conflicts detected!
450 (vc-file-setprop file 'vc-state 'edited)
451 1);; signal the error to the caller
453 (pop-to-buffer "*vc*")
454 (error "Couldn't analyze cvs update result")))
455 (message "Merging changes into %s...done" file))))
459 ;;; History functions
462 (defun vc-cvs-print-log (file)
463 "Get change log associated with FILE."
464 (vc-do-command t (if (vc-cvs-stay-local-p file) 'async 0)
465 "cvs" file "log"))
467 (defun vc-cvs-show-log-entry (version)
468 (when (re-search-forward
469 ;; also match some context, for safety
470 (concat "----\nrevision " version
471 "\\(\tlocked by:.*\n\\|\n\\)date: ") nil t)
472 ;; set the display window so that
473 ;; the whole log entry is displayed
474 (let (start end lines)
475 (beginning-of-line) (forward-line -1) (setq start (point))
476 (if (not (re-search-forward "^----*\nrevision" nil t))
477 (setq end (point-max))
478 (beginning-of-line) (forward-line -1) (setq end (point)))
479 (setq lines (count-lines start end))
480 (cond
481 ;; if the global information and this log entry fit
482 ;; into the window, display from the beginning
483 ((< (count-lines (point-min) end) (window-height))
484 (goto-char (point-min))
485 (recenter 0)
486 (goto-char start))
487 ;; if the whole entry fits into the window,
488 ;; display it centered
489 ((< (1+ lines) (window-height))
490 (goto-char start)
491 (recenter (1- (- (/ (window-height) 2) (/ lines 2)))))
492 ;; otherwise (the entry is too large for the window),
493 ;; display from the start
495 (goto-char start)
496 (recenter 0))))))
498 (defun vc-cvs-diff (file &optional oldvers newvers)
499 "Get a difference report using CVS between two versions of FILE."
500 (let (options status (diff-switches-list (vc-diff-switches-list cvs)))
501 (if (string= (vc-workfile-version file) "0")
502 ;; This file is added but not yet committed; there is no master file.
503 (if (or oldvers newvers)
504 (error "No revisions of %s exist" file)
505 ;; we regard this as "changed".
506 ;; diff it against /dev/null.
507 (apply 'vc-do-command t
508 1 "diff" file
509 (append diff-switches-list '("/dev/null"))))
510 (setq status
511 (apply 'vc-do-command t
512 (if (vc-cvs-stay-local-p file) 'async 1)
513 "cvs" file "diff"
514 (and oldvers (concat "-r" oldvers))
515 (and newvers (concat "-r" newvers))
516 diff-switches-list))
517 (if (vc-cvs-stay-local-p file)
518 1 ;; async diff, pessimistic assumption
519 status))))
521 (defun vc-cvs-annotate-command (file buffer &optional version)
522 "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER.
523 Optional arg VERSION is a version to annotate from."
524 (vc-do-command buffer 0 "cvs" file "annotate" (if version
525 (concat "-r" version))))
527 (defun vc-cvs-annotate-difference (point)
528 "Return the difference between the time of the line and the current time.
529 Return values are as defined for `current-time'."
530 ;; We need a list of months and their corresponding numbers.
531 (if (looking-at "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): ")
532 (progn
533 (let* ((day (string-to-number (match-string 1)))
534 (month (cdr (assoc (match-string 2) vc-cvs-local-month-numbers)))
535 (year-tmp (string-to-number (match-string 3)))
536 ;; Years 0..68 are 2000..2068.
537 ;; Years 69..99 are 1969..1999.
538 (year (+ (cond ((> 69 year-tmp) 2000)
539 ((> 100 year-tmp) 1900)
540 (t 0))
541 year-tmp)))
542 (goto-char (match-end 0)) ; Position at end makes for nicer overlay result
543 (- (car (current-time))
544 (car (encode-time 0 0 0 day month year)))))
545 ;; If we did not look directly at an annotation, there might be
546 ;; some further down. This is the case if we are positioned at
547 ;; the very top of the buffer, for instance.
548 (if (re-search-forward
549 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): " nil t)
550 (progn
551 (beginning-of-line nil)
552 (vc-cvs-annotate-difference (point))))))
556 ;;; Snapshot system
559 (defun vc-cvs-create-snapshot (dir name branchp)
560 "Assign to DIR's current version a given NAME.
561 If BRANCHP is non-nil, the name is created as a branch (and the current
562 workspace is immediately moved to that new branch)."
563 (vc-do-command nil 0 "cvs" dir "tag" "-c" (if branchp "-b") name)
564 (when branchp (vc-do-command nil 0 "cvs" dir "update" "-r" name)))
566 (defun vc-cvs-retrieve-snapshot (dir name update)
567 "Retrieve a snapshot at and below DIR.
568 NAME is the name of the snapshot; if it is empty, do a `cvs update'.
569 If UPDATE is non-nil, then update (resynch) any affected buffers."
570 (with-current-buffer (get-buffer-create "*vc*")
571 (let ((default-directory dir))
572 (erase-buffer)
573 (if (or (not name) (string= name ""))
574 (vc-do-command t 0 "cvs" nil "update")
575 (vc-do-command t 0 "cvs" nil "update" "-r" name))
576 (when update
577 (goto-char (point-min))
578 (while (not (eobp))
579 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
580 (let* ((file (expand-file-name (match-string 2) dir))
581 (state (match-string 1))
582 (buffer (find-buffer-visiting file)))
583 (when buffer
584 (cond
585 ((or (string= state "U")
586 (string= state "P"))
587 (vc-file-setprop file 'vc-state 'up-to-date)
588 (vc-file-setprop file 'vc-workfile-version nil)
589 (vc-file-setprop file 'vc-checkout-time
590 (nth 5 (file-attributes file))))
591 ((or (string= state "M")
592 (string= state "C"))
593 (vc-file-setprop file 'vc-state 'edited)
594 (vc-file-setprop file 'vc-workfile-version nil)
595 (vc-file-setprop file 'vc-checkout-time 0)))
596 (vc-resynch-buffer file t t))))
597 (forward-line 1))))))
601 ;;; Miscellaneous
604 (defun vc-cvs-make-version-backups-p (file)
605 "Return non-nil if version backups should be made for FILE."
606 (vc-cvs-stay-local-p file))
608 (defun vc-cvs-check-headers ()
609 "Check if the current file has any headers in it."
610 (save-excursion
611 (goto-char (point-min))
612 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
613 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
617 ;;; Internal functions
620 (defun vc-cvs-stay-local-p (file)
621 "Return non-nil if VC should stay local when handling FILE."
622 (if vc-cvs-stay-local
623 (let* ((dirname (if (file-directory-p file)
624 (directory-file-name file)
625 (file-name-directory file)))
626 (prop
627 (or (vc-file-getprop dirname 'vc-cvs-stay-local-p)
628 (let ((rootname (expand-file-name "CVS/Root" dirname)))
629 (vc-file-setprop
630 dirname 'vc-cvs-stay-local-p
631 (when (file-readable-p rootname)
632 (with-temp-buffer
633 (vc-insert-file rootname)
634 (goto-char (point-min))
635 (if (looking-at "\\([^:]*\\):")
636 (if (not (stringp vc-cvs-stay-local))
637 'yes
638 (let ((hostname (match-string 1)))
639 (if (string-match vc-cvs-stay-local hostname)
640 'yes
641 'no)))
642 'no))))))))
643 (if (eq prop 'yes) t nil))))
645 (defun vc-cvs-parse-status (&optional full)
646 "Parse output of \"cvs status\" command in the current buffer.
647 Set file properties accordingly. Unless FULL is t, parse only
648 essential information."
649 (let (file status)
650 (goto-char (point-min))
651 (if (re-search-forward "^File: " nil t)
652 (cond
653 ((looking-at "no file") nil)
654 ((re-search-forward "\\=\\([^ \t]+\\)" nil t)
655 (setq file (expand-file-name (match-string 1)))
656 (vc-file-setprop file 'vc-backend 'CVS)
657 (if (not (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t))
658 (setq status "Unknown")
659 (setq status (match-string 1)))
660 (if (and full
661 (re-search-forward
662 "\\(RCS Version\\|RCS Revision\\|Repository revision\\):\
663 \[\t ]+\\([0-9.]+\\)"
664 nil t))
665 (vc-file-setprop file 'vc-latest-version (match-string 2)))
666 (cond
667 ((string-match "Up-to-date" status)
668 (vc-file-setprop file 'vc-checkout-time
669 (nth 5 (file-attributes file)))
670 'up-to-date)
671 ((string-match "Locally Modified" status) 'edited)
672 ((string-match "Needs Merge" status) 'needs-merge)
673 ((string-match "Needs \\(Checkout\\|Patch\\)" status) 'needs-patch)
674 (t 'edited)))))))
676 (defun vc-cvs-dir-state-heuristic (dir)
677 "Find the CVS state of all files in DIR, using only local information."
678 (with-temp-buffer
679 (vc-insert-file (expand-file-name "CVS/Entries" dir))
680 (goto-char (point-min))
681 (while (not (eobp))
682 (when (looking-at "/\\([^/]*\\)/")
683 (let ((file (expand-file-name (match-string 1) dir)))
684 (unless (vc-file-getprop file 'vc-state)
685 (vc-cvs-parse-entry file t))))
686 (forward-line 1))))
688 (defun vc-cvs-parse-entry (file &optional set-state)
689 "Parse a line from CVS/Entries.
690 Compare modification time to that of the FILE, set file properties
691 accordingly. However, `vc-state' is set only if optional arg SET-STATE
692 is non-nil."
693 (cond
694 ;; entry for a "locally added" file (not yet committed)
695 ((looking-at "/[^/]+/0/")
696 (vc-file-setprop file 'vc-checkout-time 0)
697 (vc-file-setprop file 'vc-workfile-version "0")
698 (if set-state (vc-file-setprop file 'vc-state 'edited)))
699 ;; normal entry
700 ((looking-at
701 (concat "/[^/]+"
702 ;; revision
703 "/\\([^/]*\\)"
704 ;; timestamp
705 "/[A-Z][a-z][a-z]" ;; week day (irrelevant)
706 " \\([A-Z][a-z][a-z]\\)" ;; month name
707 " *\\([0-9]*\\)" ;; day of month
708 " \\([0-9]*\\):\\([0-9]*\\):\\([0-9]*\\)" ;; hms
709 " \\([0-9]*\\)" ;; year
710 ;; optional conflict field
711 "\\(+[^/]*\\)?/"))
712 (vc-file-setprop file 'vc-workfile-version (match-string 1))
713 ;; compare checkout time and modification time
714 (let ((second (string-to-number (match-string 6)))
715 (minute (string-to-number (match-string 5)))
716 (hour (string-to-number (match-string 4)))
717 (day (string-to-number (match-string 3)))
718 (year (string-to-number (match-string 7)))
719 (month (/ (string-match
720 (match-string 2)
721 "xxxJanFebMarAprMayJunJulAugSepOctNovDec")
723 (mtime (nth 5 (file-attributes file))))
724 (cond ((equal mtime
725 (encode-time second minute hour day month year 0))
726 (vc-file-setprop file 'vc-checkout-time mtime)
727 (if set-state (vc-file-setprop file 'vc-state 'up-to-date)))
729 (vc-file-setprop file 'vc-checkout-time 0)
730 (if set-state (vc-file-setprop file 'vc-state 'edited))))))
731 ;; entry with arbitrary text as timestamp
732 ;; (this means we should consider it modified)
733 ((looking-at
734 (concat "/[^/]+"
735 ;; revision
736 "/\\([^/]*\\)"
737 ;; timestamp (arbitrary text)
738 "/[^/]*"
739 ;; optional conflict field
740 "\\(+[^/]*\\)?/"))
741 (vc-file-setprop file 'vc-workfile-version (match-string 1))
742 (vc-file-setprop file 'vc-checkout-time 0)
743 (if set-state (vc-file-setprop file 'vc-state 'edited)))))
745 (provide 'vc-cvs)
747 ;;; vc-cvs.el ends here