1 ;;; vc-cvs.el --- non-resident support for CVS version-control -*- lexical-binding: t -*-
3 ;; Copyright (C) 1995, 1998-2013 Free Software Foundation, Inc.
5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
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/>.
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")
42 (let* ((file (if (consp files
) (car files
) files
))
43 (attrib (file-attributes file
)))
44 (or (vc-file-getprop file
'vc-checkout-model
)
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 ;; (If vc-mistrust-permissions was t, we actually shouldn't
52 ;; trust this, but there is no other way to learn this from
53 ;; CVS at the moment (version 1.9).)
54 (string-match "r-..-..-." (nth 8 attrib
)))
59 ;;; Customization options
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"
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
)
84 (string :tag
"Argument String")
85 (repeat :tag
"Argument List" :value
("") string
))
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
)
94 (string :tag
"Argument String")
95 (repeat :tag
"Argument List" :value
("") string
))
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
)
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)."
113 (defcustom vc-cvs-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"))))
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."
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.
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.
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)
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
)
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
"")
213 (vc-cvs-get-entries dirname
)
214 (goto-char (point-min))
215 (cond ((re-search-forward
216 (concat "^/" (regexp-quote basename
) "/[^/]") nil t
)
218 (vc-cvs-parse-entry file
)
223 (defun vc-cvs-state (file)
224 "CVS-specific version of `vc-state'."
225 (if (vc-stay-local-p file
'CVS
)
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
)
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
))))
245 ((equal checkout-time lastmod
) 'up-to-date
)
246 ((string= (vc-working-revision file
) "0") 'added
)
247 ((null checkout-time
) 'unregistered
)
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
))
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.
286 Passes either `vc-cvs-register-switches' or `vc-register-switches'
288 ;; Register the directories if needed.
291 (and (not (vc-cvs-responsible-p file
))
292 (vc-cvs-could-register file
)
293 (push (directory-file-name (file-name-directory file
)) dirs
)))
294 (if dirs
(vc-cvs-register dirs
)))
295 (apply 'vc-cvs-command nil
0 files
297 (and comment
(string-match "[^\t\n ]" comment
)
298 (concat "-m" comment
))
299 (vc-switches 'CVS
'register
)))
301 (defun vc-cvs-responsible-p (file)
302 "Return non-nil if CVS thinks it is responsible for FILE."
303 (file-directory-p (expand-file-name "CVS"
304 (if (file-directory-p file
)
306 (file-name-directory file
)))))
308 (defun vc-cvs-could-register (file)
309 "Return non-nil if FILE could be registered in CVS.
310 This is only possible if CVS is managing FILE's directory or one of
313 (while (and (stringp dir
)
314 (not (equal dir
(setq dir
(file-name-directory dir
))))
316 (setq dir
(if (file-exists-p
317 (expand-file-name "CVS/Entries" dir
))
319 (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 revision 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 'vc-file-clearprops 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 (list 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
) (read-only-mode -
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
)))
412 (vc-mode-line file
'CVS
))
413 (message "Checking out %s...done" file
))
415 (defun vc-cvs-delete-file (file)
416 (vc-cvs-command nil
0 file
"remove" "-f"))
418 (defun vc-cvs-revert (file &optional contents-done
)
419 "Revert FILE to the working revision on which it was based."
420 (vc-default-revert 'CVS file contents-done
)
421 (unless (eq (vc-cvs-checkout-model (list file
)) 'implicit
)
423 (vc-cvs-command nil
0 file
"unedit")
424 ;; Make the file read-only by switching off all w-bits
425 (set-file-modes file
(logand (file-modes file
) 3950)))))
427 (defun vc-cvs-merge (file first-revision
&optional second-revision
)
428 "Merge changes into current working copy of FILE.
429 The changes are between FIRST-REVISION and SECOND-REVISION."
430 (vc-cvs-command nil
0 file
432 (concat "-j" first-revision
)
433 (concat "-j" second-revision
))
434 (vc-file-setprop file
'vc-state
'edited
)
435 (with-current-buffer (get-buffer "*vc*")
436 (goto-char (point-min))
437 (if (re-search-forward "conflicts during merge" nil t
)
439 (vc-file-setprop file
'vc-state
'conflict
)
442 (vc-file-setprop file
'vc-state
'edited
)
446 (defun vc-cvs-merge-news (file)
447 "Merge in any new changes made to FILE."
448 (message "Merging changes into %s..." file
)
449 ;; (vc-file-setprop file 'vc-working-revision nil)
450 (vc-file-setprop file
'vc-checkout-time
0)
451 (vc-cvs-command nil nil file
"update")
452 ;; Analyze the merge result reported by CVS, and set
453 ;; file properties accordingly.
454 (with-current-buffer (get-buffer "*vc*")
455 (goto-char (point-min))
456 ;; get new working revision
457 (if (re-search-forward
458 "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t
)
459 (vc-file-setprop file
'vc-working-revision
(match-string 1))
460 (vc-file-setprop file
'vc-working-revision nil
))
463 (if (eq (buffer-size) 0)
464 0 ;; there were no news; indicate success
465 (if (re-search-forward
466 (concat "^\\([CMUP] \\)?"
468 (substring file
(1+ (length (expand-file-name
469 "." default-directory
)))))
470 "\\( already contains the differences between \\)?")
473 ;; Merge successful, we are in sync with repository now
474 ((or (match-string 2)
475 (string= (match-string 1) "U ")
476 (string= (match-string 1) "P "))
477 (vc-file-setprop file
'vc-state
'up-to-date
)
478 (vc-file-setprop file
'vc-checkout-time
479 (nth 5 (file-attributes file
)))
480 0);; indicate success to the caller
481 ;; Merge successful, but our own changes are still in the file
482 ((string= (match-string 1) "M ")
483 (vc-file-setprop file
'vc-state
'edited
)
484 0);; indicate success to the caller
485 ;; Conflicts detected!
487 (vc-file-setprop file
'vc-state
'conflict
)
488 1);; signal the error to the caller
490 (pop-to-buffer "*vc*")
491 (error "Couldn't analyze cvs update result")))
492 (message "Merging changes into %s...done" file
))))
494 (defun vc-cvs-modify-change-comment (files rev comment
)
495 "Modify the change comments for FILES on a specified REV.
496 Will fail unless you have administrative privileges on the repo."
497 (vc-cvs-command nil
0 files
"admin" (concat "-m" rev
":" comment
)))
500 ;;; History functions
503 (declare-function vc-rcs-print-log-cleanup
"vc-rcs" ())
505 (defun vc-cvs-print-log (files buffer
&optional _shortlog _start-revision limit
)
506 "Get change logs associated with FILES."
508 ;; It's just the catenation of the individual logs.
511 (if (vc-stay-local-p files
'CVS
) 'async
0)
513 (with-current-buffer buffer
514 (vc-exec-after (vc-rcs-print-log-cleanup)))
515 (when limit
'limit-unsupported
))
517 (defun vc-cvs-comment-history (file)
518 "Get comment history of a file."
519 (vc-call-backend 'RCS
'comment-history file
))
521 (defun vc-cvs-diff (files &optional oldvers newvers buffer
)
522 "Get a difference report using CVS between two revisions of FILE."
523 (let* (process-file-side-effects
524 (async (and (not vc-disable-async-diff
)
525 (vc-stay-local-p files
'CVS
)))
526 (invoke-cvs-diff-list nil
)
528 ;; Look through the file list and see if any files have backups
529 ;; that can be used to do a plain "diff" instead of "cvs diff".
533 (when (or (not ov
) (string-equal ov
""))
534 (setq ov
(vc-working-revision file
)))
535 (when (string-equal nv
"")
537 (let ((file-oldvers (vc-version-backup-file file ov
))
538 (file-newvers (if (not nv
)
540 (vc-version-backup-file file nv
)))
541 (coding-system-for-read (vc-coding-system-for-diff file
)))
542 (if (and file-oldvers file-newvers
)
544 ;; This used to append diff-switches and vc-diff-switches,
545 ;; which was consistent with the vc-diff-switches doc at that
546 ;; time, but not with the actual behavior of any other VC diff.
547 (apply 'vc-do-command
(or buffer
"*vc-diff*") 1 "diff" nil
548 ;; Not a CVS diff, does not use vc-cvs-diff-switches.
549 (append (vc-switches nil
'diff
)
550 (list (file-relative-name file-oldvers
)
551 (file-relative-name file-newvers
))))
553 (push file invoke-cvs-diff-list
)))))
554 (when invoke-cvs-diff-list
555 (setq status
(apply 'vc-cvs-command
(or buffer
"*vc-diff*")
557 invoke-cvs-diff-list
"diff"
558 (and oldvers
(concat "-r" oldvers
))
559 (and newvers
(concat "-r" newvers
))
560 (vc-switches 'CVS
'diff
))))
561 (if async
1 status
))) ; async diff, pessimistic assumption
563 (defconst vc-cvs-annotate-first-line-re
"^[0-9]")
565 (defun vc-cvs-annotate-process-filter (filter process string
)
566 (setq string
(concat (process-get process
'output
) string
))
567 (if (not (string-match vc-cvs-annotate-first-line-re string
))
568 ;; Still waiting for the first real line.
569 (process-put process
'output string
)
570 (remove-function (process-filter process
) #'vc-cvs-annotate-process-filter
)
571 (funcall filter process
(substring string
(match-beginning 0)))))
573 (defun vc-cvs-annotate-command (file buffer
&optional revision
)
574 "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER.
575 Optional arg REVISION is a revision to annotate from."
576 (vc-cvs-command buffer
577 (if (vc-stay-local-p file
'CVS
)
580 (if revision
(concat "-r" revision
)))
581 ;; Strip the leading few lines.
582 (let ((proc (get-buffer-process buffer
)))
584 ;; If running asynchronously, use a process filter.
585 (add-function :around
(process-filter proc
)
586 #'vc-cvs-annotate-process-filter
)
587 (with-current-buffer buffer
588 (goto-char (point-min))
589 (re-search-forward vc-cvs-annotate-first-line-re
)
590 (delete-region (point-min) (1- (point)))))))
592 (declare-function vc-annotate-convert-time
"vc-annotate" (time))
594 (defun vc-cvs-annotate-current-time ()
595 "Return the current time, based at midnight of the current day, and
596 encoded as fractional days."
597 (vc-annotate-convert-time
598 (apply 'encode-time
0 0 0 (nthcdr 3 (decode-time (current-time))))))
600 (defun vc-cvs-annotate-time ()
601 "Return the time of the next annotation (as fraction of days)
602 systime, or nil if there is none."
604 (cache (get-text-property bol
'vc-cvs-annotate-time
))
605 (inhibit-read-only t
)
606 (inhibit-modification-hooks t
))
610 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): ")
611 (let ((day (string-to-number (match-string 1)))
612 (month (cdr (assq (intern (match-string 2))
613 '((Jan .
1) (Feb .
2) (Mar .
3)
614 (Apr .
4) (May .
5) (Jun .
6)
615 (Jul .
7) (Aug .
8) (Sep .
9)
616 (Oct .
10) (Nov .
11) (Dec .
12)))))
617 (year (let ((tmp (string-to-number (match-string 3))))
618 ;; Years 0..68 are 2000..2068.
619 ;; Years 69..99 are 1969..1999.
620 (+ (cond ((> 69 tmp
) 2000)
625 bol
(1+ bol
) 'vc-cvs-annotate-time
627 ;; Position at end makes for nicer overlay result.
628 ;; Don't put actual buffer pos here, but only relative
629 ;; distance, so we don't ever move backward in the
630 ;; goto-char below, even if the text is moved.
631 (- (match-end 0) (match-beginning 0))
632 (vc-annotate-convert-time
633 (encode-time 0 0 0 day month year
))))))))
635 (goto-char (+ bol
(car cache
))) ; Fontify from here to eol.
636 (cdr cache
)))) ; days (float)
638 (defun vc-cvs-annotate-extract-revision-at-line ()
641 (if (re-search-forward "^\\([0-9]+\\.[0-9]+\\(\\.[0-9]+\\)*\\) +("
642 (line-end-position) t
)
643 (match-string-no-properties 1)
646 (defun vc-cvs-previous-revision (file rev
)
647 (vc-call-backend 'RCS
'previous-revision file rev
))
649 (defun vc-cvs-next-revision (file rev
)
650 (vc-call-backend 'RCS
'next-revision file rev
))
652 ;; FIXME: This should probably be replaced by code using cvs2cl.
653 (defun vc-cvs-update-changelog (files)
654 (vc-call-backend 'RCS
'update-changelog files
))
660 (defun vc-cvs-create-tag (dir name branchp
)
661 "Assign to DIR's current revision a given NAME.
662 If BRANCHP is non-nil, the name is created as a branch (and the current
663 workspace is immediately moved to that new branch)."
664 (vc-cvs-command nil
0 dir
"tag" "-c" (if branchp
"-b") name
)
665 (when branchp
(vc-cvs-command nil
0 dir
"update" "-r" name
)))
667 (defun vc-cvs-retrieve-tag (dir name update
)
668 "Retrieve a tag at and below DIR.
669 NAME is the name of the tag; if it is empty, do a `cvs update'.
670 If UPDATE is non-nil, then update (resynch) any affected buffers."
671 (with-current-buffer (get-buffer-create "*vc*")
672 (let ((default-directory dir
)
675 (if (or (not name
) (string= name
""))
676 (vc-cvs-command t
0 nil
"update")
677 (vc-cvs-command t
0 nil
"update" "-r" name
)
678 (setq sticky-tag name
))
680 (goto-char (point-min))
682 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
683 (let* ((file (expand-file-name (match-string 2) dir
))
684 (state (match-string 1))
685 (buffer (find-buffer-visiting file
)))
688 ((or (string= state
"U")
690 (vc-file-setprop file
'vc-state
'up-to-date
)
691 (vc-file-setprop file
'vc-working-revision nil
)
692 (vc-file-setprop file
'vc-checkout-time
693 (nth 5 (file-attributes file
))))
694 ((or (string= state
"M")
696 (vc-file-setprop file
'vc-state
'edited
)
697 (vc-file-setprop file
'vc-working-revision nil
)
698 (vc-file-setprop file
'vc-checkout-time
0)))
699 (vc-file-setprop file
'vc-cvs-sticky-tag sticky-tag
)
700 (vc-resynch-buffer file t t
))))
701 (forward-line 1))))))
708 (defun vc-cvs-make-version-backups-p (file)
709 "Return non-nil if version backups should be made for FILE."
710 (vc-stay-local-p file
'CVS
))
712 (defun vc-cvs-check-headers ()
713 "Check if the current file has any headers in it."
715 (goto-char (point-min))
716 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
717 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
721 ;;; Internal functions
724 (defun vc-cvs-command (buffer okstatus files
&rest flags
)
725 "A wrapper around `vc-do-command' for use in vc-cvs.el.
726 The difference to vc-do-command is that this function always invokes `cvs',
727 and that it passes `vc-cvs-global-switches' to it before FLAGS."
728 (apply 'vc-do-command
(or buffer
"*vc*") okstatus
"cvs" files
729 (if (stringp vc-cvs-global-switches
)
730 (cons vc-cvs-global-switches flags
)
731 (append vc-cvs-global-switches
734 (defun vc-cvs-stay-local-p (file) ;Back-compatibility.
735 (vc-stay-local-p file
'CVS
))
737 (defun vc-cvs-repository-hostname (dirname)
738 "Hostname of the CVS server associated to workarea DIRNAME."
739 (let ((rootname (expand-file-name "CVS/Root" dirname
)))
740 (when (file-readable-p rootname
)
742 (let ((coding-system-for-read
743 (or file-name-coding-system
744 default-file-name-coding-system
)))
745 (vc-insert-file rootname
))
746 (goto-char (point-min))
747 (nth 2 (vc-cvs-parse-root
748 (buffer-substring (point)
749 (line-end-position))))))))
751 (defun vc-cvs-parse-uhp (path)
752 "parse user@host/path into (user@host /path)"
753 (if (string-match "\\([^/]+\\)\\(/.*\\)" path
)
754 (list (match-string 1 path
) (match-string 2 path
))
757 (defun vc-cvs-parse-root (root)
758 "Split CVS ROOT specification string into a list of fields.
759 A CVS root specification of the form
760 [:METHOD:][[USER@]HOSTNAME]:?/path/to/repository
761 is converted to a normalized record with the following structure:
762 \(METHOD USER HOSTNAME CVS-ROOT).
763 The default METHOD for a CVS root of the form
766 The default METHOD for a CVS root of the form
767 [USER@]HOSTNAME:/path/to/repository
769 For an empty string, nil is returned (invalid CVS root)."
770 ;; Split CVS root into colon separated fields (0-4).
771 ;; The `x:' makes sure, that leading colons are not lost;
772 ;; `HOST:/PATH' is then different from `:METHOD:/PATH'.
773 (let* ((root-list (cdr (split-string (concat "x:" root
) ":")))
774 (len (length root-list
))
775 ;; All syntactic varieties will get a proper METHOD.
782 (let ((uhp (vc-cvs-parse-uhp (car root-list
))))
783 (cons (if (car uhp
) "ext" "local") uhp
)))
785 ;; [USER@]HOST:PATH => method `ext'
786 (and (not (equal (car root-list
) ""))
787 (cons "ext" root-list
)))
789 ;; :METHOD:PATH or :METHOD:USER@HOSTNAME/PATH
790 (cons (cadr root-list
)
791 (vc-cvs-parse-uhp (nth 2 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 directory listings only show changed files
820 ;; at the top level for CVS.
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 (setq status
(if (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t
)
839 (match-string 1) "Unknown"))
842 "\\(RCS Version\\|RCS Revision\\|Repository revision\\):\
843 \[\t ]+\\([0-9.]+\\)"
845 (vc-file-setprop file
'vc-latest-revision
(match-string 2)))
849 ((string-match "Up-to-date" status
)
850 (vc-file-setprop file
'vc-checkout-time
851 (nth 5 (file-attributes file
)))
853 ((string-match "Locally Modified" status
) 'edited
)
854 ((string-match "Needs Merge" status
) 'needs-merge
)
855 ((string-match "Needs \\(Checkout\\|Patch\\)" status
)
856 (if missing
'missing
'needs-update
))
857 ((string-match "Locally Added" status
) 'added
)
858 ((string-match "Locally Removed" status
) 'removed
)
859 ((string-match "File had conflicts " status
) 'conflict
)
860 ((string-match "Unknown" status
) 'unregistered
)
863 (defun vc-cvs-after-dir-status (update-function)
864 ;; Heavily inspired by vc-cvs-parse-status. AKA a quick hack.
865 ;; This needs a lot of testing.
872 (subdir default-directory
))
873 (goto-char (point-min))
875 ;; Look for either a file entry, an unregistered file, or a
878 "\\(^=+\n\\([^=c?\n].*\n\\|\n\\)+\\)\\|\\(\\(^?? .*\n\\)+\\)\\|\\(^cvs status: \\(Examining\\|nothing\\) .*\n\\)"
880 ;; FIXME: get rid of narrowing here.
881 (narrow-to-region (match-beginning 0) (match-end 0))
882 (goto-char (point-min))
884 (when (looking-at "cvs status: Examining \\(.+\\)")
885 (setq subdir
(expand-file-name (match-string 1))))
886 ;; Unregistered files
887 (while (looking-at "? \\(.*\\)")
888 (setq file
(file-relative-name
889 (expand-file-name (match-string 1) subdir
)))
890 (push (list file
'unregistered
) result
)
892 (when (looking-at "cvs status: nothing known about")
893 ;; We asked about a non existent file. The output looks like this:
895 ;; cvs status: nothing known about `lisp/v.diff'
896 ;; ===================================================================
897 ;; File: no file v.diff Status: Unknown
899 ;; Working revision: No entry for v.diff
900 ;; Repository revision: No revision control file
903 ;; Due to narrowing in this iteration we only see the "cvs
904 ;; status:" line, so just set a flag so that we can ignore the
905 ;; file in the next iteration.
906 (setq ignore-next t
))
908 (when (re-search-forward "^File: \\(no file \\)?\\(.*[^ \t]\\)[ \t]+Status: \\(.*\\)" nil t
)
909 (setq missing
(match-string 1))
910 (setq file
(file-relative-name
911 (expand-file-name (match-string 2) subdir
)))
912 (setq status-str
(match-string 3))
915 ((string-match "Up-to-date" status-str
) 'up-to-date
)
916 ((string-match "Locally Modified" status-str
) 'edited
)
917 ((string-match "Needs Merge" status-str
) 'needs-merge
)
918 ((string-match "Needs \\(Checkout\\|Patch\\)" status-str
)
919 (if missing
'missing
'needs-update
))
920 ((string-match "Locally Added" status-str
) 'added
)
921 ((string-match "Locally Removed" status-str
) 'removed
)
922 ((string-match "File had conflicts " status-str
) 'conflict
)
923 ((string-match "Unknown" status-str
) 'unregistered
)
926 (setq ignore-next nil
)
927 (unless (eq status
'up-to-date
)
928 (push (list file status
) result
))))
929 (goto-char (point-max))
931 (funcall update-function result
))
932 ;; Alternative implementation: use the "update" command instead of
933 ;; the "status" command.
934 ;; (let ((result nil)
935 ;; (translation '((?? . unregistered)
939 ;; (?P . needs-merge)
941 ;; (?U . needs-update))))
942 ;; (goto-char (point-min))
943 ;; (while (not (eobp))
944 ;; (if (looking-at "^[ACMPRU?] \\(.*\\)$")
945 ;; (push (list (match-string 1)
946 ;; (cdr (assoc (char-after) translation)))
949 ;; ((looking-at "cvs update: warning: \\(.*\\) was lost")
951 ;; ;; cvs update: warning: FILENAME was lost
953 ;; (push (list (match-string 1) 'missing) result)
954 ;; ;; Skip the "U" line
956 ;; ((looking-at "cvs update: New directory `\\(.*\\)' -- ignored")
957 ;; (push (list (match-string 1) 'unregistered) result))))
959 ;; (funcall update-function result)))
962 ;; Based on vc-cvs-dir-state-heuristic from Emacs 22.
963 ;; FIXME does not mention unregistered files.
964 (defun vc-cvs-dir-status-heuristic (dir update-function
&optional basedir
)
965 "Find the CVS state of all files in DIR, using only local information."
966 (let (file basename status result dirlist
)
968 (vc-cvs-get-entries dir
)
969 (goto-char (point-min))
971 (if (looking-at "D/\\([^/]*\\)////")
972 (push (expand-file-name (match-string 1) dir
) dirlist
)
973 ;; CVS-removed files are not taken under VC control.
974 (when (looking-at "/\\([^/]*\\)/[^/-]")
975 (setq basename
(match-string 1)
976 file
(expand-file-name basename dir
)
977 status
(or (vc-file-getprop file
'vc-state
)
978 (vc-cvs-parse-entry file t
)))
979 (unless (eq status
'up-to-date
)
980 (push (list (if basedir
981 (file-relative-name file basedir
)
985 (dolist (subdir dirlist
)
986 (setq result
(append result
987 (vc-cvs-dir-status-heuristic subdir nil
990 (funcall update-function result
))))
992 (defun vc-cvs-dir-status (dir update-function
)
993 "Create a list of conses (file . state) for DIR."
994 ;; FIXME check all files in DIR instead?
995 (let ((local (vc-stay-local-p dir
'CVS
)))
996 (if (and local
(not (eq local
'only-file
)))
997 (vc-cvs-dir-status-heuristic dir update-function
)
998 (vc-cvs-command (current-buffer) 'async dir
"-f" "status")
999 ;; Alternative implementation: use the "update" command instead of
1000 ;; the "status" command.
1001 ;; (vc-cvs-command (current-buffer) 'async
1002 ;; (file-relative-name dir)
1003 ;; "-f" "-n" "update" "-d" "-P")
1005 `(vc-cvs-after-dir-status (quote ,update-function
))))))
1007 (defun vc-cvs-dir-status-files (dir files _default-state update-function
)
1008 "Create a list of conses (file . state) for DIR."
1009 (apply 'vc-cvs-command
(current-buffer) 'async dir
"-f" "status" files
)
1011 `(vc-cvs-after-dir-status (quote ,update-function
))))
1013 (defun vc-cvs-file-to-string (file)
1014 "Read the content of FILE and return it as a string."
1017 (insert-file-contents file
)
1018 (goto-char (point-min))
1019 (buffer-substring (point) (point-max)))
1022 (defun vc-cvs-dir-extra-headers (_dir)
1023 "Extract and represent per-directory properties of a CVS working copy."
1027 (insert-file-contents "CVS/Root")
1028 (goto-char (point-min))
1029 (and (looking-at ":ext:") (delete-char 5))
1030 (concat (buffer-substring (point) (1- (point-max))) "\n"))
1035 (insert-file-contents "CVS/Repository")
1036 (goto-char (point-min))
1037 (skip-chars-forward "^\n")
1038 (concat (buffer-substring (point-min) (point)) "\n"))
1042 (concat (propertize "Repository : " 'face
'font-lock-type-face
)
1043 (propertize repo
'face
'font-lock-variable-name-face
)))
1046 (concat (propertize "Module : " 'face
'font-lock-type-face
)
1047 (propertize module
'face
'font-lock-variable-name-face
)))
1049 (if (file-readable-p "CVS/Tag")
1050 (let ((tag (vc-cvs-file-to-string "CVS/Tag")))
1052 ((string-match "\\`T" tag
)
1053 (concat (propertize "Tag : " 'face
'font-lock-type-face
)
1054 (propertize (substring tag
1)
1055 'face
'font-lock-variable-name-face
)))
1056 ((string-match "\\`D" tag
)
1057 (concat (propertize "Date : " 'face
'font-lock-type-face
)
1058 (propertize (substring tag
1)
1059 'face
'font-lock-variable-name-face
)))
1062 ;; In CVS, branch is a per-file property, not a per-directory property.
1063 ;; We can't really do this here without making dangerous assumptions.
1064 ;;(propertize "Branch: " 'face 'font-lock-type-face)
1065 ;;(propertize "ADD CODE TO PRINT THE BRANCH NAME\n"
1066 ;; 'face 'font-lock-warning-face)
1069 (defun vc-cvs-get-entries (dir)
1070 "Insert the CVS/Entries file from below DIR into the current buffer.
1071 This function ensures that the correct coding system is used for that,
1072 which may not be the one that is used for the files' contents.
1073 CVS/Entries should only be accessed through this function."
1074 (let ((coding-system-for-read (or file-name-coding-system
1075 default-file-name-coding-system
)))
1076 (vc-insert-file (expand-file-name "CVS/Entries" dir
))))
1078 (defun vc-cvs-valid-symbolic-tag-name-p (tag)
1079 "Return non-nil if TAG is a valid symbolic tag name."
1080 ;; According to the CVS manual, a valid symbolic tag must start with
1081 ;; an uppercase or lowercase letter and can contain uppercase and
1082 ;; lowercase letters, digits, `-', and `_'.
1083 (and (string-match "^[a-zA-Z]" tag
)
1084 (not (string-match "[^a-z0-9A-Z-_]" tag
))))
1086 (defun vc-cvs-valid-revision-number-p (tag)
1087 "Return non-nil if TAG is a valid revision number."
1088 (and (string-match "^[0-9]" tag
)
1089 (not (string-match "[^0-9.]" tag
))))
1091 (defun vc-cvs-parse-sticky-tag (match-type match-tag
)
1092 "Parse and return the sticky tag as a string.
1093 `match-data' is protected."
1094 (let ((data (match-data))
1096 (type (cond ((string= match-type
"D") 'date
)
1097 ((string= match-type
"T")
1098 (if (vc-cvs-valid-symbolic-tag-name-p match-tag
)
1105 ;; Sticky Date tag. Convert to a proper date value (`encode-time')
1108 "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)"
1110 (let* ((year-tmp (string-to-number (match-string 1 match-tag
)))
1111 (month (string-to-number (match-string 2 match-tag
)))
1112 (day (string-to-number (match-string 3 match-tag
)))
1113 (hour (string-to-number (match-string 4 match-tag
)))
1114 (min (string-to-number (match-string 5 match-tag
)))
1115 (sec (string-to-number (match-string 6 match-tag
)))
1116 ;; Years 0..68 are 2000..2068.
1117 ;; Years 69..99 are 1969..1999.
1118 (year (+ (cond ((> 69 year-tmp
) 2000)
1119 ((> 100 year-tmp
) 1900)
1122 (setq tag
(encode-time sec min hour day month year
))))
1123 ;; Sticky Tag name or revision number
1124 ((eq type
'symbolic-name
) (setq tag match-tag
))
1125 ((eq type
'revision-number
) (setq tag match-tag
))
1126 ;; Default is no sticky tag at all
1128 (cond ((eq vc-cvs-sticky-tag-display nil
) nil
)
1129 ((eq vc-cvs-sticky-tag-display t
)
1130 (cond ((eq type
'date
) (format-time-string
1131 vc-cvs-sticky-date-format-string
1133 ((eq type
'symbolic-name
) tag
)
1134 ((eq type
'revision-number
) tag
)
1136 ((functionp vc-cvs-sticky-tag-display
)
1137 (funcall vc-cvs-sticky-tag-display tag type
))
1140 (set-match-data data
))))
1142 (defun vc-cvs-parse-entry (file &optional set-state
)
1143 "Parse a line from CVS/Entries.
1144 Compare modification time to that of the FILE, set file properties
1145 accordingly. However, `vc-state' is set only if optional arg SET-STATE
1148 ;; entry for a "locally added" file (not yet committed)
1149 ((looking-at "/[^/]+/0/")
1150 (vc-file-setprop file
'vc-checkout-time
0)
1151 (vc-file-setprop file
'vc-working-revision
"0")
1152 (if set-state
(vc-file-setprop file
'vc-state
'added
)))
1158 ;; timestamp and optional conflict field
1163 "\\(.\\|\\)" ;Sticky tag type (date or tag name, could be empty)
1164 "\\(.*\\)")) ;Sticky tag
1165 (vc-file-setprop file
'vc-working-revision
(match-string 1))
1166 (vc-file-setprop file
'vc-cvs-sticky-tag
1167 (vc-cvs-parse-sticky-tag (match-string 4)
1169 ;; Compare checkout time and modification time.
1170 ;; This is intentionally different from the algorithm that CVS uses
1171 ;; (which is based on textual comparison), because there can be problems
1172 ;; generating a time string that looks exactly like the one from CVS.
1173 (let* ((time (match-string 2))
1174 (mtime (nth 5 (file-attributes file
)))
1175 (parsed-time (progn (require 'parse-time
)
1176 (parse-time-string (concat time
" +0000")))))
1177 (cond ((and (not (string-match "\\+" time
))
1179 ;; Compare just the seconds part of the file time,
1180 ;; since CVS file time stamp resolution is just 1 second.
1181 (let ((ptime (apply 'encode-time parsed-time
)))
1182 (and (eq (car mtime
) (car ptime
))
1183 (eq (cadr mtime
) (cadr ptime
)))))
1184 (vc-file-setprop file
'vc-checkout-time mtime
)
1185 (if set-state
(vc-file-setprop file
'vc-state
'up-to-date
)))
1187 (vc-file-setprop file
'vc-checkout-time
0)
1188 (if set-state
(vc-file-setprop file
'vc-state
'edited
))))))))
1190 ;; Completion of revision names.
1191 ;; Just so I don't feel like I'm duplicating code from pcl-cvs, I'll use
1192 ;; `cvs log' so I can list all the revision numbers rather than only
1195 (defun vc-cvs-revision-table (file)
1196 (let (process-file-side-effects
1197 (default-directory (file-name-directory file
))
1200 (vc-cvs-command t nil file
"log")
1201 (goto-char (point-min))
1202 (when (re-search-forward "^symbolic names:\n" nil t
)
1203 (while (looking-at "^ \\(.*\\): \\(.*\\)")
1204 (push (cons (match-string 1) (match-string 2)) res
)
1206 (while (re-search-forward "^revision \\([0-9.]+\\)" nil t
)
1207 (push (match-string 1) res
))
1210 (defun vc-cvs-revision-completion-table (files)
1211 (letrec ((table (lazy-completion-table
1212 table
(lambda () (vc-cvs-revision-table (car files
))))))
1218 ;;; vc-cvs.el ends here