don't require grep in vc-git
[bpt/emacs.git] / lisp / vc / vc-sccs.el
index 0ee75e1..fb7d959 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."
@@ -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.
@@ -181,11 +184,24 @@ For a description of possible values, see `vc-check-master-templates'."
     (vc-insert-file (vc-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-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))))))
+  (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,6 +218,8 @@ 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"))
 
+(autoload 'vc-switches "vc")
+
 (defun vc-sccs-register (files &optional rev comment)
   "Register FILES into the SCCS version-control system.
 REV is the optional revision number for the file.  COMMENT can be used
@@ -303,7 +321,7 @@ are expanded to all version-controlled subfiles."
                                 (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)
@@ -335,23 +353,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))
   (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 +441,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,6 +472,8 @@ revert all subfiles."
     (goto-char (point-min))
     (re-search-forward  "%[A-Z]%" nil t)))
 
+(autoload 'vc-rename-master "vc")
+
 (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)
@@ -419,7 +506,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."