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.6 2001/01/08 16:26:44 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.
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'."
49 :type
'(repeat string
)
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-checkout-model (file)
126 "SCCS-specific version of `vc-checkout-model'."
129 (defun vc-sccs-workfile-unchanged-p (file)
130 "SCCS-specific implementation of vc-workfile-unchanged-p."
131 (apply 'vc-do-command nil
1 "vcdiff" (vc-name file
)
133 (concat "-r" (vc-workfile-version file
)))))
137 ;;; State-changing functions
140 (defun vc-sccs-register (file &optional rev comment
)
141 "Register FILE into the SCCS version-control system.
142 REV is the optional revision number for the file. COMMENT can be used
143 to provide an initial description of FILE.
145 `vc-register-switches' and `vc-sccs-register-switches' are passed to
146 the SCCS command (in that order).
148 Automatically retrieve a read-only version of the file with keywords
149 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
150 (let* ((switches (list
151 (if (stringp vc-register-switches
)
152 (list vc-register-switches
)
153 vc-register-switches
)
154 (if (stringp vc-sccs-register-switches
)
155 (list vc-sccs-register-switches
)
156 vc-sccs-register-switches
)))
157 (dirname (or (file-name-directory file
) ""))
158 (basename (file-name-nondirectory file
))
159 (project-file (vc-sccs-search-project-dir dirname basename
)))
162 (format (car vc-sccs-master-templates
) dirname basename
)))|
)
163 (apply 'vc-do-command nil
0 "admin" nil
164 (and rev
(concat "-r" rev
))
167 (and comment
(concat "-y" comment
))
171 (if vc-keep-workfiles
172 (vc-do-command nil
0 "get" (vc-name file
)))))
174 (defun vc-sccs-responsible-p (file)
175 "Return non-nil if SCCS thinks it would be responsible for registering FILE."
176 ;; TODO: check for all the patterns in vc-sccs-master-templates
177 (or (file-directory-p (expand-file-name "SCCS" (file-name-directory file
)))
178 (stringp (vc-sccs-search-project-dir (or (file-name-directory file
) "")
179 (file-name-nondirectory file
)))))
181 (defun vc-sccs-checkin (file rev comment
)
182 "SCCS-specific version of `vc-backend-checkin'."
183 (let ((switches (if (stringp vc-checkin-switches
)
184 (list vc-checkin-switches
)
185 vc-checkin-switches
)))
186 (apply 'vc-do-command nil
0 "delta" (vc-name file
)
187 (if rev
(concat "-r" rev
))
188 (concat "-y" comment
)
190 (if vc-keep-workfiles
191 (vc-do-command nil
0 "get" (vc-name file
)))))
193 (defun vc-sccs-checkout (file &optional editable rev workfile
)
194 "Retrieve a copy of a saved version of SCCS controlled FILE into a WORKFILE.
195 EDITABLE non-nil means that the file should be writable and
196 locked. REV is the revision to check out into WORKFILE."
197 (let ((filename (or workfile file
))
198 (file-buffer (get-file-buffer file
))
200 (message "Checking out %s..." filename
)
202 ;; Change buffers to get local value of vc-checkout-switches.
203 (if file-buffer
(set-buffer file-buffer
))
204 (setq switches
(if (stringp vc-checkout-switches
)
205 (list vc-checkout-switches
)
206 vc-checkout-switches
))
207 ;; Save this buffer's default-directory
208 ;; and use save-excursion to make sure it is restored
209 ;; in the same buffer it was saved in.
210 (let ((default-directory default-directory
))
212 ;; Adjust the default-directory so that the check-out creates
213 ;; the file in the right place.
214 (setq default-directory
(file-name-directory filename
))
216 (and rev
(string= rev
"") (setq rev nil
))
218 ;; Some SCCS implementations allow checking out directly to a
219 ;; file using the -G option, but then some don't so use the
220 ;; least common denominator approach and use the -p option
222 (let ((vc-modes (logior (file-modes (vc-name file
))
223 (if editable
128 0)))
227 (let ((coding-system-for-read 'no-conversion
)
228 (coding-system-for-write 'no-conversion
))
229 (with-temp-file filename
230 (apply 'vc-do-command
231 (current-buffer) 0 "get" (vc-name file
)
232 "-s" ;; suppress diagnostic output
237 (vc-sccs-lookup-triple file rev
)))
239 (set-file-modes filename
240 (logior (file-modes (vc-name file
))
241 (if editable
128 0)))
243 (and failed
(file-exists-p filename
)
244 (delete-file filename
))))
245 (apply 'vc-do-command nil
0 "get" (vc-name file
)
247 (and rev
(concat "-r" (vc-sccs-lookup-triple file rev
)))
249 (message "Checking out %s...done" filename
)))
251 (defun vc-sccs-revert (file)
252 "Revert FILE to the version it was based on."
253 (vc-do-command nil
0 "unget" (vc-name file
))
254 (vc-do-command nil
0 "get" (vc-name file
))
255 ;; Checking out explicit versions is not supported under SCCS, yet.
256 ;; We always "revert" to the latest version; therefore
257 ;; vc-workfile-version is cleared here so that it gets recomputed.
258 (vc-file-setprop file
'vc-workfile-version nil
))
260 (defun vc-sccs-cancel-version (file editable
)
261 "Undo the most recent checkin of FILE.
262 EDITABLE non-nil means previous version should be locked."
263 (vc-do-command nil
0 "rmdel"
265 (concat "-r" (vc-workfile-version file
)))
266 (vc-do-command nil
0 "get"
270 (defun vc-sccs-steal-lock (file &optional rev
)
271 "Steal the lock on the current workfile for FILE and revision REV."
272 (vc-do-command nil
0 "unget" (vc-name file
) "-n" (if rev
(concat "-r" rev
)))
273 (vc-do-command nil
0 "get" (vc-name file
) "-g" (if rev
(concat "-r" rev
))))
277 ;;; History functions
280 (defun vc-sccs-print-log (file)
281 "Get change log associated with FILE."
282 (vc-do-command t
0 "prs" (vc-name file
)))
284 (defun vc-sccs-logentry-check ()
285 "Check that the log entry in the current buffer is acceptable for SCCS."
286 (when (>= (buffer-size) 512)
288 (error "Log must be less than 512 characters; point is now at pos 512")))
290 (defun vc-sccs-diff (file &optional oldvers newvers
)
291 "Get a difference report using SCCS between two versions of FILE."
292 (setq oldvers
(vc-sccs-lookup-triple file oldvers
))
293 (setq newvers
(vc-sccs-lookup-triple file newvers
))
294 (let* ((diff-switches-list (if (listp diff-switches
)
296 (list diff-switches
)))
297 (options (append (list "-q"
298 (and oldvers
(concat "-r" oldvers
))
299 (and newvers
(concat "-r" newvers
)))
300 diff-switches-list
)))
301 (apply 'vc-do-command t
1 "vcdiff" (vc-name file
) options
)))
308 (defun vc-sccs-assign-name (file name
)
309 "Assign to FILE's latest version a given NAME."
310 (vc-sccs-add-triple name file
(vc-workfile-version file
)))
317 (defun vc-sccs-check-headers ()
318 "Check if the current file has any headers in it."
320 (goto-char (point-min))
321 (re-search-forward "%[A-Z]%" nil t
)))
323 (defun vc-sccs-rename-file (old new
)
324 ;; Move the master file (using vc-rcs-master-templates).
325 (vc-rename-master (vc-name old
) new vc-sccs-master-templates
)
326 ;; Update the snapshot file.
329 (expand-file-name vc-sccs-name-assoc-file
330 (file-name-directory (vc-name old
))))
331 (goto-char (point-min))
332 ;; (replace-regexp (concat ":" (regexp-quote old) "$") (concat ":" new))
333 (while (re-search-forward (concat ":" (regexp-quote old
) "$") nil t
)
334 (replace-match (concat ":" new
) nil nil
))
336 (kill-buffer (current-buffer))))
340 ;;; Internal functions
343 ;; This function is wrapped with `progn' so that the autoload cookie
344 ;; copies the whole function itself into loaddefs.el rather than just placing
345 ;; a (autoload 'vc-sccs-search-project-dir "vc-sccs") which would not
346 ;; help us avoid loading vc-sccs.
348 (progn (defun vc-sccs-search-project-dir (dirname basename
)
349 "Return the name of a master file in the SCCS project directory.
350 Does not check whether the file exists but returns nil if it does not
351 find any project directory."
352 (let ((project-dir (getenv "PROJECTDIR")) dirs dir
)
354 (if (file-name-absolute-p project-dir
)
355 (setq dirs
'("SCCS" ""))
356 (setq dirs
'("src/SCCS" "src" "source/SCCS" "source"))
357 (setq project-dir
(expand-file-name (concat "~" project-dir
))))
358 (while (and (not dir
) dirs
)
359 (setq dir
(expand-file-name (car dirs
) project-dir
))
360 (unless (file-directory-p dir
)
362 (setq dirs
(cdr dirs
))))
363 (and dir
(expand-file-name (concat "s." basename
) dir
))))))
365 (defun vc-sccs-lock-file (file)
366 "Generate lock file name corresponding to FILE."
367 (let ((master (vc-name file
)))
370 (string-match "\\(.*/\\)\\(s\\.\\)\\(.*\\)" master
)
371 (replace-match "p." t t master
2))))
373 (defun vc-sccs-parse-locks ()
374 "Parse SCCS locks in current buffer.
375 The result is a list of the form ((VERSION . USER) (VERSION . USER) ...)."
377 (goto-char (point-min))
378 (while (re-search-forward "^\\([0-9.]+\\) [0-9.]+ \\([^ ]+\\) .*\n?"
381 (cons (cons (match-string 1) (match-string 2)) master-locks
)))
382 ;; FIXME: is it really necessary to reverse ?
383 (nreverse master-locks
)))
385 (defun vc-sccs-add-triple (name file rev
)
388 (expand-file-name vc-sccs-name-assoc-file
389 (file-name-directory (vc-name file
))))
390 (goto-char (point-max))
391 (insert name
"\t:\t" file
"\t" rev
"\n")
393 (kill-buffer (current-buffer))))
395 (defun vc-sccs-lookup-triple (file name
)
396 "Return the numeric version corresponding to a named snapshot of FILE.
397 If NAME is nil or a version number string it's just passed through."
399 (let ((firstchar (aref name
0)))
400 (and (>= firstchar ?
0) (<= firstchar ?
9))))
404 (expand-file-name vc-sccs-name-assoc-file
405 (file-name-directory (vc-name file
))))
406 (vc-parse-buffer (concat name
"\t:\t" file
"\t\\(.+\\)") 1))))
410 ;;; vc-sccs.el ends here