Commit | Line | Data |
---|---|---|
7a004b71 GM |
1 | ;;; vc-sccs.el --- support for SCCS version-control |
2 | ||
0d30b337 | 3 | ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
d7a0267c | 4 | ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
7a004b71 GM |
5 | |
6 | ;; Author: FSF (see vc.el for full credits) | |
7 | ;; Maintainer: Andre Spiegel <spiegel@gnu.org> | |
8 | ||
fa63cb6d | 9 | ;; $Id$ |
7a004b71 GM |
10 | |
11 | ;; This file is part of GNU Emacs. | |
12 | ||
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 2, or (at your option) | |
16 | ;; any later version. | |
17 | ||
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. | |
22 | ||
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 | |
086add15 LK |
25 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 | ;; Boston, MA 02110-1301, USA. | |
7a004b71 GM |
27 | |
28 | ;;; Commentary: | |
29 | ||
30 | ;;; Code: | |
31 | ||
f1180544 | 32 | (eval-when-compile |
a1e9f194 AS |
33 | (require 'vc)) |
34 | ||
f1180544 | 35 | ;;; |
8f98485f AS |
36 | ;;; Customization options |
37 | ;;; | |
38 | ||
7a004b71 | 39 | (defcustom vc-sccs-register-switches nil |
a7cafade DL |
40 | "*Extra switches for registering a file in SCCS. |
41 | A string or list of strings passed to the checkin program by | |
7a004b71 GM |
42 | \\[vc-sccs-register]." |
43 | :type '(choice (const :tag "None" nil) | |
44 | (string :tag "Argument String") | |
45 | (repeat :tag "Argument List" | |
46 | :value ("") | |
47 | string)) | |
a7cafade | 48 | :version "21.1" |
7a004b71 GM |
49 | :group 'vc) |
50 | ||
a1e9f194 AS |
51 | (defcustom vc-sccs-diff-switches nil |
52 | "*A string or list of strings specifying extra switches for `vcdiff', | |
53 | the diff utility used for SCCS under VC." | |
54 | :type '(choice (const :tag "None" nil) | |
55 | (string :tag "Argument String") | |
56 | (repeat :tag "Argument List" | |
57 | :value ("") | |
58 | string)) | |
59 | :version "21.1" | |
60 | :group 'vc) | |
61 | ||
7a004b71 GM |
62 | (defcustom vc-sccs-header (or (cdr (assoc 'SCCS vc-header-alist)) '("%W%")) |
63 | "*Header keywords to be inserted by `vc-insert-headers'." | |
8b7c8991 | 64 | :type '(repeat string) |
7a004b71 GM |
65 | :group 'vc) |
66 | ||
67 | ;;;###autoload | |
68 | (defcustom vc-sccs-master-templates | |
69 | '("%sSCCS/s.%s" "%ss.%s" vc-sccs-search-project-dir) | |
70 | "*Where to look for SCCS master files. | |
71 | For a description of possible values, see `vc-check-master-templates'." | |
72 | :type '(choice (const :tag "Use standard SCCS file names" | |
73 | ("%sSCCS/s.%s" "%ss.%s" vc-sccs-search-project-dir)) | |
74 | (repeat :tag "User-specified" | |
75 | (choice string | |
76 | function))) | |
a7cafade | 77 | :version "21.1" |
7a004b71 GM |
78 | :group 'vc) |
79 | ||
8f98485f AS |
80 | \f |
81 | ;;; | |
82 | ;;; Internal variables | |
83 | ;;; | |
84 | ||
099bd78a SM |
85 | (defconst vc-sccs-name-assoc-file "VC-names") |
86 | ||
8f98485f | 87 | \f |
8cdd17b4 ER |
88 | ;;; Properties of the backend |
89 | ||
90 | (defun vc-sccs-revision-granularity () | |
91 | 'file) | |
92 | ||
8f98485f AS |
93 | ;;; |
94 | ;;; State-querying functions | |
95 | ;;; | |
96 | ||
9ef33737 AS |
97 | ;;; The autoload cookie below places vc-sccs-registered directly into |
98 | ;;; loaddefs.el, so that vc-sccs.el does not need to be loaded for | |
99 | ;;; every file that is visited. The definition is repeated below | |
100 | ;;; so that Help and etags can find it. | |
101 | ||
102 | ;;;###autoload (defun vc-sccs-registered(f) (vc-default-registered 'SCCS f)) | |
af65391b | 103 | (defun vc-sccs-registered (f) (vc-default-registered 'SCCS f)) |
7a004b71 GM |
104 | |
105 | (defun vc-sccs-state (file) | |
106 | "SCCS-specific function to compute the version control state." | |
107 | (with-temp-buffer | |
108 | (if (vc-insert-file (vc-sccs-lock-file file)) | |
109 | (let* ((locks (vc-sccs-parse-locks)) | |
110 | (workfile-version (vc-workfile-version file)) | |
111 | (locking-user (cdr (assoc workfile-version locks)))) | |
112 | (if (not locking-user) | |
113 | (if (vc-workfile-unchanged-p file) | |
114 | 'up-to-date | |
115 | 'unlocked-changes) | |
bda6736f | 116 | (if (string= locking-user (vc-user-login-name file)) |
7a004b71 GM |
117 | 'edited |
118 | locking-user))) | |
119 | 'up-to-date))) | |
120 | ||
121 | (defun vc-sccs-state-heuristic (file) | |
122 | "SCCS-specific state heuristic." | |
123 | (if (not (vc-mistrust-permissions file)) | |
124 | ;; This implementation assumes that any file which is under version | |
125 | ;; control and has -rw-r--r-- is locked by its owner. This is true | |
126 | ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--. | |
127 | ;; We have to be careful not to exclude files with execute bits on; | |
128 | ;; scripts can be under version control too. Also, we must ignore the | |
129 | ;; group-read and other-read bits, since paranoid users turn them off. | |
bbd88348 AS |
130 | (let* ((attributes (file-attributes file 'string)) |
131 | (owner-name (nth 2 attributes)) | |
7a004b71 GM |
132 | (permissions (nth 8 attributes))) |
133 | (if (string-match ".r-..-..-." permissions) | |
134 | 'up-to-date | |
135 | (if (string-match ".rw..-..-." permissions) | |
136 | (if (file-ownership-preserved-p file) | |
137 | 'edited | |
bbd88348 | 138 | owner-name) |
8bfde4be AS |
139 | ;; Strange permissions. |
140 | ;; Fall through to real state computation. | |
141 | (vc-sccs-state file)))) | |
142 | (vc-sccs-state file))) | |
7a004b71 GM |
143 | |
144 | (defun vc-sccs-workfile-version (file) | |
145 | "SCCS-specific version of `vc-workfile-version'." | |
146 | (with-temp-buffer | |
8bfde4be AS |
147 | ;; The workfile version is always the latest version number. |
148 | ;; To find this number, search the entire delta table, | |
149 | ;; rather than just the first entry, because the | |
150 | ;; first entry might be a deleted ("R") version. | |
151 | (vc-insert-file (vc-name file) "^\001e\n\001[^s]") | |
7a004b71 GM |
152 | (vc-parse-buffer "^\001d D \\([^ ]+\\)" 1))) |
153 | ||
a7cafade | 154 | (defun vc-sccs-checkout-model (file) |
7a004b71 GM |
155 | "SCCS-specific version of `vc-checkout-model'." |
156 | 'locking) | |
157 | ||
158 | (defun vc-sccs-workfile-unchanged-p (file) | |
fa63cb6d | 159 | "SCCS-specific implementation of `vc-workfile-unchanged-p'." |
a1e9f194 AS |
160 | (zerop (apply 'vc-do-command nil 1 "vcdiff" (vc-name file) |
161 | (list "--brief" "-q" | |
162 | (concat "-r" (vc-workfile-version file)))))) | |
7a004b71 | 163 | |
7a004b71 | 164 | \f |
8f98485f AS |
165 | ;;; |
166 | ;;; State-changing functions | |
167 | ;;; | |
7a004b71 | 168 | |
8cdd17b4 ER |
169 | (defun vc-sccs-create-repo () |
170 | "Create a new SCCS repository." | |
171 | ;; SCCS is totally file-oriented, so all we have to do is make the directory | |
172 | (make-directory "SCCS")) | |
173 | ||
174 | (defun vc-sccs-register (files &optional rev comment) | |
175 | "Register FILES into the SCCS version-control system. | |
7a004b71 | 176 | REV is the optional revision number for the file. COMMENT can be used |
8cdd17b4 | 177 | to provide an initial description of FILES. |
7a004b71 GM |
178 | |
179 | `vc-register-switches' and `vc-sccs-register-switches' are passed to | |
180 | the SCCS command (in that order). | |
181 | ||
8cdd17b4 | 182 | Automatically retrieve a read-only version of the files with keywords |
7a004b71 | 183 | expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile." |
8cdd17b4 | 184 | (dolist (file files) |
dc0f87c9 | 185 | (let* ((dirname (or (file-name-directory file) "")) |
7a004b71 GM |
186 | (basename (file-name-nondirectory file)) |
187 | (project-file (vc-sccs-search-project-dir dirname basename))) | |
188 | (let ((vc-name | |
189 | (or project-file | |
dc0f87c9 | 190 | (format (car vc-sccs-master-templates) dirname basename)))) |
0cccd8ff | 191 | (apply 'vc-do-command nil 0 "admin" vc-name |
8cdd17b4 | 192 | (and rev (not (string= rev "")) (concat "-r" rev)) |
7a004b71 | 193 | "-fb" |
0cccd8ff | 194 | (concat "-i" (file-relative-name file)) |
7a004b71 | 195 | (and comment (concat "-y" comment)) |
dc0f87c9 | 196 | (vc-switches 'SCCS 'register))) |
7a004b71 GM |
197 | (delete-file file) |
198 | (if vc-keep-workfiles | |
8cdd17b4 | 199 | (vc-do-command nil 0 "get" (vc-name file)))))) |
7a004b71 | 200 | |
8f98485f AS |
201 | (defun vc-sccs-responsible-p (file) |
202 | "Return non-nil if SCCS thinks it would be responsible for registering FILE." | |
203 | ;; TODO: check for all the patterns in vc-sccs-master-templates | |
204 | (or (file-directory-p (expand-file-name "SCCS" (file-name-directory file))) | |
205 | (stringp (vc-sccs-search-project-dir (or (file-name-directory file) "") | |
206 | (file-name-nondirectory file))))) | |
207 | ||
8cdd17b4 | 208 | (defun vc-sccs-checkin (files rev comment) |
8f98485f | 209 | "SCCS-specific version of `vc-backend-checkin'." |
8cdd17b4 ER |
210 | (dolist (file files) |
211 | (apply 'vc-do-command nil 0 "delta" (vc-name file) | |
212 | (if rev (concat "-r" rev)) | |
213 | (concat "-y" comment) | |
214 | (vc-switches 'SCCS 'checkin)) | |
215 | (if vc-keep-workfiles | |
216 | (vc-do-command nil 0 "get" (vc-name file))))) | |
8f98485f | 217 | |
52876673 SM |
218 | (defun vc-sccs-find-version (file rev buffer) |
219 | (apply 'vc-do-command | |
220 | buffer 0 "get" (vc-name file) | |
221 | "-s" ;; suppress diagnostic output | |
222 | "-p" | |
223 | (and rev | |
224 | (concat "-r" | |
225 | (vc-sccs-lookup-triple file rev))) | |
dc0f87c9 | 226 | (vc-switches 'SCCS 'checkout))) |
52876673 SM |
227 | |
228 | (defun vc-sccs-checkout (file &optional editable rev) | |
229 | "Retrieve a copy of a saved version of SCCS controlled FILE. | |
1862f9ef | 230 | EDITABLE non-nil means that the file should be writable and |
52876673 SM |
231 | locked. REV is the revision to check out." |
232 | (let ((file-buffer (get-file-buffer file)) | |
7a004b71 | 233 | switches) |
52876673 | 234 | (message "Checking out %s..." file) |
7a004b71 GM |
235 | (save-excursion |
236 | ;; Change buffers to get local value of vc-checkout-switches. | |
237 | (if file-buffer (set-buffer file-buffer)) | |
dc0f87c9 | 238 | (setq switches (vc-switches 'SCCS 'checkout)) |
7a004b71 GM |
239 | ;; Save this buffer's default-directory |
240 | ;; and use save-excursion to make sure it is restored | |
241 | ;; in the same buffer it was saved in. | |
242 | (let ((default-directory default-directory)) | |
243 | (save-excursion | |
244 | ;; Adjust the default-directory so that the check-out creates | |
245 | ;; the file in the right place. | |
52876673 | 246 | (setq default-directory (file-name-directory file)) |
7a004b71 | 247 | |
f1180544 | 248 | (and rev (or (string= rev "") |
bbd59337 AS |
249 | (not (stringp rev))) |
250 | (setq rev nil)) | |
52876673 SM |
251 | (apply 'vc-do-command nil 0 "get" (vc-name file) |
252 | (if editable "-e") | |
253 | (and rev (concat "-r" (vc-sccs-lookup-triple file rev))) | |
254 | switches)))) | |
255 | (message "Checking out %s...done" file))) | |
7a004b71 | 256 | |
8cdd17b4 ER |
257 | (defun vc-sccs-cancel-version (files) |
258 | "Roll back, undoing the most recent checkins of FILES." | |
259 | (if (not files) | |
260 | (error "SCCS backend doesn't support directory-level rollback.")) | |
261 | (dolist (file files) | |
262 | (let ((discard (vc-workfile-version file))) | |
263 | (if (null (yes-or-no-p (format "Remove version %s from %s history? " | |
264 | discard file))) | |
265 | (error "Aborted")) | |
266 | (message "Removing revision %s from %s..." discard file) | |
267 | (vc-do-command nil 0 "rmdel" (vc-name file) (concat "-r" discard)) | |
268 | (vc-do-command nil 0 "get" (vc-name file) nil)))) | |
269 | ||
99739bbf | 270 | (defun vc-sccs-revert (file &optional contents-done) |
8f98485f AS |
271 | "Revert FILE to the version it was based on." |
272 | (vc-do-command nil 0 "unget" (vc-name file)) | |
273 | (vc-do-command nil 0 "get" (vc-name file)) | |
274 | ;; Checking out explicit versions is not supported under SCCS, yet. | |
275 | ;; We always "revert" to the latest version; therefore | |
276 | ;; vc-workfile-version is cleared here so that it gets recomputed. | |
277 | (vc-file-setprop file 'vc-workfile-version nil)) | |
278 | ||
8f98485f AS |
279 | (defun vc-sccs-steal-lock (file &optional rev) |
280 | "Steal the lock on the current workfile for FILE and revision REV." | |
281 | (vc-do-command nil 0 "unget" (vc-name file) "-n" (if rev (concat "-r" rev))) | |
282 | (vc-do-command nil 0 "get" (vc-name file) "-g" (if rev (concat "-r" rev)))) | |
283 | ||
284 | \f | |
285 | ;;; | |
286 | ;;; History functions | |
287 | ;;; | |
288 | ||
8cdd17b4 ER |
289 | (defun vc-sccs-print-log (files &optional buffer) |
290 | "Get change log associated with FILES." | |
291 | (vc-do-command buffer 0 "prs" (mapcar 'vc-name files))) | |
292 | ||
293 | (defun vc-sccs-wash-log () | |
294 | "Remove all non-comment information from log output." | |
295 | ;; FIXME: not implemented for SCCS | |
296 | nil) | |
8f98485f AS |
297 | |
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) | |
301 | (goto-char 512) | |
302 | (error "Log must be less than 512 characters; point is now at pos 512"))) | |
303 | ||
8cdd17b4 ER |
304 | (defun vc-sccs-diff (files &optional oldvers newvers buffer) |
305 | "Get a difference report using SCCS between two filesets." | |
8f98485f AS |
306 | (setq oldvers (vc-sccs-lookup-triple file oldvers)) |
307 | (setq newvers (vc-sccs-lookup-triple file newvers)) | |
8cdd17b4 ER |
308 | (apply 'vc-do-command (or buffer "*vc-diff*") |
309 | 1 "vcdiff" (mapcar 'vc-name (vc-expand-dirs files)) | |
a1e9f194 AS |
310 | (append (list "-q" |
311 | (and oldvers (concat "-r" oldvers)) | |
312 | (and newvers (concat "-r" newvers))) | |
dc0f87c9 | 313 | (vc-switches 'SCCS 'diff)))) |
8f98485f AS |
314 | |
315 | \f | |
316 | ;;; | |
317 | ;;; Snapshot system | |
318 | ;;; | |
319 | ||
320 | (defun vc-sccs-assign-name (file name) | |
321 | "Assign to FILE's latest version a given NAME." | |
322 | (vc-sccs-add-triple name file (vc-workfile-version file))) | |
323 | ||
324 | \f | |
325 | ;;; | |
326 | ;;; Miscellaneous | |
327 | ;;; | |
328 | ||
329 | (defun vc-sccs-check-headers () | |
330 | "Check if the current file has any headers in it." | |
331 | (save-excursion | |
332 | (goto-char (point-min)) | |
333 | (re-search-forward "%[A-Z]%" nil t))) | |
334 | ||
335 | (defun vc-sccs-rename-file (old new) | |
336 | ;; Move the master file (using vc-rcs-master-templates). | |
337 | (vc-rename-master (vc-name old) new vc-sccs-master-templates) | |
338 | ;; Update the snapshot file. | |
339 | (with-current-buffer | |
340 | (find-file-noselect | |
341 | (expand-file-name vc-sccs-name-assoc-file | |
342 | (file-name-directory (vc-name old)))) | |
343 | (goto-char (point-min)) | |
344 | ;; (replace-regexp (concat ":" (regexp-quote old) "$") (concat ":" new)) | |
345 | (while (re-search-forward (concat ":" (regexp-quote old) "$") nil t) | |
346 | (replace-match (concat ":" new) nil nil)) | |
347 | (basic-save-buffer) | |
348 | (kill-buffer (current-buffer)))) | |
349 | ||
350 | \f | |
351 | ;;; | |
352 | ;;; Internal functions | |
353 | ;;; | |
354 | ||
355 | ;; This function is wrapped with `progn' so that the autoload cookie | |
356 | ;; copies the whole function itself into loaddefs.el rather than just placing | |
357 | ;; a (autoload 'vc-sccs-search-project-dir "vc-sccs") which would not | |
358 | ;; help us avoid loading vc-sccs. | |
359 | ;;;###autoload | |
360 | (progn (defun vc-sccs-search-project-dir (dirname basename) | |
361 | "Return the name of a master file in the SCCS project directory. | |
362 | Does not check whether the file exists but returns nil if it does not | |
363 | find any project directory." | |
364 | (let ((project-dir (getenv "PROJECTDIR")) dirs dir) | |
365 | (when project-dir | |
366 | (if (file-name-absolute-p project-dir) | |
367 | (setq dirs '("SCCS" "")) | |
368 | (setq dirs '("src/SCCS" "src" "source/SCCS" "source")) | |
369 | (setq project-dir (expand-file-name (concat "~" project-dir)))) | |
370 | (while (and (not dir) dirs) | |
371 | (setq dir (expand-file-name (car dirs) project-dir)) | |
372 | (unless (file-directory-p dir) | |
373 | (setq dir nil) | |
374 | (setq dirs (cdr dirs)))) | |
375 | (and dir (expand-file-name (concat "s." basename) dir)))))) | |
376 | ||
377 | (defun vc-sccs-lock-file (file) | |
378 | "Generate lock file name corresponding to FILE." | |
379 | (let ((master (vc-name file))) | |
380 | (and | |
381 | master | |
382 | (string-match "\\(.*/\\)\\(s\\.\\)\\(.*\\)" master) | |
383 | (replace-match "p." t t master 2)))) | |
384 | ||
385 | (defun vc-sccs-parse-locks () | |
386 | "Parse SCCS locks in current buffer. | |
387 | The result is a list of the form ((VERSION . USER) (VERSION . USER) ...)." | |
388 | (let (master-locks) | |
389 | (goto-char (point-min)) | |
390 | (while (re-search-forward "^\\([0-9.]+\\) [0-9.]+ \\([^ ]+\\) .*\n?" | |
391 | nil t) | |
392 | (setq master-locks | |
393 | (cons (cons (match-string 1) (match-string 2)) master-locks))) | |
394 | ;; FIXME: is it really necessary to reverse ? | |
395 | (nreverse master-locks))) | |
396 | ||
397 | (defun vc-sccs-add-triple (name file rev) | |
398 | (with-current-buffer | |
399 | (find-file-noselect | |
400 | (expand-file-name vc-sccs-name-assoc-file | |
401 | (file-name-directory (vc-name file)))) | |
402 | (goto-char (point-max)) | |
403 | (insert name "\t:\t" file "\t" rev "\n") | |
404 | (basic-save-buffer) | |
405 | (kill-buffer (current-buffer)))) | |
406 | ||
407 | (defun vc-sccs-lookup-triple (file name) | |
408 | "Return the numeric version corresponding to a named snapshot of FILE. | |
409 | If NAME is nil or a version number string it's just passed through." | |
410 | (if (or (null name) | |
411 | (let ((firstchar (aref name 0))) | |
412 | (and (>= firstchar ?0) (<= firstchar ?9)))) | |
413 | name | |
414 | (with-temp-buffer | |
415 | (vc-insert-file | |
416 | (expand-file-name vc-sccs-name-assoc-file | |
417 | (file-name-directory (vc-name file)))) | |
418 | (vc-parse-buffer (concat name "\t:\t" file "\t\\(.+\\)") 1)))) | |
7a004b71 GM |
419 | |
420 | (provide 'vc-sccs) | |
421 | ||
fa63cb6d | 422 | ;; arch-tag: d751dee3-d7b3-47e1-95e3-7ae98c052041 |
7a004b71 | 423 | ;;; vc-sccs.el ends here |