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 | |
b4aa6026 | 15 | ;; the Free Software Foundation; either version 3, or (at your option) |
7a004b71 GM |
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 | ||
0792fdb4 SM |
30 | ;; TODO: |
31 | ;; - remove call to vc-expand-dirs by implementing our own (which can just | |
32 | ;; list the SCCS subdir instead). | |
33 | ||
7a004b71 GM |
34 | ;;; Code: |
35 | ||
f1180544 | 36 | (eval-when-compile |
a1e9f194 AS |
37 | (require 'vc)) |
38 | ||
f1180544 | 39 | ;;; |
8f98485f AS |
40 | ;;; Customization options |
41 | ;;; | |
42 | ||
7a004b71 | 43 | (defcustom vc-sccs-register-switches nil |
a7cafade DL |
44 | "*Extra switches for registering a file in SCCS. |
45 | A string or list of strings passed to the checkin program by | |
7a004b71 GM |
46 | \\[vc-sccs-register]." |
47 | :type '(choice (const :tag "None" nil) | |
48 | (string :tag "Argument String") | |
49 | (repeat :tag "Argument List" | |
50 | :value ("") | |
51 | string)) | |
a7cafade | 52 | :version "21.1" |
7a004b71 GM |
53 | :group 'vc) |
54 | ||
a1e9f194 AS |
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" | |
61 | :value ("") | |
62 | string)) | |
63 | :version "21.1" | |
64 | :group 'vc) | |
65 | ||
7a004b71 GM |
66 | (defcustom vc-sccs-header (or (cdr (assoc 'SCCS vc-header-alist)) '("%W%")) |
67 | "*Header keywords to be inserted by `vc-insert-headers'." | |
8b7c8991 | 68 | :type '(repeat string) |
7a004b71 GM |
69 | :group 'vc) |
70 | ||
71 | ;;;###autoload | |
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" | |
79 | (choice string | |
80 | function))) | |
a7cafade | 81 | :version "21.1" |
7a004b71 GM |
82 | :group 'vc) |
83 | ||
8f98485f AS |
84 | \f |
85 | ;;; | |
86 | ;;; Internal variables | |
87 | ;;; | |
88 | ||
099bd78a SM |
89 | (defconst vc-sccs-name-assoc-file "VC-names") |
90 | ||
8f98485f | 91 | \f |
8cdd17b4 ER |
92 | ;;; Properties of the backend |
93 | ||
94 | (defun vc-sccs-revision-granularity () | |
95 | 'file) | |
96 | ||
8f98485f AS |
97 | ;;; |
98 | ;;; State-querying functions | |
99 | ;;; | |
100 | ||
9ef33737 AS |
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. | |
105 | ||
106 | ;;;###autoload (defun vc-sccs-registered(f) (vc-default-registered 'SCCS f)) | |
af65391b | 107 | (defun vc-sccs-registered (f) (vc-default-registered 'SCCS f)) |
7a004b71 GM |
108 | |
109 | (defun vc-sccs-state (file) | |
110 | "SCCS-specific function to compute the version control state." | |
111 | (with-temp-buffer | |
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) | |
118 | 'up-to-date | |
119 | 'unlocked-changes) | |
bda6736f | 120 | (if (string= locking-user (vc-user-login-name file)) |
7a004b71 GM |
121 | 'edited |
122 | locking-user))) | |
123 | 'up-to-date))) | |
124 | ||
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. | |
bbd88348 AS |
134 | (let* ((attributes (file-attributes file 'string)) |
135 | (owner-name (nth 2 attributes)) | |
7a004b71 GM |
136 | (permissions (nth 8 attributes))) |
137 | (if (string-match ".r-..-..-." permissions) | |
138 | 'up-to-date | |
139 | (if (string-match ".rw..-..-." permissions) | |
140 | (if (file-ownership-preserved-p file) | |
141 | 'edited | |
bbd88348 | 142 | owner-name) |
8bfde4be AS |
143 | ;; Strange permissions. |
144 | ;; Fall through to real state computation. | |
145 | (vc-sccs-state file)))) | |
146 | (vc-sccs-state file))) | |
7a004b71 GM |
147 | |
148 | (defun vc-sccs-workfile-version (file) | |
149 | "SCCS-specific version of `vc-workfile-version'." | |
150 | (with-temp-buffer | |
8bfde4be AS |
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]") | |
7a004b71 GM |
156 | (vc-parse-buffer "^\001d D \\([^ ]+\\)" 1))) |
157 | ||
a7cafade | 158 | (defun vc-sccs-checkout-model (file) |
7a004b71 GM |
159 | "SCCS-specific version of `vc-checkout-model'." |
160 | 'locking) | |
161 | ||
162 | (defun vc-sccs-workfile-unchanged-p (file) | |
fa63cb6d | 163 | "SCCS-specific implementation of `vc-workfile-unchanged-p'." |
a1e9f194 AS |
164 | (zerop (apply 'vc-do-command nil 1 "vcdiff" (vc-name file) |
165 | (list "--brief" "-q" | |
166 | (concat "-r" (vc-workfile-version file)))))) | |
7a004b71 | 167 | |
7a004b71 | 168 | \f |
8f98485f AS |
169 | ;;; |
170 | ;;; State-changing functions | |
171 | ;;; | |
7a004b71 | 172 | |
8cdd17b4 ER |
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")) | |
177 | ||
178 | (defun vc-sccs-register (files &optional rev comment) | |
179 | "Register FILES into the SCCS version-control system. | |
7a004b71 | 180 | REV is the optional revision number for the file. COMMENT can be used |
8cdd17b4 | 181 | to provide an initial description of FILES. |
7a004b71 GM |
182 | |
183 | `vc-register-switches' and `vc-sccs-register-switches' are passed to | |
184 | the SCCS command (in that order). | |
185 | ||
8cdd17b4 | 186 | Automatically retrieve a read-only version of the files with keywords |
7a004b71 | 187 | expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile." |
8cdd17b4 | 188 | (dolist (file files) |
dc0f87c9 | 189 | (let* ((dirname (or (file-name-directory file) "")) |
7a004b71 GM |
190 | (basename (file-name-nondirectory file)) |
191 | (project-file (vc-sccs-search-project-dir dirname basename))) | |
192 | (let ((vc-name | |
193 | (or project-file | |
dc0f87c9 | 194 | (format (car vc-sccs-master-templates) dirname basename)))) |
0cccd8ff | 195 | (apply 'vc-do-command nil 0 "admin" vc-name |
8cdd17b4 | 196 | (and rev (not (string= rev "")) (concat "-r" rev)) |
7a004b71 | 197 | "-fb" |
0cccd8ff | 198 | (concat "-i" (file-relative-name file)) |
7a004b71 | 199 | (and comment (concat "-y" comment)) |
dc0f87c9 | 200 | (vc-switches 'SCCS 'register))) |
7a004b71 GM |
201 | (delete-file file) |
202 | (if vc-keep-workfiles | |
8cdd17b4 | 203 | (vc-do-command nil 0 "get" (vc-name file)))))) |
7a004b71 | 204 | |
8f98485f AS |
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))))) | |
211 | ||
8cdd17b4 | 212 | (defun vc-sccs-checkin (files rev comment) |
8f98485f | 213 | "SCCS-specific version of `vc-backend-checkin'." |
8cdd17b4 ER |
214 | (dolist (file files) |
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))))) | |
8f98485f | 221 | |
52876673 SM |
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 | |
226 | "-p" | |
227 | (and rev | |
228 | (concat "-r" | |
229 | (vc-sccs-lookup-triple file rev))) | |
dc0f87c9 | 230 | (vc-switches 'SCCS 'checkout))) |
52876673 SM |
231 | |
232 | (defun vc-sccs-checkout (file &optional editable rev) | |
233 | "Retrieve a copy of a saved version of SCCS controlled FILE. | |
1862f9ef | 234 | EDITABLE non-nil means that the file should be writable and |
52876673 SM |
235 | locked. REV is the revision to check out." |
236 | (let ((file-buffer (get-file-buffer file)) | |
7a004b71 | 237 | switches) |
52876673 | 238 | (message "Checking out %s..." file) |
7a004b71 GM |
239 | (save-excursion |
240 | ;; Change buffers to get local value of vc-checkout-switches. | |
241 | (if file-buffer (set-buffer file-buffer)) | |
dc0f87c9 | 242 | (setq switches (vc-switches 'SCCS 'checkout)) |
7a004b71 GM |
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)) | |
247 | (save-excursion | |
248 | ;; Adjust the default-directory so that the check-out creates | |
249 | ;; the file in the right place. | |
52876673 | 250 | (setq default-directory (file-name-directory file)) |
7a004b71 | 251 | |
f1180544 | 252 | (and rev (or (string= rev "") |
bbd59337 AS |
253 | (not (stringp rev))) |
254 | (setq rev nil)) | |
52876673 SM |
255 | (apply 'vc-do-command nil 0 "get" (vc-name file) |
256 | (if editable "-e") | |
257 | (and rev (concat "-r" (vc-sccs-lookup-triple file rev))) | |
258 | switches)))) | |
259 | (message "Checking out %s...done" file))) | |
7a004b71 | 260 | |
8cdd17b4 ER |
261 | (defun vc-sccs-cancel-version (files) |
262 | "Roll back, undoing the most recent checkins of FILES." | |
263 | (if (not files) | |
264 | (error "SCCS backend doesn't support directory-level rollback.")) | |
265 | (dolist (file files) | |
266 | (let ((discard (vc-workfile-version file))) | |
267 | (if (null (yes-or-no-p (format "Remove version %s from %s history? " | |
268 | discard file))) | |
269 | (error "Aborted")) | |
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)))) | |
273 | ||
99739bbf | 274 | (defun vc-sccs-revert (file &optional contents-done) |
8f98485f AS |
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)) | |
282 | ||
8f98485f AS |
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)))) | |
287 | ||
288 | \f | |
289 | ;;; | |
290 | ;;; History functions | |
291 | ;;; | |
292 | ||
8cdd17b4 ER |
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))) | |
296 | ||
297 | (defun vc-sccs-wash-log () | |
298 | "Remove all non-comment information from log output." | |
299 | ;; FIXME: not implemented for SCCS | |
300 | nil) | |
8f98485f AS |
301 | |
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) | |
305 | (goto-char 512) | |
306 | (error "Log must be less than 512 characters; point is now at pos 512"))) | |
307 | ||
8cdd17b4 ER |
308 | (defun vc-sccs-diff (files &optional oldvers newvers buffer) |
309 | "Get a difference report using SCCS between two filesets." | |
8f98485f AS |
310 | (setq oldvers (vc-sccs-lookup-triple file oldvers)) |
311 | (setq newvers (vc-sccs-lookup-triple file newvers)) | |
8cdd17b4 ER |
312 | (apply 'vc-do-command (or buffer "*vc-diff*") |
313 | 1 "vcdiff" (mapcar 'vc-name (vc-expand-dirs files)) | |
a1e9f194 AS |
314 | (append (list "-q" |
315 | (and oldvers (concat "-r" oldvers)) | |
316 | (and newvers (concat "-r" newvers))) | |
dc0f87c9 | 317 | (vc-switches 'SCCS 'diff)))) |
8f98485f AS |
318 | |
319 | \f | |
320 | ;;; | |
321 | ;;; Snapshot system | |
322 | ;;; | |
323 | ||
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))) | |
327 | ||
328 | \f | |
329 | ;;; | |
330 | ;;; Miscellaneous | |
331 | ;;; | |
332 | ||
333 | (defun vc-sccs-check-headers () | |
334 | "Check if the current file has any headers in it." | |
335 | (save-excursion | |
336 | (goto-char (point-min)) | |
337 | (re-search-forward "%[A-Z]%" nil t))) | |
338 | ||
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. | |
343 | (with-current-buffer | |
344 | (find-file-noselect | |
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)) | |
351 | (basic-save-buffer) | |
352 | (kill-buffer (current-buffer)))) | |
353 | ||
354 | \f | |
355 | ;;; | |
356 | ;;; Internal functions | |
357 | ;;; | |
358 | ||
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. | |
363 | ;;;###autoload | |
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) | |
369 | (when project-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) | |
377 | (setq dir nil) | |
378 | (setq dirs (cdr dirs)))) | |
379 | (and dir (expand-file-name (concat "s." basename) dir)))))) | |
380 | ||
381 | (defun vc-sccs-lock-file (file) | |
382 | "Generate lock file name corresponding to FILE." | |
383 | (let ((master (vc-name file))) | |
384 | (and | |
385 | master | |
386 | (string-match "\\(.*/\\)\\(s\\.\\)\\(.*\\)" master) | |
387 | (replace-match "p." t t master 2)))) | |
388 | ||
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) ...)." | |
392 | (let (master-locks) | |
393 | (goto-char (point-min)) | |
394 | (while (re-search-forward "^\\([0-9.]+\\) [0-9.]+ \\([^ ]+\\) .*\n?" | |
395 | nil t) | |
396 | (setq master-locks | |
397 | (cons (cons (match-string 1) (match-string 2)) master-locks))) | |
398 | ;; FIXME: is it really necessary to reverse ? | |
399 | (nreverse master-locks))) | |
400 | ||
401 | (defun vc-sccs-add-triple (name file rev) | |
402 | (with-current-buffer | |
403 | (find-file-noselect | |
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") | |
408 | (basic-save-buffer) | |
409 | (kill-buffer (current-buffer)))) | |
410 | ||
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." | |
414 | (if (or (null name) | |
415 | (let ((firstchar (aref name 0))) | |
416 | (and (>= firstchar ?0) (<= firstchar ?9)))) | |
417 | name | |
418 | (with-temp-buffer | |
419 | (vc-insert-file | |
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)))) | |
7a004b71 GM |
423 | |
424 | (provide 'vc-sccs) | |
425 | ||
fa63cb6d | 426 | ;; arch-tag: d751dee3-d7b3-47e1-95e3-7ae98c052041 |
7a004b71 | 427 | ;;; vc-sccs.el ends here |