]> code.delx.au - gnu-emacs/blob - lisp/vc/vc-cvs.el
Add a couple cells to lisp-prettify-symbols-alist
[gnu-emacs] / lisp / vc / vc-cvs.el
1 ;;; vc-cvs.el --- non-resident support for CVS version-control -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 1995, 1998-2016 Free Software Foundation, Inc.
4
5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
7 ;; Package: vc
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (eval-when-compile (require 'vc))
29
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))
35
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)
39
40 ;;; Properties of the backend.
41
42 (defun vc-cvs-revision-granularity () 'file)
43
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))))))
63
64 ;;;
65 ;;; Customization options
66 ;;;
67
68 (defgroup vc-cvs nil
69 "VC CVS backend."
70 :version "24.1"
71 :group 'vc)
72
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)
82
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)
94
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)
104
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)
115
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)
121
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)
129
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.
134
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.
138
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)
157
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)
165
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.
174
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.
177
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\")))
183
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.
188
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.
199
200 See also variable `vc-cvs-sticky-date-format-string'."
201 :type '(choice boolean function)
202 :version "22.1"
203 :group 'vc-cvs)
204
205 ;;;
206 ;;; Internal variables
207 ;;;
208
209
210 ;;;
211 ;;; State-querying functions
212 ;;;
213
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)))
220
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)
236 t)
237 (t nil))))
238 nil)))
239
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))))
254
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))))
266
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))
274
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)))
294
295
296 ;;;
297 ;;; State-changing functions
298 ;;;
299
300 (autoload 'vc-switches "vc")
301
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)))
319
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)))))
326
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))
337 t
338 (directory-file-name dir))))
339 (eq dir t)))
340
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"))))
367 (t
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"))))
390
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)))
400
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))
431
432 (defun vc-cvs-delete-file (file)
433 (vc-cvs-command nil 0 file "remove" "-f"))
434
435 (autoload 'vc-default-revert "vc")
436
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)))))
445
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)))
460 (t
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))
474
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
489 1)
490 (vc-file-setprop file 'vc-state 'edited)
491 ;; signal success
492 0)))
493
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!
534 (t
535 (vc-file-setprop file 'vc-state 'conflict)
536 1);; signal the error to the caller
537 )
538 (pop-to-buffer "*vc*")
539 (error "Couldn't analyze cvs update result")))
540 (message "Merging changes into %s...done" file))))
541
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)))
546
547 ;;;
548 ;;; History functions
549 ;;;
550
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))
554
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))
567
568 (defun vc-cvs-comment-history (file)
569 "Get comment history of a file."
570 (vc-call-backend 'RCS 'comment-history file))
571
572 (autoload 'vc-version-backup-file "vc")
573 (declare-function vc-coding-system-for-diff "vc" (file))
574
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
615
616 (defconst vc-cvs-annotate-first-line-re "^[0-9]")
617
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)))))
625
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)))))))
645
646 (declare-function vc-annotate-convert-time "vc-annotate" (&optional time))
647
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)))))
653
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)
691
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)))
699
700 (defun vc-cvs-previous-revision (file rev)
701 (vc-call-backend 'RCS 'previous-revision file rev))
702
703 (defun vc-cvs-next-revision (file rev)
704 (vc-call-backend 'RCS 'next-revision file rev))
705
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))
709
710 ;;;
711 ;;; Tag system
712 ;;;
713
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)))
720
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))
724
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))))))
760
761
762 ;;;
763 ;;; Miscellaneous
764 ;;;
765
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))
769
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)))
776
777
778 ;;;
779 ;;; Internal functions
780 ;;;
781
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))))
791
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)
809 'no
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))))))))))))
819
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))))))))
833
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)))
839
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))))
875 (t
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)))))
897
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))))))))
945
946 (defun vc-cvs-after-dir-status (update-function)
947 ;; Heavily inspired by vc-cvs-parse-status. AKA a quick hack.
948 ;; This needs a lot of testing.
949 (let ((status nil)
950 (status-str nil)
951 (file nil)
952 (result nil)
953 (missing nil)
954 (ignore-next nil)
955 (subdir default-directory))
956 (goto-char (point-min))
957 (while
958 ;; Look for either a file entry, an unregistered file, or a
959 ;; directory change.
960 (re-search-forward
961 "\\(^=+\n\\([^=c?\n].*\n\\|\n\\)+\\)\\|\\(\\(^?? .*\n\\)+\\)\\|\\(^cvs status: \\(Examining\\|nothing\\) .*\n\\)"
962 nil t)
963 ;; FIXME: get rid of narrowing here.
964 (narrow-to-region (match-beginning 0) (match-end 0))
965 (goto-char (point-min))
966 ;; The subdir
967 (when (looking-at "cvs status: Examining \\(.+\\)")
968 (setq subdir (expand-file-name (match-string 1))))
969 ;; Unregistered files
970 (while (looking-at "? \\(.*\\)")
971 (setq file (file-relative-name
972 (expand-file-name (match-string 1) subdir)))
973 (push (list file 'unregistered) result)
974 (forward-line 1))
975 (when (looking-at "cvs status: nothing known about")
976 ;; We asked about a non existent file. The output looks like this:
977
978 ;; cvs status: nothing known about `lisp/v.diff'
979 ;; ===================================================================
980 ;; File: no file v.diff Status: Unknown
981 ;;
982 ;; Working revision: No entry for v.diff
983 ;; Repository revision: No revision control file
984 ;;
985
986 ;; Due to narrowing in this iteration we only see the "cvs
987 ;; status:" line, so just set a flag so that we can ignore the
988 ;; file in the next iteration.
989 (setq ignore-next t))
990 ;; A file entry.
991 (when (re-search-forward "^File: \\(no file \\)?\\(.*[^ \t]\\)[ \t]+Status: \\(.*\\)" nil t)
992 (setq missing (match-string 1))
993 (setq file (file-relative-name
994 (expand-file-name (match-string 2) subdir)))
995 (setq status-str (match-string 3))
996 (setq status
997 (cond
998 ((string-match "Up-to-date" status-str) 'up-to-date)
999 ((string-match "Locally Modified" status-str) 'edited)
1000 ((string-match "Needs Merge" status-str) 'needs-merge)
1001 ((string-match "Needs \\(Checkout\\|Patch\\)" status-str)
1002 (if missing 'missing 'needs-update))
1003 ((string-match "Locally Added" status-str) 'added)
1004 ((string-match "Locally Removed" status-str) 'removed)
1005 ((string-match "File had conflicts " status-str) 'conflict)
1006 ((string-match "Unknown" status-str) 'unregistered)
1007 (t 'edited)))
1008 (if ignore-next
1009 (setq ignore-next nil)
1010 (unless (eq status 'up-to-date)
1011 (push (list file status) result))))
1012 (goto-char (point-max))
1013 (widen))
1014 (funcall update-function result))
1015 ;; Alternative implementation: use the "update" command instead of
1016 ;; the "status" command.
1017 ;; (let ((result nil)
1018 ;; (translation '((?? . unregistered)
1019 ;; (?A . added)
1020 ;; (?C . conflict)
1021 ;; (?M . edited)
1022 ;; (?P . needs-merge)
1023 ;; (?R . removed)
1024 ;; (?U . needs-update))))
1025 ;; (goto-char (point-min))
1026 ;; (while (not (eobp))
1027 ;; (if (looking-at "^[ACMPRU?] \\(.*\\)$")
1028 ;; (push (list (match-string 1)
1029 ;; (cdr (assoc (char-after) translation)))
1030 ;; result)
1031 ;; (cond
1032 ;; ((looking-at "cvs update: warning: \\(.*\\) was lost")
1033 ;; ;; Format is:
1034 ;; ;; cvs update: warning: FILENAME was lost
1035 ;; ;; U FILENAME
1036 ;; (push (list (match-string 1) 'missing) result)
1037 ;; ;; Skip the "U" line
1038 ;; (forward-line 1))
1039 ;; ((looking-at "cvs update: New directory `\\(.*\\)' -- ignored")
1040 ;; (push (list (match-string 1) 'unregistered) result))))
1041 ;; (forward-line 1))
1042 ;; (funcall update-function result)))
1043 )
1044
1045 ;; Based on vc-cvs-dir-state-heuristic from Emacs 22.
1046 ;; FIXME does not mention unregistered files.
1047 (defun vc-cvs-dir-status-heuristic (dir update-function &optional basedir)
1048 "Find the CVS state of all files in DIR, using only local information."
1049 (let (file basename status result dirlist)
1050 (with-temp-buffer
1051 (vc-cvs-get-entries dir)
1052 (goto-char (point-min))
1053 (while (not (eobp))
1054 (if (looking-at "D/\\([^/]*\\)////")
1055 (push (expand-file-name (match-string 1) dir) dirlist)
1056 ;; CVS-removed files are not taken under VC control.
1057 (when (looking-at "/\\([^/]*\\)/[^/-]")
1058 (setq basename (match-string 1)
1059 file (expand-file-name basename dir)
1060 status (or (vc-file-getprop file 'vc-state)
1061 (vc-cvs-parse-entry file t)))
1062 (unless (eq status 'up-to-date)
1063 (push (list (if basedir
1064 (file-relative-name file basedir)
1065 basename)
1066 status) result))))
1067 (forward-line 1)))
1068 (dolist (subdir dirlist)
1069 (setq result (append result
1070 (vc-cvs-dir-status-heuristic subdir nil
1071 (or basedir dir)))))
1072 (if basedir result
1073 (funcall update-function result))))
1074
1075 (defun vc-cvs-dir-status-files (dir files update-function)
1076 "Create a list of conses (file . state) for FILES in DIR.
1077 Query all files in DIR if files is nil."
1078 (let ((local (vc-cvs-stay-local-p dir)))
1079 (if (and (not files) local (not (eq local 'only-file)))
1080 (vc-cvs-dir-status-heuristic dir update-function)
1081 (if (not files) (setq files (vc-expand-dirs (list dir) 'CVS)))
1082 (vc-cvs-command (current-buffer) 'async files "-f" "status")
1083 ;; Alternative implementation: use the "update" command instead of
1084 ;; the "status" command.
1085 ;; (vc-cvs-command (current-buffer) 'async
1086 ;; (file-relative-name dir)
1087 ;; "-f" "-n" "update" "-d" "-P")
1088 (vc-run-delayed
1089 (vc-cvs-after-dir-status update-function)))))
1090
1091 (defun vc-cvs-file-to-string (file)
1092 "Read the content of FILE and return it as a string."
1093 (condition-case nil
1094 (with-temp-buffer
1095 (insert-file-contents file)
1096 (goto-char (point-min))
1097 (buffer-substring (point) (point-max)))
1098 (file-error nil)))
1099
1100 (defun vc-cvs-dir-extra-headers (_dir)
1101 "Extract and represent per-directory properties of a CVS working copy."
1102 (let ((repo
1103 (condition-case nil
1104 (with-temp-buffer
1105 (insert-file-contents "CVS/Root")
1106 (goto-char (point-min))
1107 (and (looking-at ":ext:") (delete-char 5))
1108 (concat (buffer-substring (point) (1- (point-max))) "\n"))
1109 (file-error nil)))
1110 (module
1111 (condition-case nil
1112 (with-temp-buffer
1113 (insert-file-contents "CVS/Repository")
1114 (goto-char (point-min))
1115 (skip-chars-forward "^\n")
1116 (concat (buffer-substring (point-min) (point)) "\n"))
1117 (file-error nil))))
1118 (concat
1119 (cond (repo
1120 (concat (propertize "Repository : " 'face 'font-lock-type-face)
1121 (propertize repo 'face 'font-lock-variable-name-face)))
1122 (t ""))
1123 (cond (module
1124 (concat (propertize "Module : " 'face 'font-lock-type-face)
1125 (propertize module 'face 'font-lock-variable-name-face)))
1126 (t ""))
1127 (if (file-readable-p "CVS/Tag")
1128 (let ((tag (vc-cvs-file-to-string "CVS/Tag")))
1129 (cond
1130 ((string-match "\\`T" tag)
1131 (concat (propertize "Tag : " 'face 'font-lock-type-face)
1132 (propertize (substring tag 1)
1133 'face 'font-lock-variable-name-face)))
1134 ((string-match "\\`D" tag)
1135 (concat (propertize "Date : " 'face 'font-lock-type-face)
1136 (propertize (substring tag 1)
1137 'face 'font-lock-variable-name-face)))
1138 (t ""))))
1139
1140 ;; In CVS, branch is a per-file property, not a per-directory property.
1141 ;; We can't really do this here without making dangerous assumptions.
1142 ;;(propertize "Branch: " 'face 'font-lock-type-face)
1143 ;;(propertize "ADD CODE TO PRINT THE BRANCH NAME\n"
1144 ;; 'face 'font-lock-warning-face)
1145 )))
1146
1147 (defun vc-cvs-get-entries (dir)
1148 "Insert the CVS/Entries file from below DIR into the current buffer.
1149 This function ensures that the correct coding system is used for that,
1150 which may not be the one that is used for the files' contents.
1151 CVS/Entries should only be accessed through this function."
1152 (let ((coding-system-for-read (or file-name-coding-system
1153 default-file-name-coding-system)))
1154 (vc-insert-file (expand-file-name "CVS/Entries" dir))))
1155
1156 (defun vc-cvs-valid-symbolic-tag-name-p (tag)
1157 "Return non-nil if TAG is a valid symbolic tag name."
1158 ;; According to the CVS manual, a valid symbolic tag must start with
1159 ;; an uppercase or lowercase letter and can contain uppercase and
1160 ;; lowercase letters, digits, `-', and `_'.
1161 (and (string-match "^[a-zA-Z]" tag)
1162 (not (string-match "[^a-z0-9A-Z-_]" tag))))
1163
1164 (defun vc-cvs-valid-revision-number-p (tag)
1165 "Return non-nil if TAG is a valid revision number."
1166 (and (string-match "^[0-9]" tag)
1167 (not (string-match "[^0-9.]" tag))))
1168
1169 (defun vc-cvs-parse-sticky-tag (match-type match-tag)
1170 "Parse and return the sticky tag as a string.
1171 `match-data' is protected."
1172 (let ((data (match-data))
1173 (tag)
1174 (type (cond ((string= match-type "D") 'date)
1175 ((string= match-type "T")
1176 (if (vc-cvs-valid-symbolic-tag-name-p match-tag)
1177 'symbolic-name
1178 'revision-number))
1179 (t nil))))
1180 (unwind-protect
1181 (progn
1182 (cond
1183 ;; Sticky Date tag. Convert to a proper date value (`encode-time')
1184 ((eq type 'date)
1185 (string-match
1186 "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)"
1187 match-tag)
1188 (let* ((year-tmp (string-to-number (match-string 1 match-tag)))
1189 (month (string-to-number (match-string 2 match-tag)))
1190 (day (string-to-number (match-string 3 match-tag)))
1191 (hour (string-to-number (match-string 4 match-tag)))
1192 (min (string-to-number (match-string 5 match-tag)))
1193 (sec (string-to-number (match-string 6 match-tag)))
1194 ;; Years 0..68 are 2000..2068.
1195 ;; Years 69..99 are 1969..1999.
1196 (year (+ (cond ((> 69 year-tmp) 2000)
1197 ((> 100 year-tmp) 1900)
1198 (t 0))
1199 year-tmp)))
1200 (setq tag (encode-time sec min hour day month year))))
1201 ;; Sticky Tag name or revision number
1202 ((eq type 'symbolic-name) (setq tag match-tag))
1203 ((eq type 'revision-number) (setq tag match-tag))
1204 ;; Default is no sticky tag at all
1205 (t nil))
1206 (cond ((eq vc-cvs-sticky-tag-display nil) nil)
1207 ((eq vc-cvs-sticky-tag-display t)
1208 (cond ((eq type 'date) (format-time-string
1209 vc-cvs-sticky-date-format-string
1210 tag))
1211 ((eq type 'symbolic-name) tag)
1212 ((eq type 'revision-number) tag)
1213 (t nil)))
1214 ((functionp vc-cvs-sticky-tag-display)
1215 (funcall vc-cvs-sticky-tag-display tag type))
1216 (t nil)))
1217
1218 (set-match-data data))))
1219
1220 (defun vc-cvs-parse-entry (file &optional set-state)
1221 "Parse a line from CVS/Entries.
1222 Compare modification time to that of the FILE, set file properties
1223 accordingly. However, `vc-state' is set only if optional arg SET-STATE
1224 is non-nil."
1225 (cond
1226 ;; entry for a "locally added" file (not yet committed)
1227 ((looking-at "/[^/]+/0/")
1228 (vc-file-setprop file 'vc-checkout-time 0)
1229 (vc-file-setprop file 'vc-working-revision "0")
1230 (if set-state (vc-file-setprop file 'vc-state 'added)))
1231 ;; normal entry
1232 ((looking-at
1233 (concat "/[^/]+"
1234 ;; revision
1235 "/\\([^/]*\\)"
1236 ;; timestamp and optional conflict field
1237 "/\\([^/]*\\)/"
1238 ;; options
1239 "\\([^/]*\\)/"
1240 ;; sticky tag
1241 "\\(.\\|\\)" ;Sticky tag type (date or tag name, could be empty)
1242 "\\(.*\\)")) ;Sticky tag
1243 (vc-file-setprop file 'vc-working-revision (match-string 1))
1244 (vc-file-setprop file 'vc-cvs-sticky-tag
1245 (vc-cvs-parse-sticky-tag (match-string 4)
1246 (match-string 5)))
1247 ;; Compare checkout time and modification time.
1248 ;; This is intentionally different from the algorithm that CVS uses
1249 ;; (which is based on textual comparison), because there can be problems
1250 ;; generating a time string that looks exactly like the one from CVS.
1251 (let* ((time (match-string 2))
1252 (mtime (nth 5 (file-attributes file)))
1253 (parsed-time (progn (require 'parse-time)
1254 (parse-time-string (concat time " +0000")))))
1255 (cond ((and (not (string-match "\\+" time))
1256 (car parsed-time)
1257 ;; Compare just the seconds part of the file time,
1258 ;; since CVS file time stamp resolution is just 1 second.
1259 (let ((ptime (apply 'encode-time parsed-time)))
1260 (and (eq (car mtime) (car ptime))
1261 (eq (cadr mtime) (cadr ptime)))))
1262 (vc-file-setprop file 'vc-checkout-time mtime)
1263 (if set-state (vc-file-setprop file 'vc-state 'up-to-date)))
1264 (t
1265 (vc-file-setprop file 'vc-checkout-time 0)
1266 (if set-state (vc-file-setprop file 'vc-state 'edited))))))))
1267
1268 ;; Completion of revision names.
1269 ;; Just so I don't feel like I'm duplicating code from pcl-cvs, I'll use
1270 ;; `cvs log' so I can list all the revision numbers rather than only
1271 ;; tag names.
1272
1273 (defun vc-cvs-revision-table (file)
1274 (let (process-file-side-effects
1275 (default-directory (file-name-directory file))
1276 (res nil))
1277 (with-temp-buffer
1278 (vc-cvs-command t nil file "log")
1279 (goto-char (point-min))
1280 (when (re-search-forward "^symbolic names:\n" nil t)
1281 (while (looking-at "^ \\(.*\\): \\(.*\\)")
1282 (push (cons (match-string 1) (match-string 2)) res)
1283 (forward-line 1)))
1284 (while (re-search-forward "^revision \\([0-9.]+\\)" nil t)
1285 (push (match-string 1) res))
1286 res)))
1287
1288 (defun vc-cvs-revision-completion-table (files)
1289 (letrec ((table (lazy-completion-table
1290 table (lambda () (vc-cvs-revision-table (car files))))))
1291 table))
1292
1293 (defun vc-cvs-find-admin-dir (file)
1294 "Return the administrative directory of FILE."
1295 (vc-find-root file "CVS"))
1296
1297 (defun vc-cvs-ignore (file &optional _directory _remove)
1298 "Ignore FILE under CVS."
1299 (vc-cvs-append-to-ignore (file-name-directory file) file))
1300
1301 (defun vc-cvs-append-to-ignore (dir str &optional old-dir)
1302 "In DIR, add STR to the .cvsignore file.
1303 If OLD-DIR is non-nil, then this is a directory that we don't want
1304 to hear about anymore."
1305 (with-current-buffer
1306 (find-file-noselect (expand-file-name ".cvsignore" dir))
1307 (when (ignore-errors
1308 (and buffer-read-only
1309 (eq 'CVS (vc-backend buffer-file-name))
1310 (not (vc-editable-p buffer-file-name))))
1311 ;; CVSREAD=on special case
1312 (vc-checkout buffer-file-name t))
1313 (goto-char (point-max))
1314 (unless (bolp) (insert "\n"))
1315 (insert str (if old-dir "/\n" "\n"))
1316 ;; FIXME this is a pcvs variable.
1317 (if (bound-and-true-p cvs-sort-ignore-file)
1318 (sort-lines nil (point-min) (point-max)))
1319 (save-buffer)))
1320
1321 (provide 'vc-cvs)
1322
1323 ;;; vc-cvs.el ends here