1 ;;; vc-cvs.el --- non-resident support for CVS version-control
3 ;; Copyright (C) 1995,98,99,2000 Free Software Foundation, Inc.
5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
8 ;; $Id: vc-cvs.el,v 1.4 2000/09/09 00:48:39 monnier Exp $
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
31 (defcustom vc-cvs-register-switches nil
32 "*Extra switches for registering a file into CVS.
33 A string or list of strings passed to the checkin program by
35 :type
'(choice (const :tag
"None" nil
)
36 (string :tag
"Argument String")
37 (repeat :tag
"Argument List"
43 (defcustom vc-cvs-header
(or (cdr (assoc 'CVS vc-header-alist
)) '("\$Id\$"))
44 "*Header keywords to be inserted by `vc-insert-headers'."
49 (defcustom vc-cvs-use-edit t
50 "*Non-nil means to use `cvs edit' to \"check out\" a file.
51 This is only meaningful if you don't use the implicit checkout model
52 \(i.e. if you have $CVSREAD set)."
57 (defcustom vc-cvs-stay-local t
58 "*Non-nil means use local operations when possible for remote repositories.
59 This avoids slow queries over the network. Turning this option on
60 will instruct VC to use only heuristics and past information to
61 determine the current status of a file. The value can also be a
62 regular expression to match against the host name of a repository;
63 then VC only stays local for hosts that match it."
64 :type
'(choice (const :tag
"Always stay local" t
)
65 (string :tag
"Host regexp")
66 (const :tag
"Don't stay local" nil
))
70 ;;;###autoload (defun vc-cvs-registered (f)
71 ;;;###autoload (when (file-readable-p (expand-file-name
72 ;;;###autoload "CVS/Entries" (file-name-directory f)))
73 ;;;###autoload (require 'vc-cvs)
74 ;;;###autoload (vc-cvs-registered f)))
76 (defun vc-cvs-registered (file)
77 "Check if FILE is CVS registered."
78 (let ((dirname (or (file-name-directory file
) ""))
79 (basename (file-name-nondirectory file
))
80 ;; make sure that the file name is searched case-sensitively
81 (case-fold-search nil
))
82 (if (file-readable-p (expand-file-name "CVS/Entries" dirname
))
84 (vc-insert-file (expand-file-name "CVS/Entries" dirname
))
85 (goto-char (point-min))
88 (concat "^/" (regexp-quote basename
) "/") nil t
)
90 (vc-cvs-parse-entry file
)
95 (defun vc-cvs-stay-local-p (file)
96 "Return non-nil if VC should stay local when handling FILE."
98 (let* ((dirname (if (file-directory-p file
)
99 (directory-file-name file
)
100 (file-name-directory file
)))
102 (or (vc-file-getprop dirname
'vc-cvs-stay-local-p
)
103 (let ((rootname (expand-file-name "CVS/Root" dirname
)))
105 dirname
'vc-cvs-stay-local-p
106 (when (file-readable-p rootname
)
108 (vc-insert-file rootname
)
109 (goto-char (point-min))
110 (if (looking-at "\\([^:]*\\):")
111 (if (not (stringp vc-cvs-stay-local
))
113 (let ((hostname (match-string 1)))
114 (if (string-match vc-cvs-stay-local hostname
)
118 (if (eq prop
'yes
) t nil
))))
120 (defun vc-cvs-workfile-version (file)
121 "CVS-specific version of `vc-workfile-version'."
122 ;; There is no need to consult RCS headers under CVS, because we
123 ;; get the workfile version for free when we recognize that a file
124 ;; is registered in CVS.
125 (vc-cvs-registered file
)
126 (vc-file-getprop file
'vc-workfile-version
))
128 (defun vc-cvs-checkout-model (file)
129 "CVS-specific version of `vc-checkout-model'."
130 (if (or (getenv "CVSREAD")
131 ;; If the file is not writable (despite CVSREAD being
132 ;; undefined), this is probably because the file is being
133 ;; "watched" by other developers.
134 ;; (If vc-mistrust-permissions was t, we actually shouldn't
135 ;; trust this, but there is no other way to learn this from CVS
136 ;; at the moment (version 1.9).)
137 (string-match "r-..-..-." (nth 8 (file-attributes file
))))
141 ;; VC Dired functions
143 (defun vc-cvs-dired-state-info (file)
144 "CVS-specific version of `vc-dired-state-info'."
145 (let* ((cvs-state (vc-state file
))
146 (state (cond ((eq cvs-state
'edited
) "modified")
147 ((eq cvs-state
'needs-patch
) "patch")
148 ((eq cvs-state
'needs-merge
) "merge")
149 ;; FIXME: those two states cannot occur right now
150 ((eq cvs-state
'unlocked-changes
) "conflict")
151 ((eq cvs-state
'locally-added
) "added")
153 (if state
(concat "(" state
")"))))
155 (defun vc-cvs-parse-status (&optional full
)
156 "Parse output of \"cvs status\" command in the current buffer.
157 Set file properties accordingly. Unless FULL is t, parse only
158 essential information."
160 (goto-char (point-min))
161 (if (re-search-forward "^File: " nil t
)
163 ((looking-at "no file") nil
)
164 ((re-search-forward "\\=\\([^ \t]+\\)" nil t
)
165 (setq file
(expand-file-name (match-string 1)))
166 (vc-file-setprop file
'vc-backend
'CVS
)
167 (if (not (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t
))
168 (setq status
"Unknown")
169 (setq status
(match-string 1)))
172 "\\(RCS Version\\|RCS Revision\\|Repository revision\\):\
173 \[\t ]+\\([0-9.]+\\)"
175 (vc-file-setprop file
'vc-latest-version
(match-string 2)))
177 ((string-match "Up-to-date" status
)
178 (vc-file-setprop file
'vc-checkout-time
179 (nth 5 (file-attributes file
)))
181 ((string-match "Locally Modified" status
) 'edited
)
182 ((string-match "Needs Merge" status
) 'needs-merge
)
183 ((string-match "Needs \\(Checkout\\|Patch\\)" status
) 'needs-patch
)
186 (defun vc-cvs-state (file)
187 "CVS-specific version of `vc-state'."
188 (if (vc-cvs-stay-local-p file
)
189 (let ((state (vc-file-getprop file
'vc-state
)))
190 ;; If we should stay local, use the heuristic but only if
191 ;; we don't have a more precise state already available.
192 (if (memq state
'(up-to-date edited
))
193 (vc-cvs-state-heuristic file
)
196 (cd (file-name-directory file
))
197 (vc-do-command t
0 "cvs" file
"status")
198 (vc-cvs-parse-status t
))))
200 (defun vc-cvs-state-heuristic (file)
201 "CVS-specific state heuristic."
202 ;; If the file has not changed since checkout, consider it `up-to-date'.
203 ;; Otherwise consider it `edited'.
204 (let ((checkout-time (vc-file-getprop file
'vc-checkout-time
))
205 (lastmod (nth 5 (file-attributes file
))))
206 (if (equal checkout-time lastmod
)
210 (defun vc-cvs-mode-line-string (file)
211 "Return string for placement into the modeline for FILE.
212 Compared to the default implementation, this function handles the
213 special case of a CVS file that is added but not yet comitted."
214 (let ((state (vc-state file
))
215 (rev (vc-workfile-version file
)))
216 (cond ((string= rev
"0")
217 ;; A file that is added but not yet comitted.
219 ((or (eq state
'up-to-date
)
220 (eq state
'needs-patch
))
223 (concat "CVS:" state
":" rev
))
225 ;; Not just for the 'edited state, but also a fallback
226 ;; for all other states. Think about different symbols
227 ;; for 'needs-patch and 'needs-merge.
228 (concat "CVS:" rev
)))))
230 (defun vc-cvs-dir-state (dir)
231 "Find the CVS state of all files in DIR."
232 (if (vc-cvs-stay-local-p dir
)
233 (vc-cvs-dir-state-heuristic dir
)
234 (let ((default-directory dir
))
235 ;; Don't specify DIR in this command, the default-directory is
236 ;; enough. Otherwise it might fail with remote repositories.
238 (vc-do-command t
0 "cvs" nil
"status" "-l")
239 (goto-char (point-min))
240 (while (re-search-forward "^=+\n\\([^=\n].*\n\\|\n\\)+" nil t
)
241 (narrow-to-region (match-beginning 0) (match-end 0))
242 (vc-cvs-parse-status)
243 (goto-char (point-max))
246 (defun vc-cvs-dir-state-heuristic (dir)
247 "Find the CVS state of all files in DIR, using only local information."
249 (vc-insert-file (expand-file-name "CVS/Entries" dir
))
250 (goto-char (point-min))
252 (when (looking-at "/\\([^/]*\\)/")
253 (let ((file (expand-file-name (match-string 1) dir
)))
254 (unless (vc-file-getprop file
'vc-state
)
255 (vc-cvs-parse-entry file t
))))
258 (defun vc-cvs-parse-entry (file &optional set-state
)
259 "Parse a line from CVS/Entries.
260 Compare modification time to that of the FILE, set file properties
261 accordingly. However, `vc-state' is set only if optional arg SET-STATE
264 ;; entry for a "locally added" file (not yet committed)
265 ((looking-at "/[^/]+/0/")
266 (vc-file-setprop file
'vc-checkout-time
0)
267 (vc-file-setprop file
'vc-workfile-version
"0")
268 (if set-state
(vc-file-setprop file
'vc-state
'edited
)))
275 "/[A-Z][a-z][a-z]" ;; week day (irrelevant)
276 " \\([A-Z][a-z][a-z]\\)" ;; month name
277 " *\\([0-9]*\\)" ;; day of month
278 " \\([0-9]*\\):\\([0-9]*\\):\\([0-9]*\\)" ;; hms
279 " \\([0-9]*\\)" ;; year
280 ;; optional conflict field
282 (vc-file-setprop file
'vc-workfile-version
(match-string 1))
283 ;; compare checkout time and modification time
284 (let ((second (string-to-number (match-string 6)))
285 (minute (string-to-number (match-string 5)))
286 (hour (string-to-number (match-string 4)))
287 (day (string-to-number (match-string 3)))
288 (year (string-to-number (match-string 7)))
289 (month (/ (string-match
291 "xxxJanFebMarAprMayJunJulAugSepOctNovDec")
293 (mtime (nth 5 (file-attributes file
))))
295 (encode-time second minute hour day month year
0))
296 (vc-file-setprop file
'vc-checkout-time mtime
)
297 (if set-state
(vc-file-setprop file
'vc-state
'up-to-date
)))
299 (vc-file-setprop file
'vc-checkout-time
0)
300 (if set-state
(vc-file-setprop file
'vc-state
'edited
))))))
301 ;; entry with arbitrary text as timestamp
302 ;; (this means we should consider it modified)
307 ;; timestamp (arbitrary text)
309 ;; optional conflict field
311 (vc-file-setprop file
'vc-workfile-version
(match-string 1))
312 (vc-file-setprop file
'vc-checkout-time
0)
313 (if set-state
(vc-file-setprop file
'vc-state
'edited
)))))
315 (defun vc-cvs-print-log (file)
316 "Get change log associated with FILE."
317 (vc-do-command t
'async
"cvs" file
"log"))
319 (defun vc-cvs-show-log-entry (version)
320 (when (re-search-forward
321 ;; also match some context, for safety
322 (concat "----\nrevision " version
323 "\\(\tlocked by:.*\n\\|\n\\)date: ") nil t
)
324 ;; set the display window so that
325 ;; the whole log entry is displayed
326 (let (start end lines
)
327 (beginning-of-line) (forward-line -
1) (setq start
(point))
328 (if (not (re-search-forward "^----*\nrevision" nil t
))
329 (setq end
(point-max))
330 (beginning-of-line) (forward-line -
1) (setq end
(point)))
331 (setq lines
(count-lines start end
))
333 ;; if the global information and this log entry fit
334 ;; into the window, display from the beginning
335 ((< (count-lines (point-min) end
) (window-height))
336 (goto-char (point-min))
339 ;; if the whole entry fits into the window,
340 ;; display it centered
341 ((< (1+ lines
) (window-height))
343 (recenter (1- (- (/ (window-height) 2) (/ lines
2)))))
344 ;; otherwise (the entry is too large for the window),
345 ;; display from the start
350 (defun vc-cvs-create-snapshot (dir name branchp
)
351 "Assign to DIR's current version a given NAME.
352 If BRANCHP is non-nil, the name is created as a branch (and the current
353 workspace is immediately moved to that new branch)."
354 (vc-do-command nil
0 "cvs" dir
"tag" "-c" (if branchp
"-b") name
)
355 (when branchp
(vc-do-command nil
0 "cvs" dir
"update" "-r" name
)))
357 (defun vc-cvs-retrieve-snapshot (dir name update
)
358 "Retrieve a snapshot at and below DIR.
359 NAME is the name of the snapshot; if it is empty, do a `cvs update'.
360 If UPDATE is non-nil, then update (resynch) any affected buffers."
361 (with-current-buffer (get-buffer-create "*vc*")
362 (let ((default-directory dir
))
364 (if (or (not name
) (string= name
""))
365 (vc-do-command t
0 "cvs" nil
"update")
366 (vc-do-command t
0 "cvs" nil
"update" "-r" name
))
368 (goto-char (point-min))
370 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
371 (let* ((file (expand-file-name (match-string 2) dir
))
372 (state (match-string 1))
373 (buffer (find-buffer-visiting file
)))
376 ((or (string= state
"U")
378 (vc-file-setprop file
'vc-state
'up-to-date
)
379 (vc-file-setprop file
'vc-workfile-version nil
)
380 (vc-file-setprop file
'vc-checkout-time
381 (nth 5 (file-attributes file
))))
382 ((or (string= state
"M")
384 (vc-file-setprop file
'vc-state
'edited
)
385 (vc-file-setprop file
'vc-workfile-version nil
)
386 (vc-file-setprop file
'vc-checkout-time
0)))
387 (vc-resynch-buffer file t t
))))
388 (forward-line 1))))))
390 (defun vc-cvs-merge (file first-version
&optional second-version
)
391 "Merge changes into current working copy of FILE.
392 The changes are between FIRST-VERSION and SECOND-VERSION."
393 (vc-do-command nil
0 "cvs" file
395 (concat "-j" first-version
)
396 (concat "-j" second-version
))
397 (vc-file-setprop file
'vc-state
'edited
)
399 (set-buffer (get-buffer "*vc*"))
400 (goto-char (point-min))
401 (if (re-search-forward "conflicts during merge" nil t
)
403 0))) ; signal success
405 (defun vc-cvs-merge-news (file)
406 "Merge in any new changes made to FILE."
407 (message "Merging changes into %s..." file
)
409 ;; (vc-file-setprop file 'vc-workfile-version nil)
410 (vc-file-setprop file
'vc-checkout-time
0)
411 (vc-do-command nil
0 "cvs" file
"update")
412 ;; Analyze the merge result reported by CVS, and set
413 ;; file properties accordingly.
414 (set-buffer (get-buffer "*vc*"))
415 (goto-char (point-min))
416 ;; get new workfile version
417 (if (re-search-forward (concat "^Merging differences between "
418 "[01234567890.]* and "
419 "\\([01234567890.]*\\) into")
421 (vc-file-setprop file
'vc-workfile-version
(match-string 1))
422 (vc-file-setprop file
'vc-workfile-version nil
))
425 (if (re-search-forward
426 (concat "^\\([CMUP] \\)?"
427 (regexp-quote (file-name-nondirectory file
))
428 "\\( already contains the differences between \\)?")
431 ;; Merge successful, we are in sync with repository now
432 ((or (match-string 2)
433 (string= (match-string 1) "U ")
434 (string= (match-string 1) "P "))
435 (vc-file-setprop file
'vc-state
'up-to-date
)
436 (vc-file-setprop file
'vc-checkout-time
437 (nth 5 (file-attributes file
)))
438 0);; indicate success to the caller
439 ;; Merge successful, but our own changes are still in the file
440 ((string= (match-string 1) "M ")
441 (vc-file-setprop file
'vc-state
'edited
)
442 0);; indicate success to the caller
443 ;; Conflicts detected!
445 (vc-file-setprop file
'vc-state
'edited
)
446 1);; signal the error to the caller
448 (pop-to-buffer "*vc*")
449 (error "Couldn't analyze cvs update result"))
450 (message "Merging changes into %s...done" file
))))
452 (defun vc-cvs-check-headers ()
453 "Check if the current file has any headers in it."
455 (goto-char (point-min))
456 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
457 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
459 (defun vc-cvs-steal (file &optional rev
)
460 "Steal the lock on the current workfile for FILE and revision REV.
461 Inappropriate for CVS"
462 (error "You cannot steal a CVS lock; there are no CVS locks to steal"))
464 ;; vc-check `not reached' for CVS.
466 (defun vc-cvs-revert (file)
467 "Revert FILE to the version it was based on."
468 ;; Check out via standard output (caused by the final argument
469 ;; FILE below), so that no sticky tag is set.
470 (vc-cvs-checkout file nil
(vc-workfile-version file
) file
)
471 ;; If "cvs edit" was used to make the file writable,
472 ;; call "cvs unedit" now to undo that.
473 (if (not (eq (vc-cvs-checkout-model file
) 'implicit
))
474 (vc-do-command nil
0 "cvs" file
"unedit")))
476 (defun vc-cvs-diff (file &optional oldvers newvers
)
477 "Get a difference report using CVS between two versions of FILE."
479 (diff-switches-list (if (listp diff-switches
)
481 (list diff-switches
))))
482 (if (string= (vc-workfile-version file
) "0")
483 ;; This file is added but not yet committed; there is no master file.
484 (if (or oldvers newvers
)
485 (error "No revisions of %s exist" file
)
486 ;; we regard this as "changed".
487 ;; diff it against /dev/null.
488 (apply 'vc-do-command t
490 (append diff-switches-list
'("/dev/null"))))
491 (apply 'vc-do-command t
492 'async
"cvs" file
"diff"
493 (and oldvers
(concat "-r" oldvers
))
494 (and newvers
(concat "-r" newvers
))
496 ;; We can't know yet, so we assume there'll be a difference
499 (defun vc-cvs-latest-on-branch-p (file)
500 "Return t iff current workfile version of FILE is the latest on its branch."
501 ;; Since this is only used as a sanity check for vc-cancel-version,
502 ;; and that is not supported under CVS at all, we can safely return t here.
503 ;; TODO: Think of getting rid of this altogether.
506 (defun vc-cvs-checkin (file rev comment
)
507 "CVS-specific version of `vc-backend-checkin'."
508 (let ((switches (if (stringp vc-checkin-switches
)
509 (list vc-checkin-switches
)
510 vc-checkin-switches
))
512 ;; explicit check-in to the trunk requires a double check-in (first
513 ;; unexplicit) (CVS-1.3)
514 (if (and rev
(vc-trunk-p rev
))
515 (apply 'vc-do-command nil
1 "cvs" file
516 "ci" "-m" "intermediate"
518 (setq status
(apply 'vc-do-command nil
1 "cvs" file
519 "ci" (if rev
(concat "-r" rev
))
520 (concat "-m" comment
)
522 ;; determine and store the new workfile version
524 (goto-char (point-min))
525 ;; Check checkin problem. We could check `status' as well.
526 (when (re-search-forward "Up-to-date check failed" nil t
)
527 (vc-file-setprop file
'vc-state
'needs-merge
)
528 (error (substitute-command-keys
529 "Up-to-date check failed: type \\[vc-next-action] to merge in changes")))
530 ;; Update file properties
532 file
'vc-workfile-version
533 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
534 ;; Forget the checkout model of the file, because we might have
535 ;; guessed wrong when we found the file. After commit, we can
536 ;; tell it from the permissions of the file (see
537 ;; vc-cvs-checkout-model).
538 (vc-file-setprop file
'vc-checkout-model nil
)
539 ;; if this was an explicit check-in, remove the sticky tag
540 (if rev
(vc-do-command t
0 "cvs" file
"update" "-A"))))
542 (defun vc-cvs-responsible-p (file)
543 "Return non-nil if CVS thinks it is responsible for FILE."
544 (file-directory-p (expand-file-name "CVS"
545 (if (file-directory-p file
)
547 (file-name-directory file
)))))
549 (defun vc-cvs-could-register (file)
550 "Return non-nil if FILE could be registered in CVS.
551 This is only possible if CVS is responsible for FILE's directory."
552 (vc-cvs-responsible-p file
))
554 (defun vc-cvs-make-version-backups (file)
555 "Return non-nil if version backups should be made for FILE."
556 (vc-cvs-stay-local-p file
))
558 (defun vc-cvs-register (file &optional rev comment
)
559 "Register FILE into the CVS version-control system.
560 COMMENT can be used to provide an initial description of FILE.
562 `vc-register-switches' and `vc-cvs-register-switches' are passed to
563 the CVS command (in that order)."
564 (let ((switches (list
565 (if (stringp vc-register-switches
)
566 (list vc-register-switches
)
567 vc-register-switches
)
568 (if (stringp vc-cvs-register-switches
)
569 (list vc-cvs-register-switches
)
570 vc-cvs-register-switches
))))
572 (apply 'vc-do-command nil
0 "cvs" file
574 (and comment
(string-match "[^\t\n ]" comment
)
575 (concat "-m" comment
))
578 (defun vc-cvs-checkout (file &optional writable rev workfile
)
579 "Retrieve a revision of FILE into a WORKFILE.
580 WRITABLE non-nil means that the file should be writable.
581 REV is the revision to check out into WORKFILE."
582 (let ((filename (or workfile file
))
583 (file-buffer (get-file-buffer file
))
585 (message "Checking out %s..." filename
)
587 ;; Change buffers to get local value of vc-checkout-switches.
588 (if file-buffer
(set-buffer file-buffer
))
589 (setq switches
(if (stringp vc-checkout-switches
)
590 (list vc-checkout-switches
)
591 vc-checkout-switches
))
592 ;; Save this buffer's default-directory
593 ;; and use save-excursion to make sure it is restored
594 ;; in the same buffer it was saved in.
595 (let ((default-directory default-directory
))
597 ;; Adjust the default-directory so that the check-out creates
598 ;; the file in the right place.
599 (setq default-directory
(file-name-directory filename
))
604 (let ((coding-system-for-read 'no-conversion
)
605 (coding-system-for-write 'no-conversion
))
606 (with-temp-file filename
607 (apply 'vc-do-command
608 (current-buffer) 0 "cvs" file
609 "-Q" ; suppress diagnostic output
611 (and rev
(not (string= rev
""))
616 (and failed
(file-exists-p filename
) (delete-file filename
))))
617 (if (and (file-exists-p file
) (not rev
))
618 ;; If no revision was specified, just make the file writable
619 ;; if necessary (using `cvs-edit' if requested).
620 (and writable
(not (eq (vc-cvs-checkout-model file
) 'implicit
))
622 (vc-do-command nil
0 "cvs" file
"edit")
623 (set-file-modes file
(logior (file-modes file
) 128))
624 (if file-buffer
(toggle-read-only -
1))))
625 ;; Check out a particular version (or recreate the file).
626 (vc-file-setprop file
'vc-workfile-version nil
)
627 (apply 'vc-do-command nil
0 "cvs" file
629 (or (not (file-exists-p file
))
630 (not (eq (vc-cvs-checkout-model file
)
634 ;; default for verbose checkout: clear the sticky tag so
635 ;; that the actual update will get the head of the trunk
636 (if (or (not rev
) (string= rev
""))
641 (message "Checking out %s...done" filename
)))))
643 (defun vc-cvs-annotate-command (file buffer
)
644 "Execute \"cvs annotate\" on FILE.
645 Use `call-process' and insert the contents in BUFFER."
646 (call-process "cvs" nil buffer nil
"annotate" file
))
648 (defvar vc-cvs-local-month-numbers
649 '(("Jan" .
1) ("Feb" .
2) ("Mar" .
3) ("Apr" .
4)
650 ("May" .
5) ("Jun" .
6) ("Jul" .
7) ("Aug" .
8)
651 ("Sep" .
9) ("Oct" .
10) ("Nov" .
11) ("Dec" .
12))
652 "Local association list of month numbers.")
654 (defun vc-cvs-annotate-difference (point)
655 "Return the difference between the time of the line and the current time.
656 Return values are as defined for `current-time'."
657 ;; We need a list of months and their corresponding numbers.
658 (if (looking-at "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): ")
660 (let* ((day (string-to-number (match-string 1)))
661 (month (cdr (assoc (match-string 2) vc-cvs-local-month-numbers
)))
662 (year-tmp (string-to-number (match-string 3)))
663 ;; Years 0..68 are 2000..2068.
664 ;; Years 69..99 are 1969..1999.
665 (year (+ (cond ((> 69 year-tmp
) 2000)
666 ((> 100 year-tmp
) 1900)
669 (goto-char (match-end 0)) ; Position at end makes for nicer overlay result
670 (- (car (current-time))
671 (car (encode-time 0 0 0 day month year
)))))
672 ;; If we did not look directly at an annotation, there might be
673 ;; some further down. This is the case if we are positioned at
674 ;; the very top of the buffer, for instance.
675 (if (re-search-forward
676 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): " nil t
)
678 (beginning-of-line nil
)
679 (vc-cvs-annotate-difference (point))))))
683 ;;; vc-cvs.el ends here