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