Remove incorrect uses of "modeline".
[bpt/emacs.git] / lisp / vc / vc-cvs.el
CommitLineData
0d42eb3e 1;;; vc-cvs.el --- non-resident support for CVS version-control -*- lexical-binding: t -*-
c1b25099 2
acaf905b 3;; Copyright (C) 1995, 1998-2012 Free Software Foundation, Inc.
c1b25099
GM
4
5;; Author: FSF (see vc.el for full credits)
6;; Maintainer: Andre Spiegel <spiegel@gnu.org>
bd78fa1d 7;; Package: vc
c1b25099 8
c1b25099
GM
9;; This file is part of GNU Emacs.
10
eb3fa2cf 11;; GNU Emacs is free software: you can redistribute it and/or modify
c1b25099 12;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
c1b25099
GM
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
eb3fa2cf 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
c1b25099
GM
23
24;;; Commentary:
25
26;;; Code:
27
2346acf6 28(eval-when-compile (require 'cl) (require 'vc))
89e65817 29
98ad325c
SM
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)
33
70e2f6c7
ER
34;;; Properties of the backend.
35
36(defun vc-cvs-revision-granularity () 'file)
37
38(defun vc-cvs-checkout-model (files)
39 "CVS-specific version of `vc-checkout-model'."
40 (if (getenv "CVSREAD")
41 'announce
42 (let* ((file (if (consp files) (car files) files))
43 (attrib (file-attributes file)))
44 (or (vc-file-getprop file 'vc-checkout-model)
45 (vc-file-setprop
46 file 'vc-checkout-model
47 (if (and attrib ;; don't check further if FILE doesn't exist
48 ;; If the file is not writable (despite CVSREAD being
49 ;; undefined), this is probably because the file is being
50 ;; "watched" by other developers.
51 ;; (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)))
55 'announce
56 'implicit))))))
57
9b0630e5 58;;;
8f98485f
AS
59;;; Customization options
60;;;
61
67b0de11
CY
62(defgroup vc-cvs nil
63 "VC CVS backend."
64 :version "24.1"
65 :group 'vc)
66
bbce0417 67(defcustom vc-cvs-global-switches nil
9201cc28 68 "Global switches to pass to any CVS command."
bbce0417
AS
69 :type '(choice (const :tag "None" nil)
70 (string :tag "Argument String")
71 (repeat :tag "Argument List"
72 :value ("")
73 string))
bf247b6e 74 :version "22.1"
67b0de11 75 :group 'vc-cvs)
bbce0417 76
c1b25099 77(defcustom vc-cvs-register-switches nil
e5c741d9 78 "Switches for registering a file into CVS.
c1b25099 79A string or list of strings passed to the checkin program by
e5c741d9
GM
80\\[vc-register]. If nil, use the value of `vc-register-switches'.
81If t, use no switches."
82 :type '(choice (const :tag "Unspecified" nil)
83 (const :tag "None" t)
c1b25099 84 (string :tag "Argument String")
e5c741d9 85 (repeat :tag "Argument List" :value ("") string))
0d685c4f 86 :version "21.1"
67b0de11 87 :group 'vc-cvs)
c1b25099 88
633147f5 89(defcustom vc-cvs-diff-switches nil
e1f650f4
GM
90 "String or list of strings specifying switches for CVS diff under VC.
91If nil, use the value of `vc-diff-switches'. If t, use no switches."
92 :type '(choice (const :tag "Unspecified" nil)
93 (const :tag "None" t)
94 (string :tag "Argument String")
95 (repeat :tag "Argument List" :value ("") string))
633147f5 96 :version "21.1"
67b0de11 97 :group 'vc-cvs)
633147f5 98
67141a37 99(defcustom vc-cvs-header '("\$Id\$")
9201cc28 100 "Header keywords to be inserted by `vc-insert-headers'."
67141a37 101 :version "24.1" ; no longer consult the obsolete vc-header-alist
ee3275df 102 :type '(repeat string)
67b0de11 103 :group 'vc-cvs)
c1b25099
GM
104
105(defcustom vc-cvs-use-edit t
9201cc28 106 "Non-nil means to use `cvs edit' to \"check out\" a file.
c1b25099
GM
107This is only meaningful if you don't use the implicit checkout model
108\(i.e. if you have $CVSREAD set)."
109 :type 'boolean
0d685c4f 110 :version "21.1"
67b0de11 111 :group 'vc-cvs)
c1b25099 112
5870cb76 113(defcustom vc-cvs-stay-local 'only-file
9201cc28 114 "Non-nil means use local operations when possible for remote repositories.
c6a84d17
SM
115This avoids slow queries over the network and instead uses heuristics
116and past information to determine the current status of a file.
f354c160 117
5870cb76
DN
118If value is the symbol `only-file' `vc-dir' will connect to the
119server, but heuristics will be used to determine the status for
120all other VC operations.
121
d3ed06c6
AS
122The value can also be a regular expression or list of regular
123expressions to match against the host name of a repository; then VC
f354c160 124only stays local for hosts that match it. Alternatively, the value
bc99a968
TTN
125can be a list of regular expressions where the first element is the
126symbol `except'; then VC always stays local except for hosts matched
f354c160 127by these regular expressions."
c1b25099 128 :type '(choice (const :tag "Always stay local" t)
efe0da9c 129 (const :tag "Only for file operations" only-file)
5870cb76 130 (const :tag "Don't stay local" nil)
e1f650f4
GM
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")
d3ed06c6 137 (repeat :format "%v%i\n" :inline t (regexp :tag "or"))))
264175a8 138 :version "23.1"
67b0de11 139 :group 'vc-cvs)
264175a8 140
51af12fc 141(defcustom vc-cvs-sticky-date-format-string "%c"
9201cc28 142 "Format string for mode-line display of sticky date.
51af12fc
AS
143Format is according to `format-time-string'. Only used if
144`vc-cvs-sticky-tag-display' is t."
145 :type '(string)
bf247b6e 146 :version "22.1"
67b0de11 147 :group 'vc-cvs)
51af12fc
AS
148
149(defcustom vc-cvs-sticky-tag-display t
9201cc28 150 "Specify the mode-line display of sticky tags.
51af12fc
AS
151Value t means default display, nil means no display at all. If the
152value is a function or macro, it is called with the sticky tag and
153its' type as parameters, in that order. TYPE can have three different
154values: `symbolic-name' (TAG is a string), `revision-number' (TAG is a
155string) and `date' (TAG is a date as returned by `encode-time'). The
156return value of the function or macro will be displayed as a string.
157
158Here's an example that will display the formatted date for sticky
159dates and the word \"Sticky\" for sticky tag names and revisions.
160
161 (lambda (tag type)
968b980c 162 (cond ((eq type 'date) (format-time-string
51af12fc
AS
163 vc-cvs-sticky-date-format-string tag))
164 ((eq type 'revision-number) \"Sticky\")
165 ((eq type 'symbolic-name) \"Sticky\")))
166
167Here's an example that will abbreviate to the first character only,
aa4af071 168any text before the first occurrence of `-' for sticky symbolic tags.
51af12fc
AS
169If the sticky tag is a revision number, the word \"Sticky\" is
170displayed. Date and time is displayed for sticky dates.
171
172 (lambda (tag type)
173 (cond ((eq type 'date) (format-time-string \"%Y%m%d %H:%M\" tag))
174 ((eq type 'revision-number) \"Sticky\")
968b980c 175 ((eq type 'symbolic-name)
51af12fc
AS
176 (condition-case nil
177 (progn
178 (string-match \"\\\\([^-]*\\\\)\\\\(.*\\\\)\" tag)
968b980c 179 (concat (substring (match-string 1 tag) 0 1) \":\"
51af12fc
AS
180 (substring (match-string 2 tag) 1 nil)))
181 (error tag))))) ; Fall-back to given tag name.
182
183See also variable `vc-cvs-sticky-date-format-string'."
184 :type '(choice boolean function)
bf247b6e 185 :version "22.1"
67b0de11 186 :group 'vc-cvs)
9b0630e5 187
8f98485f
AS
188;;;
189;;; Internal variables
190;;;
191
9b0630e5 192
8f98485f 193;;;
9b0630e5 194;;; State-querying functions
8f98485f
AS
195;;;
196
3adbe224
GM
197;;;###autoload(defun vc-cvs-registered (f)
198;;;###autoload "Return non-nil if file F is registered with CVS."
c1b25099
GM
199;;;###autoload (when (file-readable-p (expand-file-name
200;;;###autoload "CVS/Entries" (file-name-directory f)))
cfb0dbdc 201;;;###autoload (load "vc-cvs")
c1b25099
GM
202;;;###autoload (vc-cvs-registered f)))
203
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))
1d1d90d6
SS
211 (or (string= basename "")
212 (with-temp-buffer
213 (vc-cvs-get-entries dirname)
214 (goto-char (point-min))
215 (cond ((re-search-forward
216 (concat "^/" (regexp-quote basename) "/[^/]") nil t)
217 (beginning-of-line)
218 (vc-cvs-parse-entry file)
219 t)
220 (t nil))))
c1b25099
GM
221 nil)))
222
c1b25099
GM
223(defun vc-cvs-state (file)
224 "CVS-specific version of `vc-state'."
77bf3f54 225 (if (vc-stay-local-p file 'CVS)
c1b25099
GM
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.
5124dd38 229 (if (memq state '(up-to-date edited nil))
c1b25099
GM
230 (vc-cvs-state-heuristic file)
231 state))
232 (with-temp-buffer
233 (cd (file-name-directory file))
66f3089c
MA
234 (let (process-file-side-effects)
235 (vc-cvs-command t 0 file "status"))
c1b25099
GM
236 (vc-cvs-parse-status t))))
237
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))))
45b24b4d
SM
244 (cond
245 ((equal checkout-time lastmod) 'up-to-date)
246 ((string= (vc-working-revision file) "0") 'added)
47dd5958 247 ((null checkout-time) 'unregistered)
45b24b4d 248 (t 'edited))))
c1b25099 249
ac3f4c6f
ER
250(defun vc-cvs-working-revision (file)
251 "CVS-specific version of `vc-working-revision'."
8f98485f
AS
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)
ac3f4c6f 256 (vc-file-getprop file 'vc-working-revision))
8f98485f 257
099bd78a 258(defun vc-cvs-mode-line-string (file)
37269466 259 "Return a string for `vc-mode-line' to put in the mode line for FILE.
51af12fc
AS
260Compared to the default implementation, this function does two things:
261Handle the special case of a CVS file that is added but not yet
262committed and support display of sticky tags."
3a12f9f8
DN
263 (let* ((sticky-tag (vc-file-getprop file 'vc-cvs-sticky-tag))
264 help-echo
45b24b4d
SM
265 (string
266 (let ((def-ml (vc-default-mode-line-string 'CVS file)))
bdb55eba 267 (setq help-echo
45b24b4d
SM
268 (get-text-property 0 'help-echo def-ml))
269 def-ml)))
bdb55eba 270 (propertize
3a12f9f8
DN
271 (if (zerop (length sticky-tag))
272 string
bdb55eba 273 (setq help-echo (format "%s on the '%s' branch"
3a12f9f8
DN
274 help-echo sticky-tag))
275 (concat string "[" sticky-tag "]"))
276 'help-echo help-echo)))
099bd78a 277
9b0630e5 278
8f98485f
AS
279;;;
280;;; State-changing functions
281;;;
c1b25099 282
0d42eb3e 283(defun vc-cvs-register (files &optional _rev comment)
8cdd17b4
ER
284 "Register FILES into the CVS version-control system.
285COMMENT can be used to provide an initial description of FILES.
e5c741d9
GM
286Passes either `vc-cvs-register-switches' or `vc-register-switches'
287to the CVS command."
967bf297
GM
288 ;; Register the directories if needed.
289 (let (dirs)
290 (dolist (file files)
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
296 "add"
297 (and comment (string-match "[^\t\n ]" comment)
298 (concat "-m" comment))
299 (vc-switches 'CVS 'register)))
c1b25099 300
8f98485f
AS
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)
305 file
306 (file-name-directory file)))))
c1b25099 307
e54faddb 308(defun vc-cvs-could-register (file)
8f98485f 309 "Return non-nil if FILE could be registered in CVS.
e54faddb
SM
310This is only possible if CVS is managing FILE's directory or one of
311its parents."
312 (let ((dir file))
313 (while (and (stringp dir)
314 (not (equal dir (setq dir (file-name-directory dir))))
315 dir)
fcb61bee 316 (setq dir (if (file-exists-p
e54faddb 317 (expand-file-name "CVS/Entries" dir))
fcb61bee
LK
318 t
319 (directory-file-name dir))))
e54faddb 320 (eq dir t)))
c1b25099 321
4624de78 322(defun vc-cvs-checkin (files rev comment)
c1b25099 323 "CVS-specific version of `vc-backend-checkin'."
ac3f4c6f 324 (unless (or (not rev) (vc-cvs-valid-revision-number-p rev))
f153cb52
SM
325 (if (not (vc-cvs-valid-symbolic-tag-name-p rev))
326 (error "%s is not a valid symbolic tag name" rev)
9858f6c3 327 ;; If the input revision is a valid symbolic tag name, we create it
f153cb52 328 ;; as a branch, commit and switch to it.
8cdd17b4
ER
329 (apply 'vc-cvs-command nil 0 files "tag" "-b" (list rev))
330 (apply 'vc-cvs-command nil 0 files "update" "-r" (list rev))
ea139d51
ER
331 (mapc (lambda (file) (vc-file-setprop file 'vc-cvs-sticky-tag rev))
332 files)))
333 (let ((status (apply 'vc-cvs-command nil 1 files
f153cb52
SM
334 "ci" (if rev (concat "-r" rev))
335 (concat "-m" comment)
336 (vc-switches 'CVS 'checkin))))
c1b25099
GM
337 (set-buffer "*vc*")
338 (goto-char (point-min))
bee48f25
AS
339 (when (not (zerop status))
340 ;; Check checkin problem.
341 (cond
342 ((re-search-forward "Up-to-date check failed" nil t)
7d8c4332
ER
343 (mapc (lambda (file) (vc-file-setprop file 'vc-state 'needs-merge))
344 files)
8c16bd8c 345 (error "%s" (substitute-command-keys
bee48f25
AS
346 (concat "Up-to-date check failed: "
347 "type \\[vc-next-action] to merge in changes"))))
348 (t
349 (pop-to-buffer (current-buffer))
350 (goto-char (point-min))
351 (shrink-window-if-larger-than-buffer)
352 (error "Check-in failed"))))
ac3f4c6f 353 ;; Single-file commit? Then update the revision by parsing the buffer.
8cdd17b4
ER
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)
357 (vc-file-setprop
ac3f4c6f 358 (car files) 'vc-working-revision
8cdd17b4 359 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
e0607aaa 360 (mapc 'vc-file-clearprops files))
8cdd17b4 361 ;; Anyway, forget the checkout model of the file, because we might have
c1b25099
GM
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).
8cdd17b4
ER
365 (mapc (lambda (file) (vc-file-setprop file 'vc-checkout-model nil))
366 files)
51af12fc
AS
367
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)))
8cdd17b4 371 (vc-cvs-command nil 0 files "update" "-A"))))
c1b25099 372
ac3f4c6f 373(defun vc-cvs-find-revision (file rev buffer)
ea05db01
SM
374 (apply 'vc-cvs-command
375 buffer 0 file
376 "-Q" ; suppress diagnostic output
377 "update"
378 (and rev (not (string= rev ""))
379 (concat "-r" rev))
380 "-p"
f153cb52 381 (vc-switches 'CVS 'checkout)))
ea05db01 382
f4b43eb3
SM
383(defun vc-cvs-checkout (file &optional editable rev)
384 "Checkout a revision of FILE into the working area.
34abd98e 385EDITABLE non-nil means that the file should be writable.
f4b43eb3
SM
386REV 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).
70e2f6c7 393 (and editable (not (eq (vc-cvs-checkout-model (list file)) 'implicit))
f4b43eb3
SM
394 (if vc-cvs-use-edit
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))))
ac3f4c6f
ER
398 ;; Check out a particular revision (or recreate the file).
399 (vc-file-setprop file 'vc-working-revision nil)
f4b43eb3
SM
400 (apply 'vc-cvs-command nil 0 file
401 (and editable "-w")
402 "update"
403 (when rev
404 (unless (eq rev t)
405 ;; default for verbose checkout: clear the
406 ;; sticky tag so that the actual update will
407 ;; get the head of the trunk
408 (if (string= rev "")
409 "-A"
410 (concat "-r" rev))))
411 (vc-switches 'CVS 'checkout)))
77bf3f54 412 (vc-mode-line file 'CVS))
f4b43eb3 413 (message "Checking out %s...done" file))
c1b25099 414
a0688443 415(defun vc-cvs-delete-file (file)
105cac2d 416 (vc-cvs-command nil 0 file "remove" "-f"))
a0688443 417
99739bbf 418(defun vc-cvs-revert (file &optional contents-done)
ac3f4c6f 419 "Revert FILE to the working revision on which it was based."
f4b43eb3 420 (vc-default-revert 'CVS file contents-done)
70e2f6c7 421 (unless (eq (vc-cvs-checkout-model (list file)) 'implicit)
99739bbf 422 (if vc-cvs-use-edit
bbce0417 423 (vc-cvs-command nil 0 file "unedit")
99739bbf
AS
424 ;; Make the file read-only by switching off all w-bits
425 (set-file-modes file (logand (file-modes file) 3950)))))
8f98485f 426
ac3f4c6f 427(defun vc-cvs-merge (file first-revision &optional second-revision)
8f98485f 428 "Merge changes into current working copy of FILE.
ac3f4c6f 429The changes are between FIRST-REVISION and SECOND-REVISION."
bbce0417 430 (vc-cvs-command nil 0 file
8f98485f 431 "update" "-kk"
ac3f4c6f
ER
432 (concat "-j" first-revision)
433 (concat "-j" second-revision))
8f98485f 434 (vc-file-setprop file 'vc-state 'edited)
d3ee404f 435 (with-current-buffer (get-buffer "*vc*")
8f98485f
AS
436 (goto-char (point-min))
437 (if (re-search-forward "conflicts during merge" nil t)
bdb55eba 438 (progn
7fbb4797
DN
439 (vc-file-setprop file 'vc-state 'conflict)
440 ;; signal error
441 1)
442 (vc-file-setprop file 'vc-state 'edited)
443 ;; signal success
444 0)))
8f98485f
AS
445
446(defun vc-cvs-merge-news (file)
447 "Merge in any new changes made to FILE."
448 (message "Merging changes into %s..." file)
ac3f4c6f 449 ;; (vc-file-setprop file 'vc-working-revision nil)
d3ee404f 450 (vc-file-setprop file 'vc-checkout-time 0)
c6a234ac 451 (vc-cvs-command nil nil file "update")
d3ee404f
SM
452 ;; Analyze the merge result reported by CVS, and set
453 ;; file properties accordingly.
454 (with-current-buffer (get-buffer "*vc*")
8f98485f 455 (goto-char (point-min))
ac3f4c6f 456 ;; get new working revision
d3ee404f
SM
457 (if (re-search-forward
458 "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t)
ac3f4c6f
ER
459 (vc-file-setprop file 'vc-working-revision (match-string 1))
460 (vc-file-setprop file 'vc-working-revision nil))
8f98485f
AS
461 ;; get file status
462 (prog1
463 (if (eq (buffer-size) 0)
464 0 ;; there were no news; indicate success
465 (if (re-search-forward
466 (concat "^\\([CMUP] \\)?"
9ba562d3 467 (regexp-quote
ff6b00de
SS
468 (substring file (1+ (length (expand-file-name
469 "." default-directory)))))
8f98485f
AS
470 "\\( already contains the differences between \\)?")
471 nil t)
472 (cond
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!
486 (t
7fbb4797 487 (vc-file-setprop file 'vc-state 'conflict)
8f98485f
AS
488 1);; signal the error to the caller
489 )
490 (pop-to-buffer "*vc*")
491 (error "Couldn't analyze cvs update result")))
492 (message "Merging changes into %s...done" file))))
493
9b64a7f0 494(defun vc-cvs-modify-change-comment (files rev comment)
bdb55eba 495 "Modify the change comments for FILES on a specified REV.
9b64a7f0 496Will fail unless you have administrative privileges on the repo."
031f1766 497 (vc-cvs-command nil 0 files "admin" (concat "-m" rev ":" comment)))
9b0630e5 498
8f98485f
AS
499;;;
500;;; History functions
501;;;
502
db167d28
DN
503(declare-function vc-rcs-print-log-cleanup "vc-rcs" ())
504
0d42eb3e 505(defun vc-cvs-print-log (files buffer &optional _shortlog _start-revision limit)
be01714b 506 "Get change logs associated with FILES."
db167d28 507 (require 'vc-rcs)
be01714b 508 ;; It's just the catenation of the individual logs.
bbce0417 509 (vc-cvs-command
a9817cc4 510 buffer
77bf3f54 511 (if (vc-stay-local-p files 'CVS) 'async 0)
db167d28
DN
512 files "log")
513 (with-current-buffer buffer
48b27575
DN
514 (vc-exec-after (vc-rcs-print-log-cleanup)))
515 (when limit 'limit-unsupported))
8cdd17b4 516
6aa5d910
ER
517(defun vc-cvs-comment-history (file)
518 "Get comment history of a file."
519 (vc-call-backend 'RCS 'comment-history file))
8f98485f 520
8cdd17b4 521(defun vc-cvs-diff (files &optional oldvers newvers buffer)
ac3f4c6f 522 "Get a difference report using CVS between two revisions of FILE."
66f3089c
MA
523 (let* (process-file-side-effects
524 (async (and (not vc-disable-async-diff)
77bf3f54 525 (vc-stay-local-p files 'CVS)))
2e7a8a21
DN
526 (invoke-cvs-diff-list nil)
527 status)
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".
530 (dolist (file files)
531 (let ((ov oldvers)
532 (nv newvers))
533 (when (or (not ov) (string-equal ov ""))
534 (setq ov (vc-working-revision file)))
535 (when (string-equal nv "")
536 (setq nv nil))
537 (let ((file-oldvers (vc-version-backup-file file ov))
538 (file-newvers (if (not nv)
539 file
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)
543 (progn
e1f650f4
GM
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.
2e7a8a21 547 (apply 'vc-do-command (or buffer "*vc-diff*") 1 "diff" nil
e1f650f4
GM
548 ;; Not a CVS diff, does not use vc-cvs-diff-switches.
549 (append (vc-switches nil 'diff)
2e7a8a21
DN
550 (list (file-relative-name file-oldvers)
551 (file-relative-name file-newvers))))
552 (setq status 0))
553 (push file invoke-cvs-diff-list)))))
554 (when invoke-cvs-diff-list
555 (setq status (apply 'vc-cvs-command (or buffer "*vc-diff*")
f153cb52 556 (if async 'async 1)
2e7a8a21 557 invoke-cvs-diff-list "diff"
f153cb52
SM
558 (and oldvers (concat "-r" oldvers))
559 (and newvers (concat "-r" newvers))
560 (vc-switches 'CVS 'diff))))
2e7a8a21
DN
561 (if async 1 status))) ; async diff, pessimistic assumption
562
98ad325c
SM
563(defconst vc-cvs-annotate-first-line-re "^[0-9]")
564
565(defun vc-cvs-annotate-process-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 (let ((vc-filter (process-get process 'vc-filter)))
571 (set-process-filter process vc-filter)
572 (funcall vc-filter process (substring string (match-beginning 0))))))
573
ac3f4c6f 574(defun vc-cvs-annotate-command (file buffer &optional revision)
8f98485f 575 "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER.
ac3f4c6f 576Optional arg REVISION is a revision to annotate from."
98ad325c 577 (vc-cvs-command buffer
77bf3f54 578 (if (vc-stay-local-p file 'CVS)
98ad325c
SM
579 'async 0)
580 file "annotate"
ac3f4c6f 581 (if revision (concat "-r" revision)))
98ad325c
SM
582 ;; Strip the leading few lines.
583 (let ((proc (get-buffer-process buffer)))
584 (if proc
585 ;; If running asynchronously, use a process filter.
586 (progn
587 (process-put proc 'vc-filter (process-filter proc))
588 (set-process-filter proc 'vc-cvs-annotate-process-filter))
589 (with-current-buffer buffer
590 (goto-char (point-min))
591 (re-search-forward vc-cvs-annotate-first-line-re)
592 (delete-region (point-min) (1- (point)))))))
c1b25099 593
f8bd9ac6
DN
594(declare-function vc-annotate-convert-time "vc-annotate" (time))
595
8ba2df32
AS
596(defun vc-cvs-annotate-current-time ()
597 "Return the current time, based at midnight of the current day, and
598encoded as fractional days."
599 (vc-annotate-convert-time
600 (apply 'encode-time 0 0 0 (nthcdr 3 (decode-time (current-time))))))
601
602(defun vc-cvs-annotate-time ()
603 "Return the time of the next annotation (as fraction of days)
f0529b5b 604systime, or nil if there is none."
b44a1825
TTN
605 (let* ((bol (point))
606 (cache (get-text-property bol 'vc-cvs-annotate-time))
72d1ce61
SM
607 (inhibit-read-only t)
608 (inhibit-modification-hooks t))
b44a1825
TTN
609 (cond
610 (cache)
611 ((looking-at
612 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): ")
613 (let ((day (string-to-number (match-string 1)))
614 (month (cdr (assq (intern (match-string 2))
615 '((Jan . 1) (Feb . 2) (Mar . 3)
616 (Apr . 4) (May . 5) (Jun . 6)
617 (Jul . 7) (Aug . 8) (Sep . 9)
618 (Oct . 10) (Nov . 11) (Dec . 12)))))
619 (year (let ((tmp (string-to-number (match-string 3))))
620 ;; Years 0..68 are 2000..2068.
621 ;; Years 69..99 are 1969..1999.
622 (+ (cond ((> 69 tmp) 2000)
623 ((> 100 tmp) 1900)
624 (t 0))
625 tmp))))
626 (put-text-property
627 bol (1+ bol) 'vc-cvs-annotate-time
628 (setq cache (cons
629 ;; Position at end makes for nicer overlay result.
d58107b0
SM
630 ;; Don't put actual buffer pos here, but only relative
631 ;; distance, so we don't ever move backward in the
632 ;; goto-char below, even if the text is moved.
633 (- (match-end 0) (match-beginning 0))
b44a1825
TTN
634 (vc-annotate-convert-time
635 (encode-time 0 0 0 day month year))))))))
636 (when cache
d58107b0 637 (goto-char (+ bol (car cache))) ; Fontify from here to eol.
b44a1825 638 (cdr cache)))) ; days (float)
9b0630e5 639
f2a2e61b
AS
640(defun vc-cvs-annotate-extract-revision-at-line ()
641 (save-excursion
642 (beginning-of-line)
643 (if (re-search-forward "^\\([0-9]+\\.[0-9]+\\(\\.[0-9]+\\)*\\) +("
644 (line-end-position) t)
645 (match-string-no-properties 1)
646 nil)))
647
b3cca6a6
DN
648(defun vc-cvs-previous-revision (file rev)
649 (vc-call-backend 'RCS 'previous-revision file rev))
650
651(defun vc-cvs-next-revision (file rev)
652 (vc-call-backend 'RCS 'next-revision file rev))
653
654;; FIXME: This should probably be replaced by code using cvs2cl.
655(defun vc-cvs-update-changelog (files)
656 (vc-call-backend 'RCS 'update-changelog files))
657
8f98485f 658;;;
370fded4 659;;; Tag system
8f98485f
AS
660;;;
661
370fded4 662(defun vc-cvs-create-tag (dir name branchp)
ac3f4c6f 663 "Assign to DIR's current revision a given NAME.
8f98485f
AS
664If BRANCHP is non-nil, the name is created as a branch (and the current
665workspace is immediately moved to that new branch)."
bbce0417
AS
666 (vc-cvs-command nil 0 dir "tag" "-c" (if branchp "-b") name)
667 (when branchp (vc-cvs-command nil 0 dir "update" "-r" name)))
8f98485f 668
370fded4
ER
669(defun vc-cvs-retrieve-tag (dir name update)
670 "Retrieve a tag at and below DIR.
671NAME is the name of the tag; if it is empty, do a `cvs update'.
8f98485f
AS
672If UPDATE is non-nil, then update (resynch) any affected buffers."
673 (with-current-buffer (get-buffer-create "*vc*")
51af12fc
AS
674 (let ((default-directory dir)
675 (sticky-tag))
8f98485f
AS
676 (erase-buffer)
677 (if (or (not name) (string= name ""))
bbce0417
AS
678 (vc-cvs-command t 0 nil "update")
679 (vc-cvs-command t 0 nil "update" "-r" name)
51af12fc 680 (setq sticky-tag name))
8f98485f
AS
681 (when update
682 (goto-char (point-min))
683 (while (not (eobp))
684 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
685 (let* ((file (expand-file-name (match-string 2) dir))
686 (state (match-string 1))
687 (buffer (find-buffer-visiting file)))
688 (when buffer
689 (cond
690 ((or (string= state "U")
691 (string= state "P"))
692 (vc-file-setprop file 'vc-state 'up-to-date)
ac3f4c6f 693 (vc-file-setprop file 'vc-working-revision nil)
8f98485f
AS
694 (vc-file-setprop file 'vc-checkout-time
695 (nth 5 (file-attributes file))))
696 ((or (string= state "M")
697 (string= state "C"))
698 (vc-file-setprop file 'vc-state 'edited)
ac3f4c6f 699 (vc-file-setprop file 'vc-working-revision nil)
8f98485f 700 (vc-file-setprop file 'vc-checkout-time 0)))
51af12fc 701 (vc-file-setprop file 'vc-cvs-sticky-tag sticky-tag)
8f98485f
AS
702 (vc-resynch-buffer file t t))))
703 (forward-line 1))))))
704
9b0630e5 705
8f98485f
AS
706;;;
707;;; Miscellaneous
708;;;
709
77bf3f54
DN
710(defun vc-cvs-make-version-backups-p (file)
711 "Return non-nil if version backups should be made for FILE."
712 (vc-stay-local-p file 'CVS))
8f98485f
AS
713
714(defun vc-cvs-check-headers ()
715 "Check if the current file has any headers in it."
716 (save-excursion
717 (goto-char (point-min))
718 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
719\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
720
9b0630e5 721
8f98485f
AS
722;;;
723;;; Internal functions
724;;;
725
8cdd17b4 726(defun vc-cvs-command (buffer okstatus files &rest flags)
bbce0417
AS
727 "A wrapper around `vc-do-command' for use in vc-cvs.el.
728The difference to vc-do-command is that this function always invokes `cvs',
729and that it passes `vc-cvs-global-switches' to it before FLAGS."
2888a97e 730 (apply 'vc-do-command (or buffer "*vc*") okstatus "cvs" files
968b980c 731 (if (stringp vc-cvs-global-switches)
bbce0417
AS
732 (cons vc-cvs-global-switches flags)
733 (append vc-cvs-global-switches
734 flags))))
735
77bf3f54
DN
736(defun vc-cvs-stay-local-p (file) ;Back-compatibility.
737 (vc-stay-local-p file 'CVS))
e54faddb
SM
738
739(defun vc-cvs-repository-hostname (dirname)
740 "Hostname of the CVS server associated to workarea DIRNAME."
741 (let ((rootname (expand-file-name "CVS/Root" dirname)))
742 (when (file-readable-p rootname)
743 (with-temp-buffer
744 (let ((coding-system-for-read
745 (or file-name-coding-system
746 default-file-name-coding-system)))
747 (vc-insert-file rootname))
748 (goto-char (point-min))
749 (nth 2 (vc-cvs-parse-root
750 (buffer-substring (point)
751 (line-end-position))))))))
78376474 752
05342dca
SS
753(defun vc-cvs-parse-uhp (path)
754 "parse user@host/path into (user@host /path)"
755 (if (string-match "\\([^/]+\\)\\(/.*\\)" path)
756 (list (match-string 1 path) (match-string 2 path))
757 (list nil path)))
758
78376474 759(defun vc-cvs-parse-root (root)
d3ed06c6
AS
760 "Split CVS ROOT specification string into a list of fields.
761A CVS root specification of the form
05342dca 762 [:METHOD:][[USER@]HOSTNAME]:?/path/to/repository
d3ed06c6
AS
763is converted to a normalized record with the following structure:
764 \(METHOD USER HOSTNAME CVS-ROOT).
765The default METHOD for a CVS root of the form
766 /path/to/repository
767is `local'.
768The default METHOD for a CVS root of the form
769 [USER@]HOSTNAME:/path/to/repository
770is `ext'.
aaed846c 771For an empty string, nil is returned (invalid CVS root)."
d3ed06c6
AS
772 ;; Split CVS root into colon separated fields (0-4).
773 ;; The `x:' makes sure, that leading colons are not lost;
774 ;; `HOST:/PATH' is then different from `:METHOD:/PATH'.
775 (let* ((root-list (cdr (split-string (concat "x:" root) ":")))
776 (len (length root-list))
777 ;; All syntactic varieties will get a proper METHOD.
778 (root-list
779 (cond
780 ((= len 0)
781 ;; Invalid CVS root
782 nil)
783 ((= len 1)
05342dca
SS
784 (let ((uhp (vc-cvs-parse-uhp (car root-list))))
785 (cons (if (car uhp) "ext" "local") uhp)))
d3ed06c6
AS
786 ((= len 2)
787 ;; [USER@]HOST:PATH => method `ext'
788 (and (not (equal (car root-list) ""))
789 (cons "ext" root-list)))
790 ((= len 3)
05342dca 791 ;; :METHOD:PATH or :METHOD:USER@HOSTNAME/PATH
d3ed06c6 792 (cons (cadr root-list)
05342dca 793 (vc-cvs-parse-uhp (caddr root-list))))
d3ed06c6
AS
794 (t
795 ;; :METHOD:[USER@]HOST:PATH
796 (cdr root-list)))))
797 (if root-list
798 (let ((method (car root-list))
799 (uhost (or (cadr root-list) ""))
800 (root (nth 2 root-list))
801 user host)
802 ;; Split USER@HOST
803 (if (string-match "\\(.*\\)@\\(.*\\)" uhost)
804 (setq user (match-string 1 uhost)
805 host (match-string 2 uhost))
806 (setq host uhost))
807 ;; Remove empty HOST
808 (and (equal host "")
809 (setq host))
810 ;; Fix windows style CVS root `:local:C:\\project\\cvs\\some\\dir'
811 (and host
812 (equal method "local")
813 (setq root (concat host ":" root) host))
814 ;; Normalize CVS root record
815 (list method user host root)))))
8f98485f 816
4e383781
DN
817;; XXX: This does not work correctly for subdirectories. "cvs status"
818;; information is context sensitive, it contains lines like:
819;; cvs status: Examining DIRNAME
820;; and the file entries after that don't show the full path.
caf37b1f
ER
821;; Because of this VC directory listings only show changed files
822;; at the top level for CVS.
8f98485f
AS
823(defun vc-cvs-parse-status (&optional full)
824 "Parse output of \"cvs status\" command in the current buffer.
825Set file properties accordingly. Unless FULL is t, parse only
722f037f
ER
826essential information. Note that this can never set the 'ignored
827state."
920fb2b0 828 (let (file status missing)
8f98485f 829 (goto-char (point-min))
722f037f
ER
830 (while (looking-at "? \\(.*\\)")
831 (setq file (expand-file-name (match-string 1)))
832 (vc-file-setprop file 'vc-state 'unregistered)
833 (forward-line 1))
920fb2b0
DN
834 (when (re-search-forward "^File: " nil t)
835 (when (setq missing (looking-at "no file "))
836 (goto-char (match-end 0)))
837 (cond
838 ((re-search-forward "\\=\\([^ \t]+\\)" nil t)
839 (setq file (expand-file-name (match-string 1)))
47dd5958
SM
840 (setq status(if (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t)
841 (match-string 1) "Unknown"))
7fbb4797
DN
842 (when (and full
843 (re-search-forward
844 "\\(RCS Version\\|RCS Revision\\|Repository revision\\):\
8f98485f 845\[\t ]+\\([0-9.]+\\)"
7fbb4797 846 nil t))
920fb2b0
DN
847 (vc-file-setprop file 'vc-latest-revision (match-string 2)))
848 (vc-file-setprop
849 file 'vc-state
850 (cond
851 ((string-match "Up-to-date" status)
852 (vc-file-setprop file 'vc-checkout-time
853 (nth 5 (file-attributes file)))
854 'up-to-date)
855 ((string-match "Locally Modified" status) 'edited)
856 ((string-match "Needs Merge" status) 'needs-merge)
857 ((string-match "Needs \\(Checkout\\|Patch\\)" status)
3702367b 858 (if missing 'missing 'needs-update))
920fb2b0
DN
859 ((string-match "Locally Added" status) 'added)
860 ((string-match "Locally Removed" status) 'removed)
7fbb4797 861 ((string-match "File had conflicts " status) 'conflict)
47dd5958 862 ((string-match "Unknown" status) 'unregistered)
920fb2b0 863 (t 'edited))))))))
8f98485f 864
c1b51374 865(defun vc-cvs-after-dir-status (update-function)
798dafb4 866 ;; Heavily inspired by vc-cvs-parse-status. AKA a quick hack.
5a9de6d0 867 ;; This needs a lot of testing.
798dafb4
DN
868 (let ((status nil)
869 (status-str nil)
870 (file nil)
871 (result nil)
920fb2b0 872 (missing nil)
1a0cf619 873 (ignore-next nil)
798dafb4
DN
874 (subdir default-directory))
875 (goto-char (point-min))
876 (while
877 ;; Look for either a file entry, an unregistered file, or a
878 ;; directory change.
879 (re-search-forward
1a0cf619 880 "\\(^=+\n\\([^=c?\n].*\n\\|\n\\)+\\)\\|\\(\\(^?? .*\n\\)+\\)\\|\\(^cvs status: \\(Examining\\|nothing\\) .*\n\\)"
798dafb4 881 nil t)
9fc36123 882 ;; FIXME: get rid of narrowing here.
798dafb4
DN
883 (narrow-to-region (match-beginning 0) (match-end 0))
884 (goto-char (point-min))
885 ;; The subdir
886 (when (looking-at "cvs status: Examining \\(.+\\)")
887 (setq subdir (expand-file-name (match-string 1))))
888 ;; Unregistered files
889 (while (looking-at "? \\(.*\\)")
bdb55eba 890 (setq file (file-relative-name
798dafb4 891 (expand-file-name (match-string 1) subdir)))
1b3f2d4e 892 (push (list file 'unregistered) result)
798dafb4 893 (forward-line 1))
1a0cf619
DN
894 (when (looking-at "cvs status: nothing known about")
895 ;; We asked about a non existent file. The output looks like this:
896
897 ;; cvs status: nothing known about `lisp/v.diff'
898 ;; ===================================================================
899 ;; File: no file v.diff Status: Unknown
900 ;;
901 ;; Working revision: No entry for v.diff
902 ;; Repository revision: No revision control file
903 ;;
904
905 ;; Due to narrowing in this iteration we only see the "cvs
906 ;; status:" line, so just set a flag so that we can ignore the
907 ;; file in the next iteration.
908 (setq ignore-next t))
798dafb4 909 ;; A file entry.
9fc36123
DN
910 (when (re-search-forward "^File: \\(no file \\)?\\(.*[^ \t]\\)[ \t]+Status: \\(.*\\)" nil t)
911 (setq missing (match-string 1))
912 (setq file (file-relative-name
913 (expand-file-name (match-string 2) subdir)))
914 (setq status-str (match-string 3))
915 (setq status
916 (cond
917 ((string-match "Up-to-date" status-str) 'up-to-date)
918 ((string-match "Locally Modified" status-str) 'edited)
919 ((string-match "Needs Merge" status-str) 'needs-merge)
920 ((string-match "Needs \\(Checkout\\|Patch\\)" status-str)
921 (if missing 'missing 'needs-update))
922 ((string-match "Locally Added" status-str) 'added)
923 ((string-match "Locally Removed" status-str) 'removed)
924 ((string-match "File had conflicts " status-str) 'conflict)
17996b53 925 ((string-match "Unknown" status-str) 'unregistered)
9fc36123 926 (t 'edited)))
1a0cf619
DN
927 (if ignore-next
928 (setq ignore-next nil)
929 (unless (eq status 'up-to-date)
930 (push (list file status) result))))
798dafb4
DN
931 (goto-char (point-max))
932 (widen))
40de1a6a 933 (funcall update-function result))
769303ae
DN
934 ;; Alternative implementation: use the "update" command instead of
935 ;; the "status" command.
936 ;; (let ((result nil)
937 ;; (translation '((?? . unregistered)
938 ;; (?A . added)
939 ;; (?C . conflict)
940 ;; (?M . edited)
941 ;; (?P . needs-merge)
942 ;; (?R . removed)
3702367b 943 ;; (?U . needs-update))))
769303ae
DN
944 ;; (goto-char (point-min))
945 ;; (while (not (eobp))
946 ;; (if (looking-at "^[ACMPRU?] \\(.*\\)$")
bdb55eba
SS
947 ;; (push (list (match-string 1)
948 ;; (cdr (assoc (char-after) translation)))
769303ae
DN
949 ;; result)
950 ;; (cond
951 ;; ((looking-at "cvs update: warning: \\(.*\\) was lost")
952 ;; ;; Format is:
953 ;; ;; cvs update: warning: FILENAME was lost
954 ;; ;; U FILENAME
955 ;; (push (list (match-string 1) 'missing) result)
956 ;; ;; Skip the "U" line
957 ;; (forward-line 1))
958 ;; ((looking-at "cvs update: New directory `\\(.*\\)' -- ignored")
959 ;; (push (list (match-string 1) 'unregistered) result))))
960 ;; (forward-line 1))
961 ;; (funcall update-function result)))
962 )
798dafb4 963
f3e6c9f3 964;; Based on vc-cvs-dir-state-heuristic from Emacs 22.
9515cdcc 965;; FIXME does not mention unregistered files.
f3e6c9f3
GM
966(defun vc-cvs-dir-status-heuristic (dir update-function &optional basedir)
967 "Find the CVS state of all files in DIR, using only local information."
968 (let (file basename status result dirlist)
969 (with-temp-buffer
970 (vc-cvs-get-entries dir)
971 (goto-char (point-min))
972 (while (not (eobp))
973 (if (looking-at "D/\\([^/]*\\)////")
974 (push (expand-file-name (match-string 1) dir) dirlist)
975 ;; CVS-removed files are not taken under VC control.
976 (when (looking-at "/\\([^/]*\\)/[^/-]")
977 (setq basename (match-string 1)
978 file (expand-file-name basename dir)
979 status (or (vc-file-getprop file 'vc-state)
980 (vc-cvs-parse-entry file t)))
981 (unless (eq status 'up-to-date)
982 (push (list (if basedir
983 (file-relative-name file basedir)
984 basename)
985 status) result))))
986 (forward-line 1)))
987 (dolist (subdir dirlist)
988 (setq result (append result
989 (vc-cvs-dir-status-heuristic subdir nil
990 (or basedir dir)))))
991 (if basedir result
992 (funcall update-function result))))
993
c1b51374 994(defun vc-cvs-dir-status (dir update-function)
798dafb4 995 "Create a list of conses (file . state) for DIR."
f3e6c9f3 996 ;; FIXME check all files in DIR instead?
77bf3f54 997 (let ((local (vc-stay-local-p dir 'CVS)))
5870cb76
DN
998 (if (and local (not (eq local 'only-file)))
999 (vc-cvs-dir-status-heuristic dir update-function)
1000 (vc-cvs-command (current-buffer) 'async dir "-f" "status")
1001 ;; Alternative implementation: use the "update" command instead of
1002 ;; the "status" command.
1003 ;; (vc-cvs-command (current-buffer) 'async
1004 ;; (file-relative-name dir)
1005 ;; "-f" "-n" "update" "-d" "-P")
1006 (vc-exec-after
1007 `(vc-cvs-after-dir-status (quote ,update-function))))))
efe0da9c 1008
0d42eb3e 1009(defun vc-cvs-dir-status-files (dir files _default-state update-function)
847fb889
DN
1010 "Create a list of conses (file . state) for DIR."
1011 (apply 'vc-cvs-command (current-buffer) 'async dir "-f" "status" files)
1012 (vc-exec-after
1013 `(vc-cvs-after-dir-status (quote ,update-function))))
1014
98712492
ER
1015(defun vc-cvs-file-to-string (file)
1016 "Read the content of FILE and return it as a string."
1017 (condition-case nil
1018 (with-temp-buffer
1019 (insert-file-contents file)
1020 (goto-char (point-min))
1021 (buffer-substring (point) (point-max)))
1022 (file-error nil)))
1023
0d42eb3e 1024(defun vc-cvs-dir-extra-headers (_dir)
98712492 1025 "Extract and represent per-directory properties of a CVS working copy."
4c61891a 1026 (let ((repo
98712492
ER
1027 (condition-case nil
1028 (with-temp-buffer
1029 (insert-file-contents "CVS/Root")
1030 (goto-char (point-min))
4c61891a 1031 (and (looking-at ":ext:") (delete-char 5))
644896e1 1032 (concat (buffer-substring (point) (1- (point-max))) "\n"))
98712492
ER
1033 (file-error nil)))
1034 (module
1035 (condition-case nil
1036 (with-temp-buffer
1037 (insert-file-contents "CVS/Repository")
1038 (goto-char (point-min))
7f5cd554
CY
1039 (skip-chars-forward "^\n")
1040 (concat (buffer-substring (point-min) (point)) "\n"))
98712492 1041 (file-error nil))))
4c61891a 1042 (concat
4c61891a 1043 (cond (repo
bdb55eba
SS
1044 (concat (propertize "Repository : " 'face 'font-lock-type-face)
1045 (propertize repo 'face 'font-lock-variable-name-face)))
4c61891a 1046 (t ""))
644896e1
NR
1047 (cond (module
1048 (concat (propertize "Module : " 'face 'font-lock-type-face)
1049 (propertize module 'face 'font-lock-variable-name-face)))
1050 (t ""))
1051 (if (file-readable-p "CVS/Tag")
1052 (let ((tag (vc-cvs-file-to-string "CVS/Tag")))
1053 (cond
1054 ((string-match "\\`T" tag)
1055 (concat (propertize "Tag : " 'face 'font-lock-type-face)
1056 (propertize (substring tag 1)
1057 'face 'font-lock-variable-name-face)))
1058 ((string-match "\\`D" tag)
1059 (concat (propertize "Date : " 'face 'font-lock-type-face)
1060 (propertize (substring tag 1)
1061 'face 'font-lock-variable-name-face)))
1062 (t ""))))
1063
bdb55eba
SS
1064 ;; In CVS, branch is a per-file property, not a per-directory property.
1065 ;; We can't really do this here without making dangerous assumptions.
98712492
ER
1066 ;;(propertize "Branch: " 'face 'font-lock-type-face)
1067 ;;(propertize "ADD CODE TO PRINT THE BRANCH NAME\n"
1068 ;; 'face 'font-lock-warning-face)
1069 )))
47302633 1070
666721a6
AS
1071(defun vc-cvs-get-entries (dir)
1072 "Insert the CVS/Entries file from below DIR into the current buffer.
1073This function ensures that the correct coding system is used for that,
1074which may not be the one that is used for the files' contents.
1075CVS/Entries should only be accessed through this function."
1076 (let ((coding-system-for-read (or file-name-coding-system
1077 default-file-name-coding-system)))
1078 (vc-insert-file (expand-file-name "CVS/Entries" dir))))
bc99a968 1079
51af12fc
AS
1080(defun vc-cvs-valid-symbolic-tag-name-p (tag)
1081 "Return non-nil if TAG is a valid symbolic tag name."
1082 ;; According to the CVS manual, a valid symbolic tag must start with
1083 ;; an uppercase or lowercase letter and can contain uppercase and
1084 ;; lowercase letters, digits, `-', and `_'.
1085 (and (string-match "^[a-zA-Z]" tag)
1086 (not (string-match "[^a-z0-9A-Z-_]" tag))))
968b980c 1087
ac3f4c6f
ER
1088(defun vc-cvs-valid-revision-number-p (tag)
1089 "Return non-nil if TAG is a valid revision number."
93bcb353
SS
1090 (and (string-match "^[0-9]" tag)
1091 (not (string-match "[^0-9.]" tag))))
51af12fc
AS
1092
1093(defun vc-cvs-parse-sticky-tag (match-type match-tag)
968b980c 1094 "Parse and return the sticky tag as a string.
51af12fc
AS
1095`match-data' is protected."
1096 (let ((data (match-data))
1097 (tag)
1098 (type (cond ((string= match-type "D") 'date)
1099 ((string= match-type "T")
1100 (if (vc-cvs-valid-symbolic-tag-name-p match-tag)
1101 'symbolic-name
1102 'revision-number))
1103 (t nil))))
1104 (unwind-protect
1105 (progn
968b980c 1106 (cond
e6608c12 1107 ;; Sticky Date tag. Convert to a proper date value (`encode-time')
51af12fc 1108 ((eq type 'date)
968b980c
SS
1109 (string-match
1110 "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)"
51af12fc
AS
1111 match-tag)
1112 (let* ((year-tmp (string-to-number (match-string 1 match-tag)))
1113 (month (string-to-number (match-string 2 match-tag)))
1114 (day (string-to-number (match-string 3 match-tag)))
1115 (hour (string-to-number (match-string 4 match-tag)))
1116 (min (string-to-number (match-string 5 match-tag)))
1117 (sec (string-to-number (match-string 6 match-tag)))
1118 ;; Years 0..68 are 2000..2068.
1119 ;; Years 69..99 are 1969..1999.
1120 (year (+ (cond ((> 69 year-tmp) 2000)
1121 ((> 100 year-tmp) 1900)
1122 (t 0))
1123 year-tmp)))
1124 (setq tag (encode-time sec min hour day month year))))
1125 ;; Sticky Tag name or revision number
1126 ((eq type 'symbolic-name) (setq tag match-tag))
1127 ((eq type 'revision-number) (setq tag match-tag))
1128 ;; Default is no sticky tag at all
1129 (t nil))
1130 (cond ((eq vc-cvs-sticky-tag-display nil) nil)
1131 ((eq vc-cvs-sticky-tag-display t)
968b980c 1132 (cond ((eq type 'date) (format-time-string
51af12fc
AS
1133 vc-cvs-sticky-date-format-string
1134 tag))
1135 ((eq type 'symbolic-name) tag)
1136 ((eq type 'revision-number) tag)
1137 (t nil)))
968b980c 1138 ((functionp vc-cvs-sticky-tag-display)
51af12fc
AS
1139 (funcall vc-cvs-sticky-tag-display tag type))
1140 (t nil)))
1141
1142 (set-match-data data))))
1143
8f98485f
AS
1144(defun vc-cvs-parse-entry (file &optional set-state)
1145 "Parse a line from CVS/Entries.
1146Compare modification time to that of the FILE, set file properties
1147accordingly. However, `vc-state' is set only if optional arg SET-STATE
1148is non-nil."
1149 (cond
1150 ;; entry for a "locally added" file (not yet committed)
1151 ((looking-at "/[^/]+/0/")
1152 (vc-file-setprop file 'vc-checkout-time 0)
ac3f4c6f 1153 (vc-file-setprop file 'vc-working-revision "0")
45b24b4d 1154 (if set-state (vc-file-setprop file 'vc-state 'added)))
8f98485f
AS
1155 ;; normal entry
1156 ((looking-at
1157 (concat "/[^/]+"
1158 ;; revision
1159 "/\\([^/]*\\)"
92788b3b
AS
1160 ;; timestamp and optional conflict field
1161 "/\\([^/]*\\)/"
51af12fc
AS
1162 ;; options
1163 "\\([^/]*\\)/"
1164 ;; sticky tag
1165 "\\(.\\|\\)" ;Sticky tag type (date or tag name, could be empty)
1166 "\\(.*\\)")) ;Sticky tag
ac3f4c6f 1167 (vc-file-setprop file 'vc-working-revision (match-string 1))
839dacca 1168 (vc-file-setprop file 'vc-cvs-sticky-tag
bc99a968 1169 (vc-cvs-parse-sticky-tag (match-string 4)
e5d9c9a2 1170 (match-string 5)))
ecfc2ba0
AS
1171 ;; Compare checkout time and modification time.
1172 ;; This is intentionally different from the algorithm that CVS uses
e5d9c9a2 1173 ;; (which is based on textual comparison), because there can be problems
ecfc2ba0 1174 ;; generating a time string that looks exactly like the one from CVS.
9515cdcc
GM
1175 (let* ((time (match-string 2))
1176 (mtime (nth 5 (file-attributes file)))
1177 (parsed-time (progn (require 'parse-time)
1178 (parse-time-string (concat time " +0000")))))
1179 (cond ((and (not (string-match "\\+" time))
1180 (car parsed-time)
1181 (equal mtime (apply 'encode-time parsed-time)))
1182 (vc-file-setprop file 'vc-checkout-time mtime)
1183 (if set-state (vc-file-setprop file 'vc-state 'up-to-date)))
1184 (t
1185 (vc-file-setprop file 'vc-checkout-time 0)
1186 (if set-state (vc-file-setprop file 'vc-state 'edited))))))))
968b980c 1187
2346acf6
SM
1188;; Completion of revision names.
1189;; Just so I don't feel like I'm duplicating code from pcl-cvs, I'll use
1190;; `cvs log' so I can list all the revision numbers rather than only
1191;; tag names.
1192
1193(defun vc-cvs-revision-table (file)
66f3089c
MA
1194 (let (process-file-side-effects
1195 (default-directory (file-name-directory file))
2346acf6
SM
1196 (res nil))
1197 (with-temp-buffer
1198 (vc-cvs-command t nil file "log")
1199 (goto-char (point-min))
1200 (when (re-search-forward "^symbolic names:\n" nil t)
1201 (while (looking-at "^ \\(.*\\): \\(.*\\)")
1202 (push (cons (match-string 1) (match-string 2)) res)
1203 (forward-line 1)))
1204 (while (re-search-forward "^revision \\([0-9.]+\\)" nil t)
1205 (push (match-string 1) res))
1206 res)))
1207
32c58c47 1208(defun vc-cvs-revision-completion-table (files)
0d42eb3e
SM
1209 (letrec ((table (lazy-completion-table
1210 table (lambda () (vc-cvs-revision-table (car files))))))
2346acf6 1211 table))
bdb55eba 1212
2346acf6 1213
c1b25099
GM
1214(provide 'vc-cvs)
1215
1216;;; vc-cvs.el ends here