]> code.delx.au - gnu-emacs/blob - lisp/vc/vc-src.el
In vc, abolish the dir-status method.
[gnu-emacs] / lisp / vc / vc-src.el
1 ;;; vc-src.el --- support for SRC version-control -*- lexical-binding:t -*-
2
3 ;; Copyright (C) 1992-2014 Free Software Foundation, Inc.
4
5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Eric S. Raymond <esr@thyrsus.com>
7 ;; Package: vc
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;; See vc.el. SRC requires an underlying RCS version of 4.0 or greater.
27
28 ;; FUNCTION NAME STATUS
29 ;; BACKEND PROPERTIES
30 ;; * revision-granularity OK
31 ;; STATE-QUERYING FUNCTIONS
32 ;; * registered (file) OK
33 ;; * state (file) OK
34 ;; - dir-status-files (dir files uf) OK
35 ;; - dir-extra-headers (dir) NOT NEEDED
36 ;; - dir-printer (fileinfo) ??
37 ;; * working-revision (file) OK
38 ;; - latest-on-branch-p (file) ??
39 ;; * checkout-model (files) OK
40 ;; - mode-line-string (file) NOT NEEDED
41 ;; STATE-CHANGING FUNCTIONS
42 ;; * register (files &optional rev comment) OK
43 ;; * create-repo () OK
44 ;; * responsible-p (file) OK
45 ;; - receive-file (file rev) NOT NEEDED
46 ;; - unregister (file) NOT NEEDED
47 ;; * checkin (files comment) OK
48 ;; * find-revision (file rev buffer) OK
49 ;; * checkout (file &optional rev) OK
50 ;; * revert (file &optional contents-done) OK
51 ;; - rollback (files) NOT NEEDED
52 ;; - merge (file rev1 rev2) NOT NEEDED
53 ;; - merge-news (file) NOT NEEDED
54 ;; - steal-lock (file &optional revision) NOT NEEDED
55 ;; HISTORY FUNCTIONS
56 ;; * print-log (files buffer &optional shortlog start-revision limit) OK
57 ;; - log-view-mode () ??
58 ;; - show-log-entry (revision) NOT NEEDED
59 ;; - comment-history (file) NOT NEEDED
60 ;; - update-changelog (files) NOT NEEDED
61 ;; * diff (files &optional rev1 rev2 buffer) OK
62 ;; - revision-completion-table (files) ??
63 ;; - annotate-command (file buf &optional rev) ??
64 ;; - annotate-time () ??
65 ;; - annotate-current-time () NOT NEEDED
66 ;; - annotate-extract-revision-at-line () ??
67 ;; TAG SYSTEM
68 ;; - create-tag (dir name branchp) ??
69 ;; - retrieve-tag (dir name update) ??
70 ;; MISCELLANEOUS
71 ;; - make-version-backups-p (file) ??
72 ;; - previous-revision (file rev) ??
73 ;; - next-revision (file rev) ??
74 ;; - check-headers () ??
75 ;; - delete-file (file) ??
76 ;; * rename-file (old new) OK
77 ;; - find-file-hook () NOT NEEDED
78
79
80 ;;; Code:
81
82 ;;;
83 ;;; Customization options
84 ;;;
85
86 (eval-when-compile
87 (require 'cl-lib)
88 (require 'vc))
89
90 (defgroup vc-src nil
91 "VC SRC backend."
92 :version "25.1"
93 :group 'vc)
94
95 (defcustom vc-src-release nil
96 "The release number of your SRC installation, as a string.
97 If nil, VC itself computes this value when it is first needed."
98 :type '(choice (const :tag "Auto" nil)
99 (string :tag "Specified")
100 (const :tag "Unknown" unknown))
101 :group 'vc-src)
102
103 (defcustom vc-src-program "src"
104 "Name of the SRC executable (excluding any arguments)."
105 :type 'string
106 :group 'vc-src)
107
108 (defcustom vc-src-diff-switches nil
109 "String or list of strings specifying switches for SRC diff under VC.
110 If nil, use the value of `vc-diff-switches'. If t, use no switches."
111 :type '(choice (const :tag "Unspecified" nil)
112 (const :tag "None" t)
113 (string :tag "Argument String")
114 (repeat :tag "Argument List" :value ("") string))
115 :group 'vc-src)
116
117 ;; This needs to be autoloaded because vc-src-registered uses it (via
118 ;; vc-default-registered), and vc-hooks needs to be able to check
119 ;; for a registered backend without loading every backend.
120 ;;;###autoload
121 (defcustom vc-src-master-templates
122 (purecopy '("%s.src/%s,v"))
123 "Where to look for SRC master files.
124 For a description of possible values, see `vc-check-master-templates'."
125 :type '(choice (const :tag "Use standard SRC file names"
126 '("%s.src/%s,v"))
127 (repeat :tag "User-specified"
128 (choice string
129 function)))
130 :group 'vc-src)
131
132 \f
133 ;;; Properties of the backend
134
135 (defun vc-src-revision-granularity () 'file)
136 (defun vc-src-checkout-model (_files) 'implicit)
137
138 ;;;
139 ;;; State-querying functions
140 ;;;
141
142 ;; The autoload cookie below places vc-src-registered directly into
143 ;; loaddefs.el, so that vc-src.el does not need to be loaded for
144 ;; every file that is visited.
145 ;;;###autoload
146 (progn
147 (defun vc-src-registered (f) (vc-default-registered 'src f)))
148
149 (defun vc-src-state (file)
150 "SRC-specific version of `vc-state'."
151 (let*
152 ((status nil)
153 (default-directory (file-name-directory file))
154 (out
155 (with-output-to-string
156 (with-current-buffer
157 standard-output
158 (setq status
159 ;; Ignore all errors.
160 (condition-case nil
161 (process-file
162 vc-src-program nil t nil
163 "status" "-a" (file-relative-name file))
164 (error nil)))))))
165 (when (eq 0 status)
166 (when (null (string-match "does not exist or is unreadable" out))
167 (let ((state (aref out 0)))
168 (cond
169 ;; FIXME: What to do about A and L codes?
170 ((eq state ?.) 'up-to-date)
171 ((eq state ?A) 'added)
172 ((eq state ?M) 'edited)
173 ((eq state ?I) 'ignored)
174 ((eq state ?R) 'removed)
175 ((eq state ?!) 'missing)
176 ((eq state ??) 'unregistered)
177 (t 'up-to-date)))))))
178
179 (autoload 'vc-expand-dirs "vc")
180
181 (defun vc-src-dir-status-files (dir files update-function)
182 ;; FIXME: Use one src status -a call for this
183 (if (not files) (setq files (vc-expand-dirs (list dir) 'RCS)))
184 (let ((result nil))
185 (dolist (file files)
186 (let ((state (vc-state file))
187 (frel (file-relative-name file)))
188 (when (and (eq (vc-backend file) 'SRC)
189 (not (eq state 'up-to-date)))
190 (push (list frel state) result))))
191 (funcall update-function result)))
192
193 (defun vc-src-command (buffer file-or-list &rest flags)
194 "A wrapper around `vc-do-command' for use in vc-src.el.
195 This function differs from vc-do-command in that it invokes `vc-src-program'."
196 (apply 'vc-do-command (or buffer "*vc*") 0 vc-src-program file-or-list flags))
197
198 (defun vc-src-working-revision (file)
199 "SRC-specific version of `vc-working-revision'."
200 (or (ignore-errors
201 (with-output-to-string
202 (vc-src-command standard-output file "list" "-f{1}" "@")))
203 "0"))
204
205 ;;;
206 ;;; State-changing functions
207 ;;;
208
209 (defun vc-src-create-repo ()
210 "Create a new SRC repository."
211 ;; SRC is totally file-oriented, so all we have to do is make the directory.
212 (make-directory ".src"))
213
214 (autoload 'vc-switches "vc")
215
216 (defun vc-src-register (files &optional _comment)
217 "Register FILES under src. COMMENT is ignored."
218 (vc-src-command nil files "add"))
219
220 (defun vc-src-responsible-p (file)
221 "Return non-nil if SRC thinks it would be responsible for registering FILE."
222 (file-directory-p (expand-file-name ".src"
223 (if (file-directory-p file)
224 file
225 (file-name-directory file)))))
226
227 (defun vc-src-checkin (files comment)
228 "SRC-specific version of `vc-backend-checkin'.
229 REV is ignored."
230 (vc-src-command nil files "commit" "-m" comment))
231
232 (defun vc-src-find-revision (file rev buffer)
233 (let ((coding-system-for-read 'binary)
234 (coding-system-for-write 'binary))
235 (if rev
236 (vc-src-command buffer file "cat" rev)
237 (vc-src-command buffer file "cat"))))
238
239 (defun vc-src-checkout (file &optional rev)
240 "Retrieve a revision of FILE.
241 REV is the revision to check out into WORKFILE."
242 (if rev
243 (vc-src-command nil file "co" rev)
244 (vc-src-command nil file "co")))
245
246 (defun vc-src-revert (file &optional _contents-done)
247 "Revert FILE to the version it was based on. If FILE is a directory,
248 revert all registered files beneath it."
249 (if (file-directory-p file)
250 (mapc 'vc-src-revert (vc-expand-dirs (list file) 'SRC))
251 (vc-src-command nil file "co")))
252
253 (defun vc-src-modify-change-comment (files rev comment)
254 "Modify the change comments change on FILES on a specified REV. If FILE is a
255 directory the operation is applied to all registered files beneath it."
256 (dolist (file (vc-expand-dirs files 'SRC))
257 (vc-src-command nil file "amend" "-m" comment rev)))
258
259 ;; History functions
260
261 (defcustom vc-src-log-switches nil
262 "String or list of strings specifying switches for src log under VC."
263 :type '(choice (const :tag "None" nil)
264 (string :tag "Argument String")
265 (repeat :tag "Argument List" :value ("") string))
266 :group 'vc-src)
267
268 (defun vc-src-print-log (files buffer &optional shortlog _start-revision limit)
269 "Print commit log associated with FILES into specified BUFFER.
270 If SHORTLOG is non-nil, use the list method.
271 If START-REVISION is non-nil, it is the newest revision to show.
272 If LIMIT is non-nil, show no more than this many entries."
273 ;; FIXME: Implement the range restrictions.
274 ;; `vc-do-command' creates the buffer, but we need it before running
275 ;; the command.
276 (vc-setup-buffer buffer)
277 ;; If the buffer exists from a previous invocation it might be
278 ;; read-only.
279 (let ((inhibit-read-only t))
280 (with-current-buffer
281 buffer
282 (apply 'vc-src-command buffer files (if shortlog "list" "log")
283 (nconc
284 ;;(when start-revision (list (format "%s-1" start-revision)))
285 (when limit (list "-l" (format "%s" limit)))
286 vc-src-log-switches)))))
287
288 (defun vc-src-diff (files &optional _async oldvers newvers buffer)
289 "Get a difference report using src between two revisions of FILES."
290 (let* ((firstfile (car files))
291 (working (and firstfile (vc-working-revision firstfile))))
292 (when (and (equal oldvers working) (not newvers))
293 (setq oldvers nil))
294 (when (and (not oldvers) newvers)
295 (setq oldvers working))
296 (apply #'vc-src-command (or buffer "*vc-diff*") files "diff"
297 (when oldvers
298 (if newvers
299 (list (concat oldvers "-" newvers))
300 (list oldvers))))))
301
302 ;; Miscellaneous
303
304 (defun vc-src-rename-file (old new)
305 "Rename file from OLD to NEW using `src mv'."
306 (vc-src-command nil 0 new "mv" old))
307
308 (provide 'vc-src)
309
310 ;;; vc-src.el ends here