1 ;;; vc-sccs.el --- support for SCCS version-control
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
5 ;; Free Software Foundation, Inc.
7 ;; Author: FSF (see vc.el for full credits)
8 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
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 3, 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., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
30 ;; - remove call to vc-expand-dirs by implementing our own (which can just
31 ;; list the SCCS subdir instead).
39 ;;; Customization options
42 (defcustom vc-sccs-register-switches nil
43 "*Extra switches for registering a file in SCCS.
44 A string or list of strings passed to the checkin program by
45 \\[vc-sccs-register]."
46 :type
'(choice (const :tag
"None" nil
)
47 (string :tag
"Argument String")
48 (repeat :tag
"Argument List"
54 (defcustom vc-sccs-diff-switches nil
55 "*A string or list of strings specifying extra switches for `vcdiff',
56 the diff utility used for SCCS under VC."
57 :type
'(choice (const :tag
"None" nil
)
58 (string :tag
"Argument String")
59 (repeat :tag
"Argument List"
65 (defcustom vc-sccs-header
(or (cdr (assoc 'SCCS vc-header-alist
)) '("%W%"))
66 "*Header keywords to be inserted by `vc-insert-headers'."
67 :type
'(repeat string
)
71 (defcustom vc-sccs-master-templates
72 '("%sSCCS/s.%s" "%ss.%s" vc-sccs-search-project-dir
)
73 "*Where to look for SCCS master files.
74 For a description of possible values, see `vc-check-master-templates'."
75 :type
'(choice (const :tag
"Use standard SCCS file names"
76 ("%sSCCS/s.%s" "%ss.%s" vc-sccs-search-project-dir
))
77 (repeat :tag
"User-specified"
85 ;;; Internal variables
88 (defconst vc-sccs-name-assoc-file
"VC-names")
91 ;;; Properties of the backend
93 (defun vc-sccs-revision-granularity ()
97 ;;; State-querying functions
100 ;;; The autoload cookie below places vc-sccs-registered directly into
101 ;;; loaddefs.el, so that vc-sccs.el does not need to be loaded for
102 ;;; every file that is visited. The definition is repeated below
103 ;;; so that Help and etags can find it.
105 ;;;###autoload (defun vc-sccs-registered(f) (vc-default-registered 'SCCS f))
106 (defun vc-sccs-registered (f) (vc-default-registered 'SCCS f
))
108 (defun vc-sccs-state (file)
109 "SCCS-specific function to compute the version control state."
111 (if (vc-insert-file (vc-sccs-lock-file file
))
112 (let* ((locks (vc-sccs-parse-locks))
113 (working-revision (vc-working-revision file
))
114 (locking-user (cdr (assoc working-revision locks
))))
115 (if (not locking-user
)
116 (if (vc-workfile-unchanged-p file
)
119 (if (string= locking-user
(vc-user-login-name file
))
124 (defun vc-sccs-state-heuristic (file)
125 "SCCS-specific state heuristic."
126 (if (not (vc-mistrust-permissions file
))
127 ;; This implementation assumes that any file which is under version
128 ;; control and has -rw-r--r-- is locked by its owner. This is true
129 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--.
130 ;; We have to be careful not to exclude files with execute bits on;
131 ;; scripts can be under version control too. Also, we must ignore the
132 ;; group-read and other-read bits, since paranoid users turn them off.
133 (let* ((attributes (file-attributes file
'string
))
134 (owner-name (nth 2 attributes
))
135 (permissions (nth 8 attributes
)))
136 (if (string-match ".r-..-..-." permissions
)
138 (if (string-match ".rw..-..-." permissions
)
139 (if (file-ownership-preserved-p file
)
142 ;; Strange permissions.
143 ;; Fall through to real state computation.
144 (vc-sccs-state file
))))
145 (vc-sccs-state file
)))
147 ;; XXX Experimental function for the vc-dired replacement.
148 (defun vc-sccs-dir-status (dir update-function status-buffer
)
149 ;; XXX: quick hack, there should be a better way to do this,
150 ;; but it's not worse than vc-dired :-).
151 (let ((flist (vc-expand-dirs (list dir
)))
154 (let ((state (vc-state file
))
155 (frel (file-relative-name file
)))
156 (push (list frel state
) result
)))
157 (funcall update-function result status-buffer
)))
159 (defun vc-sccs-working-revision (file)
160 "SCCS-specific version of `vc-working-revision'."
162 ;; The working revision is always the latest revision number.
163 ;; To find this number, search the entire delta table,
164 ;; rather than just the first entry, because the
165 ;; first entry might be a deleted ("R") revision.
166 (vc-insert-file (vc-name file
) "^\001e\n\001[^s]")
167 (vc-parse-buffer "^\001d D \\([^ ]+\\)" 1)))
169 (defun vc-sccs-checkout-model (file)
170 "SCCS-specific version of `vc-checkout-model'."
173 (defun vc-sccs-workfile-unchanged-p (file)
174 "SCCS-specific implementation of `vc-workfile-unchanged-p'."
175 (zerop (apply 'vc-do-command nil
1 "vcdiff" (vc-name file
)
177 (concat "-r" (vc-working-revision file
))))))
181 ;;; State-changing functions
184 (defun vc-sccs-create-repo ()
185 "Create a new SCCS repository."
186 ;; SCCS is totally file-oriented, so all we have to do is make the directory
187 (make-directory "SCCS"))
189 (defun vc-sccs-register (files &optional rev comment
)
190 "Register FILES into the SCCS version-control system.
191 REV is the optional revision number for the file. COMMENT can be used
192 to provide an initial description of FILES.
194 `vc-register-switches' and `vc-sccs-register-switches' are passed to
195 the SCCS command (in that order).
197 Automatically retrieve a read-only version of the files with keywords
198 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
200 (let* ((dirname (or (file-name-directory file
) ""))
201 (basename (file-name-nondirectory file
))
202 (project-file (vc-sccs-search-project-dir dirname basename
)))
205 (format (car vc-sccs-master-templates
) dirname basename
))))
206 (apply 'vc-do-command nil
0 "admin" vc-name
207 (and rev
(not (string= rev
"")) (concat "-r" rev
))
209 (concat "-i" (file-relative-name file
))
210 (and comment
(concat "-y" comment
))
211 (vc-switches 'SCCS
'register
)))
213 (if vc-keep-workfiles
214 (vc-do-command nil
0 "get" (vc-name file
))))))
216 (defun vc-sccs-responsible-p (file)
217 "Return non-nil if SCCS thinks it would be responsible for registering FILE."
218 ;; TODO: check for all the patterns in vc-sccs-master-templates
219 (or (file-directory-p (expand-file-name "SCCS" (file-name-directory file
)))
220 (stringp (vc-sccs-search-project-dir (or (file-name-directory file
) "")
221 (file-name-nondirectory file
)))))
223 (defun vc-sccs-checkin (files rev comment
)
224 "SCCS-specific version of `vc-backend-checkin'."
226 (apply 'vc-do-command nil
0 "delta" (vc-name file
)
227 (if rev
(concat "-r" rev
))
228 (concat "-y" comment
)
229 (vc-switches 'SCCS
'checkin
))
230 (if vc-keep-workfiles
231 (vc-do-command nil
0 "get" (vc-name file
)))))
233 (defun vc-sccs-find-revision (file rev buffer
)
234 (apply 'vc-do-command
235 buffer
0 "get" (vc-name file
)
236 "-s" ;; suppress diagnostic output
240 (vc-sccs-lookup-triple file rev
)))
241 (vc-switches 'SCCS
'checkout
)))
243 (defun vc-sccs-checkout (file &optional editable rev
)
244 "Retrieve a copy of a saved revision of SCCS controlled FILE.
245 EDITABLE non-nil means that the file should be writable and
246 locked. REV is the revision to check out."
247 (let ((file-buffer (get-file-buffer file
))
249 (message "Checking out %s..." file
)
251 ;; Change buffers to get local value of vc-checkout-switches.
252 (if file-buffer
(set-buffer file-buffer
))
253 (setq switches
(vc-switches 'SCCS
'checkout
))
254 ;; Save this buffer's default-directory
255 ;; and use save-excursion to make sure it is restored
256 ;; in the same buffer it was saved in.
257 (let ((default-directory default-directory
))
259 ;; Adjust the default-directory so that the check-out creates
260 ;; the file in the right place.
261 (setq default-directory
(file-name-directory file
))
263 (and rev
(or (string= rev
"")
266 (apply 'vc-do-command nil
0 "get" (vc-name file
)
268 (and rev
(concat "-r" (vc-sccs-lookup-triple file rev
)))
270 (message "Checking out %s...done" file
)))
272 (defun vc-sccs-rollback (files)
273 "Roll back, undoing the most recent checkins of FILES."
275 (error "SCCS backend doesn't support directory-level rollback."))
277 (let ((discard (vc-working-revision file
)))
278 (if (null (yes-or-no-p (format "Remove version %s from %s history? "
281 (message "Removing revision %s from %s..." discard file
)
282 (vc-do-command nil
0 "rmdel" (vc-name file
) (concat "-r" discard
))
283 (vc-do-command nil
0 "get" (vc-name file
) nil
))))
285 (defun vc-sccs-revert (file &optional contents-done
)
286 "Revert FILE to the version it was based on."
287 (vc-do-command nil
0 "unget" (vc-name file
))
288 (vc-do-command nil
0 "get" (vc-name file
))
289 ;; Checking out explicit revisions is not supported under SCCS, yet.
290 ;; We always "revert" to the latest revision; therefore
291 ;; vc-working-revision is cleared here so that it gets recomputed.
292 (vc-file-setprop file
'vc-working-revision nil
))
294 (defun vc-sccs-steal-lock (file &optional rev
)
295 "Steal the lock on the current workfile for FILE and revision REV."
296 (vc-do-command nil
0 "unget" (vc-name file
) "-n" (if rev
(concat "-r" rev
)))
297 (vc-do-command nil
0 "get" (vc-name file
) "-g" (if rev
(concat "-r" rev
))))
299 (defun vc-sccs-modify-change-comment (files rev comment
)
300 "Modify (actually, append to) the change comments for FILES on a specified REV."
302 (vc-do-command nil
0 "cdc" (vc-name file
)
303 (concat "-y" comment
) (concat "-r" rev
))))
307 ;;; History functions
310 (defun vc-sccs-print-log (files &optional buffer
)
311 "Get change log associated with FILES."
312 (vc-do-command buffer
0 "prs" (mapcar 'vc-name files
)))
314 (defun vc-sccs-wash-log ()
315 "Remove all non-comment information from log output."
316 ;; FIXME: not implemented for SCCS
319 (defun vc-sccs-logentry-check ()
320 "Check that the log entry in the current buffer is acceptable for SCCS."
321 (when (>= (buffer-size) 512)
323 (error "Log must be less than 512 characters; point is now at pos 512")))
325 (defun vc-sccs-diff (files &optional oldvers newvers buffer
)
326 "Get a difference report using SCCS between two filesets."
327 (setq oldvers
(vc-sccs-lookup-triple (car files
) oldvers
))
328 (setq newvers
(vc-sccs-lookup-triple (car files
) newvers
))
329 (apply 'vc-do-command
(or buffer
"*vc-diff*")
330 1 "vcdiff" (mapcar 'vc-name
(vc-expand-dirs files
))
332 (and oldvers
(concat "-r" oldvers
))
333 (and newvers
(concat "-r" newvers
)))
334 (vc-switches 'SCCS
'diff
))))
341 (defun vc-sccs-assign-name (file name
)
342 "Assign to FILE's latest revision a given NAME."
343 (vc-sccs-add-triple name file
(vc-working-revision file
)))
350 (defun vc-sccs-check-headers ()
351 "Check if the current file has any headers in it."
353 (goto-char (point-min))
354 (re-search-forward "%[A-Z]%" nil t
)))
356 (defun vc-sccs-rename-file (old new
)
357 ;; Move the master file (using vc-rcs-master-templates).
358 (vc-rename-master (vc-name old
) new vc-sccs-master-templates
)
359 ;; Update the snapshot file.
362 (expand-file-name vc-sccs-name-assoc-file
363 (file-name-directory (vc-name old
))))
364 (goto-char (point-min))
365 ;; (replace-regexp (concat ":" (regexp-quote old) "$") (concat ":" new))
366 (while (re-search-forward (concat ":" (regexp-quote old
) "$") nil t
)
367 (replace-match (concat ":" new
) nil nil
))
369 (kill-buffer (current-buffer))))
373 ;;; Internal functions
376 (defun vc-sccs-root (dir)
377 (vc-find-root dir
"SCCS" t
))
379 ;; This function is wrapped with `progn' so that the autoload cookie
380 ;; copies the whole function itself into loaddefs.el rather than just placing
381 ;; a (autoload 'vc-sccs-search-project-dir "vc-sccs") which would not
382 ;; help us avoid loading vc-sccs.
384 (progn (defun vc-sccs-search-project-dir (dirname basename
)
385 "Return the name of a master file in the SCCS project directory.
386 Does not check whether the file exists but returns nil if it does not
387 find any project directory."
388 (let ((project-dir (getenv "PROJECTDIR")) dirs dir
)
390 (if (file-name-absolute-p project-dir
)
391 (setq dirs
'("SCCS" ""))
392 (setq dirs
'("src/SCCS" "src" "source/SCCS" "source"))
393 (setq project-dir
(expand-file-name (concat "~" project-dir
))))
394 (while (and (not dir
) dirs
)
395 (setq dir
(expand-file-name (car dirs
) project-dir
))
396 (unless (file-directory-p dir
)
398 (setq dirs
(cdr dirs
))))
399 (and dir
(expand-file-name (concat "s." basename
) dir
))))))
401 (defun vc-sccs-lock-file (file)
402 "Generate lock file name corresponding to FILE."
403 (let ((master (vc-name file
)))
406 (string-match "\\(.*/\\)\\(s\\.\\)\\(.*\\)" master
)
407 (replace-match "p." t t master
2))))
409 (defun vc-sccs-parse-locks ()
410 "Parse SCCS locks in current buffer.
411 The result is a list of the form ((REVISION . USER) (REVISION . USER) ...)."
413 (goto-char (point-min))
414 (while (re-search-forward "^\\([0-9.]+\\) [0-9.]+ \\([^ ]+\\) .*\n?"
417 (cons (cons (match-string 1) (match-string 2)) master-locks
)))
418 ;; FIXME: is it really necessary to reverse ?
419 (nreverse master-locks
)))
421 (defun vc-sccs-add-triple (name file rev
)
424 (expand-file-name vc-sccs-name-assoc-file
425 (file-name-directory (vc-name file
))))
426 (goto-char (point-max))
427 (insert name
"\t:\t" file
"\t" rev
"\n")
429 (kill-buffer (current-buffer))))
431 (defun vc-sccs-lookup-triple (file name
)
432 "Return the numeric revision corresponding to a named snapshot of FILE.
433 If NAME is nil or a revision number string it's just passed through."
435 (let ((firstchar (aref name
0)))
436 (and (>= firstchar ?
0) (<= firstchar ?
9))))
440 (expand-file-name vc-sccs-name-assoc-file
441 (file-name-directory (vc-name file
))))
442 (vc-parse-buffer (concat name
"\t:\t" file
"\t\\(.+\\)") 1))))
446 ;; arch-tag: d751dee3-d7b3-47e1-95e3-7ae98c052041
447 ;;; vc-sccs.el ends here