]> code.delx.au - gnu-emacs/blobdiff - lisp/vc/vc-sccs.el
Update copyright year to 2015
[gnu-emacs] / lisp / vc / vc-sccs.el
index 0df307eda85f6a9d5e056e47593ce02fce812898..1b959e22e2325aaf85ed08ac7f2a4c382dc5ec03 100644 (file)
@@ -1,6 +1,6 @@
-;;; vc-sccs.el --- support for SCCS version-control
+;;; vc-sccs.el --- support for SCCS version-control  -*- lexical-binding:t -*-
 
-;; Copyright (C) 1992-201 Free Software Foundation, Inc.
+;; Copyright (C) 1992-2015 Free Software Foundation, Inc.
 
 ;; Author:     FSF (see vc.el for full credits)
 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
 
 ;;; Commentary:
 
-;; Proper function of the SCCS diff commands requires the shellscript vcdiff
-;; to be installed somewhere on Emacs's path for executables.
-;;
-
 ;;; Code:
 
 (eval-when-compile
 ;;;
 
 ;; ;; Maybe a better solution is to not use "get" but "sccs get".
-;; (defcustom vc-sccs-path
-;;   (let ((path ()))
-;;     (dolist (dir '("/usr/sccs" "/usr/lib/sccs" "/usr/libexec/sccs"))
-;;       (if (file-directory-p dir)
-;;           (push dir path)))
-;;     path)
-;;   "List of extra directories to search for SCCS commands."
-;;   :type '(repeat directory)
-;;   :group 'vc)
+;; ;; Note for GNU CSSC, you can parse sccs -V to get the libexec path.
+;;  (defcustom vc-sccs-path
+;;    (prune-directory-list '("/usr/ccs/bin" "/usr/sccs" "/usr/lib/sccs"
+;;                        "/usr/libexec/sccs"))
+;;    "List of extra directories to search for SCCS commands."
+;;    :type '(repeat directory)
+;;    :group 'vc)
 
 (defgroup vc-sccs nil
   "VC SCCS backend."
@@ -80,6 +74,9 @@ If nil, use the value of `vc-diff-switches'.  If t, use no switches."
   :version "24.1"     ; no longer consult the obsolete vc-header-alist
   :group 'vc-sccs)
 
+;; This needs to be autoloaded because vc-sccs-registered uses it (via
+;; vc-default-registered), and vc-hooks needs to be able to check
+;; for a registered backend without loading every backend.
 ;;;###autoload
 (defcustom vc-sccs-master-templates
   (purecopy '("%sSCCS/s.%s" "%ss.%s" vc-sccs-search-project-dir))
@@ -104,7 +101,7 @@ For a description of possible values, see `vc-check-master-templates'."
 ;;; Properties of the backend
 
 (defun vc-sccs-revision-granularity () 'file)
-(defun vc-sccs-checkout-model (files) 'locking)
+(defun vc-sccs-checkout-model (_files) 'locking)
 
 ;;;
 ;;; State-querying functions
@@ -112,11 +109,10 @@ For a description of possible values, see `vc-check-master-templates'."
 
 ;; The autoload cookie below places vc-sccs-registered directly into
 ;; loaddefs.el, so that vc-sccs.el does not need to be loaded for
-;; every file that is visited.  The definition is repeated below
-;; so that Help and etags can find it.
-
-;;;###autoload (defun vc-sccs-registered(f) (vc-default-registered 'SCCS f))
-(defun vc-sccs-registered (f) (vc-default-registered 'SCCS f))
+;; every file that is visited.
+;;;###autoload
+(progn
+(defun vc-sccs-registered (f) (vc-default-registered 'SCCS f)))
 
 (defun vc-sccs-state (file)
   "SCCS-specific function to compute the version control state."
@@ -128,7 +124,7 @@ For a description of possible values, see `vc-check-master-templates'."
                 (working-revision (vc-working-revision file))
                 (locking-user (cdr (assoc working-revision locks))))
            (if (not locking-user)
-               (if (vc-workfile-unchanged-p file)
+               (if (vc-sccs-workfile-unchanged-p file)
                    'up-to-date
                  'unlocked-changes)
              (if (string= locking-user (vc-user-login-name file))
@@ -136,39 +132,12 @@ For a description of possible values, see `vc-check-master-templates'."
                locking-user)))
        'up-to-date))))
 
-(defun vc-sccs-state-heuristic (file)
-  "SCCS-specific state heuristic."
-  (if (not (vc-mistrust-permissions file))
-      ;;   This implementation assumes that any file which is under version
-      ;; control and has -rw-r--r-- is locked by its owner.  This is true
-      ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--.
-      ;; We have to be careful not to exclude files with execute bits on;
-      ;; scripts can be under version control too.  Also, we must ignore the
-      ;; group-read and other-read bits, since paranoid users turn them off.
-      (let* ((attributes  (file-attributes file 'string))
-             (owner-name  (nth 2 attributes))
-             (permissions (nth 8 attributes)))
-       (if (string-match ".r-..-..-." permissions)
-            'up-to-date
-          (if (string-match ".rw..-..-." permissions)
-              (if (file-ownership-preserved-p file)
-                  'edited
-                owner-name)
-            ;; Strange permissions.
-            ;; Fall through to real state computation.
-            (vc-sccs-state file))))
-    (vc-sccs-state file)))
-
-(defun vc-sccs-dir-status (dir update-function)
-  ;; FIXME: this function should be rewritten, using `vc-expand-dirs'
-  ;; is not TRTD because it returns files from multiple backends.
-  ;; It should also return 'unregistered files.
-
-  ;; Doing lots of individual VC-state calls is painful, but
-  ;; there is no better option in SCCS-land.
-  (let ((flist (vc-expand-dirs (list dir)))
-       (result nil))
-    (dolist (file flist)
+(autoload 'vc-expand-dirs "vc")
+
+(defun vc-sccs-dir-status-files (dir files update-function)
+  (if (not files) (setq files (vc-expand-dirs (list dir) 'RCS)))
+  (let ((result nil))
+    (dolist (file files)
       (let ((state (vc-state file))
            (frel (file-relative-name file)))
        (when (and (eq (vc-backend file) 'SCCS)
@@ -176,6 +145,8 @@ For a description of possible values, see `vc-check-master-templates'."
          (push (list frel state) result))))
     (funcall update-function result)))
 
+(autoload 'vc-master-name "vc-filewise")
+
 (defun vc-sccs-working-revision (file)
   "SCCS-specific version of `vc-working-revision'."
   (with-temp-buffer
@@ -183,14 +154,27 @@ For a description of possible values, see `vc-check-master-templates'."
     ;; To find this number, search the entire delta table,
     ;; rather than just the first entry, because the
     ;; first entry might be a deleted ("R") revision.
-    (vc-insert-file (vc-name file) "^\001e\n\001[^s]")
+    (vc-insert-file (vc-master-name file) "^\001e\n\001[^s]")
     (vc-parse-buffer "^\001d D \\([^ ]+\\)" 1)))
 
+;; Cf vc-sccs-find-revision.
+(defun vc-sccs-write-revision (file outfile &optional rev)
+  "Write the SCCS version of input file FILE to output file OUTFILE.
+Optional string REV is a revision."
+  (with-temp-buffer
+    (apply 'vc-sccs-do-command t 0 "get" (vc-master-name file)
+          (append '("-s" "-p" "-k") ; -k: no keyword expansion
+                  (if rev (list (concat "-r" rev)))))
+    (write-region nil nil outfile nil 'silent)))
+
 (defun vc-sccs-workfile-unchanged-p (file)
-  "SCCS-specific implementation of `vc-workfile-unchanged-p'."
-  (zerop (apply 'vc-do-command "*vc*" 1 "vcdiff" (vc-name file)
-                (list "--brief" "-q"
-                      (concat "-r" (vc-working-revision file))))))
+  "Has FILE remained unchanged since last checkout?"
+  (let ((tempfile (make-temp-file "vc-sccs")))
+    (unwind-protect
+       (progn
+         (vc-sccs-write-revision file tempfile (vc-working-revision file))
+         (zerop (vc-do-command "*vc*" 1 "cmp" file tempfile)))
+      (delete-file tempfile))))
 
 \f
 ;;;
@@ -207,31 +191,28 @@ For a description of possible values, see `vc-check-master-templates'."
   ;; SCCS is totally file-oriented, so all we have to do is make the directory
   (make-directory "SCCS"))
 
-(defun vc-sccs-register (files &optional rev comment)
+(autoload 'vc-switches "vc")
+
+(defun vc-sccs-register (files &optional comment)
   "Register FILES into the SCCS version-control system.
-REV is the optional revision number for the file.  COMMENT can be used
-to provide an initial description of FILES.
+Automatically retrieve a read-only version of the files with keywords expanded.
+COMMENT can be used to provide an initial description of FILES.
 Passes either `vc-sccs-register-switches' or `vc-register-switches'
-to the SCCS command.
-
-Automatically retrieve a read-only version of the files with keywords
-expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
+to the SCCS command."
   (dolist (file files)
     (let* ((dirname (or (file-name-directory file) ""))
           (basename (file-name-nondirectory file))
           (project-file (vc-sccs-search-project-dir dirname basename)))
-      (let ((vc-name
+      (let ((vc-master-name
             (or project-file
                 (format (car vc-sccs-master-templates) dirname basename))))
-       (apply 'vc-sccs-do-command nil 0 "admin" vc-name
-              (and rev (not (string= rev "")) (concat "-r" rev))
+       (apply 'vc-sccs-do-command nil 0 "admin" vc-master-name
               "-fb"
               (concat "-i" (file-relative-name file))
               (and comment (concat "-y" comment))
               (vc-switches 'SCCS 'register)))
       (delete-file file)
-      (if vc-keep-workfiles
-         (vc-sccs-do-command nil 0 "get" (vc-name file))))))
+      (vc-sccs-do-command nil 0 "get" (vc-master-name file)))))
 
 (defun vc-sccs-responsible-p (file)
   "Return non-nil if SCCS thinks it would be responsible for registering FILE."
@@ -240,19 +221,17 @@ expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
       (stringp (vc-sccs-search-project-dir (or (file-name-directory file) "")
                                           (file-name-nondirectory file)))))
 
-(defun vc-sccs-checkin (files rev comment)
+(defun vc-sccs-checkin (files comment)
   "SCCS-specific version of `vc-backend-checkin'."
-  (dolist (file (vc-expand-dirs files))
-    (apply 'vc-sccs-do-command nil 0 "delta" (vc-name file)
-          (if rev (concat "-r" rev))
+  (dolist (file (vc-expand-dirs files 'SCCS))
+    (apply 'vc-sccs-do-command nil 0 "delta" (vc-master-name file)
           (concat "-y" comment)
           (vc-switches 'SCCS 'checkin))
-    (if vc-keep-workfiles
-       (vc-sccs-do-command nil 0 "get" (vc-name file)))))
+       (vc-sccs-do-command nil 0 "get" (vc-master-name file))))
 
 (defun vc-sccs-find-revision (file rev buffer)
   (apply 'vc-sccs-do-command
-        buffer 0 "get" (vc-name file)
+        buffer 0 "get" (vc-master-name file)
         "-s" ;; suppress diagnostic output
         "-p"
         (and rev
@@ -260,13 +239,13 @@ expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
                      (vc-sccs-lookup-triple file rev)))
         (vc-switches 'SCCS 'checkout)))
 
-(defun vc-sccs-checkout (file &optional editable rev)
+(defun vc-sccs-checkout (file &optional rev)
   "Retrieve a copy of a saved revision of SCCS controlled FILE.
 If FILE is a directory, all version-controlled files beneath are checked out.
 EDITABLE non-nil means that the file should be writable and
 locked.  REV is the revision to check out."
   (if (file-directory-p file)
-      (mapc 'vc-sccs-checkout (vc-expand-dirs (list file)))
+      (mapc 'vc-sccs-checkout (vc-expand-dirs (list file) 'SCCS))
     (let ((file-buffer (get-file-buffer file))
          switches)
       (message "Checking out %s..." file)
@@ -286,35 +265,19 @@ locked.  REV is the revision to check out."
            (and rev (or (string= rev "")
                         (not (stringp rev)))
                 (setq rev nil))
-           (apply 'vc-sccs-do-command nil 0 "get" (vc-name file)
-                  (if editable "-e")
+           (apply 'vc-sccs-do-command nil 0 "get" (vc-master-name file)
+                  "-e"
                   (and rev (concat "-r" (vc-sccs-lookup-triple file rev)))
                   switches))))
       (message "Checking out %s...done" file))))
 
-(defun vc-sccs-rollback (files)
-  "Roll back, undoing the most recent checkins of FILES.  Directories
-are expanded to all version-controlled subfiles."
-  (setq files (vc-expand-dirs files))
-  (if (not files)
-      (error "SCCS backend doesn't support directory-level rollback"))
-  (dolist (file files)
-         (let ((discard (vc-working-revision file)))
-           (if (null (yes-or-no-p (format "Remove version %s from %s history? "
-                                          discard file)))
-               (error "Aborted"))
-           (message "Removing revision %s from %s..." discard file)
-           (vc-sccs-do-command nil 0 "rmdel"
-                                (vc-name file) (concat "-r" discard))
-           (vc-sccs-do-command nil 0 "get" (vc-name file) nil))))
-
-(defun vc-sccs-revert (file &optional contents-done)
+(defun vc-sccs-revert (file &optional _contents-done)
   "Revert FILE to the version it was based on. If FILE is a directory,
 revert all subfiles."
   (if (file-directory-p file)
-      (mapc 'vc-sccs-revert (vc-expand-dirs (list file)))
-    (vc-sccs-do-command nil 0 "unget" (vc-name file))
-    (vc-sccs-do-command nil 0 "get" (vc-name file))
+      (mapc 'vc-sccs-revert (vc-expand-dirs (list file) 'SCCS))
+    (vc-sccs-do-command nil 0 "unget" (vc-master-name file))
+    (vc-sccs-do-command nil 0 "get" (vc-master-name file))
     ;; Checking out explicit revisions is not supported under SCCS, yet.
     ;; We always "revert" to the latest revision; therefore
     ;; vc-working-revision is cleared here so that it gets recomputed.
@@ -323,16 +286,16 @@ revert all subfiles."
 (defun vc-sccs-steal-lock (file &optional rev)
   "Steal the lock on the current workfile for FILE and revision REV."
   (if (file-directory-p file)
-      (mapc 'vc-sccs-steal-lock (vc-expand-dirs (list file)))
+      (mapc 'vc-sccs-steal-lock (vc-expand-dirs (list file) 'SCCS))
     (vc-sccs-do-command nil 0 "unget"
-                       (vc-name file) "-n" (if rev (concat "-r" rev)))
+                       (vc-master-name file) "-n" (if rev (concat "-r" rev)))
     (vc-sccs-do-command nil 0 "get"
-                       (vc-name file) "-g" (if rev (concat "-r" rev)))))
+                       (vc-master-name file) "-g" (if rev (concat "-r" rev)))))
 
 (defun vc-sccs-modify-change-comment (files rev comment)
   "Modify (actually, append to) the change comments for FILES on a specified REV."
-  (dolist (file (vc-expand-dirs files))
-    (vc-sccs-do-command nil 0 "cdc" (vc-name file)
+  (dolist (file (vc-expand-dirs files 'SCCS))
+    (vc-sccs-do-command nil 0 "cdc" (vc-master-name file)
                         (concat "-y" comment) (concat "-r" rev))))
 
 \f
@@ -340,23 +303,87 @@ revert all subfiles."
 ;;; History functions
 ;;;
 
-(defun vc-sccs-print-log (files buffer &optional shortlog start-revision-ignored limit)
-  "Get change log associated with FILES."
-  (setq files (vc-expand-dirs files))
-  (vc-sccs-do-command buffer 0 "prs" (mapcar 'vc-name files))
+(defun vc-sccs-print-log (files buffer &optional _shortlog _start-revision-ignored limit)
+  "Print commit log associated with FILES into specified BUFFER.
+Remaining arguments are ignored."
+  (setq files (vc-expand-dirs files 'SCCS))
+  (vc-sccs-do-command buffer 0 "prs" (mapcar 'vc-master-name files))
   (when limit 'limit-unsupported))
 
-(defun vc-sccs-diff (files &optional oldvers newvers buffer)
+(autoload 'vc-setup-buffer "vc-dispatcher")
+(autoload 'vc-delistify "vc-dispatcher")
+
+(defvar w32-quote-process-args)
+
+;; FIXME use sccsdiff if present?
+(defun vc-sccs-diff (files &optional oldvers newvers buffer _async)
   "Get a difference report using SCCS between two filesets."
-  (setq files (vc-expand-dirs files))
+  (setq files (vc-expand-dirs files 'SCCS))
   (setq oldvers (vc-sccs-lookup-triple (car files) oldvers))
   (setq newvers (vc-sccs-lookup-triple (car files) newvers))
-  (apply 'vc-do-command (or buffer "*vc-diff*")
-        1 "vcdiff" (mapcar 'vc-name (vc-expand-dirs files))
-         (append (list "-q"
-                       (and oldvers (concat "-r" oldvers))
-                       (and newvers (concat "-r" newvers)))
-                 (vc-switches 'SCCS 'diff))))
+  (or buffer (setq buffer "*vc-diff*"))
+  ;; We have to reimplement pieces of vc-do-command, because
+  ;; we want to run multiple external commands, and only do the setup
+  ;; and exit pieces once.
+  (save-current-buffer
+    (unless (or (eq buffer t)
+               (and (stringp buffer) (string= (buffer-name) buffer))
+               (eq buffer (current-buffer)))
+      (vc-setup-buffer buffer))
+    (let* ((fake-flags (append (vc-switches 'SCCS 'diff)
+                              (if oldvers (list (concat " -r" oldvers)))
+                              (if newvers (list (concat " -r" newvers)))))
+          (fake-command
+           (format "diff%s %s"
+                   (if fake-flags
+                       (concat " " (mapconcat 'identity fake-flags " "))
+                     "")
+                   (vc-delistify files)))
+          (status 0)
+          (oldproc (get-buffer-process (current-buffer))))
+    (when vc-command-messages
+      (message "Running %s in foreground..." fake-command))
+    (if oldproc (delete-process oldproc))
+    (dolist (file files)
+      (let ((oldfile (make-temp-file "vc-sccs"))
+           newfile)
+       (unwind-protect
+           (progn
+             (vc-sccs-write-revision file oldfile oldvers)
+             (if newvers
+                 (vc-sccs-write-revision file (setq newfile
+                                                    (make-temp-file "vc-sccs"))
+                                         newvers))
+             (let* ((inhibit-read-only t)
+                    (buffer-undo-list t)
+                    (process-environment
+                     (cons "LC_MESSAGES=C" process-environment))
+                    (w32-quote-process-args t)
+                    (this-status
+                     (apply 'process-file "diff" nil t nil
+                            (append (vc-switches 'SCCS 'diff)
+                                    (list oldfile
+                                          (or newfile
+                                              (file-relative-name file)))))))
+               (or (integerp this-status) (setq status 'error))
+               (and (integerp status)
+                    (> this-status status)
+                    (setq status this-status))))
+         (delete-file oldfile)
+         (if newfile (delete-file newfile)))))
+    (when (or (not (integerp status)) (> status 1))
+      (unless (eq ?\s (aref (buffer-name (current-buffer)) 0))
+       (pop-to-buffer (current-buffer))
+       (goto-char (point-min))
+       (shrink-window-if-larger-than-buffer))
+      (error "Running %s...FAILED (%s)" fake-command
+            (if (integerp status) (format "status %d" status) status)))
+    (when vc-command-messages
+      (message "Running %s...OK = %d" fake-command status))
+    ;; Should we pretend we ran sccsdiff instead?
+    ;; This might not actually be a valid diff command.
+    (run-hook-with-args 'vc-post-command-functions "diff" files fake-flags)
+    status)))
 
 \f
 ;;;
@@ -364,6 +391,9 @@ revert all subfiles."
 ;;; our own set of name-to-revision mappings.
 ;;;
 
+(autoload 'vc-tag-precondition "vc")
+(declare-function vc-file-tree-walk "vc" (dirname func &rest args))
+
 (defun vc-sccs-create-tag (dir name branchp)
   (when branchp
     (error "SCCS backend does not support module branches"))
@@ -392,14 +422,16 @@ revert all subfiles."
     (goto-char (point-min))
     (re-search-forward  "%[A-Z]%" nil t)))
 
+(autoload 'vc-rename-master "vc-filewise")
+
 (defun vc-sccs-rename-file (old new)
   ;; Move the master file (using vc-rcs-master-templates).
-  (vc-rename-master (vc-name old) new vc-sccs-master-templates)
+  (vc-rename-master (vc-master-name old) new vc-sccs-master-templates)
   ;; Update the tag file.
   (with-current-buffer
       (find-file-noselect
        (expand-file-name vc-sccs-name-assoc-file
-                        (file-name-directory (vc-name old))))
+                        (file-name-directory (vc-master-name old))))
     (goto-char (point-min))
     ;; (replace-regexp (concat ":" (regexp-quote old) "$") (concat ":" new))
     (while (re-search-forward (concat ":" (regexp-quote old) "$") nil t)
@@ -424,7 +456,7 @@ revert all subfiles."
 ;; a (autoload 'vc-sccs-search-project-dir "vc-sccs") which would not
 ;; help us avoid loading vc-sccs.
 ;;;###autoload
-(progn (defun vc-sccs-search-project-dir (dirname basename)
+(progn (defun vc-sccs-search-project-dir (_dirname basename)
   "Return the name of a master file in the SCCS project directory.
 Does not check whether the file exists but returns nil if it does not
 find any project directory."
@@ -443,7 +475,7 @@ find any project directory."
 
 (defun vc-sccs-lock-file (file)
   "Generate lock file name corresponding to FILE."
-  (let ((master (vc-name file)))
+  (let ((master (vc-master-name file)))
     (and
      master
      (string-match "\\(.*/\\)\\(s\\.\\)\\(.*\\)" master)
@@ -465,7 +497,7 @@ The result is a list of the form ((REVISION . USER) (REVISION . USER) ...)."
   (with-current-buffer
       (find-file-noselect
        (expand-file-name vc-sccs-name-assoc-file
-                        (file-name-directory (vc-name file))))
+                        (file-name-directory (vc-master-name file))))
     (goto-char (point-max))
     (insert name "\t:\t" file "\t" rev "\n")
     (basic-save-buffer)
@@ -481,7 +513,7 @@ If NAME is nil or a revision number string it's just passed through."
     (with-temp-buffer
       (vc-insert-file
        (expand-file-name vc-sccs-name-assoc-file
-                        (file-name-directory (vc-name file))))
+                        (file-name-directory (vc-master-name file))))
       (vc-parse-buffer (concat name "\t:\t" file "\t\\(.+\\)") 1))))
 
 (provide 'vc-sccs)