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