]> code.delx.au - gnu-emacs/blob - lisp/vc/vc-cvs.el
Merge from emacs-23
[gnu-emacs] / lisp / vc / vc-cvs.el
1 ;;; vc-cvs.el --- non-resident support for CVS version-control
2
3 ;; Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
5
6 ;; Author: FSF (see vc.el for full credits)
7 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
8 ;; Package: vc
9
10 ;; This file is part of GNU Emacs.
11
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 3 of the License, or
15 ;; (at your option) any later version.
16
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.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl) (require 'vc))
30
31 ;; Clear up the cache to force vc-call to check again and discover
32 ;; new functions when we reload this file.
33 (put 'CVS 'vc-functions nil)
34
35 ;;; Properties of the backend.
36
37 (defun vc-cvs-revision-granularity () 'file)
38
39 (defun vc-cvs-checkout-model (files)
40 "CVS-specific version of `vc-checkout-model'."
41 (if (getenv "CVSREAD")
42 'announce
43 (let* ((file (if (consp files) (car files) files))
44 (attrib (file-attributes file)))
45 (or (vc-file-getprop file 'vc-checkout-model)
46 (vc-file-setprop
47 file 'vc-checkout-model
48 (if (and attrib ;; don't check further if FILE doesn't exist
49 ;; If the file is not writable (despite CVSREAD being
50 ;; undefined), this is probably because the file is being
51 ;; "watched" by other developers.
52 ;; (If vc-mistrust-permissions was t, we actually shouldn't
53 ;; trust this, but there is no other way to learn this from
54 ;; CVS at the moment (version 1.9).)
55 (string-match "r-..-..-." (nth 8 attrib)))
56 'announce
57 'implicit))))))
58
59 ;;;
60 ;;; Customization options
61 ;;;
62
63 (defcustom vc-cvs-global-switches nil
64 "Global switches to pass to any CVS command."
65 :type '(choice (const :tag "None" nil)
66 (string :tag "Argument String")
67 (repeat :tag "Argument List"
68 :value ("")
69 string))
70 :version "22.1"
71 :group 'vc)
72
73 (defcustom vc-cvs-register-switches nil
74 "Switches for registering a file into CVS.
75 A string or list of strings passed to the checkin program by
76 \\[vc-register]. If nil, use the value of `vc-register-switches'.
77 If t, use no switches."
78 :type '(choice (const :tag "Unspecified" nil)
79 (const :tag "None" t)
80 (string :tag "Argument String")
81 (repeat :tag "Argument List" :value ("") string))
82 :version "21.1"
83 :group 'vc)
84
85 (defcustom vc-cvs-diff-switches nil
86 "String or list of strings specifying switches for CVS diff under VC.
87 If nil, use the value of `vc-diff-switches'. If t, use no switches."
88 :type '(choice (const :tag "Unspecified" nil)
89 (const :tag "None" t)
90 (string :tag "Argument String")
91 (repeat :tag "Argument List" :value ("") string))
92 :version "21.1"
93 :group 'vc)
94
95 (defcustom vc-cvs-header '("\$Id\$")
96 "Header keywords to be inserted by `vc-insert-headers'."
97 :version "24.1" ; no longer consult the obsolete vc-header-alist
98 :type '(repeat string)
99 :group 'vc)
100
101 (defcustom vc-cvs-use-edit t
102 "Non-nil means to use `cvs edit' to \"check out\" a file.
103 This is only meaningful if you don't use the implicit checkout model
104 \(i.e. if you have $CVSREAD set)."
105 :type 'boolean
106 :version "21.1"
107 :group 'vc)
108
109 (defcustom vc-cvs-stay-local 'only-file
110 "Non-nil means use local operations when possible for remote repositories.
111 This avoids slow queries over the network and instead uses heuristics
112 and past information to determine the current status of a file.
113
114 If value is the symbol `only-file' `vc-dir' will connect to the
115 server, but heuristics will be used to determine the status for
116 all other VC operations.
117
118 The value can also be a regular expression or list of regular
119 expressions to match against the host name of a repository; then VC
120 only stays local for hosts that match it. Alternatively, the value
121 can be a list of regular expressions where the first element is the
122 symbol `except'; then VC always stays local except for hosts matched
123 by these regular expressions."
124 :type '(choice (const :tag "Always stay local" t)
125 (const :tag "Only for file operations" only-file)
126 (const :tag "Don't stay local" nil)
127 (list :format "\nExamine hostname and %v"
128 :tag "Examine hostname ..."
129 (set :format "%v" :inline t
130 (const :format "%t" :tag "don't" except))
131 (regexp :format " stay local,\n%t: %v"
132 :tag "if it matches")
133 (repeat :format "%v%i\n" :inline t (regexp :tag "or"))))
134 :version "23.1"
135 :group 'vc)
136
137 (defcustom vc-cvs-sticky-date-format-string "%c"
138 "Format string for mode-line display of sticky date.
139 Format is according to `format-time-string'. Only used if
140 `vc-cvs-sticky-tag-display' is t."
141 :type '(string)
142 :version "22.1"
143 :group 'vc)
144
145 (defcustom vc-cvs-sticky-tag-display t
146 "Specify the mode-line display of sticky tags.
147 Value t means default display, nil means no display at all. If the
148 value is a function or macro, it is called with the sticky tag and
149 its' type as parameters, in that order. TYPE can have three different
150 values: `symbolic-name' (TAG is a string), `revision-number' (TAG is a
151 string) and `date' (TAG is a date as returned by `encode-time'). The
152 return value of the function or macro will be displayed as a string.
153
154 Here's an example that will display the formatted date for sticky
155 dates and the word \"Sticky\" for sticky tag names and revisions.
156
157 (lambda (tag type)
158 (cond ((eq type 'date) (format-time-string
159 vc-cvs-sticky-date-format-string tag))
160 ((eq type 'revision-number) \"Sticky\")
161 ((eq type 'symbolic-name) \"Sticky\")))
162
163 Here's an example that will abbreviate to the first character only,
164 any text before the first occurrence of `-' for sticky symbolic tags.
165 If the sticky tag is a revision number, the word \"Sticky\" is
166 displayed. Date and time is displayed for sticky dates.
167
168 (lambda (tag type)
169 (cond ((eq type 'date) (format-time-string \"%Y%m%d %H:%M\" tag))
170 ((eq type 'revision-number) \"Sticky\")
171 ((eq type 'symbolic-name)
172 (condition-case nil
173 (progn
174 (string-match \"\\\\([^-]*\\\\)\\\\(.*\\\\)\" tag)
175 (concat (substring (match-string 1 tag) 0 1) \":\"
176 (substring (match-string 2 tag) 1 nil)))
177 (error tag))))) ; Fall-back to given tag name.
178
179 See also variable `vc-cvs-sticky-date-format-string'."
180 :type '(choice boolean function)
181 :version "22.1"
182 :group 'vc)
183
184 ;;;
185 ;;; Internal variables
186 ;;;
187
188
189 ;;;
190 ;;; State-querying functions
191 ;;;
192
193 ;;;###autoload (defun vc-cvs-registered (f)
194 ;;;###autoload (when (file-readable-p (expand-file-name
195 ;;;###autoload "CVS/Entries" (file-name-directory f)))
196 ;;;###autoload (load "vc-cvs")
197 ;;;###autoload (vc-cvs-registered f)))
198
199 (defun vc-cvs-registered (file)
200 "Check if FILE is CVS registered."
201 (let ((dirname (or (file-name-directory file) ""))
202 (basename (file-name-nondirectory file))
203 ;; make sure that the file name is searched case-sensitively
204 (case-fold-search nil))
205 (if (file-readable-p (expand-file-name "CVS/Entries" dirname))
206 (or (string= basename "")
207 (with-temp-buffer
208 (vc-cvs-get-entries dirname)
209 (goto-char (point-min))
210 (cond ((re-search-forward
211 (concat "^/" (regexp-quote basename) "/[^/]") nil t)
212 (beginning-of-line)
213 (vc-cvs-parse-entry file)
214 t)
215 (t nil))))
216 nil)))
217
218 (defun vc-cvs-state (file)
219 "CVS-specific version of `vc-state'."
220 (if (vc-stay-local-p file 'CVS)
221 (let ((state (vc-file-getprop file 'vc-state)))
222 ;; If we should stay local, use the heuristic but only if
223 ;; we don't have a more precise state already available.
224 (if (memq state '(up-to-date edited nil))
225 (vc-cvs-state-heuristic file)
226 state))
227 (with-temp-buffer
228 (cd (file-name-directory file))
229 (let (process-file-side-effects)
230 (vc-cvs-command t 0 file "status"))
231 (vc-cvs-parse-status t))))
232
233 (defun vc-cvs-state-heuristic (file)
234 "CVS-specific state heuristic."
235 ;; If the file has not changed since checkout, consider it `up-to-date'.
236 ;; Otherwise consider it `edited'.
237 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time))
238 (lastmod (nth 5 (file-attributes file))))
239 (cond
240 ((equal checkout-time lastmod) 'up-to-date)
241 ((string= (vc-working-revision file) "0") 'added)
242 ((null checkout-time) 'unregistered)
243 (t 'edited))))
244
245 (defun vc-cvs-working-revision (file)
246 "CVS-specific version of `vc-working-revision'."
247 ;; There is no need to consult RCS headers under CVS, because we
248 ;; get the workfile version for free when we recognize that a file
249 ;; is registered in CVS.
250 (vc-cvs-registered file)
251 (vc-file-getprop file 'vc-working-revision))
252
253 (defun vc-cvs-mode-line-string (file)
254 "Return string for placement into the modeline for FILE.
255 Compared to the default implementation, this function does two things:
256 Handle the special case of a CVS file that is added but not yet
257 committed and support display of sticky tags."
258 (let* ((sticky-tag (vc-file-getprop file 'vc-cvs-sticky-tag))
259 help-echo
260 (string
261 (let ((def-ml (vc-default-mode-line-string 'CVS file)))
262 (setq help-echo
263 (get-text-property 0 'help-echo def-ml))
264 def-ml)))
265 (propertize
266 (if (zerop (length sticky-tag))
267 string
268 (setq help-echo (format "%s on the '%s' branch"
269 help-echo sticky-tag))
270 (concat string "[" sticky-tag "]"))
271 'help-echo help-echo)))
272
273
274 ;;;
275 ;;; State-changing functions
276 ;;;
277
278 (defun vc-cvs-register (files &optional rev comment)
279 "Register FILES into the CVS version-control system.
280 COMMENT can be used to provide an initial description of FILES.
281 Passes either `vc-cvs-register-switches' or `vc-register-switches'
282 to the CVS command."
283 ;; Register the directories if needed.
284 (let (dirs)
285 (dolist (file files)
286 (and (not (vc-cvs-responsible-p file))
287 (vc-cvs-could-register file)
288 (push (directory-file-name (file-name-directory file)) dirs)))
289 (if dirs (vc-cvs-register dirs)))
290 (apply 'vc-cvs-command nil 0 files
291 "add"
292 (and comment (string-match "[^\t\n ]" comment)
293 (concat "-m" comment))
294 (vc-switches 'CVS 'register)))
295
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)
300 file
301 (file-name-directory file)))))
302
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 managing FILE's directory or one of
306 its parents."
307 (let ((dir file))
308 (while (and (stringp dir)
309 (not (equal dir (setq dir (file-name-directory dir))))
310 dir)
311 (setq dir (if (file-exists-p
312 (expand-file-name "CVS/Entries" dir))
313 t
314 (directory-file-name dir))))
315 (eq dir t)))
316
317 (defun vc-cvs-checkin (files rev comment)
318 "CVS-specific version of `vc-backend-checkin'."
319 (unless (or (not rev) (vc-cvs-valid-revision-number-p rev))
320 (if (not (vc-cvs-valid-symbolic-tag-name-p rev))
321 (error "%s is not a valid symbolic tag name" rev)
322 ;; If the input revison is a valid symbolic tag name, we create it
323 ;; as a branch, commit and switch to it.
324 (apply 'vc-cvs-command nil 0 files "tag" "-b" (list rev))
325 (apply 'vc-cvs-command nil 0 files "update" "-r" (list rev))
326 (mapc (lambda (file) (vc-file-setprop file 'vc-cvs-sticky-tag rev))
327 files)))
328 (let ((status (apply 'vc-cvs-command nil 1 files
329 "ci" (if rev (concat "-r" rev))
330 (concat "-m" comment)
331 (vc-switches 'CVS 'checkin))))
332 (set-buffer "*vc*")
333 (goto-char (point-min))
334 (when (not (zerop status))
335 ;; Check checkin problem.
336 (cond
337 ((re-search-forward "Up-to-date check failed" nil t)
338 (mapc (lambda (file) (vc-file-setprop file 'vc-state 'needs-merge))
339 files)
340 (error "%s" (substitute-command-keys
341 (concat "Up-to-date check failed: "
342 "type \\[vc-next-action] to merge in changes"))))
343 (t
344 (pop-to-buffer (current-buffer))
345 (goto-char (point-min))
346 (shrink-window-if-larger-than-buffer)
347 (error "Check-in failed"))))
348 ;; Single-file commit? Then update the revision by parsing the buffer.
349 ;; Otherwise we can't necessarily tell what goes with what; clear
350 ;; its properties so they have to be refetched.
351 (if (= (length files) 1)
352 (vc-file-setprop
353 (car files) 'vc-working-revision
354 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
355 (mapc 'vc-file-clearprops files))
356 ;; Anyway, forget the checkout model of the file, because we might have
357 ;; guessed wrong when we found the file. After commit, we can
358 ;; tell it from the permissions of the file (see
359 ;; vc-cvs-checkout-model).
360 (mapc (lambda (file) (vc-file-setprop file 'vc-checkout-model nil))
361 files)
362
363 ;; if this was an explicit check-in (does not include creation of
364 ;; a branch), remove the sticky tag.
365 (if (and rev (not (vc-cvs-valid-symbolic-tag-name-p rev)))
366 (vc-cvs-command nil 0 files "update" "-A"))))
367
368 (defun vc-cvs-find-revision (file rev buffer)
369 (apply 'vc-cvs-command
370 buffer 0 file
371 "-Q" ; suppress diagnostic output
372 "update"
373 (and rev (not (string= rev ""))
374 (concat "-r" rev))
375 "-p"
376 (vc-switches 'CVS 'checkout)))
377
378 (defun vc-cvs-checkout (file &optional editable rev)
379 "Checkout a revision of FILE into the working area.
380 EDITABLE non-nil means that the file should be writable.
381 REV is the revision to check out."
382 (message "Checking out %s..." file)
383 ;; Change buffers to get local value of vc-checkout-switches.
384 (with-current-buffer (or (get-file-buffer file) (current-buffer))
385 (if (and (file-exists-p file) (not rev))
386 ;; If no revision was specified, just make the file writable
387 ;; if necessary (using `cvs-edit' if requested).
388 (and editable (not (eq (vc-cvs-checkout-model (list file)) 'implicit))
389 (if vc-cvs-use-edit
390 (vc-cvs-command nil 0 file "edit")
391 (set-file-modes file (logior (file-modes file) 128))
392 (if (equal file buffer-file-name) (toggle-read-only -1))))
393 ;; Check out a particular revision (or recreate the file).
394 (vc-file-setprop file 'vc-working-revision nil)
395 (apply 'vc-cvs-command nil 0 file
396 (and editable "-w")
397 "update"
398 (when rev
399 (unless (eq rev t)
400 ;; default for verbose checkout: clear the
401 ;; sticky tag so that the actual update will
402 ;; get the head of the trunk
403 (if (string= rev "")
404 "-A"
405 (concat "-r" rev))))
406 (vc-switches 'CVS 'checkout)))
407 (vc-mode-line file 'CVS))
408 (message "Checking out %s...done" file))
409
410 (defun vc-cvs-delete-file (file)
411 (vc-cvs-command nil 0 file "remove" "-f"))
412
413 (defun vc-cvs-revert (file &optional contents-done)
414 "Revert FILE to the working revision on which it was based."
415 (vc-default-revert 'CVS file contents-done)
416 (unless (eq (vc-cvs-checkout-model (list file)) 'implicit)
417 (if vc-cvs-use-edit
418 (vc-cvs-command nil 0 file "unedit")
419 ;; Make the file read-only by switching off all w-bits
420 (set-file-modes file (logand (file-modes file) 3950)))))
421
422 (defun vc-cvs-merge (file first-revision &optional second-revision)
423 "Merge changes into current working copy of FILE.
424 The changes are between FIRST-REVISION and SECOND-REVISION."
425 (vc-cvs-command nil 0 file
426 "update" "-kk"
427 (concat "-j" first-revision)
428 (concat "-j" second-revision))
429 (vc-file-setprop file 'vc-state 'edited)
430 (with-current-buffer (get-buffer "*vc*")
431 (goto-char (point-min))
432 (if (re-search-forward "conflicts during merge" nil t)
433 (progn
434 (vc-file-setprop file 'vc-state 'conflict)
435 ;; signal error
436 1)
437 (vc-file-setprop file 'vc-state 'edited)
438 ;; signal success
439 0)))
440
441 (defun vc-cvs-merge-news (file)
442 "Merge in any new changes made to FILE."
443 (message "Merging changes into %s..." file)
444 ;; (vc-file-setprop file 'vc-working-revision nil)
445 (vc-file-setprop file 'vc-checkout-time 0)
446 (vc-cvs-command nil nil file "update")
447 ;; Analyze the merge result reported by CVS, and set
448 ;; file properties accordingly.
449 (with-current-buffer (get-buffer "*vc*")
450 (goto-char (point-min))
451 ;; get new working revision
452 (if (re-search-forward
453 "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t)
454 (vc-file-setprop file 'vc-working-revision (match-string 1))
455 (vc-file-setprop file 'vc-working-revision nil))
456 ;; get file status
457 (prog1
458 (if (eq (buffer-size) 0)
459 0 ;; there were no news; indicate success
460 (if (re-search-forward
461 (concat "^\\([CMUP] \\)?"
462 (regexp-quote
463 (substring file (1+ (length (expand-file-name
464 "." default-directory)))))
465 "\\( already contains the differences between \\)?")
466 nil t)
467 (cond
468 ;; Merge successful, we are in sync with repository now
469 ((or (match-string 2)
470 (string= (match-string 1) "U ")
471 (string= (match-string 1) "P "))
472 (vc-file-setprop file 'vc-state 'up-to-date)
473 (vc-file-setprop file 'vc-checkout-time
474 (nth 5 (file-attributes file)))
475 0);; indicate success to the caller
476 ;; Merge successful, but our own changes are still in the file
477 ((string= (match-string 1) "M ")
478 (vc-file-setprop file 'vc-state 'edited)
479 0);; indicate success to the caller
480 ;; Conflicts detected!
481 (t
482 (vc-file-setprop file 'vc-state 'conflict)
483 1);; signal the error to the caller
484 )
485 (pop-to-buffer "*vc*")
486 (error "Couldn't analyze cvs update result")))
487 (message "Merging changes into %s...done" file))))
488
489 (defun vc-cvs-modify-change-comment (files rev comment)
490 "Modify the change comments for FILES on a specified REV.
491 Will fail unless you have administrative privileges on the repo."
492 (vc-cvs-command nil 0 files "admin" (concat "-m" rev ":" comment)))
493
494 ;;;
495 ;;; History functions
496 ;;;
497
498 (declare-function vc-rcs-print-log-cleanup "vc-rcs" ())
499
500 (defun vc-cvs-print-log (files buffer &optional shortlog start-revision-ignored limit)
501 "Get change logs associated with FILES."
502 (require 'vc-rcs)
503 ;; It's just the catenation of the individual logs.
504 (vc-cvs-command
505 buffer
506 (if (vc-stay-local-p files 'CVS) 'async 0)
507 files "log")
508 (with-current-buffer buffer
509 (vc-exec-after (vc-rcs-print-log-cleanup)))
510 (when limit 'limit-unsupported))
511
512 (defun vc-cvs-comment-history (file)
513 "Get comment history of a file."
514 (vc-call-backend 'RCS 'comment-history file))
515
516 (defun vc-cvs-diff (files &optional oldvers newvers buffer)
517 "Get a difference report using CVS between two revisions of FILE."
518 (let* (process-file-side-effects
519 (async (and (not vc-disable-async-diff)
520 (vc-stay-local-p files 'CVS)))
521 (invoke-cvs-diff-list nil)
522 status)
523 ;; Look through the file list and see if any files have backups
524 ;; that can be used to do a plain "diff" instead of "cvs diff".
525 (dolist (file files)
526 (let ((ov oldvers)
527 (nv newvers))
528 (when (or (not ov) (string-equal ov ""))
529 (setq ov (vc-working-revision file)))
530 (when (string-equal nv "")
531 (setq nv nil))
532 (let ((file-oldvers (vc-version-backup-file file ov))
533 (file-newvers (if (not nv)
534 file
535 (vc-version-backup-file file nv)))
536 (coding-system-for-read (vc-coding-system-for-diff file)))
537 (if (and file-oldvers file-newvers)
538 (progn
539 ;; This used to append diff-switches and vc-diff-switches,
540 ;; which was consistent with the vc-diff-switches doc at that
541 ;; time, but not with the actual behavior of any other VC diff.
542 (apply 'vc-do-command (or buffer "*vc-diff*") 1 "diff" nil
543 ;; Not a CVS diff, does not use vc-cvs-diff-switches.
544 (append (vc-switches nil 'diff)
545 (list (file-relative-name file-oldvers)
546 (file-relative-name file-newvers))))
547 (setq status 0))
548 (push file invoke-cvs-diff-list)))))
549 (when invoke-cvs-diff-list
550 (setq status (apply 'vc-cvs-command (or buffer "*vc-diff*")
551 (if async 'async 1)
552 invoke-cvs-diff-list "diff"
553 (and oldvers (concat "-r" oldvers))
554 (and newvers (concat "-r" newvers))
555 (vc-switches 'CVS 'diff))))
556 (if async 1 status))) ; async diff, pessimistic assumption
557
558 (defconst vc-cvs-annotate-first-line-re "^[0-9]")
559
560 (defun vc-cvs-annotate-process-filter (process string)
561 (setq string (concat (process-get process 'output) string))
562 (if (not (string-match vc-cvs-annotate-first-line-re string))
563 ;; Still waiting for the first real line.
564 (process-put process 'output string)
565 (let ((vc-filter (process-get process 'vc-filter)))
566 (set-process-filter process vc-filter)
567 (funcall vc-filter process (substring string (match-beginning 0))))))
568
569 (defun vc-cvs-annotate-command (file buffer &optional revision)
570 "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER.
571 Optional arg REVISION is a revision to annotate from."
572 (vc-cvs-command buffer
573 (if (vc-stay-local-p file 'CVS)
574 'async 0)
575 file "annotate"
576 (if revision (concat "-r" revision)))
577 ;; Strip the leading few lines.
578 (let ((proc (get-buffer-process buffer)))
579 (if proc
580 ;; If running asynchronously, use a process filter.
581 (progn
582 (process-put proc 'vc-filter (process-filter proc))
583 (set-process-filter proc 'vc-cvs-annotate-process-filter))
584 (with-current-buffer buffer
585 (goto-char (point-min))
586 (re-search-forward vc-cvs-annotate-first-line-re)
587 (delete-region (point-min) (1- (point)))))))
588
589 (declare-function vc-annotate-convert-time "vc-annotate" (time))
590
591 (defun vc-cvs-annotate-current-time ()
592 "Return the current time, based at midnight of the current day, and
593 encoded as fractional days."
594 (vc-annotate-convert-time
595 (apply 'encode-time 0 0 0 (nthcdr 3 (decode-time (current-time))))))
596
597 (defun vc-cvs-annotate-time ()
598 "Return the time of the next annotation (as fraction of days)
599 systime, or nil if there is none."
600 (let* ((bol (point))
601 (cache (get-text-property bol 'vc-cvs-annotate-time))
602 (inhibit-read-only t)
603 (inhibit-modification-hooks t))
604 (cond
605 (cache)
606 ((looking-at
607 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): ")
608 (let ((day (string-to-number (match-string 1)))
609 (month (cdr (assq (intern (match-string 2))
610 '((Jan . 1) (Feb . 2) (Mar . 3)
611 (Apr . 4) (May . 5) (Jun . 6)
612 (Jul . 7) (Aug . 8) (Sep . 9)
613 (Oct . 10) (Nov . 11) (Dec . 12)))))
614 (year (let ((tmp (string-to-number (match-string 3))))
615 ;; Years 0..68 are 2000..2068.
616 ;; Years 69..99 are 1969..1999.
617 (+ (cond ((> 69 tmp) 2000)
618 ((> 100 tmp) 1900)
619 (t 0))
620 tmp))))
621 (put-text-property
622 bol (1+ bol) 'vc-cvs-annotate-time
623 (setq cache (cons
624 ;; Position at end makes for nicer overlay result.
625 ;; Don't put actual buffer pos here, but only relative
626 ;; distance, so we don't ever move backward in the
627 ;; goto-char below, even if the text is moved.
628 (- (match-end 0) (match-beginning 0))
629 (vc-annotate-convert-time
630 (encode-time 0 0 0 day month year))))))))
631 (when cache
632 (goto-char (+ bol (car cache))) ; Fontify from here to eol.
633 (cdr cache)))) ; days (float)
634
635 (defun vc-cvs-annotate-extract-revision-at-line ()
636 (save-excursion
637 (beginning-of-line)
638 (if (re-search-forward "^\\([0-9]+\\.[0-9]+\\(\\.[0-9]+\\)*\\) +("
639 (line-end-position) t)
640 (match-string-no-properties 1)
641 nil)))
642
643 (defun vc-cvs-previous-revision (file rev)
644 (vc-call-backend 'RCS 'previous-revision file rev))
645
646 (defun vc-cvs-next-revision (file rev)
647 (vc-call-backend 'RCS 'next-revision file rev))
648
649 ;; FIXME: This should probably be replaced by code using cvs2cl.
650 (defun vc-cvs-update-changelog (files)
651 (vc-call-backend 'RCS 'update-changelog files))
652
653 ;;;
654 ;;; Tag system
655 ;;;
656
657 (defun vc-cvs-create-tag (dir name branchp)
658 "Assign to DIR's current revision a given NAME.
659 If BRANCHP is non-nil, the name is created as a branch (and the current
660 workspace is immediately moved to that new branch)."
661 (vc-cvs-command nil 0 dir "tag" "-c" (if branchp "-b") name)
662 (when branchp (vc-cvs-command nil 0 dir "update" "-r" name)))
663
664 (defun vc-cvs-retrieve-tag (dir name update)
665 "Retrieve a tag at and below DIR.
666 NAME is the name of the tag; if it is empty, do a `cvs update'.
667 If UPDATE is non-nil, then update (resynch) any affected buffers."
668 (with-current-buffer (get-buffer-create "*vc*")
669 (let ((default-directory dir)
670 (sticky-tag))
671 (erase-buffer)
672 (if (or (not name) (string= name ""))
673 (vc-cvs-command t 0 nil "update")
674 (vc-cvs-command t 0 nil "update" "-r" name)
675 (setq sticky-tag name))
676 (when update
677 (goto-char (point-min))
678 (while (not (eobp))
679 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
680 (let* ((file (expand-file-name (match-string 2) dir))
681 (state (match-string 1))
682 (buffer (find-buffer-visiting file)))
683 (when buffer
684 (cond
685 ((or (string= state "U")
686 (string= state "P"))
687 (vc-file-setprop file 'vc-state 'up-to-date)
688 (vc-file-setprop file 'vc-working-revision nil)
689 (vc-file-setprop file 'vc-checkout-time
690 (nth 5 (file-attributes file))))
691 ((or (string= state "M")
692 (string= state "C"))
693 (vc-file-setprop file 'vc-state 'edited)
694 (vc-file-setprop file 'vc-working-revision nil)
695 (vc-file-setprop file 'vc-checkout-time 0)))
696 (vc-file-setprop file 'vc-cvs-sticky-tag sticky-tag)
697 (vc-resynch-buffer file t t))))
698 (forward-line 1))))))
699
700
701 ;;;
702 ;;; Miscellaneous
703 ;;;
704
705 (defun vc-cvs-make-version-backups-p (file)
706 "Return non-nil if version backups should be made for FILE."
707 (vc-stay-local-p file 'CVS))
708
709 (defun vc-cvs-check-headers ()
710 "Check if the current file has any headers in it."
711 (save-excursion
712 (goto-char (point-min))
713 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
714 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
715
716
717 ;;;
718 ;;; Internal functions
719 ;;;
720
721 (defun vc-cvs-command (buffer okstatus files &rest flags)
722 "A wrapper around `vc-do-command' for use in vc-cvs.el.
723 The difference to vc-do-command is that this function always invokes `cvs',
724 and that it passes `vc-cvs-global-switches' to it before FLAGS."
725 (apply 'vc-do-command (or buffer "*vc*") okstatus "cvs" files
726 (if (stringp vc-cvs-global-switches)
727 (cons vc-cvs-global-switches flags)
728 (append vc-cvs-global-switches
729 flags))))
730
731 (defun vc-cvs-stay-local-p (file) ;Back-compatibility.
732 (vc-stay-local-p file 'CVS))
733
734 (defun vc-cvs-repository-hostname (dirname)
735 "Hostname of the CVS server associated to workarea DIRNAME."
736 (let ((rootname (expand-file-name "CVS/Root" dirname)))
737 (when (file-readable-p rootname)
738 (with-temp-buffer
739 (let ((coding-system-for-read
740 (or file-name-coding-system
741 default-file-name-coding-system)))
742 (vc-insert-file rootname))
743 (goto-char (point-min))
744 (nth 2 (vc-cvs-parse-root
745 (buffer-substring (point)
746 (line-end-position))))))))
747
748 (defun vc-cvs-parse-uhp (path)
749 "parse user@host/path into (user@host /path)"
750 (if (string-match "\\([^/]+\\)\\(/.*\\)" path)
751 (list (match-string 1 path) (match-string 2 path))
752 (list nil path)))
753
754 (defun vc-cvs-parse-root (root)
755 "Split CVS ROOT specification string into a list of fields.
756 A CVS root specification of the form
757 [:METHOD:][[USER@]HOSTNAME]:?/path/to/repository
758 is converted to a normalized record with the following structure:
759 \(METHOD USER HOSTNAME CVS-ROOT).
760 The default METHOD for a CVS root of the form
761 /path/to/repository
762 is `local'.
763 The default METHOD for a CVS root of the form
764 [USER@]HOSTNAME:/path/to/repository
765 is `ext'.
766 For an empty string, nil is returned (invalid CVS root)."
767 ;; Split CVS root into colon separated fields (0-4).
768 ;; The `x:' makes sure, that leading colons are not lost;
769 ;; `HOST:/PATH' is then different from `:METHOD:/PATH'.
770 (let* ((root-list (cdr (split-string (concat "x:" root) ":")))
771 (len (length root-list))
772 ;; All syntactic varieties will get a proper METHOD.
773 (root-list
774 (cond
775 ((= len 0)
776 ;; Invalid CVS root
777 nil)
778 ((= len 1)
779 (let ((uhp (vc-cvs-parse-uhp (car root-list))))
780 (cons (if (car uhp) "ext" "local") uhp)))
781 ((= len 2)
782 ;; [USER@]HOST:PATH => method `ext'
783 (and (not (equal (car root-list) ""))
784 (cons "ext" root-list)))
785 ((= len 3)
786 ;; :METHOD:PATH or :METHOD:USER@HOSTNAME/PATH
787 (cons (cadr root-list)
788 (vc-cvs-parse-uhp (caddr root-list))))
789 (t
790 ;; :METHOD:[USER@]HOST:PATH
791 (cdr root-list)))))
792 (if root-list
793 (let ((method (car root-list))
794 (uhost (or (cadr root-list) ""))
795 (root (nth 2 root-list))
796 user host)
797 ;; Split USER@HOST
798 (if (string-match "\\(.*\\)@\\(.*\\)" uhost)
799 (setq user (match-string 1 uhost)
800 host (match-string 2 uhost))
801 (setq host uhost))
802 ;; Remove empty HOST
803 (and (equal host "")
804 (setq host))
805 ;; Fix windows style CVS root `:local:C:\\project\\cvs\\some\\dir'
806 (and host
807 (equal method "local")
808 (setq root (concat host ":" root) host))
809 ;; Normalize CVS root record
810 (list method user host root)))))
811
812 ;; XXX: This does not work correctly for subdirectories. "cvs status"
813 ;; information is context sensitive, it contains lines like:
814 ;; cvs status: Examining DIRNAME
815 ;; and the file entries after that don't show the full path.
816 ;; Because of this VC directory listings only show changed files
817 ;; at the top level for CVS.
818 (defun vc-cvs-parse-status (&optional full)
819 "Parse output of \"cvs status\" command in the current buffer.
820 Set file properties accordingly. Unless FULL is t, parse only
821 essential information. Note that this can never set the 'ignored
822 state."
823 (let (file status missing)
824 (goto-char (point-min))
825 (while (looking-at "? \\(.*\\)")
826 (setq file (expand-file-name (match-string 1)))
827 (vc-file-setprop file 'vc-state 'unregistered)
828 (forward-line 1))
829 (when (re-search-forward "^File: " nil t)
830 (when (setq missing (looking-at "no file "))
831 (goto-char (match-end 0)))
832 (cond
833 ((re-search-forward "\\=\\([^ \t]+\\)" nil t)
834 (setq file (expand-file-name (match-string 1)))
835 (setq status(if (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t)
836 (match-string 1) "Unknown"))
837 (when (and full
838 (re-search-forward
839 "\\(RCS Version\\|RCS Revision\\|Repository revision\\):\
840 \[\t ]+\\([0-9.]+\\)"
841 nil t))
842 (vc-file-setprop file 'vc-latest-revision (match-string 2)))
843 (vc-file-setprop
844 file 'vc-state
845 (cond
846 ((string-match "Up-to-date" status)
847 (vc-file-setprop file 'vc-checkout-time
848 (nth 5 (file-attributes file)))
849 'up-to-date)
850 ((string-match "Locally Modified" status) 'edited)
851 ((string-match "Needs Merge" status) 'needs-merge)
852 ((string-match "Needs \\(Checkout\\|Patch\\)" status)
853 (if missing 'missing 'needs-update))
854 ((string-match "Locally Added" status) 'added)
855 ((string-match "Locally Removed" status) 'removed)
856 ((string-match "File had conflicts " status) 'conflict)
857 ((string-match "Unknown" status) 'unregistered)
858 (t 'edited))))))))
859
860 (defun vc-cvs-after-dir-status (update-function)
861 ;; Heavily inspired by vc-cvs-parse-status. AKA a quick hack.
862 ;; This needs a lot of testing.
863 (let ((status nil)
864 (status-str nil)
865 (file nil)
866 (result nil)
867 (missing nil)
868 (ignore-next nil)
869 (subdir default-directory))
870 (goto-char (point-min))
871 (while
872 ;; Look for either a file entry, an unregistered file, or a
873 ;; directory change.
874 (re-search-forward
875 "\\(^=+\n\\([^=c?\n].*\n\\|\n\\)+\\)\\|\\(\\(^?? .*\n\\)+\\)\\|\\(^cvs status: \\(Examining\\|nothing\\) .*\n\\)"
876 nil t)
877 ;; FIXME: get rid of narrowing here.
878 (narrow-to-region (match-beginning 0) (match-end 0))
879 (goto-char (point-min))
880 ;; The subdir
881 (when (looking-at "cvs status: Examining \\(.+\\)")
882 (setq subdir (expand-file-name (match-string 1))))
883 ;; Unregistered files
884 (while (looking-at "? \\(.*\\)")
885 (setq file (file-relative-name
886 (expand-file-name (match-string 1) subdir)))
887 (push (list file 'unregistered) result)
888 (forward-line 1))
889 (when (looking-at "cvs status: nothing known about")
890 ;; We asked about a non existent file. The output looks like this:
891
892 ;; cvs status: nothing known about `lisp/v.diff'
893 ;; ===================================================================
894 ;; File: no file v.diff Status: Unknown
895 ;;
896 ;; Working revision: No entry for v.diff
897 ;; Repository revision: No revision control file
898 ;;
899
900 ;; Due to narrowing in this iteration we only see the "cvs
901 ;; status:" line, so just set a flag so that we can ignore the
902 ;; file in the next iteration.
903 (setq ignore-next t))
904 ;; A file entry.
905 (when (re-search-forward "^File: \\(no file \\)?\\(.*[^ \t]\\)[ \t]+Status: \\(.*\\)" nil t)
906 (setq missing (match-string 1))
907 (setq file (file-relative-name
908 (expand-file-name (match-string 2) subdir)))
909 (setq status-str (match-string 3))
910 (setq status
911 (cond
912 ((string-match "Up-to-date" status-str) 'up-to-date)
913 ((string-match "Locally Modified" status-str) 'edited)
914 ((string-match "Needs Merge" status-str) 'needs-merge)
915 ((string-match "Needs \\(Checkout\\|Patch\\)" status-str)
916 (if missing 'missing 'needs-update))
917 ((string-match "Locally Added" status-str) 'added)
918 ((string-match "Locally Removed" status-str) 'removed)
919 ((string-match "File had conflicts " status-str) 'conflict)
920 ((string-match "Unknown" status-str) 'unregistered)
921 (t 'edited)))
922 (if ignore-next
923 (setq ignore-next nil)
924 (unless (eq status 'up-to-date)
925 (push (list file status) result))))
926 (goto-char (point-max))
927 (widen))
928 (funcall update-function result))
929 ;; Alternative implementation: use the "update" command instead of
930 ;; the "status" command.
931 ;; (let ((result nil)
932 ;; (translation '((?? . unregistered)
933 ;; (?A . added)
934 ;; (?C . conflict)
935 ;; (?M . edited)
936 ;; (?P . needs-merge)
937 ;; (?R . removed)
938 ;; (?U . needs-update))))
939 ;; (goto-char (point-min))
940 ;; (while (not (eobp))
941 ;; (if (looking-at "^[ACMPRU?] \\(.*\\)$")
942 ;; (push (list (match-string 1)
943 ;; (cdr (assoc (char-after) translation)))
944 ;; result)
945 ;; (cond
946 ;; ((looking-at "cvs update: warning: \\(.*\\) was lost")
947 ;; ;; Format is:
948 ;; ;; cvs update: warning: FILENAME was lost
949 ;; ;; U FILENAME
950 ;; (push (list (match-string 1) 'missing) result)
951 ;; ;; Skip the "U" line
952 ;; (forward-line 1))
953 ;; ((looking-at "cvs update: New directory `\\(.*\\)' -- ignored")
954 ;; (push (list (match-string 1) 'unregistered) result))))
955 ;; (forward-line 1))
956 ;; (funcall update-function result)))
957 )
958
959 ;; Based on vc-cvs-dir-state-heuristic from Emacs 22.
960 ;; FIXME does not mention unregistered files.
961 (defun vc-cvs-dir-status-heuristic (dir update-function &optional basedir)
962 "Find the CVS state of all files in DIR, using only local information."
963 (let (file basename status result dirlist)
964 (with-temp-buffer
965 (vc-cvs-get-entries dir)
966 (goto-char (point-min))
967 (while (not (eobp))
968 (if (looking-at "D/\\([^/]*\\)////")
969 (push (expand-file-name (match-string 1) dir) dirlist)
970 ;; CVS-removed files are not taken under VC control.
971 (when (looking-at "/\\([^/]*\\)/[^/-]")
972 (setq basename (match-string 1)
973 file (expand-file-name basename dir)
974 status (or (vc-file-getprop file 'vc-state)
975 (vc-cvs-parse-entry file t)))
976 (unless (eq status 'up-to-date)
977 (push (list (if basedir
978 (file-relative-name file basedir)
979 basename)
980 status) result))))
981 (forward-line 1)))
982 (dolist (subdir dirlist)
983 (setq result (append result
984 (vc-cvs-dir-status-heuristic subdir nil
985 (or basedir dir)))))
986 (if basedir result
987 (funcall update-function result))))
988
989 (defun vc-cvs-dir-status (dir update-function)
990 "Create a list of conses (file . state) for DIR."
991 ;; FIXME check all files in DIR instead?
992 (let ((local (vc-stay-local-p dir 'CVS)))
993 (if (and local (not (eq local 'only-file)))
994 (vc-cvs-dir-status-heuristic dir update-function)
995 (vc-cvs-command (current-buffer) 'async dir "-f" "status")
996 ;; Alternative implementation: use the "update" command instead of
997 ;; the "status" command.
998 ;; (vc-cvs-command (current-buffer) 'async
999 ;; (file-relative-name dir)
1000 ;; "-f" "-n" "update" "-d" "-P")
1001 (vc-exec-after
1002 `(vc-cvs-after-dir-status (quote ,update-function))))))
1003
1004 (defun vc-cvs-dir-status-files (dir files default-state update-function)
1005 "Create a list of conses (file . state) for DIR."
1006 (apply 'vc-cvs-command (current-buffer) 'async dir "-f" "status" files)
1007 (vc-exec-after
1008 `(vc-cvs-after-dir-status (quote ,update-function))))
1009
1010 (defun vc-cvs-file-to-string (file)
1011 "Read the content of FILE and return it as a string."
1012 (condition-case nil
1013 (with-temp-buffer
1014 (insert-file-contents file)
1015 (goto-char (point-min))
1016 (buffer-substring (point) (point-max)))
1017 (file-error nil)))
1018
1019 (defun vc-cvs-dir-extra-headers (dir)
1020 "Extract and represent per-directory properties of a CVS working copy."
1021 (let ((repo
1022 (condition-case nil
1023 (with-temp-buffer
1024 (insert-file-contents "CVS/Root")
1025 (goto-char (point-min))
1026 (and (looking-at ":ext:") (delete-char 5))
1027 (concat (buffer-substring (point) (1- (point-max))) "\n"))
1028 (file-error nil)))
1029 (module
1030 (condition-case nil
1031 (with-temp-buffer
1032 (insert-file-contents "CVS/Repository")
1033 (goto-char (point-min))
1034 (skip-chars-forward "^\n")
1035 (concat (buffer-substring (point-min) (point)) "\n"))
1036 (file-error nil))))
1037 (concat
1038 (cond (repo
1039 (concat (propertize "Repository : " 'face 'font-lock-type-face)
1040 (propertize repo 'face 'font-lock-variable-name-face)))
1041 (t ""))
1042 (cond (module
1043 (concat (propertize "Module : " 'face 'font-lock-type-face)
1044 (propertize module 'face 'font-lock-variable-name-face)))
1045 (t ""))
1046 (if (file-readable-p "CVS/Tag")
1047 (let ((tag (vc-cvs-file-to-string "CVS/Tag")))
1048 (cond
1049 ((string-match "\\`T" tag)
1050 (concat (propertize "Tag : " 'face 'font-lock-type-face)
1051 (propertize (substring tag 1)
1052 'face 'font-lock-variable-name-face)))
1053 ((string-match "\\`D" tag)
1054 (concat (propertize "Date : " 'face 'font-lock-type-face)
1055 (propertize (substring tag 1)
1056 'face 'font-lock-variable-name-face)))
1057 (t ""))))
1058
1059 ;; In CVS, branch is a per-file property, not a per-directory property.
1060 ;; We can't really do this here without making dangerous assumptions.
1061 ;;(propertize "Branch: " 'face 'font-lock-type-face)
1062 ;;(propertize "ADD CODE TO PRINT THE BRANCH NAME\n"
1063 ;; 'face 'font-lock-warning-face)
1064 )))
1065
1066 (defun vc-cvs-get-entries (dir)
1067 "Insert the CVS/Entries file from below DIR into the current buffer.
1068 This function ensures that the correct coding system is used for that,
1069 which may not be the one that is used for the files' contents.
1070 CVS/Entries should only be accessed through this function."
1071 (let ((coding-system-for-read (or file-name-coding-system
1072 default-file-name-coding-system)))
1073 (vc-insert-file (expand-file-name "CVS/Entries" dir))))
1074
1075 (defun vc-cvs-valid-symbolic-tag-name-p (tag)
1076 "Return non-nil if TAG is a valid symbolic tag name."
1077 ;; According to the CVS manual, a valid symbolic tag must start with
1078 ;; an uppercase or lowercase letter and can contain uppercase and
1079 ;; lowercase letters, digits, `-', and `_'.
1080 (and (string-match "^[a-zA-Z]" tag)
1081 (not (string-match "[^a-z0-9A-Z-_]" tag))))
1082
1083 (defun vc-cvs-valid-revision-number-p (tag)
1084 "Return non-nil if TAG is a valid revision number."
1085 (and (string-match "^[0-9]" tag)
1086 (not (string-match "[^0-9.]" tag))))
1087
1088 (defun vc-cvs-parse-sticky-tag (match-type match-tag)
1089 "Parse and return the sticky tag as a string.
1090 `match-data' is protected."
1091 (let ((data (match-data))
1092 (tag)
1093 (type (cond ((string= match-type "D") 'date)
1094 ((string= match-type "T")
1095 (if (vc-cvs-valid-symbolic-tag-name-p match-tag)
1096 'symbolic-name
1097 'revision-number))
1098 (t nil))))
1099 (unwind-protect
1100 (progn
1101 (cond
1102 ;; Sticky Date tag. Convert to a proper date value (`encode-time')
1103 ((eq type 'date)
1104 (string-match
1105 "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)"
1106 match-tag)
1107 (let* ((year-tmp (string-to-number (match-string 1 match-tag)))
1108 (month (string-to-number (match-string 2 match-tag)))
1109 (day (string-to-number (match-string 3 match-tag)))
1110 (hour (string-to-number (match-string 4 match-tag)))
1111 (min (string-to-number (match-string 5 match-tag)))
1112 (sec (string-to-number (match-string 6 match-tag)))
1113 ;; Years 0..68 are 2000..2068.
1114 ;; Years 69..99 are 1969..1999.
1115 (year (+ (cond ((> 69 year-tmp) 2000)
1116 ((> 100 year-tmp) 1900)
1117 (t 0))
1118 year-tmp)))
1119 (setq tag (encode-time sec min hour day month year))))
1120 ;; Sticky Tag name or revision number
1121 ((eq type 'symbolic-name) (setq tag match-tag))
1122 ((eq type 'revision-number) (setq tag match-tag))
1123 ;; Default is no sticky tag at all
1124 (t nil))
1125 (cond ((eq vc-cvs-sticky-tag-display nil) nil)
1126 ((eq vc-cvs-sticky-tag-display t)
1127 (cond ((eq type 'date) (format-time-string
1128 vc-cvs-sticky-date-format-string
1129 tag))
1130 ((eq type 'symbolic-name) tag)
1131 ((eq type 'revision-number) tag)
1132 (t nil)))
1133 ((functionp vc-cvs-sticky-tag-display)
1134 (funcall vc-cvs-sticky-tag-display tag type))
1135 (t nil)))
1136
1137 (set-match-data data))))
1138
1139 (defun vc-cvs-parse-entry (file &optional set-state)
1140 "Parse a line from CVS/Entries.
1141 Compare modification time to that of the FILE, set file properties
1142 accordingly. However, `vc-state' is set only if optional arg SET-STATE
1143 is non-nil."
1144 (cond
1145 ;; entry for a "locally added" file (not yet committed)
1146 ((looking-at "/[^/]+/0/")
1147 (vc-file-setprop file 'vc-checkout-time 0)
1148 (vc-file-setprop file 'vc-working-revision "0")
1149 (if set-state (vc-file-setprop file 'vc-state 'added)))
1150 ;; normal entry
1151 ((looking-at
1152 (concat "/[^/]+"
1153 ;; revision
1154 "/\\([^/]*\\)"
1155 ;; timestamp and optional conflict field
1156 "/\\([^/]*\\)/"
1157 ;; options
1158 "\\([^/]*\\)/"
1159 ;; sticky tag
1160 "\\(.\\|\\)" ;Sticky tag type (date or tag name, could be empty)
1161 "\\(.*\\)")) ;Sticky tag
1162 (vc-file-setprop file 'vc-working-revision (match-string 1))
1163 (vc-file-setprop file 'vc-cvs-sticky-tag
1164 (vc-cvs-parse-sticky-tag (match-string 4)
1165 (match-string 5)))
1166 ;; Compare checkout time and modification time.
1167 ;; This is intentionally different from the algorithm that CVS uses
1168 ;; (which is based on textual comparison), because there can be problems
1169 ;; generating a time string that looks exactly like the one from CVS.
1170 (let* ((time (match-string 2))
1171 (mtime (nth 5 (file-attributes file)))
1172 (parsed-time (progn (require 'parse-time)
1173 (parse-time-string (concat time " +0000")))))
1174 (cond ((and (not (string-match "\\+" time))
1175 (car parsed-time)
1176 (equal mtime (apply 'encode-time parsed-time)))
1177 (vc-file-setprop file 'vc-checkout-time mtime)
1178 (if set-state (vc-file-setprop file 'vc-state 'up-to-date)))
1179 (t
1180 (vc-file-setprop file 'vc-checkout-time 0)
1181 (if set-state (vc-file-setprop file 'vc-state 'edited))))))))
1182
1183 ;; Completion of revision names.
1184 ;; Just so I don't feel like I'm duplicating code from pcl-cvs, I'll use
1185 ;; `cvs log' so I can list all the revision numbers rather than only
1186 ;; tag names.
1187
1188 (defun vc-cvs-revision-table (file)
1189 (let (process-file-side-effects
1190 (default-directory (file-name-directory file))
1191 (res nil))
1192 (with-temp-buffer
1193 (vc-cvs-command t nil file "log")
1194 (goto-char (point-min))
1195 (when (re-search-forward "^symbolic names:\n" nil t)
1196 (while (looking-at "^ \\(.*\\): \\(.*\\)")
1197 (push (cons (match-string 1) (match-string 2)) res)
1198 (forward-line 1)))
1199 (while (re-search-forward "^revision \\([0-9.]+\\)" nil t)
1200 (push (match-string 1) res))
1201 res)))
1202
1203 (defun vc-cvs-revision-completion-table (files)
1204 (lexical-let ((files files)
1205 table)
1206 (setq table (lazy-completion-table
1207 table (lambda () (vc-cvs-revision-table (car files)))))
1208 table))
1209
1210
1211 (provide 'vc-cvs)
1212
1213 ;; arch-tag: 60e1402a-aa53-4607-927a-cf74f144b432
1214 ;;; vc-cvs.el ends here