The vc-mistrust-permissions configuration variable is gone.
[emacs.git] / lisp / vc / vc-cvs.el
blob28da328db71f6453d9000a7b7b47bc23eaf98f1f
1 ;;; vc-cvs.el --- non-resident support for CVS version-control -*- lexical-binding: t -*-
3 ;; Copyright (C) 1995, 1998-2014 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-cvs-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-stay-local-p file 'CVS)
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 first-revision &optional second-revision)
444 "Merge changes into current working copy of FILE.
445 The changes are between FIRST-REVISION and SECOND-REVISION."
446 (vc-cvs-command nil 0 file
447 "update" "-kk"
448 (concat "-j" first-revision)
449 (concat "-j" second-revision))
450 (vc-file-setprop file 'vc-state 'edited)
451 (with-current-buffer (get-buffer "*vc*")
452 (goto-char (point-min))
453 (if (re-search-forward "conflicts during merge" nil t)
454 (progn
455 (vc-file-setprop file 'vc-state 'conflict)
456 ;; signal error
458 (vc-file-setprop file 'vc-state 'edited)
459 ;; signal success
460 0)))
462 (defun vc-cvs-merge-news (file)
463 "Merge in any new changes made to FILE."
464 (message "Merging changes into %s..." file)
465 ;; (vc-file-setprop file 'vc-working-revision nil)
466 (vc-file-setprop file 'vc-checkout-time 0)
467 (vc-cvs-command nil nil file "update")
468 ;; Analyze the merge result reported by CVS, and set
469 ;; file properties accordingly.
470 (with-current-buffer (get-buffer "*vc*")
471 (goto-char (point-min))
472 ;; get new working revision
473 (if (re-search-forward
474 "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t)
475 (vc-file-setprop file 'vc-working-revision (match-string 1))
476 (vc-file-setprop file 'vc-working-revision nil))
477 ;; get file status
478 (prog1
479 (if (eq (buffer-size) 0)
480 0 ;; there were no news; indicate success
481 (if (re-search-forward
482 (concat "^\\([CMUP] \\)?"
483 (regexp-quote
484 (substring file (1+ (length (expand-file-name
485 "." default-directory)))))
486 "\\( already contains the differences between \\)?")
487 nil t)
488 (cond
489 ;; Merge successful, we are in sync with repository now
490 ((or (match-string 2)
491 (string= (match-string 1) "U ")
492 (string= (match-string 1) "P "))
493 (vc-file-setprop file 'vc-state 'up-to-date)
494 (vc-file-setprop file 'vc-checkout-time
495 (nth 5 (file-attributes file)))
496 0);; indicate success to the caller
497 ;; Merge successful, but our own changes are still in the file
498 ((string= (match-string 1) "M ")
499 (vc-file-setprop file 'vc-state 'edited)
500 0);; indicate success to the caller
501 ;; Conflicts detected!
503 (vc-file-setprop file 'vc-state 'conflict)
504 1);; signal the error to the caller
506 (pop-to-buffer "*vc*")
507 (error "Couldn't analyze cvs update result")))
508 (message "Merging changes into %s...done" file))))
510 (defun vc-cvs-modify-change-comment (files rev comment)
511 "Modify the change comments for FILES on a specified REV.
512 Will fail unless you have administrative privileges on the repo."
513 (vc-cvs-command nil 0 files "admin" (concat "-m" rev ":" comment)))
516 ;;; History functions
519 (declare-function vc-rcs-print-log-cleanup "vc-rcs" ())
520 ;; Follows vc-cvs-command, which uses vc-do-command from vc-dispatcher.
521 (declare-function vc-exec-after "vc-dispatcher" (code))
523 (defun vc-cvs-print-log (files buffer &optional _shortlog _start-revision limit)
524 "Print commit log associated with FILES into specified BUFFER.
525 Remaining arguments are ignored."
526 (require 'vc-rcs)
527 ;; It's just the catenation of the individual logs.
528 (vc-cvs-command
529 buffer
530 (if (vc-stay-local-p files 'CVS) 'async 0)
531 files "log")
532 (with-current-buffer buffer
533 (vc-run-delayed (vc-rcs-print-log-cleanup)))
534 (when limit 'limit-unsupported))
536 (defun vc-cvs-comment-history (file)
537 "Get comment history of a file."
538 (vc-call-backend 'RCS 'comment-history file))
540 (autoload 'vc-version-backup-file "vc")
541 (declare-function vc-coding-system-for-diff "vc" (file))
543 (defun vc-cvs-diff (files &optional oldvers newvers buffer)
544 "Get a difference report using CVS between two revisions of FILE."
545 (let* (process-file-side-effects
546 (async (and (not vc-disable-async-diff)
547 (vc-stay-local-p files 'CVS)))
548 (invoke-cvs-diff-list nil)
549 status)
550 ;; Look through the file list and see if any files have backups
551 ;; that can be used to do a plain "diff" instead of "cvs diff".
552 (dolist (file files)
553 (let ((ov oldvers)
554 (nv newvers))
555 (when (or (not ov) (string-equal ov ""))
556 (setq ov (vc-working-revision file)))
557 (when (string-equal nv "")
558 (setq nv nil))
559 (let ((file-oldvers (vc-version-backup-file file ov))
560 (file-newvers (if (not nv)
561 file
562 (vc-version-backup-file file nv)))
563 (coding-system-for-read (vc-coding-system-for-diff file)))
564 (if (and file-oldvers file-newvers)
565 (progn
566 ;; This used to append diff-switches and vc-diff-switches,
567 ;; which was consistent with the vc-diff-switches doc at that
568 ;; time, but not with the actual behavior of any other VC diff.
569 (apply 'vc-do-command (or buffer "*vc-diff*") 1 "diff" nil
570 ;; Not a CVS diff, does not use vc-cvs-diff-switches.
571 (append (vc-switches nil 'diff)
572 (list (file-relative-name file-oldvers)
573 (file-relative-name file-newvers))))
574 (setq status 0))
575 (push file invoke-cvs-diff-list)))))
576 (when invoke-cvs-diff-list
577 (setq status (apply 'vc-cvs-command (or buffer "*vc-diff*")
578 (if async 'async 1)
579 invoke-cvs-diff-list "diff"
580 (and oldvers (concat "-r" oldvers))
581 (and newvers (concat "-r" newvers))
582 (vc-switches 'CVS 'diff))))
583 (if async 1 status))) ; async diff, pessimistic assumption
585 (defconst vc-cvs-annotate-first-line-re "^[0-9]")
587 (defun vc-cvs-annotate-process-filter (filter process string)
588 (setq string (concat (process-get process 'output) string))
589 (if (not (string-match vc-cvs-annotate-first-line-re string))
590 ;; Still waiting for the first real line.
591 (process-put process 'output string)
592 (remove-function (process-filter process) #'vc-cvs-annotate-process-filter)
593 (funcall filter process (substring string (match-beginning 0)))))
595 (defun vc-cvs-annotate-command (file buffer &optional revision)
596 "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER.
597 Optional arg REVISION is a revision to annotate from."
598 (vc-cvs-command buffer
599 (if (vc-stay-local-p file 'CVS)
600 'async 0)
601 file "annotate"
602 (if revision (concat "-r" revision)))
603 ;; Strip the leading few lines.
604 (let ((proc (get-buffer-process buffer)))
605 (if proc
606 ;; If running asynchronously, use a process filter.
607 (add-function :around (process-filter proc)
608 #'vc-cvs-annotate-process-filter)
609 (with-current-buffer buffer
610 (goto-char (point-min))
611 (re-search-forward vc-cvs-annotate-first-line-re)
612 (delete-region (point-min) (1- (point)))))))
614 (declare-function vc-annotate-convert-time "vc-annotate" (time))
616 (defun vc-cvs-annotate-current-time ()
617 "Return the current time, based at midnight of the current day, and
618 encoded as fractional days."
619 (vc-annotate-convert-time
620 (apply 'encode-time 0 0 0 (nthcdr 3 (decode-time)))))
622 (defun vc-cvs-annotate-time ()
623 "Return the time of the next annotation (as fraction of days)
624 systime, or nil if there is none."
625 (let* ((bol (point))
626 (cache (get-text-property bol 'vc-cvs-annotate-time))
627 (inhibit-read-only t)
628 (inhibit-modification-hooks t))
629 (cond
630 (cache)
631 ((looking-at
632 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): ")
633 (let ((day (string-to-number (match-string 1)))
634 (month (cdr (assq (intern (match-string 2))
635 '((Jan . 1) (Feb . 2) (Mar . 3)
636 (Apr . 4) (May . 5) (Jun . 6)
637 (Jul . 7) (Aug . 8) (Sep . 9)
638 (Oct . 10) (Nov . 11) (Dec . 12)))))
639 (year (let ((tmp (string-to-number (match-string 3))))
640 ;; Years 0..68 are 2000..2068.
641 ;; Years 69..99 are 1969..1999.
642 (+ (cond ((> 69 tmp) 2000)
643 ((> 100 tmp) 1900)
644 (t 0))
645 tmp))))
646 (put-text-property
647 bol (1+ bol) 'vc-cvs-annotate-time
648 (setq cache (cons
649 ;; Position at end makes for nicer overlay result.
650 ;; Don't put actual buffer pos here, but only relative
651 ;; distance, so we don't ever move backward in the
652 ;; goto-char below, even if the text is moved.
653 (- (match-end 0) (match-beginning 0))
654 (vc-annotate-convert-time
655 (encode-time 0 0 0 day month year))))))))
656 (when cache
657 (goto-char (+ bol (car cache))) ; Fontify from here to eol.
658 (cdr cache)))) ; days (float)
660 (defun vc-cvs-annotate-extract-revision-at-line ()
661 (save-excursion
662 (beginning-of-line)
663 (if (re-search-forward "^\\([0-9]+\\.[0-9]+\\(\\.[0-9]+\\)*\\) +("
664 (line-end-position) t)
665 (match-string-no-properties 1)
666 nil)))
668 (defun vc-cvs-previous-revision (file rev)
669 (vc-call-backend 'RCS 'previous-revision file rev))
671 (defun vc-cvs-next-revision (file rev)
672 (vc-call-backend 'RCS 'next-revision file rev))
674 ;; FIXME: This should probably be replaced by code using cvs2cl.
675 (defun vc-cvs-update-changelog (files)
676 (vc-call-backend 'RCS 'update-changelog files))
679 ;;; Tag system
682 (defun vc-cvs-create-tag (dir name branchp)
683 "Assign to DIR's current revision a given NAME.
684 If BRANCHP is non-nil, the name is created as a branch (and the current
685 workspace is immediately moved to that new branch)."
686 (vc-cvs-command nil 0 dir "tag" "-c" (if branchp "-b") name)
687 (when branchp (vc-cvs-command nil 0 dir "update" "-r" name)))
689 ;; Follows vc-cvs-command, which uses vc-do-command from vc-dispatcher.
690 (declare-function vc-resynch-buffer "vc-dispatcher"
691 (file &optional keep noquery reset-vc-info))
693 (defun vc-cvs-retrieve-tag (dir name update)
694 "Retrieve a tag at and below DIR.
695 NAME is the name of the tag; if it is empty, do a `cvs update'.
696 If UPDATE is non-nil, then update (resynch) any affected buffers."
697 (with-current-buffer (get-buffer-create "*vc*")
698 (let ((default-directory dir)
699 (sticky-tag))
700 (erase-buffer)
701 (if (or (not name) (string= name ""))
702 (vc-cvs-command t 0 nil "update")
703 (vc-cvs-command t 0 nil "update" "-r" name)
704 (setq sticky-tag name))
705 (when update
706 (goto-char (point-min))
707 (while (not (eobp))
708 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
709 (let* ((file (expand-file-name (match-string 2) dir))
710 (state (match-string 1))
711 (buffer (find-buffer-visiting file)))
712 (when buffer
713 (cond
714 ((or (string= state "U")
715 (string= state "P"))
716 (vc-file-setprop file 'vc-state 'up-to-date)
717 (vc-file-setprop file 'vc-working-revision nil)
718 (vc-file-setprop file 'vc-checkout-time
719 (nth 5 (file-attributes file))))
720 ((or (string= state "M")
721 (string= state "C"))
722 (vc-file-setprop file 'vc-state 'edited)
723 (vc-file-setprop file 'vc-working-revision nil)
724 (vc-file-setprop file 'vc-checkout-time 0)))
725 (vc-file-setprop file 'vc-cvs-sticky-tag sticky-tag)
726 (vc-resynch-buffer file t t))))
727 (forward-line 1))))))
731 ;;; Miscellaneous
734 (defun vc-cvs-make-version-backups-p (file)
735 "Return non-nil if version backups should be made for FILE."
736 (vc-stay-local-p file 'CVS))
738 (defun vc-cvs-check-headers ()
739 "Check if the current file has any headers in it."
740 (save-excursion
741 (goto-char (point-min))
742 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
743 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
747 ;;; Internal functions
750 (defun vc-cvs-command (buffer okstatus files &rest flags)
751 "A wrapper around `vc-do-command' for use in vc-cvs.el.
752 The difference to vc-do-command is that this function always invokes `cvs',
753 and that it passes `vc-cvs-global-switches' to it before FLAGS."
754 (apply 'vc-do-command (or buffer "*vc*") okstatus "cvs" files
755 (if (stringp vc-cvs-global-switches)
756 (cons vc-cvs-global-switches flags)
757 (append vc-cvs-global-switches
758 flags))))
760 (defun vc-cvs-stay-local-p (file) ;Back-compatibility.
761 (vc-stay-local-p file 'CVS))
763 (defun vc-cvs-repository-hostname (dirname)
764 "Hostname of the CVS server associated to workarea DIRNAME."
765 (let ((rootname (expand-file-name "CVS/Root" dirname)))
766 (when (file-readable-p rootname)
767 (with-temp-buffer
768 (let ((coding-system-for-read
769 (or file-name-coding-system
770 default-file-name-coding-system)))
771 (vc-insert-file rootname))
772 (goto-char (point-min))
773 (nth 2 (vc-cvs-parse-root
774 (buffer-substring (point)
775 (line-end-position))))))))
777 (defun vc-cvs-parse-uhp (path)
778 "parse user@host/path into (user@host /path)"
779 (if (string-match "\\([^/]+\\)\\(/.*\\)" path)
780 (list (match-string 1 path) (match-string 2 path))
781 (list nil path)))
783 (defun vc-cvs-parse-root (root)
784 "Split CVS ROOT specification string into a list of fields.
785 A CVS root specification of the form
786 [:METHOD:][[USER@]HOSTNAME]:?/path/to/repository
787 is converted to a normalized record with the following structure:
788 \(METHOD USER HOSTNAME CVS-ROOT).
789 The default METHOD for a CVS root of the form
790 /path/to/repository
791 is `local'.
792 The default METHOD for a CVS root of the form
793 [USER@]HOSTNAME:/path/to/repository
794 is `ext'.
795 For an empty string, nil is returned (invalid CVS root)."
796 ;; Split CVS root into colon separated fields (0-4).
797 ;; The `x:' makes sure, that leading colons are not lost;
798 ;; `HOST:/PATH' is then different from `:METHOD:/PATH'.
799 (let* ((root-list (cdr (split-string (concat "x:" root) ":")))
800 (len (length root-list))
801 ;; All syntactic varieties will get a proper METHOD.
802 (root-list
803 (cond
804 ((= len 0)
805 ;; Invalid CVS root
806 nil)
807 ((= len 1)
808 (let ((uhp (vc-cvs-parse-uhp (car root-list))))
809 (cons (if (car uhp) "ext" "local") uhp)))
810 ((= len 2)
811 ;; [USER@]HOST:PATH => method `ext'
812 (and (not (equal (car root-list) ""))
813 (cons "ext" root-list)))
814 ((= len 3)
815 ;; :METHOD:PATH or :METHOD:USER@HOSTNAME/PATH
816 (cons (cadr root-list)
817 (vc-cvs-parse-uhp (nth 2 root-list))))
819 ;; :METHOD:[USER@]HOST:PATH
820 (cdr root-list)))))
821 (if root-list
822 (let ((method (car root-list))
823 (uhost (or (cadr root-list) ""))
824 (root (nth 2 root-list))
825 user host)
826 ;; Split USER@HOST
827 (if (string-match "\\(.*\\)@\\(.*\\)" uhost)
828 (setq user (match-string 1 uhost)
829 host (match-string 2 uhost))
830 (setq host uhost))
831 ;; Remove empty HOST
832 (and (equal host "")
833 (setq host))
834 ;; Fix windows style CVS root `:local:C:\\project\\cvs\\some\\dir'
835 (and host
836 (equal method "local")
837 (setq root (concat host ":" root) host))
838 ;; Normalize CVS root record
839 (list method user host root)))))
841 ;; XXX: This does not work correctly for subdirectories. "cvs status"
842 ;; information is context sensitive, it contains lines like:
843 ;; cvs status: Examining DIRNAME
844 ;; and the file entries after that don't show the full path.
845 ;; Because of this VC directory listings only show changed files
846 ;; at the top level for CVS.
847 (defun vc-cvs-parse-status (&optional full)
848 "Parse output of \"cvs status\" command in the current buffer.
849 Set file properties accordingly. Unless FULL is t, parse only
850 essential information. Note that this can never set the 'ignored
851 state."
852 (let (file status missing)
853 (goto-char (point-min))
854 (while (looking-at "? \\(.*\\)")
855 (setq file (expand-file-name (match-string 1)))
856 (vc-file-setprop file 'vc-state 'unregistered)
857 (forward-line 1))
858 (when (re-search-forward "^File: " nil t)
859 (when (setq missing (looking-at "no file "))
860 (goto-char (match-end 0)))
861 (cond
862 ((re-search-forward "\\=\\([^ \t]+\\)" nil t)
863 (setq file (expand-file-name (match-string 1)))
864 (setq status(if (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t)
865 (match-string 1) "Unknown"))
866 (when (and full
867 (re-search-forward
868 "\\(RCS Version\\|RCS Revision\\|Repository revision\\):\
869 \[\t ]+\\([0-9.]+\\)"
870 nil t))
871 (vc-file-setprop file 'vc-latest-revision (match-string 2)))
872 (vc-file-setprop
873 file 'vc-state
874 (cond
875 ((string-match "Up-to-date" status)
876 (vc-file-setprop file 'vc-checkout-time
877 (nth 5 (file-attributes file)))
878 'up-to-date)
879 ((string-match "Locally Modified" status) 'edited)
880 ((string-match "Needs Merge" status) 'needs-merge)
881 ((string-match "Needs \\(Checkout\\|Patch\\)" status)
882 (if missing 'missing 'needs-update))
883 ((string-match "Locally Added" status) 'added)
884 ((string-match "Locally Removed" status) 'removed)
885 ((string-match "File had conflicts " status) 'conflict)
886 ((string-match "Unknown" status) 'unregistered)
887 (t 'edited))))))))
889 (defun vc-cvs-after-dir-status (update-function)
890 ;; Heavily inspired by vc-cvs-parse-status. AKA a quick hack.
891 ;; This needs a lot of testing.
892 (let ((status nil)
893 (status-str nil)
894 (file nil)
895 (result nil)
896 (missing nil)
897 (ignore-next nil)
898 (subdir default-directory))
899 (goto-char (point-min))
900 (while
901 ;; Look for either a file entry, an unregistered file, or a
902 ;; directory change.
903 (re-search-forward
904 "\\(^=+\n\\([^=c?\n].*\n\\|\n\\)+\\)\\|\\(\\(^?? .*\n\\)+\\)\\|\\(^cvs status: \\(Examining\\|nothing\\) .*\n\\)"
905 nil t)
906 ;; FIXME: get rid of narrowing here.
907 (narrow-to-region (match-beginning 0) (match-end 0))
908 (goto-char (point-min))
909 ;; The subdir
910 (when (looking-at "cvs status: Examining \\(.+\\)")
911 (setq subdir (expand-file-name (match-string 1))))
912 ;; Unregistered files
913 (while (looking-at "? \\(.*\\)")
914 (setq file (file-relative-name
915 (expand-file-name (match-string 1) subdir)))
916 (push (list file 'unregistered) result)
917 (forward-line 1))
918 (when (looking-at "cvs status: nothing known about")
919 ;; We asked about a non existent file. The output looks like this:
921 ;; cvs status: nothing known about `lisp/v.diff'
922 ;; ===================================================================
923 ;; File: no file v.diff Status: Unknown
925 ;; Working revision: No entry for v.diff
926 ;; Repository revision: No revision control file
929 ;; Due to narrowing in this iteration we only see the "cvs
930 ;; status:" line, so just set a flag so that we can ignore the
931 ;; file in the next iteration.
932 (setq ignore-next t))
933 ;; A file entry.
934 (when (re-search-forward "^File: \\(no file \\)?\\(.*[^ \t]\\)[ \t]+Status: \\(.*\\)" nil t)
935 (setq missing (match-string 1))
936 (setq file (file-relative-name
937 (expand-file-name (match-string 2) subdir)))
938 (setq status-str (match-string 3))
939 (setq status
940 (cond
941 ((string-match "Up-to-date" status-str) 'up-to-date)
942 ((string-match "Locally Modified" status-str) 'edited)
943 ((string-match "Needs Merge" status-str) 'needs-merge)
944 ((string-match "Needs \\(Checkout\\|Patch\\)" status-str)
945 (if missing 'missing 'needs-update))
946 ((string-match "Locally Added" status-str) 'added)
947 ((string-match "Locally Removed" status-str) 'removed)
948 ((string-match "File had conflicts " status-str) 'conflict)
949 ((string-match "Unknown" status-str) 'unregistered)
950 (t 'edited)))
951 (if ignore-next
952 (setq ignore-next nil)
953 (unless (eq status 'up-to-date)
954 (push (list file status) result))))
955 (goto-char (point-max))
956 (widen))
957 (funcall update-function result))
958 ;; Alternative implementation: use the "update" command instead of
959 ;; the "status" command.
960 ;; (let ((result nil)
961 ;; (translation '((?? . unregistered)
962 ;; (?A . added)
963 ;; (?C . conflict)
964 ;; (?M . edited)
965 ;; (?P . needs-merge)
966 ;; (?R . removed)
967 ;; (?U . needs-update))))
968 ;; (goto-char (point-min))
969 ;; (while (not (eobp))
970 ;; (if (looking-at "^[ACMPRU?] \\(.*\\)$")
971 ;; (push (list (match-string 1)
972 ;; (cdr (assoc (char-after) translation)))
973 ;; result)
974 ;; (cond
975 ;; ((looking-at "cvs update: warning: \\(.*\\) was lost")
976 ;; ;; Format is:
977 ;; ;; cvs update: warning: FILENAME was lost
978 ;; ;; U FILENAME
979 ;; (push (list (match-string 1) 'missing) result)
980 ;; ;; Skip the "U" line
981 ;; (forward-line 1))
982 ;; ((looking-at "cvs update: New directory `\\(.*\\)' -- ignored")
983 ;; (push (list (match-string 1) 'unregistered) result))))
984 ;; (forward-line 1))
985 ;; (funcall update-function result)))
988 ;; Based on vc-cvs-dir-state-heuristic from Emacs 22.
989 ;; FIXME does not mention unregistered files.
990 (defun vc-cvs-dir-status-heuristic (dir update-function &optional basedir)
991 "Find the CVS state of all files in DIR, using only local information."
992 (let (file basename status result dirlist)
993 (with-temp-buffer
994 (vc-cvs-get-entries dir)
995 (goto-char (point-min))
996 (while (not (eobp))
997 (if (looking-at "D/\\([^/]*\\)////")
998 (push (expand-file-name (match-string 1) dir) dirlist)
999 ;; CVS-removed files are not taken under VC control.
1000 (when (looking-at "/\\([^/]*\\)/[^/-]")
1001 (setq basename (match-string 1)
1002 file (expand-file-name basename dir)
1003 status (or (vc-file-getprop file 'vc-state)
1004 (vc-cvs-parse-entry file t)))
1005 (unless (eq status 'up-to-date)
1006 (push (list (if basedir
1007 (file-relative-name file basedir)
1008 basename)
1009 status) result))))
1010 (forward-line 1)))
1011 (dolist (subdir dirlist)
1012 (setq result (append result
1013 (vc-cvs-dir-status-heuristic subdir nil
1014 (or basedir dir)))))
1015 (if basedir result
1016 (funcall update-function result))))
1018 (defun vc-cvs-dir-status (dir update-function)
1019 "Create a list of conses (file . state) for DIR."
1020 ;; FIXME check all files in DIR instead?
1021 (let ((local (vc-stay-local-p dir 'CVS)))
1022 (if (and local (not (eq local 'only-file)))
1023 (vc-cvs-dir-status-heuristic dir update-function)
1024 (vc-cvs-command (current-buffer) 'async dir "-f" "status")
1025 ;; Alternative implementation: use the "update" command instead of
1026 ;; the "status" command.
1027 ;; (vc-cvs-command (current-buffer) 'async
1028 ;; (file-relative-name dir)
1029 ;; "-f" "-n" "update" "-d" "-P")
1030 (vc-run-delayed
1031 (vc-cvs-after-dir-status update-function)))))
1033 (defun vc-cvs-dir-status-files (dir files _default-state update-function)
1034 "Create a list of conses (file . state) for DIR."
1035 (apply 'vc-cvs-command (current-buffer) 'async dir "-f" "status" files)
1036 (vc-run-delayed
1037 (vc-cvs-after-dir-status update-function)))
1039 (defun vc-cvs-file-to-string (file)
1040 "Read the content of FILE and return it as a string."
1041 (condition-case nil
1042 (with-temp-buffer
1043 (insert-file-contents file)
1044 (goto-char (point-min))
1045 (buffer-substring (point) (point-max)))
1046 (file-error nil)))
1048 (defun vc-cvs-dir-extra-headers (_dir)
1049 "Extract and represent per-directory properties of a CVS working copy."
1050 (let ((repo
1051 (condition-case nil
1052 (with-temp-buffer
1053 (insert-file-contents "CVS/Root")
1054 (goto-char (point-min))
1055 (and (looking-at ":ext:") (delete-char 5))
1056 (concat (buffer-substring (point) (1- (point-max))) "\n"))
1057 (file-error nil)))
1058 (module
1059 (condition-case nil
1060 (with-temp-buffer
1061 (insert-file-contents "CVS/Repository")
1062 (goto-char (point-min))
1063 (skip-chars-forward "^\n")
1064 (concat (buffer-substring (point-min) (point)) "\n"))
1065 (file-error nil))))
1066 (concat
1067 (cond (repo
1068 (concat (propertize "Repository : " 'face 'font-lock-type-face)
1069 (propertize repo 'face 'font-lock-variable-name-face)))
1070 (t ""))
1071 (cond (module
1072 (concat (propertize "Module : " 'face 'font-lock-type-face)
1073 (propertize module 'face 'font-lock-variable-name-face)))
1074 (t ""))
1075 (if (file-readable-p "CVS/Tag")
1076 (let ((tag (vc-cvs-file-to-string "CVS/Tag")))
1077 (cond
1078 ((string-match "\\`T" tag)
1079 (concat (propertize "Tag : " 'face 'font-lock-type-face)
1080 (propertize (substring tag 1)
1081 'face 'font-lock-variable-name-face)))
1082 ((string-match "\\`D" tag)
1083 (concat (propertize "Date : " 'face 'font-lock-type-face)
1084 (propertize (substring tag 1)
1085 'face 'font-lock-variable-name-face)))
1086 (t ""))))
1088 ;; In CVS, branch is a per-file property, not a per-directory property.
1089 ;; We can't really do this here without making dangerous assumptions.
1090 ;;(propertize "Branch: " 'face 'font-lock-type-face)
1091 ;;(propertize "ADD CODE TO PRINT THE BRANCH NAME\n"
1092 ;; 'face 'font-lock-warning-face)
1095 (defun vc-cvs-get-entries (dir)
1096 "Insert the CVS/Entries file from below DIR into the current buffer.
1097 This function ensures that the correct coding system is used for that,
1098 which may not be the one that is used for the files' contents.
1099 CVS/Entries should only be accessed through this function."
1100 (let ((coding-system-for-read (or file-name-coding-system
1101 default-file-name-coding-system)))
1102 (vc-insert-file (expand-file-name "CVS/Entries" dir))))
1104 (defun vc-cvs-valid-symbolic-tag-name-p (tag)
1105 "Return non-nil if TAG is a valid symbolic tag name."
1106 ;; According to the CVS manual, a valid symbolic tag must start with
1107 ;; an uppercase or lowercase letter and can contain uppercase and
1108 ;; lowercase letters, digits, `-', and `_'.
1109 (and (string-match "^[a-zA-Z]" tag)
1110 (not (string-match "[^a-z0-9A-Z-_]" tag))))
1112 (defun vc-cvs-valid-revision-number-p (tag)
1113 "Return non-nil if TAG is a valid revision number."
1114 (and (string-match "^[0-9]" tag)
1115 (not (string-match "[^0-9.]" tag))))
1117 (defun vc-cvs-parse-sticky-tag (match-type match-tag)
1118 "Parse and return the sticky tag as a string.
1119 `match-data' is protected."
1120 (let ((data (match-data))
1121 (tag)
1122 (type (cond ((string= match-type "D") 'date)
1123 ((string= match-type "T")
1124 (if (vc-cvs-valid-symbolic-tag-name-p match-tag)
1125 'symbolic-name
1126 'revision-number))
1127 (t nil))))
1128 (unwind-protect
1129 (progn
1130 (cond
1131 ;; Sticky Date tag. Convert to a proper date value (`encode-time')
1132 ((eq type 'date)
1133 (string-match
1134 "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)"
1135 match-tag)
1136 (let* ((year-tmp (string-to-number (match-string 1 match-tag)))
1137 (month (string-to-number (match-string 2 match-tag)))
1138 (day (string-to-number (match-string 3 match-tag)))
1139 (hour (string-to-number (match-string 4 match-tag)))
1140 (min (string-to-number (match-string 5 match-tag)))
1141 (sec (string-to-number (match-string 6 match-tag)))
1142 ;; Years 0..68 are 2000..2068.
1143 ;; Years 69..99 are 1969..1999.
1144 (year (+ (cond ((> 69 year-tmp) 2000)
1145 ((> 100 year-tmp) 1900)
1146 (t 0))
1147 year-tmp)))
1148 (setq tag (encode-time sec min hour day month year))))
1149 ;; Sticky Tag name or revision number
1150 ((eq type 'symbolic-name) (setq tag match-tag))
1151 ((eq type 'revision-number) (setq tag match-tag))
1152 ;; Default is no sticky tag at all
1153 (t nil))
1154 (cond ((eq vc-cvs-sticky-tag-display nil) nil)
1155 ((eq vc-cvs-sticky-tag-display t)
1156 (cond ((eq type 'date) (format-time-string
1157 vc-cvs-sticky-date-format-string
1158 tag))
1159 ((eq type 'symbolic-name) tag)
1160 ((eq type 'revision-number) tag)
1161 (t nil)))
1162 ((functionp vc-cvs-sticky-tag-display)
1163 (funcall vc-cvs-sticky-tag-display tag type))
1164 (t nil)))
1166 (set-match-data data))))
1168 (defun vc-cvs-parse-entry (file &optional set-state)
1169 "Parse a line from CVS/Entries.
1170 Compare modification time to that of the FILE, set file properties
1171 accordingly. However, `vc-state' is set only if optional arg SET-STATE
1172 is non-nil."
1173 (cond
1174 ;; entry for a "locally added" file (not yet committed)
1175 ((looking-at "/[^/]+/0/")
1176 (vc-file-setprop file 'vc-checkout-time 0)
1177 (vc-file-setprop file 'vc-working-revision "0")
1178 (if set-state (vc-file-setprop file 'vc-state 'added)))
1179 ;; normal entry
1180 ((looking-at
1181 (concat "/[^/]+"
1182 ;; revision
1183 "/\\([^/]*\\)"
1184 ;; timestamp and optional conflict field
1185 "/\\([^/]*\\)/"
1186 ;; options
1187 "\\([^/]*\\)/"
1188 ;; sticky tag
1189 "\\(.\\|\\)" ;Sticky tag type (date or tag name, could be empty)
1190 "\\(.*\\)")) ;Sticky tag
1191 (vc-file-setprop file 'vc-working-revision (match-string 1))
1192 (vc-file-setprop file 'vc-cvs-sticky-tag
1193 (vc-cvs-parse-sticky-tag (match-string 4)
1194 (match-string 5)))
1195 ;; Compare checkout time and modification time.
1196 ;; This is intentionally different from the algorithm that CVS uses
1197 ;; (which is based on textual comparison), because there can be problems
1198 ;; generating a time string that looks exactly like the one from CVS.
1199 (let* ((time (match-string 2))
1200 (mtime (nth 5 (file-attributes file)))
1201 (parsed-time (progn (require 'parse-time)
1202 (parse-time-string (concat time " +0000")))))
1203 (cond ((and (not (string-match "\\+" time))
1204 (car parsed-time)
1205 ;; Compare just the seconds part of the file time,
1206 ;; since CVS file time stamp resolution is just 1 second.
1207 (let ((ptime (apply 'encode-time parsed-time)))
1208 (and (eq (car mtime) (car ptime))
1209 (eq (cadr mtime) (cadr ptime)))))
1210 (vc-file-setprop file 'vc-checkout-time mtime)
1211 (if set-state (vc-file-setprop file 'vc-state 'up-to-date)))
1213 (vc-file-setprop file 'vc-checkout-time 0)
1214 (if set-state (vc-file-setprop file 'vc-state 'edited))))))))
1216 ;; Completion of revision names.
1217 ;; Just so I don't feel like I'm duplicating code from pcl-cvs, I'll use
1218 ;; `cvs log' so I can list all the revision numbers rather than only
1219 ;; tag names.
1221 (defun vc-cvs-revision-table (file)
1222 (let (process-file-side-effects
1223 (default-directory (file-name-directory file))
1224 (res nil))
1225 (with-temp-buffer
1226 (vc-cvs-command t nil file "log")
1227 (goto-char (point-min))
1228 (when (re-search-forward "^symbolic names:\n" nil t)
1229 (while (looking-at "^ \\(.*\\): \\(.*\\)")
1230 (push (cons (match-string 1) (match-string 2)) res)
1231 (forward-line 1)))
1232 (while (re-search-forward "^revision \\([0-9.]+\\)" nil t)
1233 (push (match-string 1) res))
1234 res)))
1236 (defun vc-cvs-revision-completion-table (files)
1237 (letrec ((table (lazy-completion-table
1238 table (lambda () (vc-cvs-revision-table (car files))))))
1239 table))
1241 (defun vc-cvs-find-admin-dir (file)
1242 "Return the administrative directory of FILE."
1243 (vc-find-root file "CVS"))
1245 (defun vc-cvs-ignore (file &optional _directory _remove)
1246 "Ignore FILE under CVS."
1247 (vc-cvs-append-to-ignore (file-name-directory file) file))
1249 (defun vc-cvs-append-to-ignore (dir str &optional old-dir)
1250 "In DIR, add STR to the .cvsignore file.
1251 If OLD-DIR is non-nil, then this is a directory that we don't want
1252 to hear about anymore."
1253 (with-current-buffer
1254 (find-file-noselect (expand-file-name ".cvsignore" dir))
1255 (when (ignore-errors
1256 (and buffer-read-only
1257 (eq 'CVS (vc-backend buffer-file-name))
1258 (not (vc-editable-p buffer-file-name))))
1259 ;; CVSREAD=on special case
1260 (vc-checkout buffer-file-name t))
1261 (goto-char (point-max))
1262 (unless (bolp) (insert "\n"))
1263 (insert str (if old-dir "/\n" "\n"))
1264 ;; FIXME this is a pcvs variable.
1265 (if (bound-and-true-p cvs-sort-ignore-file)
1266 (sort-lines nil (point-min) (point-max)))
1267 (save-buffer)))
1269 (provide 'vc-cvs)
1271 ;;; vc-cvs.el ends here