1 ;;; vc-sccs.el --- support for SCCS version-control
3 ;; Copyright (C) 1992,93,94,95,96,97,98,99,2000 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.4 2000/09/09 00:48:40 monnier 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.
32 ;;; Customization options
35 (defcustom vc-sccs-register-switches nil
36 "*Extra switches for registering a file in SCCS.
37 A string or list of strings passed to the checkin program by
38 \\[vc-sccs-register]."
39 :type
'(choice (const :tag
"None" nil
)
40 (string :tag
"Argument String")
41 (repeat :tag
"Argument List"
47 (defcustom vc-sccs-header
(or (cdr (assoc 'SCCS vc-header-alist
)) '("%W%"))
48 "*Header keywords to be inserted by `vc-insert-headers'."
53 (defcustom vc-sccs-master-templates
54 '("%sSCCS/s.%s" "%ss.%s" vc-sccs-search-project-dir
)
55 "*Where to look for SCCS master files.
56 For a description of possible values, see `vc-check-master-templates'."
57 :type
'(choice (const :tag
"Use standard SCCS file names"
58 ("%sSCCS/s.%s" "%ss.%s" vc-sccs-search-project-dir
))
59 (repeat :tag
"User-specified"
67 ;;; Internal variables
70 (defconst vc-sccs-name-assoc-file
"VC-names")
74 ;;; State-querying functions
78 (progn (defun vc-sccs-registered (f) (vc-default-registered 'SCCS f
)))
80 (defun vc-sccs-state (file)
81 "SCCS-specific function to compute the version control state."
83 (if (vc-insert-file (vc-sccs-lock-file file
))
84 (let* ((locks (vc-sccs-parse-locks))
85 (workfile-version (vc-workfile-version file
))
86 (locking-user (cdr (assoc workfile-version locks
))))
87 (if (not locking-user
)
88 (if (vc-workfile-unchanged-p file
)
91 (if (string= locking-user
(vc-user-login-name))
96 (defun vc-sccs-state-heuristic (file)
97 "SCCS-specific state heuristic."
98 (if (not (vc-mistrust-permissions file
))
99 ;; This implementation assumes that any file which is under version
100 ;; control and has -rw-r--r-- is locked by its owner. This is true
101 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--.
102 ;; We have to be careful not to exclude files with execute bits on;
103 ;; scripts can be under version control too. Also, we must ignore the
104 ;; group-read and other-read bits, since paranoid users turn them off.
105 (let* ((attributes (file-attributes file
))
106 (owner-uid (nth 2 attributes
))
107 (permissions (nth 8 attributes
)))
108 (if (string-match ".r-..-..-." permissions
)
110 (if (string-match ".rw..-..-." permissions
)
111 (if (file-ownership-preserved-p file
)
113 (vc-user-login-name owner-uid
))
114 ;; Strange permissions.
115 ;; Fall through to real state computation.
116 (vc-sccs-state file
)))
117 (vc-sccs-state file
))))
119 (defun vc-sccs-workfile-version (file)
120 "SCCS-specific version of `vc-workfile-version'."
122 (vc-insert-file (vc-name file
) "^\001e")
123 (vc-parse-buffer "^\001d D \\([^ ]+\\)" 1)))
125 (defun vc-sccs-latest-on-branch-p (file)
126 "Return t iff the current workfile version of FILE is latest on its branch."
127 ;; Always return t; we do not support previous versions in the workfile
131 (defun vc-sccs-checkout-model (file)
132 "SCCS-specific version of `vc-checkout-model'."
135 (defun vc-sccs-workfile-unchanged-p (file)
136 "SCCS-specific implementation of vc-workfile-unchanged-p."
137 (apply 'vc-do-command nil
1 "vcdiff" (vc-name file
)
139 (concat "-r" (vc-workfile-version file
)))))
143 ;;; State-changing functions
146 (defun vc-sccs-register (file &optional rev comment
)
147 "Register FILE into the SCCS version-control system.
148 REV is the optional revision number for the file. COMMENT can be used
149 to provide an initial description of FILE.
151 `vc-register-switches' and `vc-sccs-register-switches' are passed to
152 the SCCS command (in that order).
154 Automatically retrieve a read-only version of the file with keywords
155 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
156 (let* ((switches (list
157 (if (stringp vc-register-switches
)
158 (list vc-register-switches
)
159 vc-register-switches
)
160 (if (stringp vc-sccs-register-switches
)
161 (list vc-sccs-register-switches
)
162 vc-sccs-register-switches
)))
163 (dirname (or (file-name-directory file
) ""))
164 (basename (file-name-nondirectory file
))
165 (project-file (vc-sccs-search-project-dir dirname basename
)))
168 (format (car vc-sccs-master-templates
) dirname basename
)))|
)
169 (apply 'vc-do-command nil
0 "admin" nil
170 (and rev
(concat "-r" rev
))
173 (and comment
(concat "-y" comment
))
177 (if vc-keep-workfiles
178 (vc-do-command nil
0 "get" (vc-name file
)))))
180 (defun vc-sccs-responsible-p (file)
181 "Return non-nil if SCCS thinks it would be responsible for registering FILE."
182 ;; TODO: check for all the patterns in vc-sccs-master-templates
183 (or (file-directory-p (expand-file-name "SCCS" (file-name-directory file
)))
184 (stringp (vc-sccs-search-project-dir (or (file-name-directory file
) "")
185 (file-name-nondirectory file
)))))
187 (defun vc-sccs-checkin (file rev comment
)
188 "SCCS-specific version of `vc-backend-checkin'."
189 (let ((switches (if (stringp vc-checkin-switches
)
190 (list vc-checkin-switches
)
191 vc-checkin-switches
)))
192 (apply 'vc-do-command nil
0 "delta" (vc-name file
)
193 (if rev
(concat "-r" rev
))
194 (concat "-y" comment
)
196 (if vc-keep-workfiles
197 (vc-do-command nil
0 "get" (vc-name file
)))))
199 (defun vc-sccs-checkout (file &optional writable rev workfile
)
200 "Retrieve a copy of a saved version of SCCS controlled FILE into a WORKFILE.
201 WRITABLE non-nil means that the file should be writable. REV is the
202 revision to check out into WORKFILE."
203 (let ((filename (or workfile file
))
204 (file-buffer (get-file-buffer file
))
206 (message "Checking out %s..." filename
)
208 ;; Change buffers to get local value of vc-checkout-switches.
209 (if file-buffer
(set-buffer file-buffer
))
210 (setq switches
(if (stringp vc-checkout-switches
)
211 (list vc-checkout-switches
)
212 vc-checkout-switches
))
213 ;; Save this buffer's default-directory
214 ;; and use save-excursion to make sure it is restored
215 ;; in the same buffer it was saved in.
216 (let ((default-directory default-directory
))
218 ;; Adjust the default-directory so that the check-out creates
219 ;; the file in the right place.
220 (setq default-directory
(file-name-directory filename
))
222 (and rev
(string= rev
"") (setq rev nil
))
224 ;; Some SCCS implementations allow checking out directly to a
225 ;; file using the -G option, but then some don't so use the
226 ;; least common denominator approach and use the -p option
228 (let ((vc-modes (logior (file-modes (vc-name file
))
229 (if writable
128 0)))
233 (let ((coding-system-for-read 'no-conversion
)
234 (coding-system-for-write 'no-conversion
))
235 (with-temp-file filename
236 (apply 'vc-do-command
237 (current-buffer) 0 "get" (vc-name file
)
238 "-s" ;; suppress diagnostic output
243 (vc-sccs-lookup-triple file rev
)))
245 (set-file-modes filename
246 (logior (file-modes (vc-name file
))
247 (if writable
128 0)))
249 (and failed
(file-exists-p filename
)
250 (delete-file filename
))))
251 (apply 'vc-do-command nil
0 "get" (vc-name file
)
253 (and rev
(concat "-r" (vc-sccs-lookup-triple file rev
)))
255 (message "Checking out %s...done" filename
)))
257 (defun vc-sccs-revert (file)
258 "Revert FILE to the version it was based on."
259 (vc-do-command nil
0 "unget" (vc-name file
))
260 (vc-do-command nil
0 "get" (vc-name file
))
261 ;; Checking out explicit versions is not supported under SCCS, yet.
262 ;; We always "revert" to the latest version; therefore
263 ;; vc-workfile-version is cleared here so that it gets recomputed.
264 (vc-file-setprop file
'vc-workfile-version nil
))
266 (defun vc-sccs-cancel-version (file writable
)
267 "Undo the most recent checkin of FILE.
268 WRITABLE non-nil means previous version should be locked."
269 (vc-do-command nil
0 "rmdel"
271 (concat "-r" (vc-workfile-version file
)))
272 (vc-do-command nil
0 "get"
276 (defun vc-sccs-steal-lock (file &optional rev
)
277 "Steal the lock on the current workfile for FILE and revision REV."
278 (vc-do-command nil
0 "unget" (vc-name file
) "-n" (if rev
(concat "-r" rev
)))
279 (vc-do-command nil
0 "get" (vc-name file
) "-g" (if rev
(concat "-r" rev
))))
283 ;;; History functions
286 (defun vc-sccs-print-log (file)
287 "Get change log associated with FILE."
288 (vc-do-command t
0 "prs" (vc-name file
)))
290 (defun vc-sccs-logentry-check ()
291 "Check that the log entry in the current buffer is acceptable for SCCS."
292 (when (>= (buffer-size) 512)
294 (error "Log must be less than 512 characters; point is now at pos 512")))
296 (defun vc-sccs-diff (file &optional oldvers newvers
)
297 "Get a difference report using SCCS between two versions of FILE."
298 (setq oldvers
(vc-sccs-lookup-triple file oldvers
))
299 (setq newvers
(vc-sccs-lookup-triple file newvers
))
300 (let* ((diff-switches-list (if (listp diff-switches
)
302 (list diff-switches
)))
303 (options (append (list "-q"
304 (and oldvers
(concat "-r" oldvers
))
305 (and newvers
(concat "-r" newvers
)))
306 diff-switches-list
)))
307 (apply 'vc-do-command t
1 "vcdiff" (vc-name file
) options
)))
314 (defun vc-sccs-assign-name (file name
)
315 "Assign to FILE's latest version a given NAME."
316 (vc-sccs-add-triple name file
(vc-workfile-version file
)))
323 (defun vc-sccs-check-headers ()
324 "Check if the current file has any headers in it."
326 (goto-char (point-min))
327 (re-search-forward "%[A-Z]%" nil t
)))
329 (defun vc-sccs-rename-file (old new
)
330 ;; Move the master file (using vc-rcs-master-templates).
331 (vc-rename-master (vc-name old
) new vc-sccs-master-templates
)
332 ;; Update the snapshot file.
335 (expand-file-name vc-sccs-name-assoc-file
336 (file-name-directory (vc-name old
))))
337 (goto-char (point-min))
338 ;; (replace-regexp (concat ":" (regexp-quote old) "$") (concat ":" new))
339 (while (re-search-forward (concat ":" (regexp-quote old
) "$") nil t
)
340 (replace-match (concat ":" new
) nil nil
))
342 (kill-buffer (current-buffer))))
346 ;;; Internal functions
349 ;; This function is wrapped with `progn' so that the autoload cookie
350 ;; copies the whole function itself into loaddefs.el rather than just placing
351 ;; a (autoload 'vc-sccs-search-project-dir "vc-sccs") which would not
352 ;; help us avoid loading vc-sccs.
354 (progn (defun vc-sccs-search-project-dir (dirname basename
)
355 "Return the name of a master file in the SCCS project directory.
356 Does not check whether the file exists but returns nil if it does not
357 find any project directory."
358 (let ((project-dir (getenv "PROJECTDIR")) dirs dir
)
360 (if (file-name-absolute-p project-dir
)
361 (setq dirs
'("SCCS" ""))
362 (setq dirs
'("src/SCCS" "src" "source/SCCS" "source"))
363 (setq project-dir
(expand-file-name (concat "~" project-dir
))))
364 (while (and (not dir
) dirs
)
365 (setq dir
(expand-file-name (car dirs
) project-dir
))
366 (unless (file-directory-p dir
)
368 (setq dirs
(cdr dirs
))))
369 (and dir
(expand-file-name (concat "s." basename
) dir
))))))
371 (defun vc-sccs-lock-file (file)
372 "Generate lock file name corresponding to FILE."
373 (let ((master (vc-name file
)))
376 (string-match "\\(.*/\\)\\(s\\.\\)\\(.*\\)" master
)
377 (replace-match "p." t t master
2))))
379 (defun vc-sccs-parse-locks ()
380 "Parse SCCS locks in current buffer.
381 The result is a list of the form ((VERSION . USER) (VERSION . USER) ...)."
383 (goto-char (point-min))
384 (while (re-search-forward "^\\([0-9.]+\\) [0-9.]+ \\([^ ]+\\) .*\n?"
387 (cons (cons (match-string 1) (match-string 2)) master-locks
)))
388 ;; FIXME: is it really necessary to reverse ?
389 (nreverse master-locks
)))
391 (defun vc-sccs-add-triple (name file rev
)
394 (expand-file-name vc-sccs-name-assoc-file
395 (file-name-directory (vc-name file
))))
396 (goto-char (point-max))
397 (insert name
"\t:\t" file
"\t" rev
"\n")
399 (kill-buffer (current-buffer))))
401 (defun vc-sccs-lookup-triple (file name
)
402 "Return the numeric version corresponding to a named snapshot of FILE.
403 If NAME is nil or a version number string it's just passed through."
405 (let ((firstchar (aref name
0)))
406 (and (>= firstchar ?
0) (<= firstchar ?
9))))
410 (expand-file-name vc-sccs-name-assoc-file
411 (file-name-directory (vc-name file
))))
412 (vc-parse-buffer (concat name
"\t:\t" file
"\t\\(.+\\)") 1))))
416 ;;; vc-sccs.el ends here