1 ;;; vc-cvs.el --- non-resident support for CVS version-control
3 ;; Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: FSF (see vc.el for full credits)
7 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 3, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
32 (eval-when-compile (require 'cl
) (require 'vc
))
34 ;; Clear up the cache to force vc-call to check again and discover
35 ;; new functions when we reload this file.
36 (put 'CVS
'vc-functions nil
)
39 ;;; Customization options
42 (defcustom vc-cvs-global-switches nil
43 "*Global switches to pass to any CVS command."
44 :type
'(choice (const :tag
"None" nil
)
45 (string :tag
"Argument String")
46 (repeat :tag
"Argument List"
52 (defcustom vc-cvs-register-switches nil
53 "*Extra switches for registering a file into CVS.
54 A string or list of strings passed to the checkin program by
56 :type
'(choice (const :tag
"None" nil
)
57 (string :tag
"Argument String")
58 (repeat :tag
"Argument List"
64 (defcustom vc-cvs-diff-switches nil
65 "*A string or list of strings specifying extra switches for cvs diff under VC."
66 :type
'(choice (const :tag
"None" nil
)
67 (string :tag
"Argument String")
68 (repeat :tag
"Argument List"
74 (defcustom vc-cvs-header
(or (cdr (assoc 'CVS vc-header-alist
)) '("\$Id\$"))
75 "*Header keywords to be inserted by `vc-insert-headers'."
77 :type
'(repeat string
)
80 (defcustom vc-cvs-use-edit t
81 "*Non-nil means to use `cvs edit' to \"check out\" a file.
82 This is only meaningful if you don't use the implicit checkout model
83 \(i.e. if you have $CVSREAD set)."
88 (defcustom vc-cvs-stay-local t
89 "*Non-nil means use local operations when possible for remote repositories.
90 This avoids slow queries over the network and instead uses heuristics
91 and past information to determine the current status of a file.
93 The value can also be a regular expression or list of regular
94 expressions to match against the host name of a repository; then VC
95 only stays local for hosts that match it. Alternatively, the value
96 can be a list of regular expressions where the first element is the
97 symbol `except'; then VC always stays local except for hosts matched
98 by these regular expressions."
99 :type
'(choice (const :tag
"Always stay local" t
)
100 (const :tag
"Don't stay local" nil
)
101 (list :format
"\nExamine hostname and %v" :tag
"Examine hostname ..."
102 (set :format
"%v" :inline t
(const :format
"%t" :tag
"don't" except
))
103 (regexp :format
" stay local,\n%t: %v" :tag
"if it matches")
104 (repeat :format
"%v%i\n" :inline t
(regexp :tag
"or"))))
108 (defcustom vc-cvs-sticky-date-format-string
"%c"
109 "*Format string for mode-line display of sticky date.
110 Format is according to `format-time-string'. Only used if
111 `vc-cvs-sticky-tag-display' is t."
116 (defcustom vc-cvs-sticky-tag-display t
117 "*Specify the mode-line display of sticky tags.
118 Value t means default display, nil means no display at all. If the
119 value is a function or macro, it is called with the sticky tag and
120 its' type as parameters, in that order. TYPE can have three different
121 values: `symbolic-name' (TAG is a string), `revision-number' (TAG is a
122 string) and `date' (TAG is a date as returned by `encode-time'). The
123 return value of the function or macro will be displayed as a string.
125 Here's an example that will display the formatted date for sticky
126 dates and the word \"Sticky\" for sticky tag names and revisions.
129 (cond ((eq type 'date) (format-time-string
130 vc-cvs-sticky-date-format-string tag))
131 ((eq type 'revision-number) \"Sticky\")
132 ((eq type 'symbolic-name) \"Sticky\")))
134 Here's an example that will abbreviate to the first character only,
135 any text before the first occurrence of `-' for sticky symbolic tags.
136 If the sticky tag is a revision number, the word \"Sticky\" is
137 displayed. Date and time is displayed for sticky dates.
140 (cond ((eq type 'date) (format-time-string \"%Y%m%d %H:%M\" tag))
141 ((eq type 'revision-number) \"Sticky\")
142 ((eq type 'symbolic-name)
145 (string-match \"\\\\([^-]*\\\\)\\\\(.*\\\\)\" tag)
146 (concat (substring (match-string 1 tag) 0 1) \":\"
147 (substring (match-string 2 tag) 1 nil)))
148 (error tag))))) ; Fall-back to given tag name.
150 See also variable `vc-cvs-sticky-date-format-string'."
151 :type
'(choice boolean function
)
156 ;;; Internal variables
161 ;;; State-querying functions
164 ;;;###autoload (defun vc-cvs-registered (f)
165 ;;;###autoload (when (file-readable-p (expand-file-name
166 ;;;###autoload "CVS/Entries" (file-name-directory f)))
167 ;;;###autoload (load "vc-cvs")
168 ;;;###autoload (vc-cvs-registered f)))
170 (defun vc-cvs-registered (file)
171 "Check if FILE is CVS registered."
172 (let ((dirname (or (file-name-directory file
) ""))
173 (basename (file-name-nondirectory file
))
174 ;; make sure that the file name is searched case-sensitively
175 (case-fold-search nil
))
176 (if (file-readable-p (expand-file-name "CVS/Entries" dirname
))
178 (vc-cvs-get-entries dirname
)
179 (goto-char (point-min))
182 ;; CVS-removed files are not taken under VC control.
183 (concat "^/" (regexp-quote basename
) "/[^/-]") nil t
)
185 (vc-cvs-parse-entry file
)
190 (defun vc-cvs-state (file)
191 "CVS-specific version of `vc-state'."
192 (if (vc-stay-local-p file
)
193 (let ((state (vc-file-getprop file
'vc-state
)))
194 ;; If we should stay local, use the heuristic but only if
195 ;; we don't have a more precise state already available.
196 (if (memq state
'(up-to-date edited nil
))
197 (vc-cvs-state-heuristic file
)
200 (cd (file-name-directory file
))
201 (vc-cvs-command t
0 file
"status")
202 (vc-cvs-parse-status t
))))
204 (defun vc-cvs-state-heuristic (file)
205 "CVS-specific state heuristic."
206 ;; If the file has not changed since checkout, consider it `up-to-date'.
207 ;; Otherwise consider it `edited'.
208 (let ((checkout-time (vc-file-getprop file
'vc-checkout-time
))
209 (lastmod (nth 5 (file-attributes file
))))
211 ((equal checkout-time lastmod
) 'up-to-date
)
212 ((string= (vc-working-revision file
) "0") 'added
)
215 (defun vc-cvs-dir-state (dir)
216 "Find the CVS state of all files in DIR and subdirectories."
217 ;; if DIR is not under CVS control, don't do anything.
218 (when (file-readable-p (expand-file-name "CVS/Entries" dir
))
219 (if (vc-stay-local-p dir
)
220 (vc-cvs-dir-state-heuristic dir
)
221 (let ((default-directory dir
))
222 ;; Don't specify DIR in this command, the default-directory is
223 ;; enough. Otherwise it might fail with remote repositories.
225 (buffer-disable-undo) ;; Because these buffers can get huge
226 (vc-cvs-command t
0 nil
"status")
227 (goto-char (point-min))
228 (while (re-search-forward "^=+\n\\([^=\n].*\n\\|\n\\)+" nil t
)
229 (narrow-to-region (match-beginning 0) (match-end 0))
230 (vc-cvs-parse-status)
231 (goto-char (point-max))
234 (defun vc-cvs-working-revision (file)
235 "CVS-specific version of `vc-working-revision'."
236 ;; There is no need to consult RCS headers under CVS, because we
237 ;; get the workfile version for free when we recognize that a file
238 ;; is registered in CVS.
239 (vc-cvs-registered file
)
240 (vc-file-getprop file
'vc-working-revision
))
242 (defun vc-cvs-checkout-model (file)
243 "CVS-specific version of `vc-checkout-model'."
244 (if (getenv "CVSREAD")
246 (let ((attrib (file-attributes file
)))
247 (if (and attrib
;; don't check further if FILE doesn't exist
248 ;; If the file is not writable (despite CVSREAD being
249 ;; undefined), this is probably because the file is being
250 ;; "watched" by other developers.
251 ;; (If vc-mistrust-permissions was t, we actually shouldn't
252 ;; trust this, but there is no other way to learn this from CVS
253 ;; at the moment (version 1.9).)
254 (string-match "r-..-..-." (nth 8 attrib
)))
258 (defun vc-cvs-mode-line-string (file)
259 "Return string for placement into the modeline 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
))
266 (let ((def-ml (vc-default-mode-line-string 'CVS file
)))
268 (get-text-property 0 'help-echo def-ml
))
271 (if (zerop (length sticky-tag
))
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 (defun vc-cvs-register (files &optional rev comment
)
284 "Register FILES into the CVS version-control system.
285 COMMENT can be used to provide an initial description of FILES.
287 `vc-register-switches' and `vc-cvs-register-switches' are passed to
288 the CVS command (in that order)."
289 ;; Register the directories if needed.
292 (and (not (vc-cvs-responsible-p file
))
293 (vc-cvs-could-register file
)
294 (push (directory-file-name (file-name-directory file
)) dirs
)))
295 (if dirs
(vc-cvs-register dirs
)))
296 (apply 'vc-cvs-command nil
0 files
298 (and comment
(string-match "[^\t\n ]" comment
)
299 (concat "-m" comment
))
300 (vc-switches 'CVS
'register
)))
302 (defun vc-cvs-responsible-p (file)
303 "Return non-nil if CVS thinks it is responsible for FILE."
304 (file-directory-p (expand-file-name "CVS"
305 (if (file-directory-p file
)
307 (file-name-directory file
)))))
309 (defun vc-cvs-could-register (file)
310 "Return non-nil if FILE could be registered in CVS.
311 This is only possible if CVS is managing FILE's directory or one of
314 (while (and (stringp dir
)
315 (not (equal dir
(setq dir
(file-name-directory dir
))))
317 (setq dir
(if (file-directory-p
318 (expand-file-name "CVS/Entries" dir
))
319 t
(directory-file-name dir
))))
322 (defun vc-cvs-checkin (files rev comment
)
323 "CVS-specific version of `vc-backend-checkin'."
324 (unless (or (not rev
) (vc-cvs-valid-revision-number-p rev
))
325 (if (not (vc-cvs-valid-symbolic-tag-name-p rev
))
326 (error "%s is not a valid symbolic tag name" rev
)
327 ;; If the input revison is a valid symbolic tag name, we create it
328 ;; as a branch, commit and switch to it.
329 (apply 'vc-cvs-command nil
0 files
"tag" "-b" (list rev
))
330 (apply 'vc-cvs-command nil
0 files
"update" "-r" (list rev
))
331 (mapc (lambda (file) (vc-file-setprop file
'vc-cvs-sticky-tag rev
))
333 (let ((status (apply 'vc-cvs-command nil
1 files
334 "ci" (if rev
(concat "-r" rev
))
335 (concat "-m" comment
)
336 (vc-switches 'CVS
'checkin
))))
338 (goto-char (point-min))
339 (when (not (zerop status
))
340 ;; Check checkin problem.
342 ((re-search-forward "Up-to-date check failed" nil t
)
343 (mapc (lambda (file) (vc-file-setprop file
'vc-state
'needs-merge
))
345 (error "%s" (substitute-command-keys
346 (concat "Up-to-date check failed: "
347 "type \\[vc-next-action] to merge in changes"))))
349 (pop-to-buffer (current-buffer))
350 (goto-char (point-min))
351 (shrink-window-if-larger-than-buffer)
352 (error "Check-in failed"))))
353 ;; Single-file commit? Then update the revision by parsing the buffer.
354 ;; Otherwise we can't necessarily tell what goes with what; clear
355 ;; its properties so they have to be refetched.
356 (if (= (length files
) 1)
358 (car files
) 'vc-working-revision
359 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
360 (mapc (lambda (file) (vc-file-clearprops file
)) files
))
361 ;; Anyway, forget the checkout model of the file, because we might have
362 ;; guessed wrong when we found the file. After commit, we can
363 ;; tell it from the permissions of the file (see
364 ;; vc-cvs-checkout-model).
365 (mapc (lambda (file) (vc-file-setprop file
'vc-checkout-model nil
))
368 ;; if this was an explicit check-in (does not include creation of
369 ;; a branch), remove the sticky tag.
370 (if (and rev
(not (vc-cvs-valid-symbolic-tag-name-p rev
)))
371 (vc-cvs-command nil
0 files
"update" "-A"))))
373 (defun vc-cvs-find-revision (file rev buffer
)
374 (apply 'vc-cvs-command
376 "-Q" ; suppress diagnostic output
378 (and rev
(not (string= rev
""))
381 (vc-switches 'CVS
'checkout
)))
383 (defun vc-cvs-checkout (file &optional editable rev
)
384 "Checkout a revision of FILE into the working area.
385 EDITABLE non-nil means that the file should be writable.
386 REV is the revision to check out."
387 (message "Checking out %s..." file
)
388 ;; Change buffers to get local value of vc-checkout-switches.
389 (with-current-buffer (or (get-file-buffer file
) (current-buffer))
390 (if (and (file-exists-p file
) (not rev
))
391 ;; If no revision was specified, just make the file writable
392 ;; if necessary (using `cvs-edit' if requested).
393 (and editable
(not (eq (vc-cvs-checkout-model file
) 'implicit
))
395 (vc-cvs-command nil
0 file
"edit")
396 (set-file-modes file
(logior (file-modes file
) 128))
397 (if (equal file buffer-file-name
) (toggle-read-only -
1))))
398 ;; Check out a particular revision (or recreate the file).
399 (vc-file-setprop file
'vc-working-revision nil
)
400 (apply 'vc-cvs-command nil
0 file
405 ;; default for verbose checkout: clear the
406 ;; sticky tag so that the actual update will
407 ;; get the head of the trunk
411 (vc-switches 'CVS
'checkout
)))
413 (message "Checking out %s...done" file
))
415 (defun vc-cvs-delete-file (file)
416 (vc-cvs-command nil
0 file
"remove" "-f")
417 (vc-cvs-command nil
0 file
"commit" "-mRemoved."))
419 (defun vc-cvs-revert (file &optional contents-done
)
420 "Revert FILE to the working revision on which it was based."
421 (vc-default-revert 'CVS file contents-done
)
422 (unless (eq (vc-checkout-model file
) 'implicit
)
424 (vc-cvs-command nil
0 file
"unedit")
425 ;; Make the file read-only by switching off all w-bits
426 (set-file-modes file
(logand (file-modes file
) 3950)))))
428 (defun vc-cvs-merge (file first-revision
&optional second-revision
)
429 "Merge changes into current working copy of FILE.
430 The changes are between FIRST-REVISION and SECOND-REVISION."
431 (vc-cvs-command nil
0 file
433 (concat "-j" first-revision
)
434 (concat "-j" second-revision
))
435 (vc-file-setprop file
'vc-state
'edited
)
436 (with-current-buffer (get-buffer "*vc*")
437 (goto-char (point-min))
438 (if (re-search-forward "conflicts during merge" nil t
)
440 0))) ; signal success
442 (defun vc-cvs-merge-news (file)
443 "Merge in any new changes made to FILE."
444 (message "Merging changes into %s..." file
)
445 ;; (vc-file-setprop file 'vc-working-revision nil)
446 (vc-file-setprop file
'vc-checkout-time
0)
447 (vc-cvs-command nil nil file
"update")
448 ;; Analyze the merge result reported by CVS, and set
449 ;; file properties accordingly.
450 (with-current-buffer (get-buffer "*vc*")
451 (goto-char (point-min))
452 ;; get new working revision
453 (if (re-search-forward
454 "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t
)
455 (vc-file-setprop file
'vc-working-revision
(match-string 1))
456 (vc-file-setprop file
'vc-working-revision nil
))
459 (if (eq (buffer-size) 0)
460 0 ;; there were no news; indicate success
461 (if (re-search-forward
462 (concat "^\\([CMUP] \\)?"
463 (regexp-quote (file-name-nondirectory file
))
464 "\\( already contains the differences between \\)?")
467 ;; Merge successful, we are in sync with repository now
468 ((or (match-string 2)
469 (string= (match-string 1) "U ")
470 (string= (match-string 1) "P "))
471 (vc-file-setprop file
'vc-state
'up-to-date
)
472 (vc-file-setprop file
'vc-checkout-time
473 (nth 5 (file-attributes file
)))
474 0);; indicate success to the caller
475 ;; Merge successful, but our own changes are still in the file
476 ((string= (match-string 1) "M ")
477 (vc-file-setprop file
'vc-state
'edited
)
478 0);; indicate success to the caller
479 ;; Conflicts detected!
481 (vc-file-setprop file
'vc-state
'edited
)
482 1);; signal the error to the caller
484 (pop-to-buffer "*vc*")
485 (error "Couldn't analyze cvs update result")))
486 (message "Merging changes into %s...done" file
))))
488 (defun vc-cvs-modify-change-comment (files rev comment
)
489 "Modify the change comments for FILES on a specified REV.
490 Will fail unless you have administrative privileges on the repo."
491 (vc-cvs-command nil
0 files
"rcs" (concat "-m" comment
":" rev
)))
494 ;;; History functions
497 (defun vc-cvs-print-log (files &optional buffer
)
498 "Get change logs associated with FILES."
499 ;; It's just the catenation of the individual logs.
502 (if (vc-stay-local-p files
) 'async
0)
505 (defun vc-cvs-wash-log ()
506 "Remove all non-comment information from log output."
507 (vc-call-backend 'RCS
'wash-log
)
510 (defun vc-cvs-diff (files &optional oldvers newvers buffer
)
511 "Get a difference report using CVS between two revisions of FILE."
512 (let* ((async (and (not vc-disable-async-diff
)
513 (vc-stay-local-p files
)))
514 (invoke-cvs-diff-list nil
)
516 ;; Look through the file list and see if any files have backups
517 ;; that can be used to do a plain "diff" instead of "cvs diff".
521 (when (or (not ov
) (string-equal ov
""))
522 (setq ov
(vc-working-revision file
)))
523 (when (string-equal nv
"")
525 (let ((file-oldvers (vc-version-backup-file file ov
))
526 (file-newvers (if (not nv
)
528 (vc-version-backup-file file nv
)))
529 (coding-system-for-read (vc-coding-system-for-diff file
)))
530 (if (and file-oldvers file-newvers
)
532 (apply 'vc-do-command
(or buffer
"*vc-diff*") 1 "diff" nil
533 (append (if (listp diff-switches
)
535 (list diff-switches
))
536 (if (listp vc-diff-switches
)
538 (list vc-diff-switches
))
539 (list (file-relative-name file-oldvers
)
540 (file-relative-name file-newvers
))))
542 (push file invoke-cvs-diff-list
)))))
543 (when invoke-cvs-diff-list
544 (setq status
(apply 'vc-cvs-command
(or buffer
"*vc-diff*")
546 invoke-cvs-diff-list
"diff"
547 (and oldvers
(concat "-r" oldvers
))
548 (and newvers
(concat "-r" newvers
))
549 (vc-switches 'CVS
'diff
))))
550 (if async
1 status
))) ; async diff, pessimistic assumption
553 (defun vc-cvs-diff-tree (dir &optional rev1 rev2
)
554 "Diff all files at and below DIR."
555 (with-current-buffer "*vc-diff*"
556 (setq default-directory dir
)
557 (if (vc-stay-local-p dir
)
558 ;; local diff: do it filewise, and only for files that are modified
563 `(let ((coding-system-for-read (vc-coding-system-for-diff ',f
)))
564 ;; possible optimization: fetch the state of all files
565 ;; in the tree via vc-cvs-dir-state-heuristic
566 (unless (vc-up-to-date-p ',f
)
567 (message "Looking at %s" ',f
)
568 (vc-diff-internal ',f
',rev1
',rev2
))))))
569 ;; cvs diff: use a single call for the entire tree
570 (let ((coding-system-for-read
571 (or coding-system-for-read
'undecided
)))
572 (apply 'vc-cvs-command
"*vc-diff*" 1 nil
"diff"
573 (and rev1
(concat "-r" rev1
))
574 (and rev2
(concat "-r" rev2
))
575 (vc-switches 'CVS
'diff
))))))
577 (defconst vc-cvs-annotate-first-line-re
"^[0-9]")
579 (defun vc-cvs-annotate-process-filter (process string
)
580 (setq string
(concat (process-get process
'output
) string
))
581 (if (not (string-match vc-cvs-annotate-first-line-re string
))
582 ;; Still waiting for the first real line.
583 (process-put process
'output string
)
584 (let ((vc-filter (process-get process
'vc-filter
)))
585 (set-process-filter process vc-filter
)
586 (funcall vc-filter process
(substring string
(match-beginning 0))))))
588 (defun vc-cvs-annotate-command (file buffer
&optional revision
)
589 "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER.
590 Optional arg REVISION is a revision to annotate from."
591 (vc-cvs-command buffer
592 (if (vc-stay-local-p file
)
595 (if revision
(concat "-r" revision
)))
596 ;; Strip the leading few lines.
597 (let ((proc (get-buffer-process buffer
)))
599 ;; If running asynchronously, use a process filter.
601 (process-put proc
'vc-filter
(process-filter proc
))
602 (set-process-filter proc
'vc-cvs-annotate-process-filter
))
603 (with-current-buffer buffer
604 (goto-char (point-min))
605 (re-search-forward vc-cvs-annotate-first-line-re
)
606 (delete-region (point-min) (1- (point)))))))
608 (defun vc-cvs-annotate-current-time ()
609 "Return the current time, based at midnight of the current day, and
610 encoded as fractional days."
611 (vc-annotate-convert-time
612 (apply 'encode-time
0 0 0 (nthcdr 3 (decode-time (current-time))))))
614 (defun vc-cvs-annotate-time ()
615 "Return the time of the next annotation (as fraction of days)
616 systime, or nil if there is none."
618 (cache (get-text-property bol
'vc-cvs-annotate-time
))
619 (inhibit-read-only t
)
620 (inhibit-modification-hooks t
))
624 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): ")
625 (let ((day (string-to-number (match-string 1)))
626 (month (cdr (assq (intern (match-string 2))
627 '((Jan .
1) (Feb .
2) (Mar .
3)
628 (Apr .
4) (May .
5) (Jun .
6)
629 (Jul .
7) (Aug .
8) (Sep .
9)
630 (Oct .
10) (Nov .
11) (Dec .
12)))))
631 (year (let ((tmp (string-to-number (match-string 3))))
632 ;; Years 0..68 are 2000..2068.
633 ;; Years 69..99 are 1969..1999.
634 (+ (cond ((> 69 tmp
) 2000)
639 bol
(1+ bol
) 'vc-cvs-annotate-time
641 ;; Position at end makes for nicer overlay result.
642 ;; Don't put actual buffer pos here, but only relative
643 ;; distance, so we don't ever move backward in the
644 ;; goto-char below, even if the text is moved.
645 (- (match-end 0) (match-beginning 0))
646 (vc-annotate-convert-time
647 (encode-time 0 0 0 day month year
))))))))
649 (goto-char (+ bol
(car cache
))) ; Fontify from here to eol.
650 (cdr cache
)))) ; days (float)
652 (defun vc-cvs-annotate-extract-revision-at-line ()
655 (if (re-search-forward "^\\([0-9]+\\.[0-9]+\\(\\.[0-9]+\\)*\\) +("
656 (line-end-position) t
)
657 (match-string-no-properties 1)
664 (defun vc-cvs-create-snapshot (dir name branchp
)
665 "Assign to DIR's current revision a given NAME.
666 If BRANCHP is non-nil, the name is created as a branch (and the current
667 workspace is immediately moved to that new branch)."
668 (vc-cvs-command nil
0 dir
"tag" "-c" (if branchp
"-b") name
)
669 (when branchp
(vc-cvs-command nil
0 dir
"update" "-r" name
)))
671 (defun vc-cvs-retrieve-snapshot (dir name update
)
672 "Retrieve a snapshot at and below DIR.
673 NAME is the name of the snapshot; if it is empty, do a `cvs update'.
674 If UPDATE is non-nil, then update (resynch) any affected buffers."
675 (with-current-buffer (get-buffer-create "*vc*")
676 (let ((default-directory dir
)
679 (if (or (not name
) (string= name
""))
680 (vc-cvs-command t
0 nil
"update")
681 (vc-cvs-command t
0 nil
"update" "-r" name
)
682 (setq sticky-tag name
))
684 (goto-char (point-min))
686 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
687 (let* ((file (expand-file-name (match-string 2) dir
))
688 (state (match-string 1))
689 (buffer (find-buffer-visiting file
)))
692 ((or (string= state
"U")
694 (vc-file-setprop file
'vc-state
'up-to-date
)
695 (vc-file-setprop file
'vc-working-revision nil
)
696 (vc-file-setprop file
'vc-checkout-time
697 (nth 5 (file-attributes file
))))
698 ((or (string= state
"M")
700 (vc-file-setprop file
'vc-state
'edited
)
701 (vc-file-setprop file
'vc-working-revision nil
)
702 (vc-file-setprop file
'vc-checkout-time
0)))
703 (vc-file-setprop file
'vc-cvs-sticky-tag sticky-tag
)
704 (vc-resynch-buffer file t t
))))
705 (forward-line 1))))))
712 (defalias 'vc-cvs-make-version-backups-p
'vc-stay-local-p
713 "Return non-nil if version backups should be made for FILE.")
715 (defun vc-cvs-check-headers ()
716 "Check if the current file has any headers in it."
718 (goto-char (point-min))
719 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
720 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
724 ;;; Internal functions
727 (defun vc-cvs-root (dir)
728 (vc-find-root dir
"CVS" t
))
730 (defun vc-cvs-command (buffer okstatus files
&rest flags
)
731 "A wrapper around `vc-do-command' for use in vc-cvs.el.
732 The difference to vc-do-command is that this function always invokes `cvs',
733 and that it passes `vc-cvs-global-switches' to it before FLAGS."
734 (apply 'vc-do-command buffer okstatus
"cvs" files
735 (if (stringp vc-cvs-global-switches
)
736 (cons vc-cvs-global-switches flags
)
737 (append vc-cvs-global-switches
740 (defalias 'vc-cvs-stay-local-p
'vc-stay-local-p
) ;Back-compatibility.
742 (defun vc-cvs-repository-hostname (dirname)
743 "Hostname of the CVS server associated to workarea DIRNAME."
744 (let ((rootname (expand-file-name "CVS/Root" dirname
)))
745 (when (file-readable-p rootname
)
747 (let ((coding-system-for-read
748 (or file-name-coding-system
749 default-file-name-coding-system
)))
750 (vc-insert-file rootname
))
751 (goto-char (point-min))
752 (nth 2 (vc-cvs-parse-root
753 (buffer-substring (point)
754 (line-end-position))))))))
756 (defun vc-cvs-parse-root (root)
757 "Split CVS ROOT specification string into a list of fields.
758 A CVS root specification of the form
759 [:METHOD:][[USER@]HOSTNAME:]/path/to/repository
760 is converted to a normalized record with the following structure:
761 \(METHOD USER HOSTNAME CVS-ROOT).
762 The default METHOD for a CVS root of the form
765 The default METHOD for a CVS root of the form
766 [USER@]HOSTNAME:/path/to/repository
768 For an empty string, nil is returned (invalid CVS root)."
769 ;; Split CVS root into colon separated fields (0-4).
770 ;; The `x:' makes sure, that leading colons are not lost;
771 ;; `HOST:/PATH' is then different from `:METHOD:/PATH'.
772 (let* ((root-list (cdr (split-string (concat "x:" root
) ":")))
773 (len (length root-list
))
774 ;; All syntactic varieties will get a proper METHOD.
781 ;; Simple PATH => method `local'
783 (cons nil root-list
)))
785 ;; [USER@]HOST:PATH => method `ext'
786 (and (not (equal (car root-list
) ""))
787 (cons "ext" root-list
)))
790 (cons (cadr root-list
)
791 (cons nil
(cddr root-list
))))
793 ;; :METHOD:[USER@]HOST:PATH
796 (let ((method (car root-list
))
797 (uhost (or (cadr root-list
) ""))
798 (root (nth 2 root-list
))
801 (if (string-match "\\(.*\\)@\\(.*\\)" uhost
)
802 (setq user
(match-string 1 uhost
)
803 host
(match-string 2 uhost
))
808 ;; Fix windows style CVS root `:local:C:\\project\\cvs\\some\\dir'
810 (equal method
"local")
811 (setq root
(concat host
":" root
) host
))
812 ;; Normalize CVS root record
813 (list method user host root
)))))
815 ;; XXX: This does not work correctly for subdirectories. "cvs status"
816 ;; information is context sensitive, it contains lines like:
817 ;; cvs status: Examining DIRNAME
818 ;; and the file entries after that don't show the full path.
819 ;; Because of this vc-dired only shows changed files at the top level
821 (defun vc-cvs-parse-status (&optional full
)
822 "Parse output of \"cvs status\" command in the current buffer.
823 Set file properties accordingly. Unless FULL is t, parse only
824 essential information. Note that this can never set the 'ignored
826 (let (file status missing
)
827 (goto-char (point-min))
828 (while (looking-at "? \\(.*\\)")
829 (setq file
(expand-file-name (match-string 1)))
830 (vc-file-setprop file
'vc-state
'unregistered
)
832 (when (re-search-forward "^File: " nil t
)
833 (when (setq missing
(looking-at "no file "))
834 (goto-char (match-end 0)))
836 ((re-search-forward "\\=\\([^ \t]+\\)" nil t
)
837 (setq file
(expand-file-name (match-string 1)))
838 (vc-file-setprop file
'vc-backend
'CVS
)
839 (if (not (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t
))
840 (setq status
"Unknown")
841 (setq status
(match-string 1)))
844 "\\(RCS Version\\|RCS Revision\\|Repository revision\\):\
845 \[\t ]+\\([0-9.]+\\)"
847 (vc-file-setprop file
'vc-latest-revision
(match-string 2)))
851 ((string-match "Up-to-date" status
)
852 (vc-file-setprop file
'vc-checkout-time
853 (nth 5 (file-attributes file
)))
855 ((string-match "Locally Modified" status
) 'edited
)
856 ((string-match "Needs Merge" status
) 'needs-merge
)
857 ((string-match "Needs \\(Checkout\\|Patch\\)" status
)
858 (if missing
'missing
'needs-patch
))
859 ((string-match "Locally Added" status
) 'added
)
860 ((string-match "Locally Removed" status
) 'removed
)
863 (defun vc-cvs-dir-state-heuristic (dir)
864 "Find the CVS state of all files in DIR, using only local information."
866 (vc-cvs-get-entries dir
)
867 (goto-char (point-min))
869 ;; CVS-removed files are not taken under VC control.
870 (when (looking-at "/\\([^/]*\\)/[^/-]")
871 (let ((file (expand-file-name (match-string 1) dir
)))
872 (unless (vc-file-getprop file
'vc-state
)
873 (vc-cvs-parse-entry file t
))))
876 ;; XXX Experimental function for the vc-dired replacement.
877 (defun vc-cvs-after-dir-status (update-function status-buffer
)
878 ;; Heavily inspired by vc-cvs-parse-status. AKA a quick hack.
879 ;; It needs a lot of testing.
885 (subdir default-directory
))
886 (goto-char (point-min))
888 ;; Look for either a file entry, an unregistered file, or a
891 "\\(^=+\n\\([^=c?\n].*\n\\|\n\\)+\\)\\|\\(\\(^?? .*\n\\)+\\)\\|\\(^cvs status: Examining .*\n\\)"
893 ;; XXX: get rid of narrowing here.
894 (narrow-to-region (match-beginning 0) (match-end 0))
895 (goto-char (point-min))
897 (when (looking-at "cvs status: Examining \\(.+\\)")
898 (setq subdir
(expand-file-name (match-string 1))))
899 ;; Unregistered files
900 (while (looking-at "? \\(.*\\)")
901 (setq file
(file-relative-name
902 (expand-file-name (match-string 1) subdir
)))
903 (push (list file
'unregistered
) result
)
906 (when (re-search-forward "^File: " nil t
)
907 (when (setq missing
(looking-at "no file "))
908 (goto-char (match-end 0)))
910 ((re-search-forward "\\=\\([^ \t]+\\)" nil t
)
911 (setq file
(file-relative-name
912 (expand-file-name (match-string 1) subdir
)))
913 (if (not (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t
))
914 (push (list file
'unregistered
) result
)
915 (setq status-str
(match-string 1))
918 ((string-match "Up-to-date" status-str
) 'up-to-date
)
919 ((string-match "Locally Modified" status-str
) 'edited
)
920 ((string-match "Needs Merge" status-str
) 'needs-merge
)
921 ((string-match "Needs \\(Checkout\\|Patch\\)" status-str
)
922 (if missing
'missing
'needs-patch
))
923 ((string-match "Locally Added" status-str
) 'added
)
924 ((string-match "Locally Removed" status-str
) 'removed
)
926 (unless (eq status
'up-to-date
)
927 (push (list file status
) result
))))))
928 (goto-char (point-max))
930 (funcall update-function result status-buffer
)))
932 ;; XXX Experimental function for the vc-dired replacement.
933 (defun vc-cvs-dir-status (dir update-function status-buffer
)
934 "Create a list of conses (file . state) for DIR."
935 (vc-cvs-command (current-buffer) 'async dir
"status")
937 `(vc-cvs-after-dir-status (quote ,update-function
) ,status-buffer
)))
939 (defun vc-cvs-get-entries (dir)
940 "Insert the CVS/Entries file from below DIR into the current buffer.
941 This function ensures that the correct coding system is used for that,
942 which may not be the one that is used for the files' contents.
943 CVS/Entries should only be accessed through this function."
944 (let ((coding-system-for-read (or file-name-coding-system
945 default-file-name-coding-system
)))
946 (vc-insert-file (expand-file-name "CVS/Entries" dir
))))
948 (defun vc-cvs-valid-symbolic-tag-name-p (tag)
949 "Return non-nil if TAG is a valid symbolic tag name."
950 ;; According to the CVS manual, a valid symbolic tag must start with
951 ;; an uppercase or lowercase letter and can contain uppercase and
952 ;; lowercase letters, digits, `-', and `_'.
953 (and (string-match "^[a-zA-Z]" tag
)
954 (not (string-match "[^a-z0-9A-Z-_]" tag
))))
956 (defun vc-cvs-valid-revision-number-p (tag)
957 "Return non-nil if TAG is a valid revision number."
958 (and (string-match "^[0-9]" tag
)
959 (not (string-match "[^0-9.]" tag
))))
961 (defun vc-cvs-parse-sticky-tag (match-type match-tag
)
962 "Parse and return the sticky tag as a string.
963 `match-data' is protected."
964 (let ((data (match-data))
966 (type (cond ((string= match-type
"D") 'date
)
967 ((string= match-type
"T")
968 (if (vc-cvs-valid-symbolic-tag-name-p match-tag
)
975 ;; Sticky Date tag. Convert to a proper date value (`encode-time')
978 "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)"
980 (let* ((year-tmp (string-to-number (match-string 1 match-tag
)))
981 (month (string-to-number (match-string 2 match-tag
)))
982 (day (string-to-number (match-string 3 match-tag
)))
983 (hour (string-to-number (match-string 4 match-tag
)))
984 (min (string-to-number (match-string 5 match-tag
)))
985 (sec (string-to-number (match-string 6 match-tag
)))
986 ;; Years 0..68 are 2000..2068.
987 ;; Years 69..99 are 1969..1999.
988 (year (+ (cond ((> 69 year-tmp
) 2000)
989 ((> 100 year-tmp
) 1900)
992 (setq tag
(encode-time sec min hour day month year
))))
993 ;; Sticky Tag name or revision number
994 ((eq type
'symbolic-name
) (setq tag match-tag
))
995 ((eq type
'revision-number
) (setq tag match-tag
))
996 ;; Default is no sticky tag at all
998 (cond ((eq vc-cvs-sticky-tag-display nil
) nil
)
999 ((eq vc-cvs-sticky-tag-display t
)
1000 (cond ((eq type
'date
) (format-time-string
1001 vc-cvs-sticky-date-format-string
1003 ((eq type
'symbolic-name
) tag
)
1004 ((eq type
'revision-number
) tag
)
1006 ((functionp vc-cvs-sticky-tag-display
)
1007 (funcall vc-cvs-sticky-tag-display tag type
))
1010 (set-match-data data
))))
1012 (defun vc-cvs-parse-entry (file &optional set-state
)
1013 "Parse a line from CVS/Entries.
1014 Compare modification time to that of the FILE, set file properties
1015 accordingly. However, `vc-state' is set only if optional arg SET-STATE
1018 ;; entry for a "locally added" file (not yet committed)
1019 ((looking-at "/[^/]+/0/")
1020 (vc-file-setprop file
'vc-backend
'CVS
)
1021 (vc-file-setprop file
'vc-checkout-time
0)
1022 (vc-file-setprop file
'vc-working-revision
"0")
1023 (if set-state
(vc-file-setprop file
'vc-state
'added
)))
1029 ;; timestamp and optional conflict field
1034 "\\(.\\|\\)" ;Sticky tag type (date or tag name, could be empty)
1035 "\\(.*\\)")) ;Sticky tag
1036 (vc-file-setprop file
'vc-backend
'CVS
)
1037 (vc-file-setprop file
'vc-working-revision
(match-string 1))
1038 (vc-file-setprop file
'vc-cvs-sticky-tag
1039 (vc-cvs-parse-sticky-tag (match-string 4)
1041 ;; Compare checkout time and modification time.
1042 ;; This is intentionally different from the algorithm that CVS uses
1043 ;; (which is based on textual comparison), because there can be problems
1044 ;; generating a time string that looks exactly like the one from CVS.
1045 (let ((mtime (nth 5 (file-attributes file
))))
1046 (require 'parse-time
)
1048 (parse-time-string (concat (match-string 2) " +0000"))))
1049 (cond ((and (not (string-match "\\+" (match-string 2)))
1051 (equal mtime
(apply 'encode-time parsed-time
)))
1052 (vc-file-setprop file
'vc-checkout-time mtime
)
1053 (if set-state
(vc-file-setprop file
'vc-state
'up-to-date
)))
1055 (vc-file-setprop file
'vc-checkout-time
0)
1056 (if set-state
(vc-file-setprop file
'vc-state
'edited
)))))))))
1058 ;; Completion of revision names.
1059 ;; Just so I don't feel like I'm duplicating code from pcl-cvs, I'll use
1060 ;; `cvs log' so I can list all the revision numbers rather than only
1063 (defun vc-cvs-revision-table (file)
1064 (let ((default-directory (file-name-directory file
))
1067 (vc-cvs-command t nil file
"log")
1068 (goto-char (point-min))
1069 (when (re-search-forward "^symbolic names:\n" nil t
)
1070 (while (looking-at "^ \\(.*\\): \\(.*\\)")
1071 (push (cons (match-string 1) (match-string 2)) res
)
1073 (while (re-search-forward "^revision \\([0-9.]+\\)" nil t
)
1074 (push (match-string 1) res
))
1077 (defun vc-cvs-revision-completion-table (files)
1078 (lexical-let ((files files
)
1080 (setq table
(lazy-completion-table
1081 table
(lambda () (vc-cvs-revision-table (car files
)))))
1087 ;; arch-tag: 60e1402a-aa53-4607-927a-cf74f144b432
1088 ;;; vc-cvs.el ends here