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 of the License, or
16 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
30 (eval-when-compile (require 'cl
) (require 'vc
))
32 ;; Clear up the cache to force vc-call to check again and discover
33 ;; new functions when we reload this file.
34 (put 'CVS
'vc-functions nil
)
36 ;;; Properties of the backend.
38 (defun vc-cvs-revision-granularity () 'file
)
40 (defun vc-cvs-checkout-model (files)
41 "CVS-specific version of `vc-checkout-model'."
42 (if (getenv "CVSREAD")
44 (let* ((file (if (consp files
) (car files
) files
))
45 (attrib (file-attributes file
)))
46 (or (vc-file-getprop file
'vc-checkout-model
)
48 file
'vc-checkout-model
49 (if (and attrib
;; don't check further if FILE doesn't exist
50 ;; If the file is not writable (despite CVSREAD being
51 ;; undefined), this is probably because the file is being
52 ;; "watched" by other developers.
53 ;; (If vc-mistrust-permissions was t, we actually shouldn't
54 ;; trust this, but there is no other way to learn this from
55 ;; CVS at the moment (version 1.9).)
56 (string-match "r-..-..-." (nth 8 attrib
)))
61 ;;; Customization options
64 (defcustom vc-cvs-global-switches nil
65 "*Global switches to pass to any CVS command."
66 :type
'(choice (const :tag
"None" nil
)
67 (string :tag
"Argument String")
68 (repeat :tag
"Argument List"
74 (defcustom vc-cvs-register-switches nil
75 "*Extra switches for registering a file into CVS.
76 A string or list of strings passed to the checkin program by
78 :type
'(choice (const :tag
"None" nil
)
79 (string :tag
"Argument String")
80 (repeat :tag
"Argument List"
86 (defcustom vc-cvs-diff-switches nil
87 "*A string or list of strings specifying extra switches for cvs diff under VC."
88 :type
'(choice (const :tag
"None" nil
)
89 (string :tag
"Argument String")
90 (repeat :tag
"Argument List"
96 (defcustom vc-cvs-header
(or (cdr (assoc 'CVS vc-header-alist
)) '("\$Id\$"))
97 "*Header keywords to be inserted by `vc-insert-headers'."
99 :type
'(repeat string
)
102 (defcustom vc-cvs-use-edit t
103 "*Non-nil means to use `cvs edit' to \"check out\" a file.
104 This is only meaningful if you don't use the implicit checkout model
105 \(i.e. if you have $CVSREAD set)."
110 (defcustom vc-cvs-stay-local t
111 "*Non-nil means use local operations when possible for remote repositories.
112 This avoids slow queries over the network and instead uses heuristics
113 and past information to determine the current status of a file.
115 The value can also be a regular expression or list of regular
116 expressions to match against the host name of a repository; then VC
117 only stays local for hosts that match it. Alternatively, the value
118 can be a list of regular expressions where the first element is the
119 symbol `except'; then VC always stays local except for hosts matched
120 by these regular expressions."
121 :type
'(choice (const :tag
"Always stay local" t
)
122 (const :tag
"Don't stay local" nil
)
123 (list :format
"\nExamine hostname and %v" :tag
"Examine hostname ..."
124 (set :format
"%v" :inline t
(const :format
"%t" :tag
"don't" except
))
125 (regexp :format
" stay local,\n%t: %v" :tag
"if it matches")
126 (repeat :format
"%v%i\n" :inline t
(regexp :tag
"or"))))
130 (defcustom vc-cvs-sticky-date-format-string
"%c"
131 "*Format string for mode-line display of sticky date.
132 Format is according to `format-time-string'. Only used if
133 `vc-cvs-sticky-tag-display' is t."
138 (defcustom vc-cvs-sticky-tag-display t
139 "*Specify the mode-line display of sticky tags.
140 Value t means default display, nil means no display at all. If the
141 value is a function or macro, it is called with the sticky tag and
142 its' type as parameters, in that order. TYPE can have three different
143 values: `symbolic-name' (TAG is a string), `revision-number' (TAG is a
144 string) and `date' (TAG is a date as returned by `encode-time'). The
145 return value of the function or macro will be displayed as a string.
147 Here's an example that will display the formatted date for sticky
148 dates and the word \"Sticky\" for sticky tag names and revisions.
151 (cond ((eq type 'date) (format-time-string
152 vc-cvs-sticky-date-format-string tag))
153 ((eq type 'revision-number) \"Sticky\")
154 ((eq type 'symbolic-name) \"Sticky\")))
156 Here's an example that will abbreviate to the first character only,
157 any text before the first occurrence of `-' for sticky symbolic tags.
158 If the sticky tag is a revision number, the word \"Sticky\" is
159 displayed. Date and time is displayed for sticky dates.
162 (cond ((eq type 'date) (format-time-string \"%Y%m%d %H:%M\" tag))
163 ((eq type 'revision-number) \"Sticky\")
164 ((eq type 'symbolic-name)
167 (string-match \"\\\\([^-]*\\\\)\\\\(.*\\\\)\" tag)
168 (concat (substring (match-string 1 tag) 0 1) \":\"
169 (substring (match-string 2 tag) 1 nil)))
170 (error tag))))) ; Fall-back to given tag name.
172 See also variable `vc-cvs-sticky-date-format-string'."
173 :type
'(choice boolean function
)
178 ;;; Internal variables
183 ;;; State-querying functions
186 ;;;###autoload (defun vc-cvs-registered (f)
187 ;;;###autoload (when (file-readable-p (expand-file-name
188 ;;;###autoload "CVS/Entries" (file-name-directory f)))
189 ;;;###autoload (load "vc-cvs")
190 ;;;###autoload (vc-cvs-registered f)))
192 (defun vc-cvs-registered (file)
193 "Check if FILE is CVS registered."
194 (let ((dirname (or (file-name-directory file
) ""))
195 (basename (file-name-nondirectory file
))
196 ;; make sure that the file name is searched case-sensitively
197 (case-fold-search nil
))
198 (if (file-readable-p (expand-file-name "CVS/Entries" dirname
))
200 (vc-cvs-get-entries dirname
)
201 (goto-char (point-min))
204 (concat "^/" (regexp-quote basename
) "/[^/]") nil t
)
206 (vc-cvs-parse-entry file
)
211 (defun vc-cvs-state (file)
212 "CVS-specific version of `vc-state'."
213 (if (vc-stay-local-p file
)
214 (let ((state (vc-file-getprop file
'vc-state
)))
215 ;; If we should stay local, use the heuristic but only if
216 ;; we don't have a more precise state already available.
217 (if (memq state
'(up-to-date edited nil
))
218 (vc-cvs-state-heuristic file
)
221 (cd (file-name-directory file
))
222 (vc-cvs-command t
0 file
"status")
223 (vc-cvs-parse-status t
))))
225 (defun vc-cvs-state-heuristic (file)
226 "CVS-specific state heuristic."
227 ;; If the file has not changed since checkout, consider it `up-to-date'.
228 ;; Otherwise consider it `edited'.
229 (let ((checkout-time (vc-file-getprop file
'vc-checkout-time
))
230 (lastmod (nth 5 (file-attributes file
))))
232 ((equal checkout-time lastmod
) 'up-to-date
)
233 ((string= (vc-working-revision file
) "0") 'added
)
236 (defun vc-cvs-working-revision (file)
237 "CVS-specific version of `vc-working-revision'."
238 ;; There is no need to consult RCS headers under CVS, because we
239 ;; get the workfile version for free when we recognize that a file
240 ;; is registered in CVS.
241 (vc-cvs-registered file
)
242 (vc-file-getprop file
'vc-working-revision
))
244 (defun vc-cvs-mode-line-string (file)
245 "Return string for placement into the modeline for FILE.
246 Compared to the default implementation, this function does two things:
247 Handle the special case of a CVS file that is added but not yet
248 committed and support display of sticky tags."
249 (let* ((sticky-tag (vc-file-getprop file
'vc-cvs-sticky-tag
))
252 (let ((def-ml (vc-default-mode-line-string 'CVS file
)))
254 (get-text-property 0 'help-echo def-ml
))
257 (if (zerop (length sticky-tag
))
259 (setq help-echo
(format "%s on the '%s' branch"
260 help-echo sticky-tag
))
261 (concat string
"[" sticky-tag
"]"))
262 'help-echo help-echo
)))
266 ;;; State-changing functions
269 (defun vc-cvs-register (files &optional rev comment
)
270 "Register FILES into the CVS version-control system.
271 COMMENT can be used to provide an initial description of FILES.
273 `vc-register-switches' and `vc-cvs-register-switches' are passed to
274 the CVS command (in that order)."
275 ;; Register the directories if needed.
278 (and (not (vc-cvs-responsible-p file
))
279 (vc-cvs-could-register file
)
280 (push (directory-file-name (file-name-directory file
)) dirs
)))
281 (if dirs
(vc-cvs-register dirs
)))
282 (apply 'vc-cvs-command nil
0 files
284 (and comment
(string-match "[^\t\n ]" comment
)
285 (concat "-m" comment
))
286 (vc-switches 'CVS
'register
)))
288 (defun vc-cvs-responsible-p (file)
289 "Return non-nil if CVS thinks it is responsible for FILE."
290 (file-directory-p (expand-file-name "CVS"
291 (if (file-directory-p file
)
293 (file-name-directory file
)))))
295 (defun vc-cvs-could-register (file)
296 "Return non-nil if FILE could be registered in CVS.
297 This is only possible if CVS is managing FILE's directory or one of
300 (while (and (stringp dir
)
301 (not (equal dir
(setq dir
(file-name-directory dir
))))
303 (setq dir
(if (file-directory-p
304 (expand-file-name "CVS/Entries" dir
))
305 t
(directory-file-name dir
))))
308 (defun vc-cvs-checkin (files rev comment
)
309 "CVS-specific version of `vc-backend-checkin'."
310 (unless (or (not rev
) (vc-cvs-valid-revision-number-p rev
))
311 (if (not (vc-cvs-valid-symbolic-tag-name-p rev
))
312 (error "%s is not a valid symbolic tag name" rev
)
313 ;; If the input revison is a valid symbolic tag name, we create it
314 ;; as a branch, commit and switch to it.
315 (apply 'vc-cvs-command nil
0 files
"tag" "-b" (list rev
))
316 (apply 'vc-cvs-command nil
0 files
"update" "-r" (list rev
))
317 (mapc (lambda (file) (vc-file-setprop file
'vc-cvs-sticky-tag rev
))
319 (let ((status (apply 'vc-cvs-command nil
1 files
320 "ci" (if rev
(concat "-r" rev
))
321 (concat "-m" comment
)
322 (vc-switches 'CVS
'checkin
))))
324 (goto-char (point-min))
325 (when (not (zerop status
))
326 ;; Check checkin problem.
328 ((re-search-forward "Up-to-date check failed" nil t
)
329 (mapc (lambda (file) (vc-file-setprop file
'vc-state
'needs-merge
))
331 (error "%s" (substitute-command-keys
332 (concat "Up-to-date check failed: "
333 "type \\[vc-next-action] to merge in changes"))))
335 (pop-to-buffer (current-buffer))
336 (goto-char (point-min))
337 (shrink-window-if-larger-than-buffer)
338 (error "Check-in failed"))))
339 ;; Single-file commit? Then update the revision by parsing the buffer.
340 ;; Otherwise we can't necessarily tell what goes with what; clear
341 ;; its properties so they have to be refetched.
342 (if (= (length files
) 1)
344 (car files
) 'vc-working-revision
345 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
346 (mapc 'vc-file-clearprops files
))
347 ;; Anyway, forget the checkout model of the file, because we might have
348 ;; guessed wrong when we found the file. After commit, we can
349 ;; tell it from the permissions of the file (see
350 ;; vc-cvs-checkout-model).
351 (mapc (lambda (file) (vc-file-setprop file
'vc-checkout-model nil
))
354 ;; if this was an explicit check-in (does not include creation of
355 ;; a branch), remove the sticky tag.
356 (if (and rev
(not (vc-cvs-valid-symbolic-tag-name-p rev
)))
357 (vc-cvs-command nil
0 files
"update" "-A"))))
359 (defun vc-cvs-find-revision (file rev buffer
)
360 (apply 'vc-cvs-command
362 "-Q" ; suppress diagnostic output
364 (and rev
(not (string= rev
""))
367 (vc-switches 'CVS
'checkout
)))
369 (defun vc-cvs-checkout (file &optional editable rev
)
370 "Checkout a revision of FILE into the working area.
371 EDITABLE non-nil means that the file should be writable.
372 REV is the revision to check out."
373 (message "Checking out %s..." file
)
374 ;; Change buffers to get local value of vc-checkout-switches.
375 (with-current-buffer (or (get-file-buffer file
) (current-buffer))
376 (if (and (file-exists-p file
) (not rev
))
377 ;; If no revision was specified, just make the file writable
378 ;; if necessary (using `cvs-edit' if requested).
379 (and editable
(not (eq (vc-cvs-checkout-model (list file
)) 'implicit
))
381 (vc-cvs-command nil
0 file
"edit")
382 (set-file-modes file
(logior (file-modes file
) 128))
383 (if (equal file buffer-file-name
) (toggle-read-only -
1))))
384 ;; Check out a particular revision (or recreate the file).
385 (vc-file-setprop file
'vc-working-revision nil
)
386 (apply 'vc-cvs-command nil
0 file
391 ;; default for verbose checkout: clear the
392 ;; sticky tag so that the actual update will
393 ;; get the head of the trunk
397 (vc-switches 'CVS
'checkout
)))
399 (message "Checking out %s...done" file
))
401 (defun vc-cvs-delete-file (file)
402 (vc-cvs-command nil
0 file
"remove" "-f"))
404 (defun vc-cvs-revert (file &optional contents-done
)
405 "Revert FILE to the working revision on which it was based."
406 (vc-default-revert 'CVS file contents-done
)
407 (unless (eq (vc-cvs-checkout-model (list file
)) 'implicit
)
409 (vc-cvs-command nil
0 file
"unedit")
410 ;; Make the file read-only by switching off all w-bits
411 (set-file-modes file
(logand (file-modes file
) 3950)))))
413 (defun vc-cvs-merge (file first-revision
&optional second-revision
)
414 "Merge changes into current working copy of FILE.
415 The changes are between FIRST-REVISION and SECOND-REVISION."
416 (vc-cvs-command nil
0 file
418 (concat "-j" first-revision
)
419 (concat "-j" second-revision
))
420 (vc-file-setprop file
'vc-state
'edited
)
421 (with-current-buffer (get-buffer "*vc*")
422 (goto-char (point-min))
423 (if (re-search-forward "conflicts during merge" nil t
)
425 (vc-file-setprop file
'vc-state
'conflict
)
428 (vc-file-setprop file
'vc-state
'edited
)
432 (defun vc-cvs-merge-news (file)
433 "Merge in any new changes made to FILE."
434 (message "Merging changes into %s..." file
)
435 ;; (vc-file-setprop file 'vc-working-revision nil)
436 (vc-file-setprop file
'vc-checkout-time
0)
437 (vc-cvs-command nil nil file
"update")
438 ;; Analyze the merge result reported by CVS, and set
439 ;; file properties accordingly.
440 (with-current-buffer (get-buffer "*vc*")
441 (goto-char (point-min))
442 ;; get new working revision
443 (if (re-search-forward
444 "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t
)
445 (vc-file-setprop file
'vc-working-revision
(match-string 1))
446 (vc-file-setprop file
'vc-working-revision nil
))
449 (if (eq (buffer-size) 0)
450 0 ;; there were no news; indicate success
451 (if (re-search-forward
452 (concat "^\\([CMUP] \\)?"
453 (regexp-quote (file-name-nondirectory file
))
454 "\\( already contains the differences between \\)?")
457 ;; Merge successful, we are in sync with repository now
458 ((or (match-string 2)
459 (string= (match-string 1) "U ")
460 (string= (match-string 1) "P "))
461 (vc-file-setprop file
'vc-state
'up-to-date
)
462 (vc-file-setprop file
'vc-checkout-time
463 (nth 5 (file-attributes file
)))
464 0);; indicate success to the caller
465 ;; Merge successful, but our own changes are still in the file
466 ((string= (match-string 1) "M ")
467 (vc-file-setprop file
'vc-state
'edited
)
468 0);; indicate success to the caller
469 ;; Conflicts detected!
471 (vc-file-setprop file
'vc-state
'conflict
)
472 1);; signal the error to the caller
474 (pop-to-buffer "*vc*")
475 (error "Couldn't analyze cvs update result")))
476 (message "Merging changes into %s...done" file
))))
478 (defun vc-cvs-modify-change-comment (files rev comment
)
479 "Modify the change comments for FILES on a specified REV.
480 Will fail unless you have administrative privileges on the repo."
481 (vc-cvs-command nil
0 files
"admin" (concat "-m" rev
":" comment
)))
484 ;;; History functions
487 (defun vc-cvs-print-log (files &optional buffer
)
488 "Get change logs associated with FILES."
489 ;; It's just the catenation of the individual logs.
492 (if (vc-stay-local-p files
) 'async
0)
495 (defun vc-cvs-comment-history (file)
496 "Get comment history of a file."
497 (vc-call-backend 'RCS
'comment-history file
))
499 (defun vc-cvs-diff (files &optional oldvers newvers buffer
)
500 "Get a difference report using CVS between two revisions of FILE."
501 (let* ((async (and (not vc-disable-async-diff
)
502 (vc-stay-local-p files
)))
503 (invoke-cvs-diff-list nil
)
505 ;; Look through the file list and see if any files have backups
506 ;; that can be used to do a plain "diff" instead of "cvs diff".
510 (when (or (not ov
) (string-equal ov
""))
511 (setq ov
(vc-working-revision file
)))
512 (when (string-equal nv
"")
514 (let ((file-oldvers (vc-version-backup-file file ov
))
515 (file-newvers (if (not nv
)
517 (vc-version-backup-file file nv
)))
518 (coding-system-for-read (vc-coding-system-for-diff file
)))
519 (if (and file-oldvers file-newvers
)
521 (apply 'vc-do-command
(or buffer
"*vc-diff*") 1 "diff" nil
522 (append (if (listp diff-switches
)
524 (list diff-switches
))
525 (if (listp vc-diff-switches
)
527 (list vc-diff-switches
))
528 (list (file-relative-name file-oldvers
)
529 (file-relative-name file-newvers
))))
531 (push file invoke-cvs-diff-list
)))))
532 (when invoke-cvs-diff-list
533 (setq status
(apply 'vc-cvs-command
(or buffer
"*vc-diff*")
535 invoke-cvs-diff-list
"diff"
536 (and oldvers
(concat "-r" oldvers
))
537 (and newvers
(concat "-r" newvers
))
538 (vc-switches 'CVS
'diff
))))
539 (if async
1 status
))) ; async diff, pessimistic assumption
541 (defconst vc-cvs-annotate-first-line-re
"^[0-9]")
543 (defun vc-cvs-annotate-process-filter (process string
)
544 (setq string
(concat (process-get process
'output
) string
))
545 (if (not (string-match vc-cvs-annotate-first-line-re string
))
546 ;; Still waiting for the first real line.
547 (process-put process
'output string
)
548 (let ((vc-filter (process-get process
'vc-filter
)))
549 (set-process-filter process vc-filter
)
550 (funcall vc-filter process
(substring string
(match-beginning 0))))))
552 (defun vc-cvs-annotate-command (file buffer
&optional revision
)
553 "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER.
554 Optional arg REVISION is a revision to annotate from."
555 (vc-cvs-command buffer
556 (if (vc-stay-local-p file
)
559 (if revision
(concat "-r" revision
)))
560 ;; Strip the leading few lines.
561 (let ((proc (get-buffer-process buffer
)))
563 ;; If running asynchronously, use a process filter.
565 (process-put proc
'vc-filter
(process-filter proc
))
566 (set-process-filter proc
'vc-cvs-annotate-process-filter
))
567 (with-current-buffer buffer
568 (goto-char (point-min))
569 (re-search-forward vc-cvs-annotate-first-line-re
)
570 (delete-region (point-min) (1- (point)))))))
572 (defun vc-cvs-annotate-current-time ()
573 "Return the current time, based at midnight of the current day, and
574 encoded as fractional days."
575 (vc-annotate-convert-time
576 (apply 'encode-time
0 0 0 (nthcdr 3 (decode-time (current-time))))))
578 (defun vc-cvs-annotate-time ()
579 "Return the time of the next annotation (as fraction of days)
580 systime, or nil if there is none."
582 (cache (get-text-property bol
'vc-cvs-annotate-time
))
583 (inhibit-read-only t
)
584 (inhibit-modification-hooks t
))
588 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): ")
589 (let ((day (string-to-number (match-string 1)))
590 (month (cdr (assq (intern (match-string 2))
591 '((Jan .
1) (Feb .
2) (Mar .
3)
592 (Apr .
4) (May .
5) (Jun .
6)
593 (Jul .
7) (Aug .
8) (Sep .
9)
594 (Oct .
10) (Nov .
11) (Dec .
12)))))
595 (year (let ((tmp (string-to-number (match-string 3))))
596 ;; Years 0..68 are 2000..2068.
597 ;; Years 69..99 are 1969..1999.
598 (+ (cond ((> 69 tmp
) 2000)
603 bol
(1+ bol
) 'vc-cvs-annotate-time
605 ;; Position at end makes for nicer overlay result.
606 ;; Don't put actual buffer pos here, but only relative
607 ;; distance, so we don't ever move backward in the
608 ;; goto-char below, even if the text is moved.
609 (- (match-end 0) (match-beginning 0))
610 (vc-annotate-convert-time
611 (encode-time 0 0 0 day month year
))))))))
613 (goto-char (+ bol
(car cache
))) ; Fontify from here to eol.
614 (cdr cache
)))) ; days (float)
616 (defun vc-cvs-annotate-extract-revision-at-line ()
619 (if (re-search-forward "^\\([0-9]+\\.[0-9]+\\(\\.[0-9]+\\)*\\) +("
620 (line-end-position) t
)
621 (match-string-no-properties 1)
628 (defun vc-cvs-create-snapshot (dir name branchp
)
629 "Assign to DIR's current revision a given NAME.
630 If BRANCHP is non-nil, the name is created as a branch (and the current
631 workspace is immediately moved to that new branch)."
632 (vc-cvs-command nil
0 dir
"tag" "-c" (if branchp
"-b") name
)
633 (when branchp
(vc-cvs-command nil
0 dir
"update" "-r" name
)))
635 (defun vc-cvs-retrieve-snapshot (dir name update
)
636 "Retrieve a snapshot at and below DIR.
637 NAME is the name of the snapshot; if it is empty, do a `cvs update'.
638 If UPDATE is non-nil, then update (resynch) any affected buffers."
639 (with-current-buffer (get-buffer-create "*vc*")
640 (let ((default-directory dir
)
643 (if (or (not name
) (string= name
""))
644 (vc-cvs-command t
0 nil
"update")
645 (vc-cvs-command t
0 nil
"update" "-r" name
)
646 (setq sticky-tag name
))
648 (goto-char (point-min))
650 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
651 (let* ((file (expand-file-name (match-string 2) dir
))
652 (state (match-string 1))
653 (buffer (find-buffer-visiting file
)))
656 ((or (string= state
"U")
658 (vc-file-setprop file
'vc-state
'up-to-date
)
659 (vc-file-setprop file
'vc-working-revision nil
)
660 (vc-file-setprop file
'vc-checkout-time
661 (nth 5 (file-attributes file
))))
662 ((or (string= state
"M")
664 (vc-file-setprop file
'vc-state
'edited
)
665 (vc-file-setprop file
'vc-working-revision nil
)
666 (vc-file-setprop file
'vc-checkout-time
0)))
667 (vc-file-setprop file
'vc-cvs-sticky-tag sticky-tag
)
668 (vc-resynch-buffer file t t
))))
669 (forward-line 1))))))
676 (defalias 'vc-cvs-make-version-backups-p
'vc-stay-local-p
677 "Return non-nil if version backups should be made for FILE.")
679 (defun vc-cvs-check-headers ()
680 "Check if the current file has any headers in it."
682 (goto-char (point-min))
683 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
684 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
688 ;;; Internal functions
691 (defun vc-cvs-root (dir)
692 (vc-find-root dir
"CVS" t
))
694 (defun vc-cvs-command (buffer okstatus files
&rest flags
)
695 "A wrapper around `vc-do-command' for use in vc-cvs.el.
696 The difference to vc-do-command is that this function always invokes `cvs',
697 and that it passes `vc-cvs-global-switches' to it before FLAGS."
698 (apply 'vc-do-command
(or buffer
"*vc*") okstatus
"cvs" files
699 (if (stringp vc-cvs-global-switches
)
700 (cons vc-cvs-global-switches flags
)
701 (append vc-cvs-global-switches
704 (defalias 'vc-cvs-stay-local-p
'vc-stay-local-p
) ;Back-compatibility.
706 (defun vc-cvs-repository-hostname (dirname)
707 "Hostname of the CVS server associated to workarea DIRNAME."
708 (let ((rootname (expand-file-name "CVS/Root" dirname
)))
709 (when (file-readable-p rootname
)
711 (let ((coding-system-for-read
712 (or file-name-coding-system
713 default-file-name-coding-system
)))
714 (vc-insert-file rootname
))
715 (goto-char (point-min))
716 (nth 2 (vc-cvs-parse-root
717 (buffer-substring (point)
718 (line-end-position))))))))
720 (defun vc-cvs-parse-root (root)
721 "Split CVS ROOT specification string into a list of fields.
722 A CVS root specification of the form
723 [:METHOD:][[USER@]HOSTNAME:]/path/to/repository
724 is converted to a normalized record with the following structure:
725 \(METHOD USER HOSTNAME CVS-ROOT).
726 The default METHOD for a CVS root of the form
729 The default METHOD for a CVS root of the form
730 [USER@]HOSTNAME:/path/to/repository
732 For an empty string, nil is returned (invalid CVS root)."
733 ;; Split CVS root into colon separated fields (0-4).
734 ;; The `x:' makes sure, that leading colons are not lost;
735 ;; `HOST:/PATH' is then different from `:METHOD:/PATH'.
736 (let* ((root-list (cdr (split-string (concat "x:" root
) ":")))
737 (len (length root-list
))
738 ;; All syntactic varieties will get a proper METHOD.
745 ;; Simple PATH => method `local'
747 (cons nil root-list
)))
749 ;; [USER@]HOST:PATH => method `ext'
750 (and (not (equal (car root-list
) ""))
751 (cons "ext" root-list
)))
754 (cons (cadr root-list
)
755 (cons nil
(cddr root-list
))))
757 ;; :METHOD:[USER@]HOST:PATH
760 (let ((method (car root-list
))
761 (uhost (or (cadr root-list
) ""))
762 (root (nth 2 root-list
))
765 (if (string-match "\\(.*\\)@\\(.*\\)" uhost
)
766 (setq user
(match-string 1 uhost
)
767 host
(match-string 2 uhost
))
772 ;; Fix windows style CVS root `:local:C:\\project\\cvs\\some\\dir'
774 (equal method
"local")
775 (setq root
(concat host
":" root
) host
))
776 ;; Normalize CVS root record
777 (list method user host root
)))))
779 ;; XXX: This does not work correctly for subdirectories. "cvs status"
780 ;; information is context sensitive, it contains lines like:
781 ;; cvs status: Examining DIRNAME
782 ;; and the file entries after that don't show the full path.
783 ;; Because of this VC directory listings only show changed files
784 ;; at the top level for CVS.
785 (defun vc-cvs-parse-status (&optional full
)
786 "Parse output of \"cvs status\" command in the current buffer.
787 Set file properties accordingly. Unless FULL is t, parse only
788 essential information. Note that this can never set the 'ignored
790 (let (file status missing
)
791 (goto-char (point-min))
792 (while (looking-at "? \\(.*\\)")
793 (setq file
(expand-file-name (match-string 1)))
794 (vc-file-setprop file
'vc-state
'unregistered
)
796 (when (re-search-forward "^File: " nil t
)
797 (when (setq missing
(looking-at "no file "))
798 (goto-char (match-end 0)))
800 ((re-search-forward "\\=\\([^ \t]+\\)" nil t
)
801 (setq file
(expand-file-name (match-string 1)))
802 (vc-file-setprop file
'vc-backend
'CVS
)
803 (if (not (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t
))
804 (setq status
"Unknown")
805 (setq status
(match-string 1)))
808 "\\(RCS Version\\|RCS Revision\\|Repository revision\\):\
809 \[\t ]+\\([0-9.]+\\)"
811 (vc-file-setprop file
'vc-latest-revision
(match-string 2)))
815 ((string-match "Up-to-date" status
)
816 (vc-file-setprop file
'vc-checkout-time
817 (nth 5 (file-attributes file
)))
819 ((string-match "Locally Modified" status
) 'edited
)
820 ((string-match "Needs Merge" status
) 'needs-merge
)
821 ((string-match "Needs \\(Checkout\\|Patch\\)" status
)
822 (if missing
'missing
'needs-update
))
823 ((string-match "Locally Added" status
) 'added
)
824 ((string-match "Locally Removed" status
) 'removed
)
825 ((string-match "File had conflicts " status
) 'conflict
)
828 (defun vc-cvs-after-dir-status (update-function)
829 ;; Heavily inspired by vc-cvs-parse-status. AKA a quick hack.
830 ;; This needs a lot of testing.
836 (subdir default-directory
))
837 (goto-char (point-min))
839 ;; Look for either a file entry, an unregistered file, or a
842 "\\(^=+\n\\([^=c?\n].*\n\\|\n\\)+\\)\\|\\(\\(^?? .*\n\\)+\\)\\|\\(^cvs status: Examining .*\n\\)"
844 ;; XXX: get rid of narrowing here.
845 (narrow-to-region (match-beginning 0) (match-end 0))
846 (goto-char (point-min))
848 (when (looking-at "cvs status: Examining \\(.+\\)")
849 (setq subdir
(expand-file-name (match-string 1))))
850 ;; Unregistered files
851 (while (looking-at "? \\(.*\\)")
852 (setq file
(file-relative-name
853 (expand-file-name (match-string 1) subdir
)))
854 (push (list file
'unregistered
) result
)
857 (when (re-search-forward "^File: " nil t
)
858 (when (setq missing
(looking-at "no file "))
859 (goto-char (match-end 0)))
861 ((re-search-forward "\\=\\([^ \t]+\\)" nil t
)
862 (setq file
(file-relative-name
863 (expand-file-name (match-string 1) subdir
)))
864 (if (not (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t
))
865 (push (list file
'unregistered
) result
)
866 (setq status-str
(match-string 1))
869 ((string-match "Up-to-date" status-str
) 'up-to-date
)
870 ((string-match "Locally Modified" status-str
) 'edited
)
871 ((string-match "Needs Merge" status-str
) 'needs-merge
)
872 ((string-match "Needs \\(Checkout\\|Patch\\)" status-str
)
873 (if missing
'missing
'needs-update
))
874 ((string-match "Locally Added" status-str
) 'added
)
875 ((string-match "Locally Removed" status-str
) 'removed
)
876 ((string-match "File had conflicts " status-str
) 'conflict
)
878 (unless (eq status
'up-to-date
)
879 (push (list file status
) result
))))))
880 (goto-char (point-max))
882 (funcall update-function result
))
883 ;; Alternative implementation: use the "update" command instead of
884 ;; the "status" command.
885 ;; (let ((result nil)
886 ;; (translation '((?? . unregistered)
890 ;; (?P . needs-merge)
892 ;; (?U . needs-update))))
893 ;; (goto-char (point-min))
894 ;; (while (not (eobp))
895 ;; (if (looking-at "^[ACMPRU?] \\(.*\\)$")
896 ;; (push (list (match-string 1)
897 ;; (cdr (assoc (char-after) translation)))
900 ;; ((looking-at "cvs update: warning: \\(.*\\) was lost")
902 ;; ;; cvs update: warning: FILENAME was lost
904 ;; (push (list (match-string 1) 'missing) result)
905 ;; ;; Skip the "U" line
907 ;; ((looking-at "cvs update: New directory `\\(.*\\)' -- ignored")
908 ;; (push (list (match-string 1) 'unregistered) result))))
910 ;; (funcall update-function result)))
913 (defun vc-cvs-dir-status (dir update-function
)
914 "Create a list of conses (file . state) for DIR."
915 (vc-cvs-command (current-buffer) 'async dir
"status")
916 ;; Alternative implementation: use the "update" command instead of
917 ;; the "status" command.
918 ;; (vc-cvs-command (current-buffer) 'async
919 ;; (file-relative-name dir)
920 ;; "-f" "-n" "update" "-d" "-P")
922 `(vc-cvs-after-dir-status (quote ,update-function
))))
924 (defun vc-cvs-status-extra-headers (dir)
926 ;; FIXME: see how PCL-CVS gets the data to print all these
927 (propertize "Module : " 'face
'font-lock-type-face
)
928 (propertize "ADD CODE TO PRINT THE MODULE\n"
929 'face
'font-lock-warning-face
)
930 (propertize "Repository : " 'face
'font-lock-type-face
)
931 (propertize "ADD CODE TO PRINT THE REPOSITORY\n"
932 'face
'font-lock-warning-face
)
933 (propertize "Branch : " 'face
'font-lock-type-face
)
934 (propertize "ADD CODE TO PRINT THE BRANCH NAME\n"
935 'face
'font-lock-warning-face
)))
937 (defun vc-cvs-get-entries (dir)
938 "Insert the CVS/Entries file from below DIR into the current buffer.
939 This function ensures that the correct coding system is used for that,
940 which may not be the one that is used for the files' contents.
941 CVS/Entries should only be accessed through this function."
942 (let ((coding-system-for-read (or file-name-coding-system
943 default-file-name-coding-system
)))
944 (vc-insert-file (expand-file-name "CVS/Entries" dir
))))
946 (defun vc-cvs-valid-symbolic-tag-name-p (tag)
947 "Return non-nil if TAG is a valid symbolic tag name."
948 ;; According to the CVS manual, a valid symbolic tag must start with
949 ;; an uppercase or lowercase letter and can contain uppercase and
950 ;; lowercase letters, digits, `-', and `_'.
951 (and (string-match "^[a-zA-Z]" tag
)
952 (not (string-match "[^a-z0-9A-Z-_]" tag
))))
954 (defun vc-cvs-valid-revision-number-p (tag)
955 "Return non-nil if TAG is a valid revision number."
956 (and (string-match "^[0-9]" tag
)
957 (not (string-match "[^0-9.]" tag
))))
959 (defun vc-cvs-parse-sticky-tag (match-type match-tag
)
960 "Parse and return the sticky tag as a string.
961 `match-data' is protected."
962 (let ((data (match-data))
964 (type (cond ((string= match-type
"D") 'date
)
965 ((string= match-type
"T")
966 (if (vc-cvs-valid-symbolic-tag-name-p match-tag
)
973 ;; Sticky Date tag. Convert to a proper date value (`encode-time')
976 "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)"
978 (let* ((year-tmp (string-to-number (match-string 1 match-tag
)))
979 (month (string-to-number (match-string 2 match-tag
)))
980 (day (string-to-number (match-string 3 match-tag
)))
981 (hour (string-to-number (match-string 4 match-tag
)))
982 (min (string-to-number (match-string 5 match-tag
)))
983 (sec (string-to-number (match-string 6 match-tag
)))
984 ;; Years 0..68 are 2000..2068.
985 ;; Years 69..99 are 1969..1999.
986 (year (+ (cond ((> 69 year-tmp
) 2000)
987 ((> 100 year-tmp
) 1900)
990 (setq tag
(encode-time sec min hour day month year
))))
991 ;; Sticky Tag name or revision number
992 ((eq type
'symbolic-name
) (setq tag match-tag
))
993 ((eq type
'revision-number
) (setq tag match-tag
))
994 ;; Default is no sticky tag at all
996 (cond ((eq vc-cvs-sticky-tag-display nil
) nil
)
997 ((eq vc-cvs-sticky-tag-display t
)
998 (cond ((eq type
'date
) (format-time-string
999 vc-cvs-sticky-date-format-string
1001 ((eq type
'symbolic-name
) tag
)
1002 ((eq type
'revision-number
) tag
)
1004 ((functionp vc-cvs-sticky-tag-display
)
1005 (funcall vc-cvs-sticky-tag-display tag type
))
1008 (set-match-data data
))))
1010 (defun vc-cvs-parse-entry (file &optional set-state
)
1011 "Parse a line from CVS/Entries.
1012 Compare modification time to that of the FILE, set file properties
1013 accordingly. However, `vc-state' is set only if optional arg SET-STATE
1016 ;; entry for a "locally added" file (not yet committed)
1017 ((looking-at "/[^/]+/0/")
1018 (vc-file-setprop file
'vc-backend
'CVS
)
1019 (vc-file-setprop file
'vc-checkout-time
0)
1020 (vc-file-setprop file
'vc-working-revision
"0")
1021 (if set-state
(vc-file-setprop file
'vc-state
'added
)))
1027 ;; timestamp and optional conflict field
1032 "\\(.\\|\\)" ;Sticky tag type (date or tag name, could be empty)
1033 "\\(.*\\)")) ;Sticky tag
1034 (vc-file-setprop file
'vc-backend
'CVS
)
1035 (vc-file-setprop file
'vc-working-revision
(match-string 1))
1036 (vc-file-setprop file
'vc-cvs-sticky-tag
1037 (vc-cvs-parse-sticky-tag (match-string 4)
1039 ;; Compare checkout time and modification time.
1040 ;; This is intentionally different from the algorithm that CVS uses
1041 ;; (which is based on textual comparison), because there can be problems
1042 ;; generating a time string that looks exactly like the one from CVS.
1043 (let ((mtime (nth 5 (file-attributes file
))))
1044 (require 'parse-time
)
1046 (parse-time-string (concat (match-string 2) " +0000"))))
1047 (cond ((and (not (string-match "\\+" (match-string 2)))
1049 (equal mtime
(apply 'encode-time parsed-time
)))
1050 (vc-file-setprop file
'vc-checkout-time mtime
)
1051 (if set-state
(vc-file-setprop file
'vc-state
'up-to-date
)))
1053 (vc-file-setprop file
'vc-checkout-time
0)
1054 (if set-state
(vc-file-setprop file
'vc-state
'edited
)))))))))
1056 ;; Completion of revision names.
1057 ;; Just so I don't feel like I'm duplicating code from pcl-cvs, I'll use
1058 ;; `cvs log' so I can list all the revision numbers rather than only
1061 (defun vc-cvs-revision-table (file)
1062 (let ((default-directory (file-name-directory file
))
1065 (vc-cvs-command t nil file
"log")
1066 (goto-char (point-min))
1067 (when (re-search-forward "^symbolic names:\n" nil t
)
1068 (while (looking-at "^ \\(.*\\): \\(.*\\)")
1069 (push (cons (match-string 1) (match-string 2)) res
)
1071 (while (re-search-forward "^revision \\([0-9.]+\\)" nil t
)
1072 (push (match-string 1) res
))
1075 (defun vc-cvs-revision-completion-table (files)
1076 (lexical-let ((files files
)
1078 (setq table
(lazy-completion-table
1079 table
(lambda () (vc-cvs-revision-table (car files
)))))
1085 ;; arch-tag: 60e1402a-aa53-4607-927a-cf74f144b432
1086 ;;; vc-cvs.el ends here