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