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