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 Free Software Foundation, Inc.
6 ;; Author: FSF (see vc.el for full credits)
7 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 3, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
31 ;; - remove call to vc-expand-dirs by implementing our own (which can just
32 ;; list the SCCS subdir instead).
40 ;;; Customization options
43 (defcustom vc-sccs-register-switches nil
44 "*Extra switches for registering a file in SCCS.
45 A string or list of strings passed to the checkin program by
46 \\[vc-sccs-register]."
47 :type
'(choice (const :tag
"None" nil
)
48 (string :tag
"Argument String")
49 (repeat :tag
"Argument List"
55 (defcustom vc-sccs-diff-switches nil
56 "*A string or list of strings specifying extra switches for `vcdiff',
57 the diff utility used for SCCS under VC."
58 :type
'(choice (const :tag
"None" nil
)
59 (string :tag
"Argument String")
60 (repeat :tag
"Argument List"
66 (defcustom vc-sccs-header
(or (cdr (assoc 'SCCS vc-header-alist
)) '("%W%"))
67 "*Header keywords to be inserted by `vc-insert-headers'."
68 :type
'(repeat string
)
72 (defcustom vc-sccs-master-templates
73 '("%sSCCS/s.%s" "%ss.%s" vc-sccs-search-project-dir
)
74 "*Where to look for SCCS master files.
75 For a description of possible values, see `vc-check-master-templates'."
76 :type
'(choice (const :tag
"Use standard SCCS file names"
77 ("%sSCCS/s.%s" "%ss.%s" vc-sccs-search-project-dir
))
78 (repeat :tag
"User-specified"
86 ;;; Internal variables
89 (defconst vc-sccs-name-assoc-file
"VC-names")
92 ;;; Properties of the backend
94 (defun vc-sccs-revision-granularity ()
98 ;;; State-querying functions
101 ;;; The autoload cookie below places vc-sccs-registered directly into
102 ;;; loaddefs.el, so that vc-sccs.el does not need to be loaded for
103 ;;; every file that is visited. The definition is repeated below
104 ;;; so that Help and etags can find it.
106 ;;;###autoload (defun vc-sccs-registered(f) (vc-default-registered 'SCCS f))
107 (defun vc-sccs-registered (f) (vc-default-registered 'SCCS f
))
109 (defun vc-sccs-state (file)
110 "SCCS-specific function to compute the version control state."
112 (if (vc-insert-file (vc-sccs-lock-file file
))
113 (let* ((locks (vc-sccs-parse-locks))
114 (workfile-version (vc-workfile-version file
))
115 (locking-user (cdr (assoc workfile-version locks
))))
116 (if (not locking-user
)
117 (if (vc-workfile-unchanged-p file
)
120 (if (string= locking-user
(vc-user-login-name file
))
125 (defun vc-sccs-state-heuristic (file)
126 "SCCS-specific state heuristic."
127 (if (not (vc-mistrust-permissions file
))
128 ;; This implementation assumes that any file which is under version
129 ;; control and has -rw-r--r-- is locked by its owner. This is true
130 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--.
131 ;; We have to be careful not to exclude files with execute bits on;
132 ;; scripts can be under version control too. Also, we must ignore the
133 ;; group-read and other-read bits, since paranoid users turn them off.
134 (let* ((attributes (file-attributes file
'string
))
135 (owner-name (nth 2 attributes
))
136 (permissions (nth 8 attributes
)))
137 (if (string-match ".r-..-..-." permissions
)
139 (if (string-match ".rw..-..-." permissions
)
140 (if (file-ownership-preserved-p file
)
143 ;; Strange permissions.
144 ;; Fall through to real state computation.
145 (vc-sccs-state file
))))
146 (vc-sccs-state file
)))
148 (defun vc-sccs-workfile-version (file)
149 "SCCS-specific version of `vc-workfile-version'."
151 ;; The workfile version is always the latest version number.
152 ;; To find this number, search the entire delta table,
153 ;; rather than just the first entry, because the
154 ;; first entry might be a deleted ("R") version.
155 (vc-insert-file (vc-name file
) "^\001e\n\001[^s]")
156 (vc-parse-buffer "^\001d D \\([^ ]+\\)" 1)))
158 (defun vc-sccs-checkout-model (file)
159 "SCCS-specific version of `vc-checkout-model'."
162 (defun vc-sccs-workfile-unchanged-p (file)
163 "SCCS-specific implementation of `vc-workfile-unchanged-p'."
164 (zerop (apply 'vc-do-command nil
1 "vcdiff" (vc-name file
)
166 (concat "-r" (vc-workfile-version file
))))))
170 ;;; State-changing functions
173 (defun vc-sccs-create-repo ()
174 "Create a new SCCS repository."
175 ;; SCCS is totally file-oriented, so all we have to do is make the directory
176 (make-directory "SCCS"))
178 (defun vc-sccs-register (files &optional rev comment
)
179 "Register FILES into the SCCS version-control system.
180 REV is the optional revision number for the file. COMMENT can be used
181 to provide an initial description of FILES.
183 `vc-register-switches' and `vc-sccs-register-switches' are passed to
184 the SCCS command (in that order).
186 Automatically retrieve a read-only version of the files with keywords
187 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
189 (let* ((dirname (or (file-name-directory file
) ""))
190 (basename (file-name-nondirectory file
))
191 (project-file (vc-sccs-search-project-dir dirname basename
)))
194 (format (car vc-sccs-master-templates
) dirname basename
))))
195 (apply 'vc-do-command nil
0 "admin" vc-name
196 (and rev
(not (string= rev
"")) (concat "-r" rev
))
198 (concat "-i" (file-relative-name file
))
199 (and comment
(concat "-y" comment
))
200 (vc-switches 'SCCS
'register
)))
202 (if vc-keep-workfiles
203 (vc-do-command nil
0 "get" (vc-name file
))))))
205 (defun vc-sccs-responsible-p (file)
206 "Return non-nil if SCCS thinks it would be responsible for registering FILE."
207 ;; TODO: check for all the patterns in vc-sccs-master-templates
208 (or (file-directory-p (expand-file-name "SCCS" (file-name-directory file
)))
209 (stringp (vc-sccs-search-project-dir (or (file-name-directory file
) "")
210 (file-name-nondirectory file
)))))
212 (defun vc-sccs-checkin (files rev comment
)
213 "SCCS-specific version of `vc-backend-checkin'."
215 (apply 'vc-do-command nil
0 "delta" (vc-name file
)
216 (if rev
(concat "-r" rev
))
217 (concat "-y" comment
)
218 (vc-switches 'SCCS
'checkin
))
219 (if vc-keep-workfiles
220 (vc-do-command nil
0 "get" (vc-name file
)))))
222 (defun vc-sccs-find-version (file rev buffer
)
223 (apply 'vc-do-command
224 buffer
0 "get" (vc-name file
)
225 "-s" ;; suppress diagnostic output
229 (vc-sccs-lookup-triple file rev
)))
230 (vc-switches 'SCCS
'checkout
)))
232 (defun vc-sccs-checkout (file &optional editable rev
)
233 "Retrieve a copy of a saved version of SCCS controlled FILE.
234 EDITABLE non-nil means that the file should be writable and
235 locked. REV is the revision to check out."
236 (let ((file-buffer (get-file-buffer file
))
238 (message "Checking out %s..." file
)
240 ;; Change buffers to get local value of vc-checkout-switches.
241 (if file-buffer
(set-buffer file-buffer
))
242 (setq switches
(vc-switches 'SCCS
'checkout
))
243 ;; Save this buffer's default-directory
244 ;; and use save-excursion to make sure it is restored
245 ;; in the same buffer it was saved in.
246 (let ((default-directory default-directory
))
248 ;; Adjust the default-directory so that the check-out creates
249 ;; the file in the right place.
250 (setq default-directory
(file-name-directory file
))
252 (and rev
(or (string= rev
"")
255 (apply 'vc-do-command nil
0 "get" (vc-name file
)
257 (and rev
(concat "-r" (vc-sccs-lookup-triple file rev
)))
259 (message "Checking out %s...done" file
)))
261 (defun vc-sccs-cancel-version (files)
262 "Roll back, undoing the most recent checkins of FILES."
264 (error "SCCS backend doesn't support directory-level rollback."))
266 (let ((discard (vc-workfile-version file
)))
267 (if (null (yes-or-no-p (format "Remove version %s from %s history? "
270 (message "Removing revision %s from %s..." discard file
)
271 (vc-do-command nil
0 "rmdel" (vc-name file
) (concat "-r" discard
))
272 (vc-do-command nil
0 "get" (vc-name file
) nil
))))
274 (defun vc-sccs-revert (file &optional contents-done
)
275 "Revert FILE to the version it was based on."
276 (vc-do-command nil
0 "unget" (vc-name file
))
277 (vc-do-command nil
0 "get" (vc-name file
))
278 ;; Checking out explicit versions is not supported under SCCS, yet.
279 ;; We always "revert" to the latest version; therefore
280 ;; vc-workfile-version is cleared here so that it gets recomputed.
281 (vc-file-setprop file
'vc-workfile-version nil
))
283 (defun vc-sccs-steal-lock (file &optional rev
)
284 "Steal the lock on the current workfile for FILE and revision REV."
285 (vc-do-command nil
0 "unget" (vc-name file
) "-n" (if rev
(concat "-r" rev
)))
286 (vc-do-command nil
0 "get" (vc-name file
) "-g" (if rev
(concat "-r" rev
))))
290 ;;; History functions
293 (defun vc-sccs-print-log (files &optional buffer
)
294 "Get change log associated with FILES."
295 (vc-do-command buffer
0 "prs" (mapcar 'vc-name files
)))
297 (defun vc-sccs-wash-log ()
298 "Remove all non-comment information from log output."
299 ;; FIXME: not implemented for SCCS
302 (defun vc-sccs-logentry-check ()
303 "Check that the log entry in the current buffer is acceptable for SCCS."
304 (when (>= (buffer-size) 512)
306 (error "Log must be less than 512 characters; point is now at pos 512")))
308 (defun vc-sccs-diff (files &optional oldvers newvers buffer
)
309 "Get a difference report using SCCS between two filesets."
310 (setq oldvers
(vc-sccs-lookup-triple file oldvers
))
311 (setq newvers
(vc-sccs-lookup-triple file newvers
))
312 (apply 'vc-do-command
(or buffer
"*vc-diff*")
313 1 "vcdiff" (mapcar 'vc-name
(vc-expand-dirs files
))
315 (and oldvers
(concat "-r" oldvers
))
316 (and newvers
(concat "-r" newvers
)))
317 (vc-switches 'SCCS
'diff
))))
324 (defun vc-sccs-assign-name (file name
)
325 "Assign to FILE's latest version a given NAME."
326 (vc-sccs-add-triple name file
(vc-workfile-version file
)))
333 (defun vc-sccs-check-headers ()
334 "Check if the current file has any headers in it."
336 (goto-char (point-min))
337 (re-search-forward "%[A-Z]%" nil t
)))
339 (defun vc-sccs-rename-file (old new
)
340 ;; Move the master file (using vc-rcs-master-templates).
341 (vc-rename-master (vc-name old
) new vc-sccs-master-templates
)
342 ;; Update the snapshot file.
345 (expand-file-name vc-sccs-name-assoc-file
346 (file-name-directory (vc-name old
))))
347 (goto-char (point-min))
348 ;; (replace-regexp (concat ":" (regexp-quote old) "$") (concat ":" new))
349 (while (re-search-forward (concat ":" (regexp-quote old
) "$") nil t
)
350 (replace-match (concat ":" new
) nil nil
))
352 (kill-buffer (current-buffer))))
356 ;;; Internal functions
359 ;; This function is wrapped with `progn' so that the autoload cookie
360 ;; copies the whole function itself into loaddefs.el rather than just placing
361 ;; a (autoload 'vc-sccs-search-project-dir "vc-sccs") which would not
362 ;; help us avoid loading vc-sccs.
364 (progn (defun vc-sccs-search-project-dir (dirname basename
)
365 "Return the name of a master file in the SCCS project directory.
366 Does not check whether the file exists but returns nil if it does not
367 find any project directory."
368 (let ((project-dir (getenv "PROJECTDIR")) dirs dir
)
370 (if (file-name-absolute-p project-dir
)
371 (setq dirs
'("SCCS" ""))
372 (setq dirs
'("src/SCCS" "src" "source/SCCS" "source"))
373 (setq project-dir
(expand-file-name (concat "~" project-dir
))))
374 (while (and (not dir
) dirs
)
375 (setq dir
(expand-file-name (car dirs
) project-dir
))
376 (unless (file-directory-p dir
)
378 (setq dirs
(cdr dirs
))))
379 (and dir
(expand-file-name (concat "s." basename
) dir
))))))
381 (defun vc-sccs-lock-file (file)
382 "Generate lock file name corresponding to FILE."
383 (let ((master (vc-name file
)))
386 (string-match "\\(.*/\\)\\(s\\.\\)\\(.*\\)" master
)
387 (replace-match "p." t t master
2))))
389 (defun vc-sccs-parse-locks ()
390 "Parse SCCS locks in current buffer.
391 The result is a list of the form ((VERSION . USER) (VERSION . USER) ...)."
393 (goto-char (point-min))
394 (while (re-search-forward "^\\([0-9.]+\\) [0-9.]+ \\([^ ]+\\) .*\n?"
397 (cons (cons (match-string 1) (match-string 2)) master-locks
)))
398 ;; FIXME: is it really necessary to reverse ?
399 (nreverse master-locks
)))
401 (defun vc-sccs-add-triple (name file rev
)
404 (expand-file-name vc-sccs-name-assoc-file
405 (file-name-directory (vc-name file
))))
406 (goto-char (point-max))
407 (insert name
"\t:\t" file
"\t" rev
"\n")
409 (kill-buffer (current-buffer))))
411 (defun vc-sccs-lookup-triple (file name
)
412 "Return the numeric version corresponding to a named snapshot of FILE.
413 If NAME is nil or a version number string it's just passed through."
415 (let ((firstchar (aref name
0)))
416 (and (>= firstchar ?
0) (<= firstchar ?
9))))
420 (expand-file-name vc-sccs-name-assoc-file
421 (file-name-directory (vc-name file
))))
422 (vc-parse-buffer (concat name
"\t:\t" file
"\t\\(.+\\)") 1))))
426 ;; arch-tag: d751dee3-d7b3-47e1-95e3-7ae98c052041
427 ;;; vc-sccs.el ends here