comparison lisp/vc-cvs.el @ 31384:f6cb7dfe5e7c

(vc-cvs-show-log-entry): New function. (vc-cvs-stay-local): Allow it to be a hostname regexp as well. (vc-cvs-remote-p): Renamed to vc-cvs-stay-local-p. Handle hostname regexps. Updated all callers. (vc-cvs-responsible-p): Handle directories as well. (vc-cvs-could-register): New function. (vc-cvs-retrieve-snapshot): Parse "cvs update" output, keep file properties up-to-date. (vc-cvs-checkout): Do the right thing when the workfile does not exist. (vc-cvs-registered): Use new function vc-cvs-parse-entry to do the actual work. (vc-cvs-remote-p): Allow FILE to be a directory, too. (vc-cvs-dir-state): New function. (vc-cvs-dir-state-heuristic): New function, subroutine of the above. (vc-cvs-parse-entry): New function, also to be used in vc-cvs-registered. (vc-cvs-checkout): Slight restructuring to make the control-flow more clear and to avoid running `cvs' twice. (vc-cvs-workfile-version): Removed comment that this is not reached. It is. (vc-cvs-merge): Set state to 'edited after merge. (vc-cvs-merge-news): Set workfile version to nil if not known. (vc-cvs-latest-on-branch-p): Recommented. Candidate for removal. (vc-cvs-checkin): Raise the max-correct status from 0 to 1. Make sure to switch to *vc* before looking for an error message. Use vc-parse-buffer. (vc-cvs-create-snapshot): Swap DIR and NAME. (vc-cvs-retrieve-snapshot): New function (untested). (vc-cvs-stay-local): Default to t. (vc-cvs-remote-p): New function and property. (vc-cvs-state): Stay local only if the above is t. (vc-handle-cvs): Removed. (vc-cvs-registered): Don't check vc-handle-cvs -- it should all be done via vc-handled-backends now. (vc-cvs-header): Escape Id. (vc-cvs-state, vc-cvs-fetch-status): Use with-temp-file. Use the new BUFFER=t argument to vc-do-command. (vc-cvs-print-log, vc-cvs-diff): Insert in the current buffer. (vc-cvs-state): Use vc-do-command instead of vc-simple-command. (vc-cvs-diff): Remove unused and unsupported argument CMP. (vc-cvs-registered): Obey vc-handle-cvs. (vc-cvs-registered): Use with-temp-buffer. Reorder extraction of fields and call to file-attributes because of a temporary bug in rcp.el. (vc-cvs-fetch-status): Use with-current-buffer. Merge in code from vc-cvs-hooks.el. (proto vc-cvs-registered): Require 'vc-cvs instead of 'vc-cvs-hooks. Don't require 'vc anymore. (vc-cvs-responsible-p): Use expand-file-name instead of concat and file-directory-p instead of file-exists-p. (vc-cvs-create-snapshot): New function, replacing vc-cvs-assign-name. (vc-cvs-assign-name): Remove. (vc-cvs-header): New var. Update Copyright. (vc-cvs-diff): Remove unused `backend' variable. (vc-cvs-checkout): Only toggle read-only if the buffer is setup right. (tail): Provide vc-cvs. (vc-cvs-merge-news, vc-cvs-checkout): Removed call to vc-file-clear-masterprops. (vc-cvs-state): Typo. (vc-cvs-merge-news): Return the status code rather than the error msg. (vc-cvs-state): Don't overwrite a non-heuristic state with a heuristic one. (vc-cvs-merge-news): Just use 'edited for the case with conflicts. (vc-cvs-checkin): Do a trivial parse to set the state in case of error. That allows us to get to 'needs-merge even in the stay-local case. There's still no way to detect 'needs-patch in such a setup (or to force an update for that matter). (vc-cvs-logentry-check): Remove, the default works as well. (vc-cvs-print-log, vc-cvs-diff): Run cvs asynchronously. (vc-cvs-stay-local): Renamed from vc-cvs-simple-toggle. Redocumented. (vc-cvs-state): If locality is wanted, use vc-cvs-state-heuristic. (vc-cvs-toggle-read-only): Removed. (for compiler warnings). (vc-cvs-release, vc-cvs-system-release): Remove. (vc-cvs-use-edit, vc-cvs-simple-toggle): New config variables. (vc-cvs-dired-state-info): Use `cvs-state' and slightly different status symbols. (vc-cvs-parse-status, vc-cvs-state): Move from vc-cvs-hooks.el. (vc-cvs-toggle-read-only): First cut at a function to allow a cvs-status-free vc-toggle-read-only. (vc-cvs-merge-news): Move from cvs-merge-news in vc.el. (vc-cvs-checkin): Use vc-recompute-state+vc-state instead of vc-cvs-status. Also set vc-state rather than vc-locking-user. (vc-cvs-checkout): Modify access rights directly if the user requested not to use `cvs edit'. And refresh the mode line. (if workfile' that got lost when the code was extracted from vc.el. And merged the tail with the rest of the code (not possible in the old vc.el where the tail was shared among all backends). And explicitly set the state to 'edited if `writable' is set. (vc-cvs-revert,vc-cvs-checkout): References to `vc-checkout-model' updated to `vc-cvs-update-model'. (vc-cvs-logentry-check): Function added. (vc-cvs-revert,vc-cvs-checkout): Function calls to `vc-checkout-required' updated to `vc-cvs-uses-locking'. (vc-cvs-admin): Added the query-only option as required by the vc.el file. (vc-cvs-annotate-difference): Updated to handle beginning of annotate buffers correctly. Rename `vc-uses-locking' to `vc-checkout-required'. Rename the `locked' state to `reserved'. (vc-cvs-annotate-difference): Handle possible millenium problem (merged from mainline). Split the annotate feature into a BACKEND-specific part and moved the non-BACKEND stuff to vc.el. (vc-cvs-latest-on-branch-p): Function added. (vc-cvs-revert): Merged and adapted "unedit" patch from main line. (vc-cvs-diff): Function added. (vc-cvs-checkout): Function `vc-cvs-checkout' added. Require vc when compiling. (vc-cvs-register-switches): Doc fix. (vc-annotate-color-map, vc-annotate-menu-elements): Fix custom type. (vc-cvs-print-log, vc-cvs-assign-name, vc-cvs-merge) (vc-cvs-check-headers, vc-cvs-steal, vc-cvs-revert, vc-cvs-checkin): New functions (code from vc.el). (vc-annotate-display-default): Fix interactive spec. (vc-annotate-time-span): Doc fix. Moved the annotate functionality from vc.el. (vc-cvs-admin, vc-cvs-fetch-status): Added from vc.el. (vc-cvs-system-release): Renamed from vc-cvs-backend-release. (vc-cvs-release): Moved from vc.el. (vc-cvs-backend-release): New function. (vc-cvs-dired-state-info, vc-cvs-fetch-status): Moved from vc.el and renamed.
author Gerd Moellmann <gerd@gnu.org>
date Mon, 04 Sep 2000 19:48:04 +0000
parents
children f2ab9420390f
comparison
equal deleted inserted replaced
31383:860d7ac182e3 31384:f6cb7dfe5e7c
1 ;;; vc-cvs.el --- non-resident support for CVS version-control
2
3 ;; Copyright (C) 1995,98,99,2000 Free Software Foundation, Inc.
4
5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
7
8 ;; $Id: vc-cvs.el,v 1.58 2000/08/12 18:47:41 spiegel Exp $
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (defcustom vc-cvs-register-switches nil
32 "*Extra switches for registering a file into CVS.
33 A string or list of strings passed to the checkin program by
34 \\[vc-register]."
35 :type '(choice (const :tag "None" nil)
36 (string :tag "Argument String")
37 (repeat :tag "Argument List"
38 :value ("")
39 string))
40 :group 'vc)
41
42 (defcustom vc-cvs-header (or (cdr (assoc 'CVS vc-header-alist)) '("\$Id\$"))
43 "*Header keywords to be inserted by `vc-insert-headers'."
44 :type 'string
45 :group 'vc)
46
47 (defcustom vc-cvs-use-edit t
48 "*Non-nil means to use `cvs edit' to \"check out\" a file.
49 This is only meaningful if you don't use the implicit checkout model
50 \(i.e. if you have $CVSREAD set)."
51 :type 'boolean
52 :group 'vc)
53
54 (defcustom vc-cvs-stay-local t
55 "*Non-nil means that for remote CVS repositories, VC will
56 use local operations whenever possible, avoiding slow queries
57 over the network. Turning this option on will instruct VC to use only
58 heuristics and past information to determine the current status of a
59 file. The value can also be a regular expression to match against the
60 host name of a repository; then VC only stays local for hosts that match
61 it."
62 :type '(choice (const :tag "Always stay local" t)
63 (string :tag "Host regexp")
64 (const :tag "Don't stay local" nil))
65 :group 'vc)
66
67 ;;;###autoload (defun vc-cvs-registered (f)
68 ;;;###autoload (when (file-readable-p (expand-file-name
69 ;;;###autoload "CVS/Entries" (file-name-directory f)))
70 ;;;###autoload (require 'vc-cvs)
71 ;;;###autoload (vc-cvs-registered f)))
72
73 (defun vc-cvs-registered (file)
74 "Check if FILE is CVS registered."
75 (let ((dirname (or (file-name-directory file) ""))
76 (basename (file-name-nondirectory file))
77 ;; make sure that the file name is searched case-sensitively
78 (case-fold-search nil))
79 (if (file-readable-p (expand-file-name "CVS/Entries" dirname))
80 (with-temp-buffer
81 (vc-insert-file (expand-file-name "CVS/Entries" dirname))
82 (goto-char (point-min))
83 (cond
84 ((re-search-forward
85 (concat "^/" (regexp-quote basename) "/") nil t)
86 (beginning-of-line)
87 (vc-cvs-parse-entry file)
88 t)
89 (t nil)))
90 nil)))
91
92 (defun vc-cvs-stay-local-p (file)
93 "Return non-nil if VC should stay local when handling FILE."
94 (if vc-cvs-stay-local
95 (let* ((dirname (if (file-directory-p file)
96 (directory-file-name file)
97 (file-name-directory file)))
98 (prop
99 (or (vc-file-getprop dirname 'vc-cvs-stay-local-p)
100 (let ((rootname (expand-file-name "CVS/Root" dirname)))
101 (vc-file-setprop
102 dirname 'vc-cvs-stay-local-p
103 (when (file-readable-p rootname)
104 (with-temp-buffer
105 (vc-insert-file rootname)
106 (goto-char (point-min))
107 (if (looking-at "\\([^:]*\\):")
108 (if (not (stringp vc-cvs-stay-local))
109 'yes
110 (let ((hostname (match-string 1)))
111 (if (string-match vc-cvs-stay-local hostname)
112 'yes
113 'no)))
114 'no))))))))
115 (if (eq prop 'yes) t nil))))
116
117 (defun vc-cvs-workfile-version (file)
118 "CVS-specific version of `vc-workfile-version'."
119 ;; There is no need to consult RCS headers under CVS, because we
120 ;; get the workfile version for free when we recognize that a file
121 ;; is registered in CVS.
122 (vc-cvs-registered file)
123 (vc-file-getprop file 'vc-workfile-version))
124
125 (defun vc-cvs-checkout-model (file)
126 "CVS-specific version of `vc-checkout-model'."
127 (if (or (getenv "CVSREAD")
128 ;; If the file is not writable (despite CVSREAD being
129 ;; undefined), this is probably because the file is being
130 ;; "watched" by other developers.
131 ;; (If vc-mistrust-permissions was t, we actually shouldn't
132 ;; trust this, but there is no other way to learn this from CVS
133 ;; at the moment (version 1.9).)
134 (string-match "r-..-..-." (nth 8 (file-attributes file))))
135 'announce
136 'implicit))
137
138 ;; VC Dired functions
139
140 (defun vc-cvs-dired-state-info (file)
141 "CVS-specific version of `vc-dired-state-info'."
142 (let* ((cvs-state (vc-state file))
143 (state (cond ((eq cvs-state 'edited) "modified")
144 ((eq cvs-state 'needs-patch) "patch")
145 ((eq cvs-state 'needs-merge) "merge")
146 ;; FIXME: those two states cannot occur right now
147 ((eq cvs-state 'unlocked-changes) "conflict")
148 ((eq cvs-state 'locally-added) "added")
149 )))
150 (if state (concat "(" state ")"))))
151
152 (defun vc-cvs-parse-status (&optional full)
153 "Parse output of \"cvs status\" command in the current buffer.
154 Set file properties accordingly. Unless FULL is t, parse only
155 essential information."
156 (let (file status)
157 (goto-char (point-min))
158 (if (re-search-forward "^File: " nil t)
159 (cond
160 ((looking-at "no file") nil)
161 ((re-search-forward "\\=\\([^ \t]+\\)" nil t)
162 (setq file (expand-file-name (match-string 1)))
163 (vc-file-setprop file 'vc-backend 'CVS)
164 (if (not (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t))
165 (setq status "Unknown")
166 (setq status (match-string 1)))
167 (if (and full
168 (re-search-forward
169 "\\(RCS Version\\|RCS Revision\\|Repository revision\\):\
170 \[\t ]+\\([0-9.]+\\)"
171 nil t))
172 (vc-file-setprop file 'vc-latest-version (match-string 2)))
173 (cond
174 ((string-match "Up-to-date" status)
175 (vc-file-setprop file 'vc-checkout-time
176 (nth 5 (file-attributes file)))
177 'up-to-date)
178 ((string-match "Locally Modified" status) 'edited)
179 ((string-match "Needs Merge" status) 'needs-merge)
180 ((string-match "Needs \\(Checkout\\|Patch\\)" status) 'needs-patch)
181 (t 'edited)))))))
182
183 (defun vc-cvs-state (file)
184 "CVS-specific version of `vc-state'."
185 (if (vc-cvs-stay-local-p file)
186 (let ((state (vc-file-getprop file 'vc-state)))
187 ;; If we should stay local, use the heuristic but only if
188 ;; we don't have a more precise state already available.
189 (if (memq state '(up-to-date edited))
190 (vc-cvs-state-heuristic file)
191 state))
192 (with-temp-buffer
193 (cd (file-name-directory file))
194 (vc-do-command t 0 "cvs" file "status")
195 (vc-cvs-parse-status t))))
196
197 (defun vc-cvs-state-heuristic (file)
198 "CVS-specific state heuristic."
199 ;; If the file has not changed since checkout, consider it `up-to-date'.
200 ;; Otherwise consider it `edited'.
201 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time))
202 (lastmod (nth 5 (file-attributes file))))
203 (if (equal checkout-time lastmod)
204 'up-to-date
205 'edited)))
206
207 (defun vc-cvs-dir-state (dir)
208 "Find the CVS state of all files in DIR."
209 (if (vc-cvs-stay-local-p dir)
210 (vc-cvs-dir-state-heuristic dir)
211 (let ((default-directory dir))
212 ;; Don't specify DIR in this command, the default-directory is
213 ;; enough. Otherwise it might fail with remote repositories.
214 (with-temp-buffer
215 (vc-do-command t 0 "cvs" nil "status" "-l")
216 (goto-char (point-min))
217 (while (re-search-forward "^=+\n\\([^=\n].*\n\\|\n\\)+" nil t)
218 (narrow-to-region (match-beginning 0) (match-end 0))
219 (vc-cvs-parse-status)
220 (goto-char (point-max))
221 (widen))))))
222
223 (defun vc-cvs-dir-state-heuristic (dir)
224 "Find the CVS state of all files in DIR, using only local information."
225 (with-temp-buffer
226 (vc-insert-file (expand-file-name "CVS/Entries" dir))
227 (goto-char (point-min))
228 (while (not (eobp))
229 (when (looking-at "/\\([^/]*\\)/")
230 (let ((file (expand-file-name (match-string 1) dir)))
231 (unless (vc-file-getprop file 'vc-state)
232 (vc-cvs-parse-entry file t))))
233 (forward-line 1))))
234
235 (defun vc-cvs-parse-entry (file &optional set-state)
236 "Parse a line from CVS/Entries, compare modification time to that of
237 the FILE, set file properties accordingly. However, vc-state is set only
238 if optional arg SET-STATE is non-nil."
239 (cond
240 ;; entry for a "locally added" file (not yet committed)
241 ((looking-at "/[^/]+/0/")
242 (vc-file-setprop file 'vc-checkout-time 0)
243 (vc-file-setprop file 'vc-workfile-version "0")
244 (if set-state (vc-file-setprop file 'vc-state 'edited)))
245 ;; normal entry
246 ((looking-at
247 (concat "/[^/]+"
248 ;; revision
249 "/\\([^/]*\\)"
250 ;; timestamp
251 "/[A-Z][a-z][a-z]" ;; week day (irrelevant)
252 " \\([A-Z][a-z][a-z]\\)" ;; month name
253 " *\\([0-9]*\\)" ;; day of month
254 " \\([0-9]*\\):\\([0-9]*\\):\\([0-9]*\\)" ;; hms
255 " \\([0-9]*\\)" ;; year
256 ;; optional conflict field
257 "\\(+[^/]*\\)?/"))
258 (vc-file-setprop file 'vc-workfile-version (match-string 1))
259 ;; compare checkout time and modification time
260 (let ((second (string-to-number (match-string 6)))
261 (minute (string-to-number (match-string 5)))
262 (hour (string-to-number (match-string 4)))
263 (day (string-to-number (match-string 3)))
264 (year (string-to-number (match-string 7)))
265 (month (/ (string-match
266 (match-string 2)
267 "xxxJanFebMarAprMayJunJulAugSepOctNovDec")
268 3))
269 (mtime (nth 5 (file-attributes file))))
270 (cond ((equal mtime
271 (encode-time second minute hour day month year 0))
272 (vc-file-setprop file 'vc-checkout-time mtime)
273 (if set-state (vc-file-setprop file 'vc-state 'up-to-date)))
274 (t
275 (vc-file-setprop file 'vc-checkout-time 0)
276 (if set-state (vc-file-setprop file 'vc-state 'edited))))))
277 ;; entry with arbitrary text as timestamp
278 ;; (this means we should consider it modified)
279 ((looking-at
280 (concat "/[^/]+"
281 ;; revision
282 "/\\([^/]*\\)"
283 ;; timestamp (arbitrary text)
284 "/[^/]*"
285 ;; optional conflict field
286 "\\(+[^/]*\\)?/"))
287 (vc-file-setprop file 'vc-workfile-version (match-string 1))
288 (vc-file-setprop file 'vc-checkout-time 0)
289 (if set-state (vc-file-setprop file 'vc-state 'edited)))))
290
291 (defun vc-cvs-print-log (file)
292 "Get change log associated with FILE."
293 (vc-do-command t 'async "cvs" file "log"))
294
295 (defun vc-cvs-show-log-entry (version)
296 (when (re-search-forward
297 ;; also match some context, for safety
298 (concat "----\nrevision " version
299 "\\(\tlocked by:.*\n\\|\n\\)date: ") nil t)
300 ;; set the display window so that
301 ;; the whole log entry is displayed
302 (let (start end lines)
303 (beginning-of-line) (forward-line -1) (setq start (point))
304 (if (not (re-search-forward "^----*\nrevision" nil t))
305 (setq end (point-max))
306 (beginning-of-line) (forward-line -1) (setq end (point)))
307 (setq lines (count-lines start end))
308 (cond
309 ;; if the global information and this log entry fit
310 ;; into the window, display from the beginning
311 ((< (count-lines (point-min) end) (window-height))
312 (goto-char (point-min))
313 (recenter 0)
314 (goto-char start))
315 ;; if the whole entry fits into the window,
316 ;; display it centered
317 ((< (1+ lines) (window-height))
318 (goto-char start)
319 (recenter (1- (- (/ (window-height) 2) (/ lines 2)))))
320 ;; otherwise (the entry is too large for the window),
321 ;; display from the start
322 (t
323 (goto-char start)
324 (recenter 0))))))
325
326 (defun vc-cvs-create-snapshot (dir name branchp)
327 "Assign to DIR's current version a given NAME.
328 If BRANCHP is non-nil, the name is created as a branch (and the current
329 workspace is immediately moved to that new branch)."
330 (vc-do-command nil 0 "cvs" dir "tag" "-c" (if branchp "-b") name)
331 (when branchp (vc-do-command nil 0 "cvs" dir "update" "-r" name)))
332
333 (defun vc-cvs-retrieve-snapshot (dir name update)
334 "Retrieve a snapshot at and below DIR.
335 NAME is the name of the snapshot; if it is empty, do a `cvs update'.
336 If UPDATE is non-nil, then update (resynch) any affected buffers."
337 (with-current-buffer (get-buffer-create "*vc*")
338 (let ((default-directory dir))
339 (erase-buffer)
340 (if (or (not name) (string= name ""))
341 (vc-do-command t 0 "cvs" nil "update")
342 (vc-do-command t 0 "cvs" nil "update" "-r" name))
343 (when update
344 (goto-char (point-min))
345 (while (not (eobp))
346 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
347 (let* ((file (expand-file-name (match-string 2) dir))
348 (state (match-string 1))
349 (buffer (find-buffer-visiting file)))
350 (when buffer
351 (cond
352 ((or (string= state "U")
353 (string= state "P"))
354 (vc-file-setprop file 'vc-state 'up-to-date)
355 (vc-file-setprop file 'vc-workfile-version nil)
356 (vc-file-setprop file 'vc-checkout-time
357 (nth 5 (file-attributes file))))
358 ((or (string= state "M")
359 (string= state "C"))
360 (vc-file-setprop file 'vc-state 'edited)
361 (vc-file-setprop file 'vc-workfile-version nil)
362 (vc-file-setprop file 'vc-checkout-time 0)))
363 (vc-resynch-buffer file t t))))
364 (forward-line 1))))))
365
366 (defun vc-cvs-merge (file first-version &optional second-version)
367 "Merge changes into current working copy of FILE.
368 The changes are between FIRST-VERSION and SECOND-VERSION."
369 (vc-do-command nil 0 "cvs" file
370 "update" "-kk"
371 (concat "-j" first-version)
372 (concat "-j" second-version))
373 (vc-file-setprop file 'vc-state 'edited)
374 (save-excursion
375 (set-buffer (get-buffer "*vc*"))
376 (goto-char (point-min))
377 (if (re-search-forward "conflicts during merge" nil t)
378 1 ; signal error
379 0))) ; signal success
380
381 (defun vc-cvs-merge-news (file)
382 "Merge in any new changes made to FILE."
383 (message "Merging changes into %s..." file)
384 (save-excursion
385 ;; (vc-file-setprop file 'vc-workfile-version nil)
386 (vc-file-setprop file 'vc-checkout-time 0)
387 (vc-do-command nil 0 "cvs" file "update")
388 ;; Analyze the merge result reported by CVS, and set
389 ;; file properties accordingly.
390 (set-buffer (get-buffer "*vc*"))
391 (goto-char (point-min))
392 ;; get new workfile version
393 (if (re-search-forward (concat "^Merging differences between "
394 "[01234567890.]* and "
395 "\\([01234567890.]*\\) into")
396 nil t)
397 (vc-file-setprop file 'vc-workfile-version (match-string 1))
398 (vc-file-setprop file 'vc-workfile-version nil))
399 ;; get file status
400 (prog1
401 (if (re-search-forward
402 (concat "^\\([CMUP] \\)?"
403 (regexp-quote (file-name-nondirectory file))
404 "\\( already contains the differences between \\)?")
405 nil t)
406 (cond
407 ;; Merge successful, we are in sync with repository now
408 ((or (match-string 2)
409 (string= (match-string 1) "U ")
410 (string= (match-string 1) "P "))
411 (vc-file-setprop file 'vc-state 'up-to-date)
412 (vc-file-setprop file 'vc-checkout-time
413 (nth 5 (file-attributes file)))
414 0);; indicate success to the caller
415 ;; Merge successful, but our own changes are still in the file
416 ((string= (match-string 1) "M ")
417 (vc-file-setprop file 'vc-state 'edited)
418 0);; indicate success to the caller
419 ;; Conflicts detected!
420 (t
421 (vc-file-setprop file 'vc-state 'edited)
422 1);; signal the error to the caller
423 )
424 (pop-to-buffer "*vc*")
425 (error "Couldn't analyze cvs update result"))
426 (message "Merging changes into %s...done" file))))
427
428 (defun vc-cvs-check-headers ()
429 "Check if the current file has any headers in it."
430 (save-excursion
431 (goto-char (point-min))
432 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
433 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
434
435 (defun vc-cvs-steal (file &optional rev)
436 "Steal the lock on the current workfile for FILE and revision REV.
437 Inappropriate for CVS"
438 (error "You cannot steal a CVS lock; there are no CVS locks to steal"))
439
440 ;; vc-check `not reached' for CVS.
441
442 (defun vc-cvs-revert (file)
443 "Revert FILE to the version it was based on."
444 ;; Check out via standard output (caused by the final argument
445 ;; FILE below), so that no sticky tag is set.
446 (vc-cvs-checkout file nil (vc-workfile-version file) file)
447 ;; If "cvs edit" was used to make the file writable,
448 ;; call "cvs unedit" now to undo that.
449 (if (not (eq (vc-cvs-checkout-model file) 'implicit))
450 (vc-do-command nil 0 "cvs" file "unedit")))
451
452 (defun vc-cvs-diff (file &optional oldvers newvers)
453 "Get a difference report using CVS between two versions of FILE."
454 (let (options status
455 (diff-switches-list (if (listp diff-switches)
456 diff-switches
457 (list diff-switches))))
458 (if (string= (vc-workfile-version file) "0")
459 ;; This file is added but not yet committed; there is no master file.
460 (if (or oldvers newvers)
461 (error "No revisions of %s exist" file)
462 ;; we regard this as "changed".
463 ;; diff it against /dev/null.
464 (apply 'vc-do-command t
465 'async "diff" file
466 (append diff-switches-list '("/dev/null"))))
467 (apply 'vc-do-command t
468 'async "cvs" file "diff"
469 (and oldvers (concat "-r" oldvers))
470 (and newvers (concat "-r" newvers))
471 diff-switches-list))
472 ;; We can't know yet, so we assume there'll be a difference
473 1))
474
475 (defun vc-cvs-latest-on-branch-p (file)
476 "Return t iff the current workfile version of FILE is the latest on
477 its branch."
478 ;; Since this is only used as a sanity check for vc-cancel-version,
479 ;; and that is not supported under CVS at all, we can safely return t here.
480 ;; TODO: Think of getting rid of this altogether.
481 t)
482
483 (defun vc-cvs-checkin (file rev comment)
484 "CVS-specific version of `vc-backend-checkin'."
485 (let ((switches (if (stringp vc-checkin-switches)
486 (list vc-checkin-switches)
487 vc-checkin-switches))
488 status)
489 ;; explicit check-in to the trunk requires a double check-in (first
490 ;; unexplicit) (CVS-1.3)
491 (if (and rev (vc-trunk-p rev))
492 (apply 'vc-do-command nil 1 "cvs" file
493 "ci" "-m" "intermediate"
494 switches))
495 (setq status (apply 'vc-do-command nil 1 "cvs" file
496 "ci" (if rev (concat "-r" rev))
497 (concat "-m" comment)
498 switches))
499 ;; determine and store the new workfile version
500 (set-buffer "*vc*")
501 (goto-char (point-min))
502 ;; Check checkin problem. We could check `status' as well.
503 (when (re-search-forward "Up-to-date check failed" nil t)
504 (vc-file-setprop file 'vc-state 'needs-merge)
505 (error (substitute-command-keys
506 "Up-to-date check failed: type \\[vc-next-action] to merge in changes")))
507 ;; Update file properties
508 (vc-file-setprop
509 file 'vc-workfile-version
510 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
511 ;; Forget the checkout model of the file, because we might have
512 ;; guessed wrong when we found the file. After commit, we can
513 ;; tell it from the permissions of the file (see
514 ;; vc-cvs-checkout-model).
515 (vc-file-setprop file 'vc-checkout-model nil)
516 (vc-file-setprop file 'vc-state 'up-to-date)
517 (vc-file-setprop file 'vc-checkout-time (nth 5 (file-attributes file)))
518 ;; if this was an explicit check-in, remove the sticky tag
519 (if rev (vc-do-command t 0 "cvs" file "update" "-A"))))
520
521 (defun vc-cvs-responsible-p (file)
522 "Return non-nil if CVS thinks it is responsible for FILE."
523 (file-directory-p (expand-file-name "CVS"
524 (if (file-directory-p file)
525 file
526 (file-name-directory file)))))
527
528 (defun vc-cvs-could-register (file)
529 "Return non-nil if FILE could be registered in CVS.
530 This is only possible if CVS is responsible for FILE's directory."
531 (vc-cvs-responsible-p file))
532
533 (defun vc-cvs-register (file &optional rev comment)
534 "Register FILE into the CVS version-control system.
535 COMMENT can be used to provide an initial description of FILE.
536
537 `vc-register-switches' and `vc-cvs-register-switches' are passed to
538 the CVS command (in that order)."
539 (vc-file-clearprops file)
540 (let ((switches (list
541 (if (stringp vc-register-switches)
542 (list vc-register-switches)
543 vc-register-switches)
544 (if (stringp vc-cvs-register-switches)
545 (list vc-cvs-register-switches)
546 vc-cvs-register-switches))))
547
548 (apply 'vc-do-command nil 0 "cvs" file
549 "add"
550 (and comment (string-match "[^\t\n ]" comment)
551 (concat "-m" comment))
552 switches)))
553
554 (defun vc-cvs-checkout (file &optional writable rev workfile)
555 "Retrieve a revision of FILE into a WORKFILE.
556 WRITABLE non-nil means that the file should be writable.
557 REV is the revision to check out into WORKFILE."
558 (let ((filename (or workfile file))
559 (file-buffer (get-file-buffer file))
560 switches)
561 (message "Checking out %s..." filename)
562 (save-excursion
563 ;; Change buffers to get local value of vc-checkout-switches.
564 (if file-buffer (set-buffer file-buffer))
565 (setq switches (if (stringp vc-checkout-switches)
566 (list vc-checkout-switches)
567 vc-checkout-switches))
568 ;; Save this buffer's default-directory
569 ;; and use save-excursion to make sure it is restored
570 ;; in the same buffer it was saved in.
571 (let ((default-directory default-directory))
572 (save-excursion
573 ;; Adjust the default-directory so that the check-out creates
574 ;; the file in the right place.
575 (setq default-directory (file-name-directory filename))
576 (if workfile
577 (let ((failed t))
578 (unwind-protect
579 (progn
580 (let ((coding-system-for-read 'no-conversion)
581 (coding-system-for-write 'no-conversion))
582 (with-temp-file filename
583 (apply 'vc-do-command
584 (current-buffer) 0 "cvs" file
585 "-Q" ; suppress diagnostic output
586 "update"
587 (and rev (not (string= rev ""))
588 (concat "-r" rev))
589 "-p"
590 switches)))
591 (setq failed nil))
592 (and failed (file-exists-p filename) (delete-file filename))))
593 (if (and (file-exists-p file) (not rev))
594 ;; If no revision was specified, just make the file writable
595 ;; if necessary (using `cvs-edit' if requested).
596 (and writable (not (eq (vc-cvs-checkout-model file) 'implicit))
597 (if vc-cvs-use-edit
598 (vc-do-command nil 0 "cvs" file "edit")
599 (set-file-modes file (logior (file-modes file) 128))
600 (if file-buffer (toggle-read-only -1))))
601 ;; Check out a particular version (or recreate the file).
602 (vc-file-setprop file 'vc-workfile-version nil)
603 (apply 'vc-do-command nil 0 "cvs" file
604 (and writable
605 (or (not (file-exists-p file))
606 (not (eq (vc-cvs-checkout-model file)
607 'implicit)))
608 "-w")
609 "update"
610 ;; default for verbose checkout: clear the sticky tag so
611 ;; that the actual update will get the head of the trunk
612 (if (or (not rev) (string= rev ""))
613 "-A"
614 (concat "-r" rev))
615 switches))
616 (when writable (vc-file-setprop file 'vc-state 'edited))
617 (vc-file-setprop file
618 'vc-checkout-time (nth 5 (file-attributes file)))))
619 (vc-mode-line file)
620 (message "Checking out %s...done" filename)))))
621
622 (defun vc-cvs-annotate-command (file buffer)
623 "Execute \"cvs annotate\" on FILE by using `call-process' and insert
624 the contents in BUFFER."
625 (call-process "cvs" nil buffer nil "annotate" file))
626
627 (defvar vc-cvs-local-month-numbers
628 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4)
629 ("May" . 5) ("Jun" . 6) ("Jul" . 7) ("Aug" . 8)
630 ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12))
631 "Local association list of month numbers")
632
633 (defun vc-cvs-annotate-difference (point)
634 "Return the difference between the time of the line and the current
635 time. Return values are as defined for `current-time'."
636 ;; We need a list of months and their corresponding numbers.
637 (if (looking-at "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): ")
638 (progn
639 (let* ((day (string-to-number (match-string 1)))
640 (month (cdr (assoc (match-string 2) vc-cvs-local-month-numbers)))
641 (year-tmp (string-to-number (match-string 3)))
642 ;; Years 0..68 are 2000..2068.
643 ;; Years 69..99 are 1969..1999.
644 (year (+ (cond ((> 69 year-tmp) 2000)
645 ((> 100 year-tmp) 1900)
646 (t 0))
647 year-tmp)))
648 (goto-char (match-end 0)) ; Position at end makes for nicer overlay result
649 (- (car (current-time))
650 (car (encode-time 0 0 0 day month year)))))
651 ;; If we did not look directly at an annotation, there might be
652 ;; some further down. This is the case if we are positioned at
653 ;; the very top of the buffer, for instance.
654 (if (re-search-forward
655 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): " nil t)
656 (progn
657 (beginning-of-line nil)
658 (vc-cvs-annotate-difference (point))))))
659
660 (provide 'vc-cvs)
661
662 ;;; vc-cvs.el ends here