31384
|
1 ;;; vc-cvs.el --- non-resident support for CVS version-control
|
|
2
|
51733
|
3 ;; Copyright (C) 1995,98,99,2000,2001,02,2003 Free Software Foundation, Inc.
|
31384
|
4
|
|
5 ;; Author: FSF (see vc.el for full credits)
|
|
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
|
|
7
|
54465
|
8 ;; $Id: vc-cvs.el,v 1.67 2004/01/20 17:41:18 uid65624 Exp $
|
31384
|
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
|
35702
|
31 (eval-when-compile
|
35839
|
32 (require 'vc))
|
35584
|
33
|
35569
|
34 ;;;
|
33560
|
35 ;;; Customization options
|
|
36 ;;;
|
|
37
|
44197
|
38 (defcustom vc-cvs-global-switches nil
|
|
39 "*Global switches to pass to any CVS command."
|
|
40 :type '(choice (const :tag "None" nil)
|
|
41 (string :tag "Argument String")
|
|
42 (repeat :tag "Argument List"
|
|
43 :value ("")
|
|
44 string))
|
45255
|
45 :version "21.4"
|
44197
|
46 :group 'vc)
|
|
47
|
31384
|
48 (defcustom vc-cvs-register-switches nil
|
|
49 "*Extra switches for registering a file into CVS.
|
|
50 A string or list of strings passed to the checkin program by
|
|
51 \\[vc-register]."
|
|
52 :type '(choice (const :tag "None" nil)
|
|
53 (string :tag "Argument String")
|
|
54 (repeat :tag "Argument List"
|
|
55 :value ("")
|
|
56 string))
|
31475
|
57 :version "21.1"
|
31384
|
58 :group 'vc)
|
|
59
|
35821
|
60 (defcustom vc-cvs-diff-switches nil
|
|
61 "*A string or list of strings specifying extra switches for cvs diff under VC."
|
|
62 :type '(choice (const :tag "None" nil)
|
|
63 (string :tag "Argument String")
|
|
64 (repeat :tag "Argument List"
|
|
65 :value ("")
|
|
66 string))
|
|
67 :version "21.1"
|
|
68 :group 'vc)
|
|
69
|
31384
|
70 (defcustom vc-cvs-header (or (cdr (assoc 'CVS vc-header-alist)) '("\$Id\$"))
|
|
71 "*Header keywords to be inserted by `vc-insert-headers'."
|
31475
|
72 :version "21.1"
|
35177
|
73 :type '(repeat string)
|
31384
|
74 :group 'vc)
|
|
75
|
|
76 (defcustom vc-cvs-use-edit t
|
|
77 "*Non-nil means to use `cvs edit' to \"check out\" a file.
|
|
78 This is only meaningful if you don't use the implicit checkout model
|
|
79 \(i.e. if you have $CVSREAD set)."
|
|
80 :type 'boolean
|
31475
|
81 :version "21.1"
|
31384
|
82 :group 'vc)
|
|
83
|
50671
|
84 (defcustom vc-cvs-stay-local t
|
31475
|
85 "*Non-nil means use local operations when possible for remote repositories.
|
38288
|
86 This avoids slow queries over the network and instead uses heuristics
|
|
87 and past information to determine the current status of a file.
|
50671
|
88
|
50668
|
89 The value can also be a regular expression or list of regular
|
|
90 expressions to match against the host name of a repository; then VC
|
50671
|
91 only stays local for hosts that match it. Alternatively, the value
|
|
92 can be a list of regular expressions where the first element is the
|
|
93 symbol `except'; then VC always stays local except for hosts matched
|
|
94 by these regular expressions."
|
31384
|
95 :type '(choice (const :tag "Always stay local" t)
|
50668
|
96 (const :tag "Don't stay local" nil)
|
|
97 (list :format "\nExamine hostname and %v" :tag "Examine hostname ..."
|
|
98 (set :format "%v" :inline t (const :format "%t" :tag "don't" except))
|
|
99 (regexp :format " stay local,\n%t: %v" :tag "if it matches")
|
|
100 (repeat :format "%v%i\n" :inline t (regexp :tag "or"))))
|
31475
|
101 :version "21.1"
|
31384
|
102 :group 'vc)
|
|
103
|
43447
|
104 (defcustom vc-cvs-sticky-date-format-string "%c"
|
|
105 "*Format string for mode-line display of sticky date.
|
|
106 Format is according to `format-time-string'. Only used if
|
|
107 `vc-cvs-sticky-tag-display' is t."
|
|
108 :type '(string)
|
45255
|
109 :version "21.4"
|
43447
|
110 :group 'vc)
|
|
111
|
|
112 (defcustom vc-cvs-sticky-tag-display t
|
|
113 "*Specify the mode-line display of sticky tags.
|
|
114 Value t means default display, nil means no display at all. If the
|
|
115 value is a function or macro, it is called with the sticky tag and
|
|
116 its' type as parameters, in that order. TYPE can have three different
|
|
117 values: `symbolic-name' (TAG is a string), `revision-number' (TAG is a
|
|
118 string) and `date' (TAG is a date as returned by `encode-time'). The
|
|
119 return value of the function or macro will be displayed as a string.
|
|
120
|
|
121 Here's an example that will display the formatted date for sticky
|
|
122 dates and the word \"Sticky\" for sticky tag names and revisions.
|
|
123
|
|
124 (lambda (tag type)
|
44436
|
125 (cond ((eq type 'date) (format-time-string
|
43447
|
126 vc-cvs-sticky-date-format-string tag))
|
|
127 ((eq type 'revision-number) \"Sticky\")
|
|
128 ((eq type 'symbolic-name) \"Sticky\")))
|
|
129
|
|
130 Here's an example that will abbreviate to the first character only,
|
47917
|
131 any text before the first occurrence of `-' for sticky symbolic tags.
|
43447
|
132 If the sticky tag is a revision number, the word \"Sticky\" is
|
|
133 displayed. Date and time is displayed for sticky dates.
|
|
134
|
|
135 (lambda (tag type)
|
|
136 (cond ((eq type 'date) (format-time-string \"%Y%m%d %H:%M\" tag))
|
|
137 ((eq type 'revision-number) \"Sticky\")
|
44436
|
138 ((eq type 'symbolic-name)
|
43447
|
139 (condition-case nil
|
|
140 (progn
|
|
141 (string-match \"\\\\([^-]*\\\\)\\\\(.*\\\\)\" tag)
|
44436
|
142 (concat (substring (match-string 1 tag) 0 1) \":\"
|
43447
|
143 (substring (match-string 2 tag) 1 nil)))
|
|
144 (error tag))))) ; Fall-back to given tag name.
|
|
145
|
|
146 See also variable `vc-cvs-sticky-date-format-string'."
|
|
147 :type '(choice boolean function)
|
45255
|
148 :version "21.4"
|
43447
|
149 :group 'vc)
|
35569
|
150
|
33560
|
151 ;;;
|
|
152 ;;; Internal variables
|
|
153 ;;;
|
|
154
|
|
155 (defvar vc-cvs-local-month-numbers
|
|
156 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4)
|
|
157 ("May" . 5) ("Jun" . 6) ("Jul" . 7) ("Aug" . 8)
|
|
158 ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12))
|
|
159 "Local association list of month numbers.")
|
|
160
|
35569
|
161
|
33560
|
162 ;;;
|
35569
|
163 ;;; State-querying functions
|
33560
|
164 ;;;
|
|
165
|
31384
|
166 ;;;###autoload (defun vc-cvs-registered (f)
|
|
167 ;;;###autoload (when (file-readable-p (expand-file-name
|
|
168 ;;;###autoload "CVS/Entries" (file-name-directory f)))
|
47811
8b1c72f30fea
(vc-cvs-registered): In the autoload version use load instead of
Markus Rost <rost@math.uni-bielefeld.de>
diff
changeset
|
169 ;;;###autoload (load "vc-cvs")
|
31384
|
170 ;;;###autoload (vc-cvs-registered f)))
|
|
171
|
|
172 (defun vc-cvs-registered (file)
|
|
173 "Check if FILE is CVS registered."
|
|
174 (let ((dirname (or (file-name-directory file) ""))
|
|
175 (basename (file-name-nondirectory file))
|
|
176 ;; make sure that the file name is searched case-sensitively
|
|
177 (case-fold-search nil))
|
|
178 (if (file-readable-p (expand-file-name "CVS/Entries" dirname))
|
|
179 (with-temp-buffer
|
50453
e499daf7fb22
(vc-cvs-get-entries): New function that uses the right coding system for
André Spiegel <spiegel@gnu.org>
diff
changeset
|
180 (vc-cvs-get-entries dirname)
|
31384
|
181 (goto-char (point-min))
|
31475
|
182 (cond
|
|
183 ((re-search-forward
|
44104
|
184 ;; CVS-removed files are not taken under VC control.
|
|
185 (concat "^/" (regexp-quote basename) "/[^/-]") nil t)
|
31384
|
186 (beginning-of-line)
|
|
187 (vc-cvs-parse-entry file)
|
|
188 t)
|
|
189 (t nil)))
|
|
190 nil)))
|
|
191
|
|
192 (defun vc-cvs-state (file)
|
|
193 "CVS-specific version of `vc-state'."
|
51733
|
194 (if (vc-stay-local-p file)
|
31384
|
195 (let ((state (vc-file-getprop file 'vc-state)))
|
|
196 ;; If we should stay local, use the heuristic but only if
|
|
197 ;; we don't have a more precise state already available.
|
|
198 (if (memq state '(up-to-date edited))
|
|
199 (vc-cvs-state-heuristic file)
|
|
200 state))
|
|
201 (with-temp-buffer
|
|
202 (cd (file-name-directory file))
|
44197
|
203 (vc-cvs-command t 0 file "status")
|
31384
|
204 (vc-cvs-parse-status t))))
|
|
205
|
|
206 (defun vc-cvs-state-heuristic (file)
|
|
207 "CVS-specific state heuristic."
|
|
208 ;; If the file has not changed since checkout, consider it `up-to-date'.
|
|
209 ;; Otherwise consider it `edited'.
|
|
210 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time))
|
|
211 (lastmod (nth 5 (file-attributes file))))
|
|
212 (if (equal checkout-time lastmod)
|
|
213 'up-to-date
|
|
214 'edited)))
|
|
215
|
33560
|
216 (defun vc-cvs-dir-state (dir)
|
|
217 "Find the CVS state of all files in DIR."
|
50645
|
218 ;; if DIR is not under CVS control, don't do anything.
|
|
219 (when (file-readable-p (expand-file-name "CVS/Entries" dir))
|
51733
|
220 (if (vc-stay-local-p dir)
|
50645
|
221 (vc-cvs-dir-state-heuristic dir)
|
|
222 (let ((default-directory dir))
|
|
223 ;; Don't specify DIR in this command, the default-directory is
|
|
224 ;; enough. Otherwise it might fail with remote repositories.
|
|
225 (with-temp-buffer
|
|
226 (vc-cvs-command t 0 nil "status" "-l")
|
|
227 (goto-char (point-min))
|
|
228 (while (re-search-forward "^=+\n\\([^=\n].*\n\\|\n\\)+" nil t)
|
|
229 (narrow-to-region (match-beginning 0) (match-end 0))
|
|
230 (vc-cvs-parse-status)
|
|
231 (goto-char (point-max))
|
|
232 (widen)))))))
|
33560
|
233
|
|
234 (defun vc-cvs-workfile-version (file)
|
|
235 "CVS-specific version of `vc-workfile-version'."
|
|
236 ;; There is no need to consult RCS headers under CVS, because we
|
|
237 ;; get the workfile version for free when we recognize that a file
|
|
238 ;; is registered in CVS.
|
|
239 (vc-cvs-registered file)
|
|
240 (vc-file-getprop file 'vc-workfile-version))
|
|
241
|
|
242 (defun vc-cvs-checkout-model (file)
|
|
243 "CVS-specific version of `vc-checkout-model'."
|
|
244 (if (or (getenv "CVSREAD")
|
|
245 ;; If the file is not writable (despite CVSREAD being
|
|
246 ;; undefined), this is probably because the file is being
|
|
247 ;; "watched" by other developers.
|
|
248 ;; (If vc-mistrust-permissions was t, we actually shouldn't
|
|
249 ;; trust this, but there is no other way to learn this from CVS
|
|
250 ;; at the moment (version 1.9).)
|
|
251 (string-match "r-..-..-." (nth 8 (file-attributes file))))
|
|
252 'announce
|
|
253 'implicit))
|
|
254
|
31404
|
255 (defun vc-cvs-mode-line-string (file)
|
|
256 "Return string for placement into the modeline for FILE.
|
43447
|
257 Compared to the default implementation, this function does two things:
|
|
258 Handle the special case of a CVS file that is added but not yet
|
|
259 committed and support display of sticky tags."
|
50923
3eab629b1239
(vc-cvs-mode-line-string): Use vc-default-mode-line-string.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
260 (let ((sticky-tag (vc-file-getprop file 'vc-cvs-sticky-tag))
|
3eab629b1239
(vc-cvs-mode-line-string): Use vc-default-mode-line-string.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
261 (string (if (string= (vc-workfile-version file) "0")
|
3eab629b1239
(vc-cvs-mode-line-string): Use vc-default-mode-line-string.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
262 ;; A file that is added but not yet committed.
|
3eab629b1239
(vc-cvs-mode-line-string): Use vc-default-mode-line-string.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
263 "CVS @@"
|
3eab629b1239
(vc-cvs-mode-line-string): Use vc-default-mode-line-string.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
264 (vc-default-mode-line-string 'CVS file))))
|
3eab629b1239
(vc-cvs-mode-line-string): Use vc-default-mode-line-string.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
265 (if (zerop (length sticky-tag))
|
3eab629b1239
(vc-cvs-mode-line-string): Use vc-default-mode-line-string.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
266 string
|
3eab629b1239
(vc-cvs-mode-line-string): Use vc-default-mode-line-string.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
267 (concat string "[" sticky-tag "]"))))
|
31404
|
268
|
33560
|
269 (defun vc-cvs-dired-state-info (file)
|
|
270 "CVS-specific version of `vc-dired-state-info'."
|
50898
8806616471e2
(vc-cvs-dired-state-info): Use `added' for added files and
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
271 (let ((cvs-state (vc-state file)))
|
8806616471e2
(vc-cvs-dired-state-info): Use `added' for added files and
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
272 (cond ((eq cvs-state 'edited)
|
50909
|
273 (if (equal (vc-workfile-version file) "0")
|
50898
8806616471e2
(vc-cvs-dired-state-info): Use `added' for added files and
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
274 "(added)" "(modified)"))
|
8806616471e2
(vc-cvs-dired-state-info): Use `added' for added files and
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
275 ((eq cvs-state 'needs-patch) "(patch)")
|
8806616471e2
(vc-cvs-dired-state-info): Use `added' for added files and
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
276 ((eq cvs-state 'needs-merge) "(merge)"))))
|
31384
|
277
|
35569
|
278
|
33560
|
279 ;;;
|
|
280 ;;; State-changing functions
|
|
281 ;;;
|
31384
|
282
|
33560
|
283 (defun vc-cvs-register (file &optional rev comment)
|
|
284 "Register FILE into the CVS version-control system.
|
|
285 COMMENT can be used to provide an initial description of FILE.
|
31384
|
286
|
33560
|
287 `vc-register-switches' and `vc-cvs-register-switches' are passed to
|
|
288 the CVS command (in that order)."
|
51733
|
289 (when (and (not (vc-cvs-responsible-p file))
|
|
290 (vc-cvs-could-register file))
|
|
291 ;; Register the directory if needed.
|
|
292 (vc-cvs-register (directory-file-name (file-name-directory file))))
|
50910
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
293 (apply 'vc-cvs-command nil 0 file
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
294 "add"
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
295 (and comment (string-match "[^\t\n ]" comment)
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
296 (concat "-m" comment))
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
297 (vc-switches 'CVS 'register)))
|
31384
|
298
|
33560
|
299 (defun vc-cvs-responsible-p (file)
|
|
300 "Return non-nil if CVS thinks it is responsible for FILE."
|
|
301 (file-directory-p (expand-file-name "CVS"
|
|
302 (if (file-directory-p file)
|
|
303 file
|
|
304 (file-name-directory file)))))
|
31384
|
305
|
51733
|
306 (defun vc-cvs-could-register (file)
|
33560
|
307 "Return non-nil if FILE could be registered in CVS.
|
51733
|
308 This is only possible if CVS is managing FILE's directory or one of
|
|
309 its parents."
|
|
310 (let ((dir file))
|
|
311 (while (and (stringp dir)
|
|
312 (not (equal dir (setq dir (file-name-directory dir))))
|
|
313 dir)
|
|
314 (setq dir (if (file-directory-p
|
|
315 (expand-file-name "CVS/Entries" dir))
|
|
316 t (directory-file-name dir))))
|
|
317 (eq dir t)))
|
31384
|
318
|
|
319 (defun vc-cvs-checkin (file rev comment)
|
|
320 "CVS-specific version of `vc-backend-checkin'."
|
50910
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
321 (unless (or (not rev) (vc-cvs-valid-version-number-p rev))
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
322 (if (not (vc-cvs-valid-symbolic-tag-name-p rev))
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
323 (error "%s is not a valid symbolic tag name" rev)
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
324 ;; If the input revison is a valid symbolic tag name, we create it
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
325 ;; as a branch, commit and switch to it.
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
326 (apply 'vc-cvs-command nil 0 file "tag" "-b" (list rev))
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
327 (apply 'vc-cvs-command nil 0 file "update" "-r" (list rev))
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
328 (vc-file-setprop file 'vc-cvs-sticky-tag rev)))
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
329 (let ((status (apply 'vc-cvs-command nil 1 file
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
330 "ci" (if rev (concat "-r" rev))
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
331 (concat "-m" comment)
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
332 (vc-switches 'CVS 'checkin))))
|
31384
|
333 (set-buffer "*vc*")
|
|
334 (goto-char (point-min))
|
32948
3c95af2888f6
(vc-cvs-checkin): Check both status and error message after command.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
335 (when (not (zerop status))
|
3c95af2888f6
(vc-cvs-checkin): Check both status and error message after command.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
336 ;; Check checkin problem.
|
3c95af2888f6
(vc-cvs-checkin): Check both status and error message after command.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
337 (cond
|
3c95af2888f6
(vc-cvs-checkin): Check both status and error message after command.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
338 ((re-search-forward "Up-to-date check failed" nil t)
|
3c95af2888f6
(vc-cvs-checkin): Check both status and error message after command.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
339 (vc-file-setprop file 'vc-state 'needs-merge)
|
3c95af2888f6
(vc-cvs-checkin): Check both status and error message after command.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
340 (error (substitute-command-keys
|
3c95af2888f6
(vc-cvs-checkin): Check both status and error message after command.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
341 (concat "Up-to-date check failed: "
|
3c95af2888f6
(vc-cvs-checkin): Check both status and error message after command.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
342 "type \\[vc-next-action] to merge in changes"))))
|
3c95af2888f6
(vc-cvs-checkin): Check both status and error message after command.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
343 (t
|
3c95af2888f6
(vc-cvs-checkin): Check both status and error message after command.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
344 (pop-to-buffer (current-buffer))
|
3c95af2888f6
(vc-cvs-checkin): Check both status and error message after command.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
345 (goto-char (point-min))
|
3c95af2888f6
(vc-cvs-checkin): Check both status and error message after command.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
346 (shrink-window-if-larger-than-buffer)
|
3c95af2888f6
(vc-cvs-checkin): Check both status and error message after command.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
347 (error "Check-in failed"))))
|
31384
|
348 ;; Update file properties
|
|
349 (vc-file-setprop
|
|
350 file 'vc-workfile-version
|
|
351 (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
|
|
352 ;; Forget the checkout model of the file, because we might have
|
|
353 ;; guessed wrong when we found the file. After commit, we can
|
|
354 ;; tell it from the permissions of the file (see
|
|
355 ;; vc-cvs-checkout-model).
|
|
356 (vc-file-setprop file 'vc-checkout-model nil)
|
43447
|
357
|
|
358 ;; if this was an explicit check-in (does not include creation of
|
|
359 ;; a branch), remove the sticky tag.
|
|
360 (if (and rev (not (vc-cvs-valid-symbolic-tag-name-p rev)))
|
44197
|
361 (vc-cvs-command nil 0 file "update" "-A"))))
|
31384
|
362
|
47799
|
363 (defun vc-cvs-find-version (file rev buffer)
|
|
364 (apply 'vc-cvs-command
|
|
365 buffer 0 file
|
|
366 "-Q" ; suppress diagnostic output
|
|
367 "update"
|
|
368 (and rev (not (string= rev ""))
|
|
369 (concat "-r" rev))
|
|
370 "-p"
|
50910
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
371 (vc-switches 'CVS 'checkout)))
|
47799
|
372
|
35132
|
373 (defun vc-cvs-checkout (file &optional editable rev workfile)
|
31384
|
374 "Retrieve a revision of FILE into a WORKFILE.
|
35132
|
375 EDITABLE non-nil means that the file should be writable.
|
31384
|
376 REV is the revision to check out into WORKFILE."
|
|
377 (let ((filename (or workfile file))
|
|
378 (file-buffer (get-file-buffer file))
|
|
379 switches)
|
|
380 (message "Checking out %s..." filename)
|
|
381 (save-excursion
|
|
382 ;; Change buffers to get local value of vc-checkout-switches.
|
|
383 (if file-buffer (set-buffer file-buffer))
|
50910
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
384 (setq switches (vc-switches 'CVS 'checkout))
|
31384
|
385 ;; Save this buffer's default-directory
|
|
386 ;; and use save-excursion to make sure it is restored
|
|
387 ;; in the same buffer it was saved in.
|
|
388 (let ((default-directory default-directory))
|
|
389 (save-excursion
|
|
390 ;; Adjust the default-directory so that the check-out creates
|
|
391 ;; the file in the right place.
|
|
392 (setq default-directory (file-name-directory filename))
|
|
393 (if workfile
|
35569
|
394 (let ((failed t)
|
33637
|
395 (backup-name (if (string= file workfile)
|
33549
8a998774febc
(vc-cvs-revert): Use `cvs unedit' only if `vc-cvs-use-edit' is on.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
396 (car (find-backup-file-name filename)))))
|
8a998774febc
(vc-cvs-revert): Use `cvs unedit' only if `vc-cvs-use-edit' is on.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
397 (when backup-name
|
35569
|
398 (copy-file filename backup-name
|
33549
8a998774febc
(vc-cvs-revert): Use `cvs unedit' only if `vc-cvs-use-edit' is on.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
399 'ok-if-already-exists 'keep-date)
|
8a998774febc
(vc-cvs-revert): Use `cvs unedit' only if `vc-cvs-use-edit' is on.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
400 (unless (file-writable-p filename)
|
8a998774febc
(vc-cvs-revert): Use `cvs unedit' only if `vc-cvs-use-edit' is on.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
401 (set-file-modes filename
|
8a998774febc
(vc-cvs-revert): Use `cvs unedit' only if `vc-cvs-use-edit' is on.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
402 (logior (file-modes filename) 128))))
|
31384
|
403 (unwind-protect
|
|
404 (progn
|
|
405 (let ((coding-system-for-read 'no-conversion)
|
|
406 (coding-system-for-write 'no-conversion))
|
|
407 (with-temp-file filename
|
44197
|
408 (apply 'vc-cvs-command
|
|
409 (current-buffer) 0 file
|
31384
|
410 "-Q" ; suppress diagnostic output
|
43727
|
411 "update"
|
48965
|
412 (and (stringp rev)
|
|
413 (not (string= rev ""))
|
31384
|
414 (concat "-r" rev))
|
|
415 "-p"
|
|
416 switches)))
|
|
417 (setq failed nil))
|
35569
|
418 (if failed
|
33637
|
419 (if backup-name
|
35569
|
420 (rename-file backup-name filename
|
33637
|
421 'ok-if-already-exists)
|
|
422 (if (file-exists-p filename)
|
|
423 (delete-file filename)))
|
33549
8a998774febc
(vc-cvs-revert): Use `cvs unedit' only if `vc-cvs-use-edit' is on.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
424 (and backup-name
|
8a998774febc
(vc-cvs-revert): Use `cvs unedit' only if `vc-cvs-use-edit' is on.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
425 (not vc-make-backup-files)
|
8a998774febc
(vc-cvs-revert): Use `cvs unedit' only if `vc-cvs-use-edit' is on.
André Spiegel <spiegel@gnu.org>
diff
changeset
|
426 (delete-file backup-name)))))
|
31384
|
427 (if (and (file-exists-p file) (not rev))
|
|
428 ;; If no revision was specified, just make the file writable
|
|
429 ;; if necessary (using `cvs-edit' if requested).
|
50910
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
430 (and editable (not (eq (vc-cvs-checkout-model file) 'implicit))
|
48965
|
431 (if vc-cvs-use-edit
|
|
432 (vc-cvs-command nil 0 file "edit")
|
|
433 (set-file-modes file (logior (file-modes file) 128))
|
|
434 (if file-buffer (toggle-read-only -1))))
|
|
435 ;; Check out a particular version (or recreate the file).
|
|
436 (vc-file-setprop file 'vc-workfile-version nil)
|
|
437 (apply 'vc-cvs-command nil 0 file
|
|
438 (and editable
|
|
439 (or (not (file-exists-p file))
|
|
440 (not (eq (vc-cvs-checkout-model file)
|
|
441 'implicit)))
|
|
442 "-w")
|
|
443 "update"
|
51164
|
444 (when rev
|
|
445 (unless (eq rev t)
|
|
446 ;; default for verbose checkout: clear the
|
|
447 ;; sticky tag so that the actual update will
|
|
448 ;; get the head of the trunk
|
|
449 (if (string= rev "")
|
|
450 "-A"
|
|
451 (concat "-r" rev))))
|
48965
|
452 switches))))
|
31384
|
453 (vc-mode-line file)
|
|
454 (message "Checking out %s...done" filename)))))
|
|
455
|
50923
3eab629b1239
(vc-cvs-mode-line-string): Use vc-default-mode-line-string.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
456 (defun vc-cvs-delete-file (file)
|
3eab629b1239
(vc-cvs-mode-line-string): Use vc-default-mode-line-string.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
457 (vc-cvs-command nil 0 file "remove" "-f"))
|
3eab629b1239
(vc-cvs-mode-line-string): Use vc-default-mode-line-string.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
458
|
39001
|
459 (defun vc-cvs-revert (file &optional contents-done)
|
33560
|
460 "Revert FILE to the version it was based on."
|
39001
|
461 (unless contents-done
|
|
462 ;; Check out via standard output (caused by the final argument
|
|
463 ;; FILE below), so that no sticky tag is set.
|
50910
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
464 (vc-cvs-checkout file nil (vc-workfile-version file) file))
|
39001
|
465 (unless (eq (vc-checkout-model file) 'implicit)
|
|
466 (if vc-cvs-use-edit
|
44197
|
467 (vc-cvs-command nil 0 file "unedit")
|
39001
|
468 ;; Make the file read-only by switching off all w-bits
|
|
469 (set-file-modes file (logand (file-modes file) 3950)))))
|
33560
|
470
|
|
471 (defun vc-cvs-merge (file first-version &optional second-version)
|
|
472 "Merge changes into current working copy of FILE.
|
|
473 The changes are between FIRST-VERSION and SECOND-VERSION."
|
44197
|
474 (vc-cvs-command nil 0 file
|
33560
|
475 "update" "-kk"
|
|
476 (concat "-j" first-version)
|
|
477 (concat "-j" second-version))
|
|
478 (vc-file-setprop file 'vc-state 'edited)
|
50645
|
479 (with-current-buffer (get-buffer "*vc*")
|
33560
|
480 (goto-char (point-min))
|
|
481 (if (re-search-forward "conflicts during merge" nil t)
|
|
482 1 ; signal error
|
|
483 0))) ; signal success
|
|
484
|
|
485 (defun vc-cvs-merge-news (file)
|
|
486 "Merge in any new changes made to FILE."
|
|
487 (message "Merging changes into %s..." file)
|
50645
|
488 ;; (vc-file-setprop file 'vc-workfile-version nil)
|
|
489 (vc-file-setprop file 'vc-checkout-time 0)
|
|
490 (vc-cvs-command nil 0 file "update")
|
|
491 ;; Analyze the merge result reported by CVS, and set
|
|
492 ;; file properties accordingly.
|
|
493 (with-current-buffer (get-buffer "*vc*")
|
33560
|
494 (goto-char (point-min))
|
|
495 ;; get new workfile version
|
50645
|
496 (if (re-search-forward
|
|
497 "^Merging differences between [0-9.]* and \\([0-9.]*\\) into" nil t)
|
33560
|
498 (vc-file-setprop file 'vc-workfile-version (match-string 1))
|
|
499 (vc-file-setprop file 'vc-workfile-version nil))
|
|
500 ;; get file status
|
|
501 (prog1
|
|
502 (if (eq (buffer-size) 0)
|
|
503 0 ;; there were no news; indicate success
|
|
504 (if (re-search-forward
|
|
505 (concat "^\\([CMUP] \\)?"
|
|
506 (regexp-quote (file-name-nondirectory file))
|
|
507 "\\( already contains the differences between \\)?")
|
|
508 nil t)
|
|
509 (cond
|
|
510 ;; Merge successful, we are in sync with repository now
|
|
511 ((or (match-string 2)
|
|
512 (string= (match-string 1) "U ")
|
|
513 (string= (match-string 1) "P "))
|
|
514 (vc-file-setprop file 'vc-state 'up-to-date)
|
|
515 (vc-file-setprop file 'vc-checkout-time
|
|
516 (nth 5 (file-attributes file)))
|
|
517 0);; indicate success to the caller
|
|
518 ;; Merge successful, but our own changes are still in the file
|
|
519 ((string= (match-string 1) "M ")
|
|
520 (vc-file-setprop file 'vc-state 'edited)
|
|
521 0);; indicate success to the caller
|
|
522 ;; Conflicts detected!
|
|
523 (t
|
|
524 (vc-file-setprop file 'vc-state 'edited)
|
|
525 1);; signal the error to the caller
|
|
526 )
|
|
527 (pop-to-buffer "*vc*")
|
|
528 (error "Couldn't analyze cvs update result")))
|
|
529 (message "Merging changes into %s...done" file))))
|
|
530
|
35569
|
531
|
33560
|
532 ;;;
|
|
533 ;;; History functions
|
|
534 ;;;
|
|
535
|
54465
|
536 (defun vc-cvs-print-log (file &optional buffer)
|
33560
|
537 "Get change log associated with FILE."
|
44197
|
538 (vc-cvs-command
|
54465
|
539 buffer
|
51733
|
540 (if (and (vc-stay-local-p file) (fboundp 'start-process)) 'async 0)
|
44197
|
541 file "log"))
|
33560
|
542
|
54465
|
543 (defun vc-cvs-diff (file &optional oldvers newvers buffer)
|
33560
|
544 "Get a difference report using CVS between two versions of FILE."
|
50910
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
545 (if (string= (vc-workfile-version file) "0")
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
546 ;; This file is added but not yet committed; there is no master file.
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
547 (if (or oldvers newvers)
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
548 (error "No revisions of %s exist" file)
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
549 ;; We regard this as "changed".
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
550 ;; Diff it against /dev/null.
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
551 ;; Note: this is NOT a "cvs diff".
|
54465
|
552 (apply 'vc-do-command (or buffer "*vc-diff*")
|
50910
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
553 1 "diff" file
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
554 (append (vc-switches nil 'diff) '("/dev/null")))
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
555 ;; Even if it's empty, it's locally modified.
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
556 1)
|
51733
|
557 (let* ((async (and (vc-stay-local-p file) (fboundp 'start-process)))
|
54465
|
558 (status (apply 'vc-cvs-command (or buffer "*vc-diff*")
|
50910
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
559 (if async 'async 1)
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
560 file "diff"
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
561 (and oldvers (concat "-r" oldvers))
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
562 (and newvers (concat "-r" newvers))
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
563 (vc-switches 'CVS 'diff))))
|
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
564 (if async 1 status)))) ; async diff, pessimistic assumption
|
33560
|
565
|
40125
|
566 (defun vc-cvs-diff-tree (dir &optional rev1 rev2)
|
|
567 "Diff all files at and below DIR."
|
|
568 (with-current-buffer "*vc-diff*"
|
|
569 (setq default-directory dir)
|
51733
|
570 (if (vc-stay-local-p dir)
|
40125
|
571 ;; local diff: do it filewise, and only for files that are modified
|
|
572 (vc-file-tree-walk
|
|
573 dir
|
|
574 (lambda (f)
|
|
575 (vc-exec-after
|
|
576 `(let ((coding-system-for-read (vc-coding-system-for-diff ',f)))
|
|
577 ;; possible optimization: fetch the state of all files
|
|
578 ;; in the tree via vc-cvs-dir-state-heuristic
|
|
579 (unless (vc-up-to-date-p ',f)
|
|
580 (message "Looking at %s" ',f)
|
43727
|
581 (vc-diff-internal ',f ',rev1 ',rev2))))))
|
40125
|
582 ;; cvs diff: use a single call for the entire tree
|
|
583 (let ((coding-system-for-read
|
|
584 (or coding-system-for-read 'undecided)))
|
44197
|
585 (apply 'vc-cvs-command "*vc-diff*" 1 nil "diff"
|
43727
|
586 (and rev1 (concat "-r" rev1))
|
|
587 (and rev2 (concat "-r" rev2))
|
50910
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
588 (vc-switches 'CVS 'diff))))))
|
40125
|
589
|
33545
|
590 (defun vc-cvs-annotate-command (file buffer &optional version)
|
|
591 "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER.
|
|
592 Optional arg VERSION is a version to annotate from."
|
50910
8c4130079acf
(vc-cvs-register, vc-cvs-checkin, vc-cvs-find-version, vc-cvs-diff)
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
593 (vc-cvs-command buffer 0 file "annotate" (if version (concat "-r" version))))
|
31384
|
594
|
40171
|
595 (defun vc-cvs-annotate-current-time ()
|
|
596 "Return the current time, based at midnight of the current day, and
|
|
597 encoded as fractional days."
|
|
598 (vc-annotate-convert-time
|
|
599 (apply 'encode-time 0 0 0 (nthcdr 3 (decode-time (current-time))))))
|
|
600
|
|
601 (defun vc-cvs-annotate-time ()
|
|
602 "Return the time of the next annotation (as fraction of days)
|
42206
|
603 systime, or nil if there is none."
|
44436
|
604 (let ((time-stamp
|
40171
|
605 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): "))
|
|
606 (if (looking-at time-stamp)
|
31384
|
607 (progn
|
|
608 (let* ((day (string-to-number (match-string 1)))
|
44436
|
609 (month (cdr (assoc (match-string 2)
|
40171
|
610 vc-cvs-local-month-numbers)))
|
31384
|
611 (year-tmp (string-to-number (match-string 3)))
|
|
612 ;; Years 0..68 are 2000..2068.
|
|
613 ;; Years 69..99 are 1969..1999.
|
|
614 (year (+ (cond ((> 69 year-tmp) 2000)
|
|
615 ((> 100 year-tmp) 1900)
|
|
616 (t 0))
|
|
617 year-tmp)))
|
|
618 (goto-char (match-end 0)) ; Position at end makes for nicer overlay result
|
40171
|
619 (vc-annotate-convert-time (encode-time 0 0 0 day month year))))
|
31384
|
620 ;; If we did not look directly at an annotation, there might be
|
|
621 ;; some further down. This is the case if we are positioned at
|
|
622 ;; the very top of the buffer, for instance.
|
40171
|
623 (if (re-search-forward time-stamp nil t)
|
31384
|
624 (progn
|
|
625 (beginning-of-line nil)
|
40171
|
626 (vc-cvs-annotate-time))))))
|
35569
|
627
|
53631
|
628 (defun vc-cvs-annotate-extract-revision-at-line ()
|
|
629 (save-excursion
|
|
630 (beginning-of-line)
|
|
631 (if (re-search-forward "^\\([0-9]+\\.[0-9]+\\(\\.[0-9]+\\)*\\) +("
|
|
632 (line-end-position) t)
|
|
633 (match-string-no-properties 1)
|
|
634 nil)))
|
|
635
|
33560
|
636 ;;;
|
|
637 ;;; Snapshot system
|
|
638 ;;;
|
|
639
|
|
640 (defun vc-cvs-create-snapshot (dir name branchp)
|
|
641 "Assign to DIR's current version a given NAME.
|
|
642 If BRANCHP is non-nil, the name is created as a branch (and the current
|
|
643 workspace is immediately moved to that new branch)."
|
44197
|
644 (vc-cvs-command nil 0 dir "tag" "-c" (if branchp "-b") name)
|
|
645 (when branchp (vc-cvs-command nil 0 dir "update" "-r" name)))
|
33560
|
646
|
|
647 (defun vc-cvs-retrieve-snapshot (dir name update)
|
|
648 "Retrieve a snapshot at and below DIR.
|
|
649 NAME is the name of the snapshot; if it is empty, do a `cvs update'.
|
|
650 If UPDATE is non-nil, then update (resynch) any affected buffers."
|
|
651 (with-current-buffer (get-buffer-create "*vc*")
|
43447
|
652 (let ((default-directory dir)
|
|
653 (sticky-tag))
|
33560
|
654 (erase-buffer)
|
|
655 (if (or (not name) (string= name ""))
|
44197
|
656 (vc-cvs-command t 0 nil "update")
|
|
657 (vc-cvs-command t 0 nil "update" "-r" name)
|
43447
|
658 (setq sticky-tag name))
|
33560
|
659 (when update
|
|
660 (goto-char (point-min))
|
|
661 (while (not (eobp))
|
|
662 (if (looking-at "\\([CMUP]\\) \\(.*\\)")
|
|
663 (let* ((file (expand-file-name (match-string 2) dir))
|
|
664 (state (match-string 1))
|
|
665 (buffer (find-buffer-visiting file)))
|
|
666 (when buffer
|
|
667 (cond
|
|
668 ((or (string= state "U")
|
|
669 (string= state "P"))
|
|
670 (vc-file-setprop file 'vc-state 'up-to-date)
|
|
671 (vc-file-setprop file 'vc-workfile-version nil)
|
|
672 (vc-file-setprop file 'vc-checkout-time
|
|
673 (nth 5 (file-attributes file))))
|
|
674 ((or (string= state "M")
|
|
675 (string= state "C"))
|
|
676 (vc-file-setprop file 'vc-state 'edited)
|
|
677 (vc-file-setprop file 'vc-workfile-version nil)
|
|
678 (vc-file-setprop file 'vc-checkout-time 0)))
|
43447
|
679 (vc-file-setprop file 'vc-cvs-sticky-tag sticky-tag)
|
33560
|
680 (vc-resynch-buffer file t t))))
|
|
681 (forward-line 1))))))
|
|
682
|
35569
|
683
|
33560
|
684 ;;;
|
|
685 ;;; Miscellaneous
|
|
686 ;;;
|
|
687
|
51733
|
688 (defalias 'vc-cvs-make-version-backups-p 'vc-stay-local-p
|
50645
|
689 "Return non-nil if version backups should be made for FILE.")
|
33560
|
690
|
|
691 (defun vc-cvs-check-headers ()
|
|
692 "Check if the current file has any headers in it."
|
|
693 (save-excursion
|
|
694 (goto-char (point-min))
|
|
695 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
|
|
696 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
|
|
697
|
35569
|
698
|
33560
|
699 ;;;
|
|
700 ;;; Internal functions
|
|
701 ;;;
|
|
702
|
44197
|
703 (defun vc-cvs-command (buffer okstatus file &rest flags)
|
|
704 "A wrapper around `vc-do-command' for use in vc-cvs.el.
|
|
705 The difference to vc-do-command is that this function always invokes `cvs',
|
|
706 and that it passes `vc-cvs-global-switches' to it before FLAGS."
|
|
707 (apply 'vc-do-command buffer okstatus "cvs" file
|
44436
|
708 (if (stringp vc-cvs-global-switches)
|
44197
|
709 (cons vc-cvs-global-switches flags)
|
|
710 (append vc-cvs-global-switches
|
|
711 flags))))
|
|
712
|
51733
|
713 (defalias 'vc-cvs-stay-local-p 'vc-stay-local-p) ;Back-compatibility.
|
|
714
|
|
715 (defun vc-cvs-repository-hostname (dirname)
|
|
716 "Hostname of the CVS server associated to workarea DIRNAME."
|
|
717 (let ((rootname (expand-file-name "CVS/Root" dirname)))
|
|
718 (when (file-readable-p rootname)
|
|
719 (with-temp-buffer
|
|
720 (let ((coding-system-for-read
|
|
721 (or file-name-coding-system
|
|
722 default-file-name-coding-system)))
|
|
723 (vc-insert-file rootname))
|
|
724 (goto-char (point-min))
|
|
725 (nth 2 (vc-cvs-parse-root
|
|
726 (buffer-substring (point)
|
|
727 (line-end-position))))))))
|
50668
|
728
|
50898
8806616471e2
(vc-cvs-dired-state-info): Use `added' for added files and
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
729 (defun vc-cvs-parse-root (root)
|
50668
|
730 "Split CVS ROOT specification string into a list of fields.
|
|
731 A CVS root specification of the form
|
|
732 [:METHOD:][[USER@]HOSTNAME:]/path/to/repository
|
|
733 is converted to a normalized record with the following structure:
|
|
734 \(METHOD USER HOSTNAME CVS-ROOT).
|
|
735 The default METHOD for a CVS root of the form
|
|
736 /path/to/repository
|
|
737 is `local'.
|
|
738 The default METHOD for a CVS root of the form
|
|
739 [USER@]HOSTNAME:/path/to/repository
|
|
740 is `ext'.
|
|
741 For an empty string, nil is returned (illegal CVS root)."
|
|
742 ;; Split CVS root into colon separated fields (0-4).
|
|
743 ;; The `x:' makes sure, that leading colons are not lost;
|
|
744 ;; `HOST:/PATH' is then different from `:METHOD:/PATH'.
|
|
745 (let* ((root-list (cdr (split-string (concat "x:" root) ":")))
|
|
746 (len (length root-list))
|
|
747 ;; All syntactic varieties will get a proper METHOD.
|
|
748 (root-list
|
|
749 (cond
|
|
750 ((= len 0)
|
|
751 ;; Invalid CVS root
|
|
752 nil)
|
|
753 ((= len 1)
|
|
754 ;; Simple PATH => method `local'
|
|
755 (cons "local"
|
|
756 (cons nil root-list)))
|
|
757 ((= len 2)
|
|
758 ;; [USER@]HOST:PATH => method `ext'
|
|
759 (and (not (equal (car root-list) ""))
|
|
760 (cons "ext" root-list)))
|
|
761 ((= len 3)
|
|
762 ;; :METHOD:PATH
|
|
763 (cons (cadr root-list)
|
|
764 (cons nil (cddr root-list))))
|
|
765 (t
|
|
766 ;; :METHOD:[USER@]HOST:PATH
|
|
767 (cdr root-list)))))
|
|
768 (if root-list
|
|
769 (let ((method (car root-list))
|
|
770 (uhost (or (cadr root-list) ""))
|
|
771 (root (nth 2 root-list))
|
|
772 user host)
|
|
773 ;; Split USER@HOST
|
|
774 (if (string-match "\\(.*\\)@\\(.*\\)" uhost)
|
|
775 (setq user (match-string 1 uhost)
|
|
776 host (match-string 2 uhost))
|
|
777 (setq host uhost))
|
|
778 ;; Remove empty HOST
|
|
779 (and (equal host "")
|
|
780 (setq host))
|
|
781 ;; Fix windows style CVS root `:local:C:\\project\\cvs\\some\\dir'
|
|
782 (and host
|
|
783 (equal method "local")
|
|
784 (setq root (concat host ":" root) host))
|
|
785 ;; Normalize CVS root record
|
|
786 (list method user host root)))))
|
33560
|
787
|
|
788 (defun vc-cvs-parse-status (&optional full)
|
|
789 "Parse output of \"cvs status\" command in the current buffer.
|
|
790 Set file properties accordingly. Unless FULL is t, parse only
|
|
791 essential information."
|
|
792 (let (file status)
|
|
793 (goto-char (point-min))
|
|
794 (if (re-search-forward "^File: " nil t)
|
|
795 (cond
|
|
796 ((looking-at "no file") nil)
|
|
797 ((re-search-forward "\\=\\([^ \t]+\\)" nil t)
|
|
798 (setq file (expand-file-name (match-string 1)))
|
|
799 (vc-file-setprop file 'vc-backend 'CVS)
|
|
800 (if (not (re-search-forward "\\=[ \t]+Status: \\(.*\\)" nil t))
|
|
801 (setq status "Unknown")
|
|
802 (setq status (match-string 1)))
|
|
803 (if (and full
|
|
804 (re-search-forward
|
41707
94df6eb103b3
(vc-cvs-parse-status): Store file state in property, don't just return
André Spiegel <spiegel@gnu.org>
diff
changeset
|
805 "\\(RCS Version\\|RCS Revision\\|Repository revision\\):\
|
33560
|
806 \[\t ]+\\([0-9.]+\\)"
|
|
807 nil t))
|
|
808 (vc-file-setprop file 'vc-latest-version (match-string 2)))
|
44436
|
809 (vc-file-setprop
|
41707
94df6eb103b3
(vc-cvs-parse-status): Store file state in property, don't just return
André Spiegel <spiegel@gnu.org>
diff
changeset
|
810 file 'vc-state
|
94df6eb103b3
(vc-cvs-parse-status): Store file state in property, don't just return
André Spiegel <spiegel@gnu.org>
diff
changeset
|
811 (cond
|
94df6eb103b3
(vc-cvs-parse-status): Store file state in property, don't just return
André Spiegel <spiegel@gnu.org>
diff
changeset
|
812 ((string-match "Up-to-date" status)
|
94df6eb103b3
(vc-cvs-parse-status): Store file state in property, don't just return
André Spiegel <spiegel@gnu.org>
diff
changeset
|
813 (vc-file-setprop file 'vc-checkout-time
|
94df6eb103b3
(vc-cvs-parse-status): Store file state in property, don't just return
André Spiegel <spiegel@gnu.org>
diff
changeset
|
814 (nth 5 (file-attributes file)))
|
94df6eb103b3
(vc-cvs-parse-status): Store file state in property, don't just return
André Spiegel <spiegel@gnu.org>
diff
changeset
|
815 'up-to-date)
|
94df6eb103b3
(vc-cvs-parse-status): Store file state in property, don't just return
André Spiegel <spiegel@gnu.org>
diff
changeset
|
816 ((string-match "Locally Modified" status) 'edited)
|
94df6eb103b3
(vc-cvs-parse-status): Store file state in property, don't just return
André Spiegel <spiegel@gnu.org>
diff
changeset
|
817 ((string-match "Needs Merge" status) 'needs-merge)
|
94df6eb103b3
(vc-cvs-parse-status): Store file state in property, don't just return
André Spiegel <spiegel@gnu.org>
diff
changeset
|
818 ((string-match "Needs \\(Checkout\\|Patch\\)" status) 'needs-patch)
|
94df6eb103b3
(vc-cvs-parse-status): Store file state in property, don't just return
André Spiegel <spiegel@gnu.org>
diff
changeset
|
819 (t 'edited))))))))
|
33560
|
820
|
|
821 (defun vc-cvs-dir-state-heuristic (dir)
|
|
822 "Find the CVS state of all files in DIR, using only local information."
|
|
823 (with-temp-buffer
|
50453
e499daf7fb22
(vc-cvs-get-entries): New function that uses the right coding system for
André Spiegel <spiegel@gnu.org>
diff
changeset
|
824 (vc-cvs-get-entries dir)
|
33560
|
825 (goto-char (point-min))
|
|
826 (while (not (eobp))
|
44104
|
827 ;; CVS-removed files are not taken under VC control.
|
|
828 (when (looking-at "/\\([^/]*\\)/[^/-]")
|
33560
|
829 (let ((file (expand-file-name (match-string 1) dir)))
|
|
830 (unless (vc-file-getprop file 'vc-state)
|
|
831 (vc-cvs-parse-entry file t))))
|
|
832 (forward-line 1))))
|
|
833
|
50453
e499daf7fb22
(vc-cvs-get-entries): New function that uses the right coding system for
André Spiegel <spiegel@gnu.org>
diff
changeset
|
834 (defun vc-cvs-get-entries (dir)
|
e499daf7fb22
(vc-cvs-get-entries): New function that uses the right coding system for
André Spiegel <spiegel@gnu.org>
diff
changeset
|
835 "Insert the CVS/Entries file from below DIR into the current buffer.
|
e499daf7fb22
(vc-cvs-get-entries): New function that uses the right coding system for
André Spiegel <spiegel@gnu.org>
diff
changeset
|
836 This function ensures that the correct coding system is used for that,
|
e499daf7fb22
(vc-cvs-get-entries): New function that uses the right coding system for
André Spiegel <spiegel@gnu.org>
diff
changeset
|
837 which may not be the one that is used for the files' contents.
|
e499daf7fb22
(vc-cvs-get-entries): New function that uses the right coding system for
André Spiegel <spiegel@gnu.org>
diff
changeset
|
838 CVS/Entries should only be accessed through this function."
|
e499daf7fb22
(vc-cvs-get-entries): New function that uses the right coding system for
André Spiegel <spiegel@gnu.org>
diff
changeset
|
839 (let ((coding-system-for-read (or file-name-coding-system
|
e499daf7fb22
(vc-cvs-get-entries): New function that uses the right coding system for
André Spiegel <spiegel@gnu.org>
diff
changeset
|
840 default-file-name-coding-system)))
|
e499daf7fb22
(vc-cvs-get-entries): New function that uses the right coding system for
André Spiegel <spiegel@gnu.org>
diff
changeset
|
841 (vc-insert-file (expand-file-name "CVS/Entries" dir))))
|
e499daf7fb22
(vc-cvs-get-entries): New function that uses the right coding system for
André Spiegel <spiegel@gnu.org>
diff
changeset
|
842
|
43447
|
843 (defun vc-cvs-valid-symbolic-tag-name-p (tag)
|
|
844 "Return non-nil if TAG is a valid symbolic tag name."
|
|
845 ;; According to the CVS manual, a valid symbolic tag must start with
|
|
846 ;; an uppercase or lowercase letter and can contain uppercase and
|
|
847 ;; lowercase letters, digits, `-', and `_'.
|
|
848 (and (string-match "^[a-zA-Z]" tag)
|
|
849 (not (string-match "[^a-z0-9A-Z-_]" tag))))
|
44436
|
850
|
44462
|
851 (defun vc-cvs-valid-version-number-p (tag)
|
|
852 "Return non-nil if TAG is a valid version number."
|
|
853 (and (string-match "^[0-9]" tag)
|
|
854 (not (string-match "[^0-9.]" tag))))
|
43447
|
855
|
|
856 (defun vc-cvs-parse-sticky-tag (match-type match-tag)
|
44436
|
857 "Parse and return the sticky tag as a string.
|
43447
|
858 `match-data' is protected."
|
|
859 (let ((data (match-data))
|
|
860 (tag)
|
|
861 (type (cond ((string= match-type "D") 'date)
|
|
862 ((string= match-type "T")
|
|
863 (if (vc-cvs-valid-symbolic-tag-name-p match-tag)
|
|
864 'symbolic-name
|
|
865 'revision-number))
|
|
866 (t nil))))
|
|
867 (unwind-protect
|
|
868 (progn
|
44436
|
869 (cond
|
46163
|
870 ;; Sticky Date tag. Convert to a proper date value (`encode-time')
|
43447
|
871 ((eq type 'date)
|
44436
|
872 (string-match
|
|
873 "\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)"
|
43447
|
874 match-tag)
|
|
875 (let* ((year-tmp (string-to-number (match-string 1 match-tag)))
|
|
876 (month (string-to-number (match-string 2 match-tag)))
|
|
877 (day (string-to-number (match-string 3 match-tag)))
|
|
878 (hour (string-to-number (match-string 4 match-tag)))
|
|
879 (min (string-to-number (match-string 5 match-tag)))
|
|
880 (sec (string-to-number (match-string 6 match-tag)))
|
|
881 ;; Years 0..68 are 2000..2068.
|
|
882 ;; Years 69..99 are 1969..1999.
|
|
883 (year (+ (cond ((> 69 year-tmp) 2000)
|
|
884 ((> 100 year-tmp) 1900)
|
|
885 (t 0))
|
|
886 year-tmp)))
|
|
887 (setq tag (encode-time sec min hour day month year))))
|
|
888 ;; Sticky Tag name or revision number
|
|
889 ((eq type 'symbolic-name) (setq tag match-tag))
|
|
890 ((eq type 'revision-number) (setq tag match-tag))
|
|
891 ;; Default is no sticky tag at all
|
|
892 (t nil))
|
|
893 (cond ((eq vc-cvs-sticky-tag-display nil) nil)
|
|
894 ((eq vc-cvs-sticky-tag-display t)
|
44436
|
895 (cond ((eq type 'date) (format-time-string
|
43447
|
896 vc-cvs-sticky-date-format-string
|
|
897 tag))
|
|
898 ((eq type 'symbolic-name) tag)
|
|
899 ((eq type 'revision-number) tag)
|
|
900 (t nil)))
|
44436
|
901 ((functionp vc-cvs-sticky-tag-display)
|
43447
|
902 (funcall vc-cvs-sticky-tag-display tag type))
|
|
903 (t nil)))
|
|
904
|
|
905 (set-match-data data))))
|
|
906
|
33560
|
907 (defun vc-cvs-parse-entry (file &optional set-state)
|
|
908 "Parse a line from CVS/Entries.
|
|
909 Compare modification time to that of the FILE, set file properties
|
|
910 accordingly. However, `vc-state' is set only if optional arg SET-STATE
|
|
911 is non-nil."
|
|
912 (cond
|
|
913 ;; entry for a "locally added" file (not yet committed)
|
|
914 ((looking-at "/[^/]+/0/")
|
|
915 (vc-file-setprop file 'vc-checkout-time 0)
|
|
916 (vc-file-setprop file 'vc-workfile-version "0")
|
|
917 (if set-state (vc-file-setprop file 'vc-state 'edited)))
|
|
918 ;; normal entry
|
|
919 ((looking-at
|
|
920 (concat "/[^/]+"
|
|
921 ;; revision
|
|
922 "/\\([^/]*\\)"
|
50321
|
923 ;; timestamp and optional conflict field
|
|
924 "/\\([^/]*\\)/"
|
43447
|
925 ;; options
|
|
926 "\\([^/]*\\)/"
|
|
927 ;; sticky tag
|
|
928 "\\(.\\|\\)" ;Sticky tag type (date or tag name, could be empty)
|
|
929 "\\(.*\\)")) ;Sticky tag
|
33560
|
930 (vc-file-setprop file 'vc-workfile-version (match-string 1))
|
44104
|
931 (vc-file-setprop file 'vc-cvs-sticky-tag
|
52624
|
932 (vc-cvs-parse-sticky-tag (match-string 4)
|
|
933 (match-string 5)))
|
52602
|
934 ;; Compare checkout time and modification time.
|
|
935 ;; This is intentionally different from the algorithm that CVS uses
|
52624
|
936 ;; (which is based on textual comparison), because there can be problems
|
52602
|
937 ;; generating a time string that looks exactly like the one from CVS.
|
52717
|
938 (let ((mtime (nth 5 (file-attributes file))))
|
|
939 (require 'parse-time)
|
|
940 (let ((parsed-time
|
|
941 (parse-time-string (concat (match-string 2) " +0000"))))
|
|
942 (cond ((and (not (string-match "\\+" (match-string 2)))
|
|
943 (car parsed-time)
|
|
944 (equal mtime (apply 'encode-time parsed-time)))
|
|
945 (vc-file-setprop file 'vc-checkout-time mtime)
|
|
946 (if set-state (vc-file-setprop file 'vc-state 'up-to-date)))
|
|
947 (t
|
|
948 (vc-file-setprop file 'vc-checkout-time 0)
|
|
949 (if set-state (vc-file-setprop file 'vc-state 'edited)))))))))
|
44436
|
950
|
31384
|
951 (provide 'vc-cvs)
|
|
952
|
52401
|
953 ;;; arch-tag: 60e1402a-aa53-4607-927a-cf74f144b432
|
31384
|
954 ;;; vc-cvs.el ends here
|