]> code.delx.au - gnu-emacs/blobdiff - lisp/vc/vc-sccs.el
API simplification: remove vc-workfile-unchanged-p from pubic methods.
[gnu-emacs] / lisp / vc / vc-sccs.el
index 26e7b020b463ee1991260e8e5c57196b3f47a6e7..8c9595a7461eb56200f45afcd3203117435c925a 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-2014 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."
+  :version "24.1"
+  :group 'vc)
 
 (defcustom vc-sccs-register-switches nil
   "Switches for registering a file in SCCS.
@@ -57,7 +56,7 @@ If t, use no switches."
                 (string :tag "Argument String")
                 (repeat :tag "Argument List" :value ("") string))
   :version "21.1"
-  :group 'vc)
+  :group 'vc-sccs)
 
 (defcustom vc-sccs-diff-switches nil
   "String or list of strings specifying switches for SCCS diff under VC.
@@ -67,14 +66,17 @@ If nil, use the value of `vc-diff-switches'.  If t, use no switches."
                 (string :tag "Argument String")
                 (repeat :tag "Argument List" :value ("") string))
   :version "21.1"
-  :group 'vc)
+  :group 'vc-sccs)
 
 (defcustom vc-sccs-header '("%W%")
   "Header keywords to be inserted by `vc-insert-headers'."
   :type '(repeat string)
   :version "24.1"     ; no longer consult the obsolete vc-header-alist
-  :group 'vc)
+  :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))
@@ -86,7 +88,7 @@ For a description of possible values, see `vc-check-master-templates'."
                         (choice string
                                 function)))
   :version "21.1"
-  :group 'vc)
+  :group 'vc-sccs)
 
 \f
 ;;;
@@ -99,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
@@ -107,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."
@@ -123,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))
@@ -154,6 +155,8 @@ For a description of possible values, see `vc-check-master-templates'."
             (vc-sccs-state file))))
     (vc-sccs-state file)))
 
+(autoload 'vc-expand-dirs "vc")
+
 (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.
@@ -171,6 +174,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
@@ -178,14 +183,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
 ;;;
@@ -202,10 +220,11 @@ 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.
+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.
 
@@ -215,18 +234,17 @@ expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
     (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."
@@ -235,19 +253,18 @@ 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))
+    (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
@@ -255,7 +272,7 @@ 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
@@ -281,8 +298,8 @@ 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))))
@@ -300,16 +317,16 @@ are expanded to all version-controlled subfiles."
                (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))))
+                                (vc-master-name file) (concat "-r" discard))
+           (vc-sccs-do-command nil 0 "get" (vc-master-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))
+    (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.
@@ -320,14 +337,14 @@ revert all subfiles."
   (if (file-directory-p file)
       (mapc 'vc-sccs-steal-lock (vc-expand-dirs (list file)))
     (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)
+    (vc-sccs-do-command nil 0 "cdc" (vc-master-name file)
                         (concat "-y" comment) (concat "-r" rev))))
 
 \f
@@ -335,23 +352,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."
+(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))
-  (vc-sccs-do-command buffer 0 "prs" (mapcar 'vc-name files))
+  (vc-sccs-do-command buffer 0 "prs" (mapcar 'vc-master-name files))
   (when limit 'limit-unsupported))
 
+(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)
   "Get a difference report using SCCS between two filesets."
   (setq files (vc-expand-dirs files))
   (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
 ;;;
@@ -359,9 +440,12 @@ revert all subfiles."
 ;;; our own set of name-to-revision mappings.
 ;;;
 
-(defun vc-sccs-create-tag (backend dir name branchp)
+(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 %s does not support module branches" backend))
+    (error "SCCS backend does not support module branches"))
   (let ((result (vc-tag-precondition dir)))
     (if (stringp result)
        (error "File %s is not up-to-date" result)
@@ -387,14 +471,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)
@@ -419,7 +505,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."
@@ -438,7 +524,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)
@@ -460,7 +546,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)
@@ -476,7 +562,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)