1 ;;; vc-src.el --- support for SRC version-control -*- lexical-binding:t -*-
3 ;; Copyright (C) 1992-2017 Free Software Foundation, Inc.
5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: emacs-devel@gnu.org
9 ;; This file is part of GNU Emacs.
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.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
26 ;; See vc.el. SRC requires an underlying RCS version of 4.0 or greater.
28 ;; FUNCTION NAME STATUS
30 ;; * revision-granularity OK
31 ;; STATE-QUERYING FUNCTIONS
32 ;; * registered (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 ;; * checkout-model (files) OK
39 ;; - mode-line-string (file) NOT NEEDED
40 ;; STATE-CHANGING FUNCTIONS
41 ;; * register (files &optional rev comment) OK
42 ;; * create-repo () OK
43 ;; * responsible-p (file) OK
44 ;; - receive-file (file rev) NOT NEEDED
45 ;; - unregister (file) NOT NEEDED
46 ;; * checkin (files comment) OK
47 ;; * find-revision (file rev buffer) OK
48 ;; * checkout (file &optional rev) OK
49 ;; * revert (file &optional contents-done) OK
50 ;; - merge (file rev1 rev2) NOT NEEDED
51 ;; - merge-news (file) NOT NEEDED
52 ;; - steal-lock (file &optional revision) NOT NEEDED
54 ;; * print-log (files buffer &optional shortlog start-revision limit) OK
55 ;; - log-view-mode () ??
56 ;; - show-log-entry (revision) NOT NEEDED
57 ;; - comment-history (file) NOT NEEDED
58 ;; - update-changelog (files) NOT NEEDED
59 ;; * diff (files &optional rev1 rev2 buffer) OK
60 ;; - revision-completion-table (files) ??
61 ;; - annotate-command (file buf &optional rev) ??
62 ;; - annotate-time () ??
63 ;; - annotate-current-time () NOT NEEDED
64 ;; - annotate-extract-revision-at-line () ??
66 ;; - create-tag (dir name branchp) ??
67 ;; - retrieve-tag (dir name update) ??
69 ;; - make-version-backups-p (file) ??
70 ;; - previous-revision (file rev) ??
71 ;; - next-revision (file rev) ??
72 ;; - check-headers () ??
73 ;; - delete-file (file) ??
74 ;; * rename-file (old new) OK
75 ;; - find-file-hook () NOT NEEDED
81 ;;; Customization options
88 (declare-function vc-setup-buffer
"vc-dispatcher" (buf))
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
))
103 (defcustom vc-src-program
"src"
104 "Name of the SRC executable (excluding any arguments)."
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
))
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.
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"
127 (repeat :tag
"User-specified"
133 ;;; Properties of the backend
135 (defun vc-src-revision-granularity () 'file
)
136 (defun vc-src-checkout-model (_files) 'implicit
)
139 ;;; State-querying functions
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.
147 (defun vc-src-registered (f) (vc-default-registered 'src f
)))
149 (defun vc-src-state (file)
150 "SRC-specific version of `vc-state'."
153 (default-directory (file-name-directory file
))
155 (with-output-to-string
159 ;; Ignore all errors.
162 vc-src-program nil t nil
163 "status" "-a" (file-relative-name file
))
166 (when (null (string-match "does not exist or is unreadable" out
))
167 (let ((state (aref out
0)))
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
)))))))
179 (autoload 'vc-expand-dirs
"vc")
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
) 'SRC
)))
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
)))
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'."
197 (cond ((stringp file-or-list
)
198 (setq file-list
(list "--" file-or-list
)))
200 (setq file-list
(cons "--" file-or-list
))))
201 (apply 'vc-do-command
(or buffer
"*vc*") 0 vc-src-program file-list flags
)))
203 (defun vc-src-working-revision (file)
204 "SRC-specific version of `vc-working-revision'."
205 (let ((result (ignore-errors
206 (with-output-to-string
207 (vc-src-command standard-output file
"list" "-f{1}" "@")))))
208 (if (zerop (length result
)) "0" result
)))
211 ;;; State-changing functions
214 (defun vc-src-create-repo ()
215 "Create a new SRC repository."
216 ;; SRC is totally file-oriented, so all we have to do is make the directory.
217 (make-directory ".src"))
219 (autoload 'vc-switches
"vc")
221 (defun vc-src-register (files &optional _comment
)
222 "Register FILES under src. COMMENT is ignored."
223 (vc-src-command nil files
"add"))
225 (defun vc-src-responsible-p (file)
226 "Return non-nil if SRC thinks it would be responsible for registering FILE."
227 (file-directory-p (expand-file-name ".src"
228 (if (file-directory-p file
)
230 (file-name-directory file
)))))
232 (defun vc-src-checkin (files comment
&optional _rev
)
233 "SRC-specific version of `vc-backend-checkin'.
235 (vc-src-command nil files
"commit" "-m" comment
))
237 (defun vc-src-find-revision (file rev buffer
)
238 (let ((coding-system-for-read 'binary
)
239 (coding-system-for-write 'binary
))
241 (vc-src-command buffer file
"cat" rev
)
242 (vc-src-command buffer file
"cat"))))
244 (defun vc-src-checkout (file &optional rev
)
245 "Retrieve a revision of FILE.
246 REV is the revision to check out into WORKFILE."
248 (vc-src-command nil file
"co" rev
)
249 (vc-src-command nil file
"co")))
251 (defun vc-src-revert (file &optional _contents-done
)
252 "Revert FILE to the version it was based on. If FILE is a directory,
253 revert all registered files beneath it."
254 (if (file-directory-p file
)
255 (mapc 'vc-src-revert
(vc-expand-dirs (list file
) 'SRC
))
256 (vc-src-command nil file
"co")))
258 (defun vc-src-modify-change-comment (files rev comment
)
259 "Modify the change comments change on FILES on a specified REV. If FILE is a
260 directory the operation is applied to all registered files beneath it."
261 (dolist (file (vc-expand-dirs files
'SRC
))
262 (vc-src-command nil file
"amend" "-m" comment rev
)))
266 (defcustom vc-src-log-switches nil
267 "String or list of strings specifying switches for src log under VC."
268 :type
'(choice (const :tag
"None" nil
)
269 (string :tag
"Argument String")
270 (repeat :tag
"Argument List" :value
("") string
))
273 (defun vc-src-print-log (files buffer
&optional shortlog _start-revision limit
)
274 "Print commit log associated with FILES into specified BUFFER.
275 If SHORTLOG is non-nil, use the list method.
276 If START-REVISION is non-nil, it is the newest revision to show.
277 If LIMIT is non-nil, show no more than this many entries."
278 ;; FIXME: Implement the range restrictions.
279 ;; `vc-do-command' creates the buffer, but we need it before running
281 (vc-setup-buffer buffer
)
282 ;; If the buffer exists from a previous invocation it might be
284 (let ((inhibit-read-only t
))
287 (apply 'vc-src-command buffer files
(if shortlog
"list" "log")
289 ;;(when start-revision (list (format "%s-1" start-revision)))
290 (when limit
(list "-l" (format "%s" limit
)))
291 vc-src-log-switches
)))))
293 (defun vc-src-diff (files &optional oldvers newvers buffer _async
)
294 "Get a difference report using src between two revisions of FILES."
295 (let* ((firstfile (car files
))
296 (working (and firstfile
(vc-working-revision firstfile
))))
297 (when (and (equal oldvers working
) (not newvers
))
299 (when (and (not oldvers
) newvers
)
300 (setq oldvers working
))
301 (apply #'vc-src-command
(or buffer
"*vc-diff*") files
"diff"
304 (list (concat oldvers
"-" newvers
))
309 (defun vc-src-rename-file (old new
)
310 "Rename file from OLD to NEW using `src mv'."
311 (vc-src-command nil
0 new
"mv" old
))
315 ;;; vc-src.el ends here