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