1 ;;; vc-sccs.el --- support for SCCS version-control
3 ;; Copyright (C) 1992,93,94,95,96,97,98,99,2000,2001 Free Software Foundation, Inc.
5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
8 ;; $Id: vc-sccs.el,v 1.8 2001/02/01 15:12:35 spiegel Exp $
10 ;; This file is part of GNU Emacs.
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)
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.
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.
35 ;;; Customization options
38 (defcustom vc-sccs-register-switches nil
39 "*Extra switches for registering a file in SCCS.
40 A string or list of strings passed to the checkin program by
41 \\[vc-sccs-register]."
42 :type
'(choice (const :tag
"None" nil
)
43 (string :tag
"Argument String")
44 (repeat :tag
"Argument List"
50 (defcustom vc-sccs-diff-switches nil
51 "*A string or list of strings specifying extra switches for `vcdiff',
52 the diff utility used for SCCS under VC."
53 :type
'(choice (const :tag
"None" nil
)
54 (string :tag
"Argument String")
55 (repeat :tag
"Argument List"
61 (defcustom vc-sccs-header
(or (cdr (assoc 'SCCS vc-header-alist
)) '("%W%"))
62 "*Header keywords to be inserted by `vc-insert-headers'."
63 :type
'(repeat string
)
67 (defcustom vc-sccs-master-templates
68 '("%sSCCS/s.%s" "%ss.%s" vc-sccs-search-project-dir
)
69 "*Where to look for SCCS master files.
70 For a description of possible values, see `vc-check-master-templates'."
71 :type
'(choice (const :tag
"Use standard SCCS file names"
72 ("%sSCCS/s.%s" "%ss.%s" vc-sccs-search-project-dir
))
73 (repeat :tag
"User-specified"
81 ;;; Internal variables
84 (defconst vc-sccs-name-assoc-file
"VC-names")
88 ;;; State-querying functions
92 (progn (defun vc-sccs-registered (f) (vc-default-registered 'SCCS f
)))
94 (defun vc-sccs-state (file)
95 "SCCS-specific function to compute the version control state."
97 (if (vc-insert-file (vc-sccs-lock-file file
))
98 (let* ((locks (vc-sccs-parse-locks))
99 (workfile-version (vc-workfile-version file
))
100 (locking-user (cdr (assoc workfile-version locks
))))
101 (if (not locking-user
)
102 (if (vc-workfile-unchanged-p file
)
105 (if (string= locking-user
(vc-user-login-name))
110 (defun vc-sccs-state-heuristic (file)
111 "SCCS-specific state heuristic."
112 (if (not (vc-mistrust-permissions file
))
113 ;; This implementation assumes that any file which is under version
114 ;; control and has -rw-r--r-- is locked by its owner. This is true
115 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--.
116 ;; We have to be careful not to exclude files with execute bits on;
117 ;; scripts can be under version control too. Also, we must ignore the
118 ;; group-read and other-read bits, since paranoid users turn them off.
119 (let* ((attributes (file-attributes file
))
120 (owner-uid (nth 2 attributes
))
121 (permissions (nth 8 attributes
)))
122 (if (string-match ".r-..-..-." permissions
)
124 (if (string-match ".rw..-..-." permissions
)
125 (if (file-ownership-preserved-p file
)
127 (vc-user-login-name owner-uid
))
128 ;; Strange permissions.
129 ;; Fall through to real state computation.
130 (vc-sccs-state file
)))
131 (vc-sccs-state file
))))
133 (defun vc-sccs-workfile-version (file)
134 "SCCS-specific version of `vc-workfile-version'."
136 (vc-insert-file (vc-name file
) "^\001e")
137 (vc-parse-buffer "^\001d D \\([^ ]+\\)" 1)))
139 (defun vc-sccs-checkout-model (file)
140 "SCCS-specific version of `vc-checkout-model'."
143 (defun vc-sccs-workfile-unchanged-p (file)
144 "SCCS-specific implementation of vc-workfile-unchanged-p."
145 (zerop (apply 'vc-do-command nil
1 "vcdiff" (vc-name file
)
147 (concat "-r" (vc-workfile-version file
))))))
151 ;;; State-changing functions
154 (defun vc-sccs-register (file &optional rev comment
)
155 "Register FILE into the SCCS version-control system.
156 REV is the optional revision number for the file. COMMENT can be used
157 to provide an initial description of FILE.
159 `vc-register-switches' and `vc-sccs-register-switches' are passed to
160 the SCCS command (in that order).
162 Automatically retrieve a read-only version of the file with keywords
163 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
164 (let* ((switches (list
165 (if (stringp vc-register-switches
)
166 (list vc-register-switches
)
167 vc-register-switches
)
168 (if (stringp vc-sccs-register-switches
)
169 (list vc-sccs-register-switches
)
170 vc-sccs-register-switches
)))
171 (dirname (or (file-name-directory file
) ""))
172 (basename (file-name-nondirectory file
))
173 (project-file (vc-sccs-search-project-dir dirname basename
)))
176 (format (car vc-sccs-master-templates
) dirname basename
)))|
)
177 (apply 'vc-do-command nil
0 "admin" nil
178 (and rev
(concat "-r" rev
))
181 (and comment
(concat "-y" comment
))
185 (if vc-keep-workfiles
186 (vc-do-command nil
0 "get" (vc-name file
)))))
188 (defun vc-sccs-responsible-p (file)
189 "Return non-nil if SCCS thinks it would be responsible for registering FILE."
190 ;; TODO: check for all the patterns in vc-sccs-master-templates
191 (or (file-directory-p (expand-file-name "SCCS" (file-name-directory file
)))
192 (stringp (vc-sccs-search-project-dir (or (file-name-directory file
) "")
193 (file-name-nondirectory file
)))))
195 (defun vc-sccs-checkin (file rev comment
)
196 "SCCS-specific version of `vc-backend-checkin'."
197 (let ((switches (if (stringp vc-checkin-switches
)
198 (list vc-checkin-switches
)
199 vc-checkin-switches
)))
200 (apply 'vc-do-command nil
0 "delta" (vc-name file
)
201 (if rev
(concat "-r" rev
))
202 (concat "-y" comment
)
204 (if vc-keep-workfiles
205 (vc-do-command nil
0 "get" (vc-name file
)))))
207 (defun vc-sccs-checkout (file &optional editable rev workfile
)
208 "Retrieve a copy of a saved version of SCCS controlled FILE into a WORKFILE.
209 EDITABLE non-nil means that the file should be writable and
210 locked. REV is the revision to check out into WORKFILE."
211 (let ((filename (or workfile file
))
212 (file-buffer (get-file-buffer file
))
214 (message "Checking out %s..." filename
)
216 ;; Change buffers to get local value of vc-checkout-switches.
217 (if file-buffer
(set-buffer file-buffer
))
218 (setq switches
(if (stringp vc-checkout-switches
)
219 (list vc-checkout-switches
)
220 vc-checkout-switches
))
221 ;; Save this buffer's default-directory
222 ;; and use save-excursion to make sure it is restored
223 ;; in the same buffer it was saved in.
224 (let ((default-directory default-directory
))
226 ;; Adjust the default-directory so that the check-out creates
227 ;; the file in the right place.
228 (setq default-directory
(file-name-directory filename
))
230 (and rev
(string= rev
"") (setq rev nil
))
232 ;; Some SCCS implementations allow checking out directly to a
233 ;; file using the -G option, but then some don't so use the
234 ;; least common denominator approach and use the -p option
236 (let ((vc-modes (logior (file-modes (vc-name file
))
237 (if editable
128 0)))
241 (let ((coding-system-for-read 'no-conversion
)
242 (coding-system-for-write 'no-conversion
))
243 (with-temp-file filename
244 (apply 'vc-do-command
245 (current-buffer) 0 "get" (vc-name file
)
246 "-s" ;; suppress diagnostic output
251 (vc-sccs-lookup-triple file rev
)))
253 (set-file-modes filename
254 (logior (file-modes (vc-name file
))
255 (if editable
128 0)))
257 (and failed
(file-exists-p filename
)
258 (delete-file filename
))))
259 (apply 'vc-do-command nil
0 "get" (vc-name file
)
261 (and rev
(concat "-r" (vc-sccs-lookup-triple file rev
)))
263 (message "Checking out %s...done" filename
)))
265 (defun vc-sccs-revert (file)
266 "Revert FILE to the version it was based on."
267 (vc-do-command nil
0 "unget" (vc-name file
))
268 (vc-do-command nil
0 "get" (vc-name file
))
269 ;; Checking out explicit versions is not supported under SCCS, yet.
270 ;; We always "revert" to the latest version; therefore
271 ;; vc-workfile-version is cleared here so that it gets recomputed.
272 (vc-file-setprop file
'vc-workfile-version nil
))
274 (defun vc-sccs-cancel-version (file editable
)
275 "Undo the most recent checkin of FILE.
276 EDITABLE non-nil means previous version should be locked."
277 (vc-do-command nil
0 "rmdel"
279 (concat "-r" (vc-workfile-version file
)))
280 (vc-do-command nil
0 "get"
284 (defun vc-sccs-steal-lock (file &optional rev
)
285 "Steal the lock on the current workfile for FILE and revision REV."
286 (vc-do-command nil
0 "unget" (vc-name file
) "-n" (if rev
(concat "-r" rev
)))
287 (vc-do-command nil
0 "get" (vc-name file
) "-g" (if rev
(concat "-r" rev
))))
291 ;;; History functions
294 (defun vc-sccs-print-log (file)
295 "Get change log associated with FILE."
296 (vc-do-command t
0 "prs" (vc-name file
)))
298 (defun vc-sccs-logentry-check ()
299 "Check that the log entry in the current buffer is acceptable for SCCS."
300 (when (>= (buffer-size) 512)
302 (error "Log must be less than 512 characters; point is now at pos 512")))
304 (defun vc-sccs-diff (file &optional oldvers newvers
)
305 "Get a difference report using SCCS between two versions of FILE."
306 (setq oldvers
(vc-sccs-lookup-triple file oldvers
))
307 (setq newvers
(vc-sccs-lookup-triple file newvers
))
308 (apply 'vc-do-command t
1 "vcdiff" (vc-name file
)
310 (and oldvers
(concat "-r" oldvers
))
311 (and newvers
(concat "-r" newvers
)))
312 (vc-diff-switches-list sccs
))))
319 (defun vc-sccs-assign-name (file name
)
320 "Assign to FILE's latest version a given NAME."
321 (vc-sccs-add-triple name file
(vc-workfile-version file
)))
328 (defun vc-sccs-check-headers ()
329 "Check if the current file has any headers in it."
331 (goto-char (point-min))
332 (re-search-forward "%[A-Z]%" nil t
)))
334 (defun vc-sccs-rename-file (old new
)
335 ;; Move the master file (using vc-rcs-master-templates).
336 (vc-rename-master (vc-name old
) new vc-sccs-master-templates
)
337 ;; Update the snapshot file.
340 (expand-file-name vc-sccs-name-assoc-file
341 (file-name-directory (vc-name old
))))
342 (goto-char (point-min))
343 ;; (replace-regexp (concat ":" (regexp-quote old) "$") (concat ":" new))
344 (while (re-search-forward (concat ":" (regexp-quote old
) "$") nil t
)
345 (replace-match (concat ":" new
) nil nil
))
347 (kill-buffer (current-buffer))))
351 ;;; Internal functions
354 ;; This function is wrapped with `progn' so that the autoload cookie
355 ;; copies the whole function itself into loaddefs.el rather than just placing
356 ;; a (autoload 'vc-sccs-search-project-dir "vc-sccs") which would not
357 ;; help us avoid loading vc-sccs.
359 (progn (defun vc-sccs-search-project-dir (dirname basename
)
360 "Return the name of a master file in the SCCS project directory.
361 Does not check whether the file exists but returns nil if it does not
362 find any project directory."
363 (let ((project-dir (getenv "PROJECTDIR")) dirs dir
)
365 (if (file-name-absolute-p project-dir
)
366 (setq dirs
'("SCCS" ""))
367 (setq dirs
'("src/SCCS" "src" "source/SCCS" "source"))
368 (setq project-dir
(expand-file-name (concat "~" project-dir
))))
369 (while (and (not dir
) dirs
)
370 (setq dir
(expand-file-name (car dirs
) project-dir
))
371 (unless (file-directory-p dir
)
373 (setq dirs
(cdr dirs
))))
374 (and dir
(expand-file-name (concat "s." basename
) dir
))))))
376 (defun vc-sccs-lock-file (file)
377 "Generate lock file name corresponding to FILE."
378 (let ((master (vc-name file
)))
381 (string-match "\\(.*/\\)\\(s\\.\\)\\(.*\\)" master
)
382 (replace-match "p." t t master
2))))
384 (defun vc-sccs-parse-locks ()
385 "Parse SCCS locks in current buffer.
386 The result is a list of the form ((VERSION . USER) (VERSION . USER) ...)."
388 (goto-char (point-min))
389 (while (re-search-forward "^\\([0-9.]+\\) [0-9.]+ \\([^ ]+\\) .*\n?"
392 (cons (cons (match-string 1) (match-string 2)) master-locks
)))
393 ;; FIXME: is it really necessary to reverse ?
394 (nreverse master-locks
)))
396 (defun vc-sccs-add-triple (name file rev
)
399 (expand-file-name vc-sccs-name-assoc-file
400 (file-name-directory (vc-name file
))))
401 (goto-char (point-max))
402 (insert name
"\t:\t" file
"\t" rev
"\n")
404 (kill-buffer (current-buffer))))
406 (defun vc-sccs-lookup-triple (file name
)
407 "Return the numeric version corresponding to a named snapshot of FILE.
408 If NAME is nil or a version number string it's just passed through."
410 (let ((firstchar (aref name
0)))
411 (and (>= firstchar ?
0) (<= firstchar ?
9))))
415 (expand-file-name vc-sccs-name-assoc-file
416 (file-name-directory (vc-name file
))))
417 (vc-parse-buffer (concat name
"\t:\t" file
"\t\\(.+\\)") 1))))
421 ;;; vc-sccs.el ends here