]> code.delx.au - gnu-emacs/blobdiff - lisp/vc-cvs.el
Sync with Tramp 2.1.19.
[gnu-emacs] / lisp / vc-cvs.el
index 23dc61b01de4d3a8a67e18eacbba89b2ed58c454..1abef9f48b8dca7ff8a2e48c2665ee15629ec42c 100644 (file)
@@ -1,13 +1,11 @@
 ;;; vc-cvs.el --- non-resident support for CVS version-control
 
-;; Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003,
-;;   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
+;;   2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 ;; Author:      FSF (see vc.el for full credits)
 ;; Maintainer:  Andre Spiegel <spiegel@gnu.org>
 
-;; $Id$
-
 ;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software: you can redistribute it and/or modify
@@ -62,7 +60,7 @@
 ;;;
 
 (defcustom vc-cvs-global-switches nil
-  "*Global switches to pass to any CVS command."
+  "Global switches to pass to any CVS command."
   :type '(choice (const :tag "None" nil)
                 (string :tag "Argument String")
                 (repeat :tag "Argument List"
   :group 'vc)
 
 (defcustom vc-cvs-register-switches nil
-  "*Extra switches for registering a file into CVS.
+  "Switches for registering a file into CVS.
 A string or list of strings passed to the checkin program by
-\\[vc-register]."
-  :type '(choice (const :tag "None" nil)
+\\[vc-register].  If nil, use the value of `vc-register-switches'.
+If t, use no switches."
+  :type '(choice (const :tag "Unspecified" nil)
+                (const :tag "None" t)
                 (string :tag "Argument String")
-                (repeat :tag "Argument List"
-                        :value ("")
-                        string))
+                (repeat :tag "Argument List" :value ("") string))
   :version "21.1"
   :group 'vc)
 
 (defcustom vc-cvs-diff-switches nil
-  "*A string or list of strings specifying extra switches for cvs diff under VC."
-    :type '(choice (const :tag "None" nil)
-                (string :tag "Argument String")
-                (repeat :tag "Argument List"
-                        :value ("")
-                        string))
+  "String or list of strings specifying switches for CVS diff under VC.
+If nil, use the value of `vc-diff-switches'.  If t, use no switches."
+  :type '(choice (const :tag "Unspecified" nil)
+                 (const :tag "None" t)
+                 (string :tag "Argument String")
+                 (repeat :tag "Argument List" :value ("") string))
   :version "21.1"
   :group 'vc)
 
 (defcustom vc-cvs-header (or (cdr (assoc 'CVS vc-header-alist)) '("\$Id\$"))
-  "*Header keywords to be inserted by `vc-insert-headers'."
+  "Header keywords to be inserted by `vc-insert-headers'."
   :version "21.1"
   :type '(repeat string)
   :group 'vc)
 
 (defcustom vc-cvs-use-edit t
-  "*Non-nil means to use `cvs edit' to \"check out\" a file.
+  "Non-nil means to use `cvs edit' to \"check out\" a file.
 This is only meaningful if you don't use the implicit checkout model
 \(i.e. if you have $CVSREAD set)."
   :type 'boolean
   :version "21.1"
   :group 'vc)
 
-(defcustom vc-cvs-stay-local t
-  "*Non-nil means use local operations when possible for remote repositories.
+(defcustom vc-cvs-stay-local 'only-file
+  "Non-nil means use local operations when possible for remote repositories.
 This avoids slow queries over the network and instead uses heuristics
 and past information to determine the current status of a file.
 
+If value is the symbol `only-file' `vc-dir' will connect to the
+server, but heuristics will be used to determine the status for
+all other VC operations.
+
 The value can also be a regular expression or list of regular
 expressions to match against the host name of a repository; then VC
 only stays local for hosts that match it.  Alternatively, the value
@@ -119,16 +121,20 @@ can be a list of regular expressions where the first element is the
 symbol `except'; then VC always stays local except for hosts matched
 by these regular expressions."
   :type '(choice (const :tag "Always stay local" t)
-                (const :tag "Don't stay local" nil)
-                 (list :format "\nExamine hostname and %v" :tag "Examine hostname ..."
-                       (set :format "%v" :inline t (const :format "%t" :tag "don't" except))
-                       (regexp :format " stay local,\n%t: %v" :tag "if it matches")
+                (const :tag "Only for file operations" only-file)
+                (const :tag "Don't stay local" nil)
+                 (list :format "\nExamine hostname and %v"
+                       :tag "Examine hostname ..."
+                       (set :format "%v" :inline t
+                            (const :format "%t" :tag "don't" except))
+                       (regexp :format " stay local,\n%t: %v"
+                               :tag "if it matches")
                        (repeat :format "%v%i\n" :inline t (regexp :tag "or"))))
-  :version "21.1"
+  :version "23.1"
   :group 'vc)
 
 (defcustom vc-cvs-sticky-date-format-string "%c"
-  "*Format string for mode-line display of sticky date.
+  "Format string for mode-line display of sticky date.
 Format is according to `format-time-string'.  Only used if
 `vc-cvs-sticky-tag-display' is t."
   :type '(string)
@@ -136,7 +142,7 @@ Format is according to `format-time-string'.  Only used if
   :group 'vc)
 
 (defcustom vc-cvs-sticky-tag-display t
-  "*Specify the mode-line display of sticky tags.
+  "Specify the mode-line display of sticky tags.
 Value t means default display, nil means no display at all.  If the
 value is a function or macro, it is called with the sticky tag and
 its' type as parameters, in that order.  TYPE can have three different
@@ -210,7 +216,7 @@ See also variable `vc-cvs-sticky-date-format-string'."
 
 (defun vc-cvs-state (file)
   "CVS-specific version of `vc-state'."
-  (if (vc-stay-local-p file)
+  (if (vc-stay-local-p file 'CVS)
       (let ((state (vc-file-getprop file 'vc-state)))
         ;; If we should stay local, use the heuristic but only if
         ;; we don't have a more precise state already available.
@@ -219,7 +225,8 @@ See also variable `vc-cvs-sticky-date-format-string'."
          state))
     (with-temp-buffer
       (cd (file-name-directory file))
-      (vc-cvs-command t 0 file "status")
+      (let (process-file-side-effects)
+       (vc-cvs-command t 0 file "status"))
       (vc-cvs-parse-status t))))
 
 (defun vc-cvs-state-heuristic (file)
@@ -270,9 +277,8 @@ committed and support display of sticky tags."
 (defun vc-cvs-register (files &optional rev comment)
   "Register FILES into the CVS version-control system.
 COMMENT can be used to provide an initial description of FILES.
-
-`vc-register-switches' and `vc-cvs-register-switches' are passed to
-the CVS command (in that order)."
+Passes either `vc-cvs-register-switches' or `vc-register-switches'
+to the CVS command."
   ;; Register the directories if needed.
   (let (dirs)
     (dolist (file files)
@@ -301,9 +307,10 @@ its parents."
     (while (and (stringp dir)
                 (not (equal dir (setq dir (file-name-directory dir))))
                 dir)
-      (setq dir (if (file-directory-p
+      (setq dir (if (file-exists-p
                      (expand-file-name "CVS/Entries" dir))
-                    t (directory-file-name dir))))
+                    t
+                  (directory-file-name dir))))
     (eq dir t)))
 
 (defun vc-cvs-checkin (files rev comment)
@@ -396,7 +403,7 @@ REV is the revision to check out."
                      "-A"
                    (concat "-r" rev))))
              (vc-switches 'CVS 'checkout)))
-    (vc-mode-line file))
+    (vc-mode-line file 'CVS))
   (message "Checking out %s...done" file))
 
 (defun vc-cvs-delete-file (file)
@@ -451,7 +458,9 @@ The changes are between FIRST-REVISION and SECOND-REVISION."
             0 ;; there were no news; indicate success
           (if (re-search-forward
                (concat "^\\([CMUP] \\)?"
-                       (regexp-quote (file-name-nondirectory file))
+                       (regexp-quote
+                        (substring file (1+ (length (expand-file-name
+                                                     "." default-directory)))))
                        "\\( already contains the differences between \\)?")
                nil t)
               (cond
@@ -485,13 +494,19 @@ Will fail unless you have administrative privileges on the repo."
 ;;; History functions
 ;;;
 
-(defun vc-cvs-print-log (files &optional buffer)
+(declare-function vc-rcs-print-log-cleanup "vc-rcs" ())
+
+(defun vc-cvs-print-log (files buffer &optional shortlog start-revision-ignored limit)
   "Get change logs associated with FILES."
+  (require 'vc-rcs)
   ;; It's just the catenation of the individual logs.
   (vc-cvs-command
    buffer
-   (if (vc-stay-local-p files) 'async 0)
-   files "log"))
+   (if (vc-stay-local-p files 'CVS) 'async 0)
+   files "log")
+  (with-current-buffer buffer
+    (vc-exec-after (vc-rcs-print-log-cleanup)))
+  (when limit 'limit-unsupported))
 
 (defun vc-cvs-comment-history (file)
   "Get comment history of a file."
@@ -499,8 +514,9 @@ Will fail unless you have administrative privileges on the repo."
 
 (defun vc-cvs-diff (files &optional oldvers newvers buffer)
   "Get a difference report using CVS between two revisions of FILE."
-  (let* ((async (and (not vc-disable-async-diff)
-                    (vc-stay-local-p files)))
+  (let* (process-file-side-effects
+        (async (and (not vc-disable-async-diff)
+                    (vc-stay-local-p files 'CVS)))
         (invoke-cvs-diff-list nil)
         status)
     ;; Look through the file list and see if any files have backups
@@ -519,13 +535,12 @@ Will fail unless you have administrative privileges on the repo."
              (coding-system-for-read (vc-coding-system-for-diff file)))
          (if (and file-oldvers file-newvers)
              (progn
+               ;; This used to append diff-switches and vc-diff-switches,
+               ;; which was consistent with the vc-diff-switches doc at that
+               ;; time, but not with the actual behavior of any other VC diff.
                (apply 'vc-do-command (or buffer "*vc-diff*") 1 "diff" nil
-                      (append (if (listp diff-switches)
-                                  diff-switches
-                                (list diff-switches))
-                              (if (listp vc-diff-switches)
-                                  vc-diff-switches
-                                (list vc-diff-switches))
+                      ;; Not a CVS diff, does not use vc-cvs-diff-switches.
+                      (append (vc-switches nil 'diff)
                               (list (file-relative-name file-oldvers)
                                     (file-relative-name file-newvers))))
                (setq status 0))
@@ -554,7 +569,7 @@ Will fail unless you have administrative privileges on the repo."
   "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER.
 Optional arg REVISION is a revision to annotate from."
   (vc-cvs-command buffer
-                  (if (vc-stay-local-p file)
+                  (if (vc-stay-local-p file 'CVS)
                      'async 0)
                   file "annotate"
                   (if revision (concat "-r" revision)))
@@ -624,6 +639,16 @@ systime, or nil if there is none."
        (match-string-no-properties 1)
       nil)))
 
+(defun vc-cvs-previous-revision (file rev)
+  (vc-call-backend 'RCS 'previous-revision file rev))
+
+(defun vc-cvs-next-revision (file rev)
+  (vc-call-backend 'RCS 'next-revision file rev))
+
+;; FIXME: This should probably be replaced by code using cvs2cl.
+(defun vc-cvs-update-changelog (files)
+  (vc-call-backend 'RCS 'update-changelog files))
+
 ;;;
 ;;; Tag system
 ;;;
@@ -676,8 +701,9 @@ If UPDATE is non-nil, then update (resynch) any affected buffers."
 ;;; Miscellaneous
 ;;;
 
-(defalias 'vc-cvs-make-version-backups-p 'vc-stay-local-p
-  "Return non-nil if version backups should be made for FILE.")
+(defun vc-cvs-make-version-backups-p (file)
+  "Return non-nil if version backups should be made for FILE."
+  (vc-stay-local-p file 'CVS))
 
 (defun vc-cvs-check-headers ()
   "Check if the current file has any headers in it."
@@ -701,7 +727,8 @@ and that it passes `vc-cvs-global-switches' to it before FLAGS."
            (append vc-cvs-global-switches
                    flags))))
 
-(defalias 'vc-cvs-stay-local-p 'vc-stay-local-p)  ;Back-compatibility.
+(defun vc-cvs-stay-local-p (file)  ;Back-compatibility.
+  (vc-stay-local-p file 'CVS))
 
 (defun vc-cvs-repository-hostname (dirname)
   "Hostname of the CVS server associated to workarea DIRNAME."
@@ -717,10 +744,16 @@ and that it passes `vc-cvs-global-switches' to it before FLAGS."
                (buffer-substring (point)
                                  (line-end-position))))))))
 
+(defun vc-cvs-parse-uhp (path)
+  "parse user@host/path into (user@host /path)"
+  (if (string-match "\\([^/]+\\)\\(/.*\\)" path)
+      (list (match-string 1 path) (match-string 2 path))
+      (list nil path)))
+
 (defun vc-cvs-parse-root (root)
   "Split CVS ROOT specification string into a list of fields.
 A CVS root specification of the form
-  [:METHOD:][[USER@]HOSTNAME:]/path/to/repository
+  [:METHOD:][[USER@]HOSTNAME]:?/path/to/repository
 is converted to a normalized record with the following structure:
   \(METHOD USER HOSTNAME CVS-ROOT).
 The default METHOD for a CVS root of the form
@@ -742,17 +775,16 @@ For an empty string, nil is returned (invalid CVS root)."
             ;; Invalid CVS root
             nil)
            ((= len 1)
-            ;; Simple PATH => method `local'
-            (cons "local"
-                  (cons nil root-list)))
+            (let ((uhp (vc-cvs-parse-uhp (car root-list))))
+              (cons (if (car uhp) "ext" "local") uhp)))
            ((= len 2)
             ;; [USER@]HOST:PATH => method `ext'
             (and (not (equal (car root-list) ""))
                  (cons "ext" root-list)))
            ((= len 3)
-            ;; :METHOD:PATH
+            ;; :METHOD:PATH or :METHOD:USER@HOSTNAME/PATH
             (cons (cadr root-list)
-                  (cons nil (cddr root-list))))
+                  (vc-cvs-parse-uhp (caddr root-list))))
            (t
             ;; :METHOD:[USER@]HOST:PATH
             (cdr root-list)))))
@@ -832,13 +864,14 @@ state."
        (file nil)
        (result nil)
        (missing nil)
+       (ignore-next nil)
        (subdir default-directory))
     (goto-char (point-min))
     (while
        ;; Look for either a file entry, an unregistered file, or a
        ;; directory change.
        (re-search-forward
-        "\\(^=+\n\\([^=c?\n].*\n\\|\n\\)+\\)\\|\\(\\(^?? .*\n\\)+\\)\\|\\(^cvs status: Examining .*\n\\)"
+        "\\(^=+\n\\([^=c?\n].*\n\\|\n\\)+\\)\\|\\(\\(^?? .*\n\\)+\\)\\|\\(^cvs status: \\(Examining\\|nothing\\) .*\n\\)"
         nil t)
       ;; FIXME: get rid of narrowing here.
       (narrow-to-region (match-beginning 0) (match-end 0))
@@ -852,6 +885,21 @@ state."
                    (expand-file-name (match-string 1) subdir)))
        (push (list file 'unregistered) result)
        (forward-line 1))
+      (when (looking-at "cvs status: nothing known about")
+       ;; We asked about a non existent file.  The output looks like this:
+
+       ;; cvs status: nothing known about `lisp/v.diff'
+       ;; ===================================================================
+       ;; File: no file v.diff            Status: Unknown
+       ;;
+       ;;    Working revision:    No entry for v.diff
+       ;;    Repository revision: No revision control file
+       ;;
+
+       ;; Due to narrowing in this iteration we only see the "cvs
+       ;; status:" line, so just set a flag so that we can ignore the
+       ;; file in the next iteration.
+       (setq ignore-next t))
       ;; A file entry.
       (when (re-search-forward "^File: \\(no file \\)?\\(.*[^ \t]\\)[ \t]+Status: \\(.*\\)" nil t)
        (setq missing (match-string 1))
@@ -870,8 +918,10 @@ state."
               ((string-match "File had conflicts " status-str) 'conflict)
               ((string-match "Unknown" status-str) 'unregistered)
               (t 'edited)))
-       (unless (eq status 'up-to-date)
-         (push (list file status) result)))
+       (if ignore-next
+           (setq ignore-next nil)
+         (unless (eq status 'up-to-date)
+           (push (list file status) result))))
       (goto-char (point-max))
       (widen))
     (funcall update-function result))
@@ -905,14 +955,54 @@ state."
   ;;   (funcall update-function result)))
   )
 
+;; Based on vc-cvs-dir-state-heuristic from Emacs 22.
+;; FIXME does not mention unregistered files.
+(defun vc-cvs-dir-status-heuristic (dir update-function &optional basedir)
+  "Find the CVS state of all files in DIR, using only local information."
+  (let (file basename status result dirlist)
+    (with-temp-buffer
+      (vc-cvs-get-entries dir)
+      (goto-char (point-min))
+      (while (not (eobp))
+        (if (looking-at "D/\\([^/]*\\)////")
+            (push (expand-file-name (match-string 1) dir) dirlist)
+          ;; CVS-removed files are not taken under VC control.
+          (when (looking-at "/\\([^/]*\\)/[^/-]")
+            (setq basename (match-string 1)
+                  file (expand-file-name basename dir)
+                  status (or (vc-file-getprop file 'vc-state)
+                             (vc-cvs-parse-entry file t)))
+            (unless (eq status 'up-to-date)
+              (push (list (if basedir
+                              (file-relative-name file basedir)
+                            basename)
+                          status) result))))
+        (forward-line 1)))
+    (dolist (subdir dirlist)
+      (setq result (append result
+                           (vc-cvs-dir-status-heuristic subdir nil
+                                                        (or basedir dir)))))
+    (if basedir result
+      (funcall update-function result))))
+
 (defun vc-cvs-dir-status (dir update-function)
   "Create a list of conses (file . state) for DIR."
-  (vc-cvs-command (current-buffer) 'async dir "-f" "status")
-  ;; Alternative implementation: use the "update" command instead of
-  ;; the "status" command.
-  ;; (vc-cvs-command (current-buffer) 'async
-  ;;             (file-relative-name dir)
-  ;;             "-f" "-n" "update" "-d" "-P")
+  ;; FIXME check all files in DIR instead?
+  (let ((local (vc-stay-local-p dir 'CVS)))
+    (if (and local (not (eq local 'only-file)))
+       (vc-cvs-dir-status-heuristic dir update-function)
+      (vc-cvs-command (current-buffer) 'async dir "-f" "status")
+      ;; Alternative implementation: use the "update" command instead of
+      ;; the "status" command.
+      ;; (vc-cvs-command (current-buffer) 'async
+      ;;                 (file-relative-name dir)
+      ;;                 "-f" "-n" "update" "-d" "-P")
+      (vc-exec-after
+       `(vc-cvs-after-dir-status (quote ,update-function))))))
+
+(defun vc-cvs-dir-status-files (dir files default-state update-function)
+  "Create a list of conses (file . state) for DIR."
+  (apply 'vc-cvs-command (current-buffer) 'async dir "-f" "status" files)
   (vc-exec-after
    `(vc-cvs-after-dir-status (quote ,update-function))))
 
@@ -925,7 +1015,7 @@ state."
        (buffer-substring (point) (point-max)))
     (file-error nil)))
 
-(defun vc-cvs-status-extra-headers (dir)
+(defun vc-cvs-dir-extra-headers (dir)
   "Extract and represent per-directory properties of a CVS working copy."
   (let ((repo
         (condition-case nil
@@ -933,25 +1023,38 @@ state."
               (insert-file-contents "CVS/Root")
               (goto-char (point-min))
               (and (looking-at ":ext:") (delete-char 5))
-              (buffer-substring (point) (1- (point-max))))
+              (concat (buffer-substring (point) (1- (point-max))) "\n"))
           (file-error nil)))
        (module
         (condition-case nil
             (with-temp-buffer
               (insert-file-contents "CVS/Repository")
               (goto-char (point-min))
-              (re-search-forward "[^/\n]*" nil t)
-              (concat (match-string 0) "\n"))
+              (skip-chars-forward "^\n")
+              (concat (buffer-substring (point-min) (point)) "\n"))
           (file-error nil))))
     (concat
-     (cond (module
-           (concat (propertize "Module     : " 'face 'font-lock-type-face)
-                    (propertize module 'face 'font-lock-variable-name-face)))
-          (t ""))
      (cond (repo
            (concat (propertize "Repository : " 'face 'font-lock-type-face)
                     (propertize repo 'face 'font-lock-variable-name-face)))
           (t ""))
+     (cond (module
+           (concat (propertize "Module     : " 'face 'font-lock-type-face)
+                    (propertize module 'face 'font-lock-variable-name-face)))
+          (t ""))
+     (if (file-readable-p "CVS/Tag")
+        (let ((tag (vc-cvs-file-to-string "CVS/Tag")))
+          (cond
+           ((string-match "\\`T" tag)
+            (concat (propertize "Tag        : " 'face 'font-lock-type-face)
+                    (propertize (substring tag 1)
+                                'face 'font-lock-variable-name-face)))
+           ((string-match "\\`D" tag)
+            (concat (propertize "Date       : " 'face 'font-lock-type-face)
+                    (propertize (substring tag 1)
+                                'face 'font-lock-variable-name-face)))
+           (t ""))))
+
      ;; In CVS, branch is a per-file property, not a per-directory property.
      ;; We can't really do this here without making dangerous assumptions.
      ;;(propertize "Branch:     " 'face 'font-lock-type-face)
@@ -1063,18 +1166,18 @@ is non-nil."
     ;; This is intentionally different from the algorithm that CVS uses
     ;; (which is based on textual comparison), because there can be problems
     ;; generating a time string that looks exactly like the one from CVS.
-    (let ((mtime (nth 5 (file-attributes file))))
-      (require 'parse-time)
-      (let ((parsed-time
-            (parse-time-string (concat (match-string 2) " +0000"))))
-       (cond ((and (not (string-match "\\+" (match-string 2)))
-                   (car parsed-time)
-                   (equal mtime (apply 'encode-time parsed-time)))
-              (vc-file-setprop file 'vc-checkout-time mtime)
-              (if set-state (vc-file-setprop file 'vc-state 'up-to-date)))
-             (t
-              (vc-file-setprop file 'vc-checkout-time 0)
-              (if set-state (vc-file-setprop file 'vc-state 'edited)))))))))
+    (let* ((time (match-string 2))
+           (mtime (nth 5 (file-attributes file)))
+           (parsed-time (progn (require 'parse-time)
+                               (parse-time-string (concat time " +0000")))))
+      (cond ((and (not (string-match "\\+" time))
+                  (car parsed-time)
+                  (equal mtime (apply 'encode-time parsed-time)))
+             (vc-file-setprop file 'vc-checkout-time mtime)
+             (if set-state (vc-file-setprop file 'vc-state 'up-to-date)))
+            (t
+             (vc-file-setprop file 'vc-checkout-time 0)
+             (if set-state (vc-file-setprop file 'vc-state 'edited))))))))
 
 ;; Completion of revision names.
 ;; Just so I don't feel like I'm duplicating code from pcl-cvs, I'll use
@@ -1082,7 +1185,8 @@ is non-nil."
 ;; tag names.
 
 (defun vc-cvs-revision-table (file)
-  (let ((default-directory (file-name-directory file))
+  (let (process-file-side-effects
+       (default-directory (file-name-directory file))
         (res nil))
     (with-temp-buffer
       (vc-cvs-command t nil file "log")