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