view lisp/pcvs-parse.el @ 47576:b31c8ab7336a

Sync with version 2.0.20. Lengthy ChangeLog follows: 2002-09-22 Kai Gro?ohann <grossjoh@ls6.informatik.uni-dortmund.de> Version 2.0.20 released. 2002-09-20 Kai Gro?ohann <grossjoh@ls6.informatik.uni-dortmund.de> * net/tramp.el (tramp-completion-function-alist): Escape open paren in docstring. (tramp-user-regexp, tramp-host-regexp): Allow empty strings. (tramp-handle-insert-file-contents): Call tramp-message-for-buffer instead of tramp-message. (tramp-open-connection-rsh): Handle empty string as user name. (tramp-open-connection-su): Handle empty string as host name. Handle nil user name. (tramp-handle-file-local-copy, tramp-handle-write-region) (tramp-completion-handle-file-name-all-completions) (tramp-open-connection-telnet, tramp-open-connection-rsh) (tramp-open-connection-su, tramp-post-connection) (tramp-maybe-open-connection, tramp-method-out-of-band-p) (tramp-get-connection-function, tramp-get-remote-sh) (tramp-get-rsh-program, tramp-get-rsh-args) (tramp-get-rcp-program, tramp-get-rcp-args) (tramp-get-rcp-keep-date-arg, tramp-get-su-program) (tramp-get-su-args, tramp-get-telnet-program) (tramp-get-telnet-args): Use `tramp-find-method', perhaps require additional args USER, HOST. (tramp-action-password, tramp-open-connection-telnet) (tramp-open-connection-su, tramp-open-connection-multi) (tramp-method-out-of-band-p): `tramp-method-out-of-band-p' now takes USER and HOST arguments, to be able to use `tramp-find-method'. Update callers. (tramp-find-method): New function. 2002-09-20 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-handle-insert-directory): Handle "--dired" in SWITCHES (by removing it). 2002-09-18 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-file-name-handler): Add `file-remote-p' property. 2002-09-17 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (top-level): Maybe autoload uudecode-decode-region. 2002-09-16 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-bug): Add tramp-methods. 2002-09-16 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-methods): Update docstring: tramp-encoding-command, tramp-decoding-command, tramp-encoding-function and tramp-decoding-function are not parameters anymore. (tramp-uuencode-region): Autoload it. 2002-09-13 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> Version 2.0.19 released. * net/tramp-uu.el: New file, implements uuencode in Lisp. * net/tramp.el (tramp-coding-commands): Use `tramp-uuencode-region' as local encoder for the uuencode based entries. 2002-09-13 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-handle-write-region): Wrong parens. 2002-09-13 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> Version 2.0.18 released. * net/tramp.el (tramp-perl-decode): Perl changes to accomodate older versions of Perl. Now tested with 5.004. Suggestion from Michael Albinus. 2002-09-12 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-find-inline-encoding): Call tramp-call-local-coding-command with nil for INPUT and OUTPUT. (tramp-call-local-coding-command): OUTPUT equals nil means to discard the output. INPUT equals nil means /dev/null. 2002-09-12 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-encoding-shell): Default to environment variable COMSPEC on Windows. (tramp-handle-write-region): More debugging output. (tramp-find-inline-encoding): Ditto. 2002-09-11 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-handle-file-name-all-completions): Define `result1'. (tramp-parse-hosts-group): Discard IPv6 entries. 2002-09-11 Kai Gro?ohann <grossjoh@ls6.informatik.uni-dortmund.de> * net/tramp.el (tramp-post-connection): Only send Perl mime-encode/decode implementations when using inline method. (tramp-handle-file-local-copy) (tramp-handle-write-region, tramp-post-connection) (tramp-coding-commands, tramp-find-inline-encoding): For the inline encodings, distinguish between local and remote commands, instead of between commands and functions. (The local commands can be functions, too.) If the local host is a Windows machine, we can't expect the same commands to work there as on the remote host. (tramp-call-local-coding-command): New function for calling local encoding and decoding commands. (tramp-set-remote-encoding, tramp-get-remote-encoding) (tramp-set-remote-decoding, tramp-get-remote-decoding) (tramp-set-local-encoding, tramp-get-local-encoding) (tramp-set-local-decoding, tramp-get-local-decoding): New functions. (tramp-get-encoding-command, tramp-set-encoding-command) (tramp-get-decoding-command, tramp-set-decoding-command) (tramp-get-encoding-function, tramp-set-encoding-function) (tramp-get-decoding-function, tramp-set-decoding-function): Old functions, removed. 2002-09-10 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-open-connection-setup-interactive-shell): Change command to invoke /bin/sh slightly to make it compatible with the `rc' shell. Suggested by Daniel Pittman. 2002-09-10 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-handle-write-region): Added missing `)'. Hope it's the right place. 2002-09-09 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-open-connection-setup-interactive-shell): Do "exec env PS1='$ ' /bin/sh" instead of just "exec /bin/sh" in order to get a sane shell prompt. If people have ${CWD}, say, in their shell prompt, then the default login shell might display something harmless, but the /bin/sh will display a dollar sign which confused the subsequent prompt recognition. (tramp-multi-action-password): More debugging output. (tramp-encoding-shell): Renamed from tramp-sh-program. More documentation. Default to cmd.exe on Windows NT. (tramp-encoding-command-switch): New variable. Use instead of hard-wired "-c" which is only good for /bin/sh. (tramp-encoding-reads-stdin): New variable. If t, commands are called like "/bin/sh -c COMMAND <INPUT", if nil, they are called like "/bin/sh -c COMMAND INPUT", ie the input file is the last argument. (tramp-multi-sh-program): Always default to tramp-encoding-shell. (tramp-handle-file-local-copy, tramp-handle-write-region): Respect tramp-encoding-shell and friends. (tramp-find-inline-encoding): Use new-style calls for checking if the local commands work. 2002-09-07 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-methods): Remove `tramp-completion-function' entries. They are handled now by `tramp-completion-function-alist'. (tramp-completion-function): Defvar removed. I've never used it. Hmm. (tramp-get-completion-function) (tramp-get-completion-rsh, tramp-get-completion-ssh) (tramp-get-completion-telnet, tramp-get-completion-su): Functions removed as well. Not necessary any longer due to extended customization means. (tramp-completion-function-alist): New defcustom. Holds all FUNCTION FILE pairs used for user and host name completion relevant for METHOD. (tramp-completion-function-alist-rsh) (tramp-completion-function-alist-ssh) (tramp-completion-function-alist-telnet) (tramp-completion-function-alist-su): Defconst for initializing `tramp-completion-function-alist'. Unfortunately, mainly UNIX-like values are known for me until now. Needs to be completed for at least VMS++ like operating systems. (tramp-set-completion-function) (tramp-get-completion-function): New functions for configuration of `tramp-completion-function-alist'. The old definition of `tramp-get-completion-function' has been discarded. (tramp-completion-handle-file-name-all-completions): Change function call for user/host completion according to definition in `tramp-completion-function-alist'. (tramp-parse-passwd): Added exception handling for "root", because `tramp-get-completion-su' (the previous place for this stuff) doesn't exist any longer. 2002-09-07 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-enter-password): Use `tramp-password-end-of-line' to terminate the line. (tramp-bug): Include new variable `tramp-password-end-of-line'. (tramp-password-end-of-line): New variable. People who use plink under Windows might have to issue "\r\n" after the password, but they need to send just "\n" after the other commands. So this variable was introduced to complement `tramp-rsh-end-of-line'. (tramp-wait-for-output, tramp-post-connection): Allow "\r" at end of line of the output delimiter. 2002-09-06 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-handle-file-local-copy, tramp-find-shell) (tramp-open-connection-setup-interactive-shell): Add some comments about Douglas Grey Stephen's suggestions to make Tramp work better with plink under Windows. I'm not sure what to think of them, but now I have a guinea pig to try it out on. Said guinea pig is having other problems, though... Also remove some commented-out code. 2002-09-06 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-get-completion-methods): Algorithm slightly tuned. (tramp-get-completion-user-host): Accept user names as they are if typed until "@". (tramp-completion-mode): Replace `last-input-char' by modern `last-input-event'. Check for `event-modifiers'. 2002-09-06 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (file-expand-wildcards): Corrected check to see if advising is necessary. 2002-09-05 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-postfix-single-method-format) (tramp-postfix-multi-method-format) (tramp-postfix-multi-hop-format) (tramp-postfix-user-format): New format strings. (tramp-postfix-single-method-regexp) (tramp-postfix-multi-method-regexp) (tramp-postfix-multi-hop-regexp) (tramp-postfix-user-regexp) (tramp-make-multi-tramp-file-format) (tramp-make-tramp-file-name): Apply them. (tramp-completion-handle-file-name-all-completions): Fix for invoking ange-ftp in case of "/ftp:xxx" file names. 2002-09-04 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-prefix-format) (tramp-postfix-host-format): New format strings. (tramp-prefix-regexp, tramp-method-regexp) (tramp-postfix-single-method-regexp) (tramp-postfix-multi-method-regexp) (tramp-postfix-multi-hop-regexp) (tramp-user-regexp, tramp-postfix-user-regexp) (tramp-host-regexp, tramp-postfix-host-regexp) (tramp-path-regexp): New atomar regular expressions. If corresponding format strings exist, derived from them. (tramp-file-name-structure) (tramp-multi-file-name-structure) (tramp-multi-file-name-hop-structure) (tramp-make-multi-tramp-file-format) (tramp-completion-mode) (tramp-completion-dissect-file-name) (tramp-parse-rhosts-group) (tramp-parse-shosts-group) (tramp-parse-hosts-group) (tramp-parse-passwd-group): Apply these expressions. (tramp-file-name-structure-unified) (tramp-file-name-structure-separate) (tramp-make-tramp-file-format-unified) (tramp-make-tramp-file-format-separate) (tramp-make-tramp-file-format) (tramp-make-tramp-file-user-nil-format-unified) (tramp-make-tramp-file-user-nil-format-separate) (tramp-make-tramp-file-user-nil-format) (tramp-multi-file-name-structure-unified) (tramp-multi-file-name-structure-separate) (tramp-multi-file-name-hop-structure-unified) (tramp-multi-file-name-hop-structure-separate) (tramp-make-multi-tramp-file-format-unified) (tramp-make-multi-tramp-file-format-separate): Removed. (tramp-make-tramp-file-name): Allow partial tramp file names. Generate tramp file format on-the-fly depending on parameters. Apply atomar format strings resp expressions. (tramp-get-completion-methods) (tramp-get-completion-user-host): Apply `tramp-make-tramp-file-name'. (tramp-parse-hosts-group): Take all host names and IP addresses into account. (tramp-bug): Remove `tramp-make-tramp-file-format'. 2002-09-01 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-methods): Add `tramp-completion-function' for "su" and "sudo". (tramp-get-completion-telnet): Implement it. (tramp-parse-hosts) (tramp-parse-hosts-group) (tramp-get-completion-su) (tramp-parse-passwd) (tramp-parse-passwd-group): New functions. 2002-08-31 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-mode): Check for `last-input-char'. (tramp-completion-file-name-handler-alist): Add handler for `file-exists-p. (tramp-completion-handle-file-exists-p): New function. (tramp-completion-handle-file-name-completion): Simplified. (tramp-completion-dissect-file-name): Regexp's reorganised. (tramp-completion-handle-file-name-all-completions): Call completion-function only if `user' or `host' is given. (tramp-get-completion-user-host): New function. (tramp-get-completion-rsh) (tramp-get-completion-ssh): Apply it. 2002-08-29 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-file-name-handler-alist): Add handler for `expand-file-name'. (tramp-completion-handle-expand-file-name): New function. 2002-08-26 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-mode): New function. (tramp-completion-handle-file-name-directory) (tramp-completion-handle-file-name-all-completions): Apply it. (tramp-methods): Remove double definition of `ssh1-old' and `ssh2-old'. (tramp-point-at-eol): New defalias. (tramp-parse-rhosts-group) (tramp-parse-shosts-group):: Apply it. 2002-08-25 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-get-completion-methods) (tramp-get-completion-rsh) (tramp-get-completion-ssh): Add "[" for Xemacs. (tramp-completion-file-name-regexp-separate): Expression adapted. (tramp-completion-file-name-handler-alist): Add handler for `file-name-directory' and `file-name-nondirectory'. (tramp-completion-handle-file-name-directory) (tramp-completion-handle-file-name-nondirectory) (tramp-completion-run-real-handler): New functions. (tramp-completion-file-name-handler) (tramp-completion-handle-file-name-all-completions): Apply `tramp-completion-run-real-handler'. (tramp-parse-rhosts) (tramp-parse-shosts): Use `with-temp-buffer'. `result? renamed to `res' (otherwise side effects in XEmacs). 2002-08-24 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-file-name-regexp) (tramp-completion-file-name-handler-alist) (tramp-flatten-list) (tramp-completion-dissect-file-name) (tramp-get-completion-rsh) (tramp-parse-rhosts) (tramp-parse-rhosts-group) (tramp-get-completion-ssh): Doc string tuned. (tramp-methods): Doc string and custom type extended for `tramp-completion-function'. (tramp-completion-function): Variable added. Is it really used? Other variables like `tramp-completion-function' aren't used. (tramp-completion-file-name-handler-alist): Add handler for `file-name-completion'. (tramp-completion-handle-file-name-completion): New function. 2002-08-18 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-parse-rhosts) (tramp-parse-rhosts-group) (tramp-parse-shosts) (tramp-parse-shosts-group): New functions. 2002-08-17 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-dissect-file-name) (tramp-completion-dissect-file-name1): New functions. 2002-08-16 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-get-completion-function) (tramp-get-completion-rsh) (tramp-get-completion-ssh) (tramp-get-completion-telnet): New functions. (tramp-methods): Add `tramp-completion-function' for all methods. 2002-08-15 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-get-completion-methods): New function. (tramp-find-default-method): Allow host to be nil (like user). 2002-08-14 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-file-name-regexp-unified) (tramp-completion-file-name-regexp-separate) (tramp-completion-file-name-regexp) (tramp-completion-file-name-handler-alist): New defcustoms. (tramp-completion-file-name-handler): New function. Add `tramp-completion-file-name-handler' to `file-name-handler-alist'. (tramp-run-real-handler): Add `tramp-completion-file-name-handler' to `inhibit-file-name-handlers'. (tramp-completion-handle-file-name-all-completions) (tramp-completion-handle-file-name-completion): New functions. 2002-08-12 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-invoke-ange-ftp): `tramp-disable-ange-ftp' must be called again after activating `ange-ftp'. (tramp-ange-ftp-file-name-p): Check for Xemacs. 2002-08-08 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-do-copy-or-rename-file): Don't pass KEEP-DATE to tramp-invoke-ange-ftp 'rename. (tramp-handle-write-region): Don't pass LOCKNAME and CONFIRM to tramp-invoke-ange-ftp 'write-region. (tramp-handle-set-file-modes): Change order of FILENAME and MODE passing to tramp-invoke-ange-ftp 'set-file-modes. (tramp-flatten-list): New function. Maybe this functionality does exist already elsewhere in the libraries. (tramp-invoke-ange-ftp): Apply `tramp-flatten-list' to parameter list in order to avoid nested lists, f.e. when invoked from `tramp-handle-dired-call-process'. 2002-09-05 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-chunksize): New kluge variable. (tramp-send-region): If tramp-chunksize is non-nil, send region in parts and sleep 0.1 seconds between chunks. 2002-09-03 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-handle-insert-directory): Use `insert-buffer-substring' instead of `insert-buffer', which is not supposed to be used from Lisp. Remember old point in a variable instead of using `mark'. Suggestion from Stefan Monnier. (tramp-unified-filenames): New variable. Use it in default value of other filename variables. (file-expand-wildcards): Don't advise unless "[" and "]" are used in the filename format. 2002-09-01 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-methods): Remove duplicate definition of ssh1-old and ssh2-old.
author Kai Großjohann <kgrossjo@eu.uu.net>
date Sun, 22 Sep 2002 13:23:36 +0000
parents 47f646d9e151
children e88404e8f2cf
line wrap: on
line source

;;; pcvs-parse.el --- the CVS output parser

;; Copyright (C) 1991,92,93,94,95,96,97,98,99,2000,2002
;; 		 Free Software Foundation, Inc.

;; Author: Stefan Monnier <monnier@cs.yale.edu>
;; Keywords: pcl-cvs
;; Revision: $Id: pcvs-parse.el,v 1.12 2002/06/24 22:49:06 monnier Exp $

;; This file is part of GNU Emacs.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;;; Bugs:

;; - when merging a modified file, if the merge says that the file already
;;   contained in the changes, it marks the file as `up-to-date' although
;;   it might still contain further changes.
;;   Example: merging a zero-change commit.

;;; Code:

(eval-when-compile (require 'cl))

(require 'pcvs-util)
(require 'pcvs-info)

;; imported from pcvs.el
(defvar cvs-execute-single-dir)

;; parse vars

(defcustom cvs-update-prog-output-skip-regexp "$"
  "*A regexp that matches the end of the output from all cvs update programs.
That is, output from any programs that are run by CVS (by the flag -u
in the `modules' file - see cvs(5)) when `cvs update' is performed should
terminate with a line that this regexp matches.  It is enough that
some part of the line is matched.

The default (a single $) fits programs without output."
  :group 'pcl-cvs
  :type '(regexp :value "$"))

(defcustom cvs-parse-ignored-messages
  '("Executing ssh-askpass to query the password.*$"
    ".*Remote host denied X11 forwarding.*$")
  "*A list of regexps matching messages that should be ignored by the parser.
Each regexp should match a whole set of lines and should hence be terminated
by `$'."
  :group 'pcl-cvs
  :type '(repeat regexp))

;; a few more defvars just to shut up the compiler
(defvar cvs-start)
(defvar cvs-current-dir)
(defvar cvs-current-subdir)
(defvar dont-change-disc)

;;;; The parser

(defconst cvs-parse-known-commands
  '("status" "add" "commit" "update" "remove" "checkout" "ci")
  "List of CVS commands whose output is understood by the parser.")

(defun cvs-parse-buffer (parse-spec dont-change-disc &optional subdir)
  "Parse current buffer according to PARSE-SPEC.
PARSE-SPEC is a function of no argument advancing the point and returning
  either a fileinfo or t (if the matched text should be ignored) or
  nil if it didn't match anything.
DONT-CHANGE-DISC just indicates whether the command was changing the disc
  or not (useful to tell the difference between `cvs-examine' and `cvs-update'
  output.
The path names should be interpreted as relative to SUBDIR (defaults
  to the `default-directory').
Return a list of collected entries, or t if an error occurred."
  (goto-char (point-min))
  (let ((fileinfos ())
	(cvs-current-dir "")
	(case-fold-search nil)
	(cvs-current-subdir (or subdir "")))
    (while (not (or (eobp) (eq fileinfos t)))
      (let ((ret (cvs-parse-run-table parse-spec)))
	(cond
	 ;; it matched a known information message
	 ((cvs-fileinfo-p ret) (push ret fileinfos))
	 ;; it didn't match anything at all (impossible)
	 ((and (consp ret) (cvs-fileinfo-p (car ret)))
	  (setq fileinfos (append ret fileinfos)))
	 ((null ret) (setq fileinfos t))
	 ;; it matched something that should be ignored
	 (t nil))))
    (nreverse fileinfos)))


;; All those parsing macros/functions should return a success indicator
(defsubst cvs-parse-msg () (buffer-substring cvs-start (1- (point))))

;;(defsubst COLLECT (exp) (push exp *result*))
;;(defsubst PROG (e) t)
;;(defmacro SEQ (&rest seqs) (cons 'and seqs))

(defmacro cvs-match (re &rest matches)
  "Try to match RE and extract submatches.
If RE matches, advance the point until the line after the match and
then assign the variables as specified in MATCHES (via `setq')."
  (cons 'cvs-do-match
	(cons re (mapcar (lambda (match)
			   `(cons ',(first match) ,(second match)))
			 matches))))

(defun cvs-do-match (re &rest matches)
  "Internal function for the `cvs-match' macro.
Match RE and if successful, execute MATCHES."
  ;; Is it a match?
  (when (looking-at re)
    (goto-char (match-end 0))
    ;; Skip the newline (unless we already are at the end of the buffer).
    (when (and (eolp) (< (point) (point-max))) (forward-char))
    ;; assign the matches
    (dolist (match matches t)
      (let ((val (cdr match)))
	(set (car match) (if (integerp val) (match-string val) val))))))

(defmacro cvs-or (&rest alts)
  "Try each one of the ALTS alternatives until one matches."
  `(let ((-cvs-parse-point (point)))
     ,(cons 'or
	    (mapcar (lambda (es)
		      `(or ,es (ignore (goto-char -cvs-parse-point))))
		    alts))))
(def-edebug-spec cvs-or t)

;; This is how parser tables should be executed
(defun cvs-parse-run-table (parse-spec)
  "Run PARSE-SPEC and provide sensible default behavior."
  (unless (bolp) (forward-line 1))	;this should never be needed
  (let ((cvs-start (point)))
    (cvs-or
     (funcall parse-spec)

     (dolist (re cvs-parse-ignored-messages)
       (when (cvs-match re) (return t)))

     ;; This is a parse error.  Create a message-type fileinfo.
     (and
      (cvs-match ".*$")
      (cvs-create-fileinfo 'MESSAGE cvs-current-dir " "
			   ;; (concat " Unknown msg: '"
			   (cvs-parse-msg) ;; "'")
			   :subtype 'ERROR)))))


(defun cvs-parsed-fileinfo (type path &optional directory &rest keys)
  "Create a fileinfo.
TYPE can either be a type symbol or a cons of the form (TYPE . SUBTYPE).
PATH is the filename.
DIRECTORY influences the way PATH is interpreted:
- if it's a string, it denotes the directory in which PATH (which should then be
  a plain file name with no directory component) resides.
- if it's nil, the PATH should not be trusted: if it has a directory
  component, use it, else, assume it is relative to the current directory.
- else, the PATH should be trusted to be relative to the root
  directory (i.e. if there is no directory component, it means the file
  is inside the main directory).
The remaining KEYS are passed directly to `cvs-create-fileinfo'."
  (let ((dir directory)
	(file path))
    ;; only trust the directory if it's a string
    (unless (stringp directory)
      ;; else, if the directory is true, the path should be trusted
      (setq dir (or (file-name-directory path) (if directory "")))
      (setq file (file-name-nondirectory path)))

    (let ((type (if (consp type) (car type) type))
	  (subtype (if (consp type) (cdr type))))
      (when dir (setq cvs-current-dir dir))
      (apply 'cvs-create-fileinfo type
	     (concat cvs-current-subdir (or dir cvs-current-dir))
	     file (cvs-parse-msg) :subtype subtype keys))))

;;;; CVS Process Parser Tables:
;;;;
;;;; The table for status and update could actually be merged since they
;;;; don't conflict.  But they don't overlap much either.

(defun cvs-parse-table ()
  "Table of message objects for `cvs-parse-process'."
  (let (c file dir path type base-rev subtype)
    (cvs-or
     
     (cvs-parse-status)
     (cvs-parse-merge)
     (cvs-parse-commit)

     ;; this is not necessary because the fileinfo merging will remove
     ;; such duplicate info and luckily the second info is the one we want.
     ;; (and (cvs-match "M \\(.*\\)$" (path 1))
     ;;      (cvs-parse-merge path))
     
     ;; Normal file state indicator.
     (and
      (cvs-match "\\([MARCUPNJ?]\\) \\(.*\\)$" (c 1) (path 2))
      ;; M: The file is modified by the user, and untouched in the repository.
      ;; A: The file is "cvs add"ed, but not "cvs ci"ed.
      ;; R: The file is "cvs remove"ed, but not "cvs ci"ed.
      ;; C: Conflict
      ;; U: The file is copied from the repository.
      ;; P: The file was patched from the repository.
      ;; ?: Unknown file.
      (let ((code (aref c 0)))
	(cvs-parsed-fileinfo
	 (case code
	   (?M 'MODIFIED)
	   (?A 'ADDED)
	   (?R 'REMOVED)
	   (?? 'UNKNOWN)
	   (?C
	    (if (not dont-change-disc) 'CONFLICT
	      ;; This is ambiguous.  We should look for conflict markers in the
	      ;; file to decide between CONFLICT and NEED-MERGE.  With CVS-1.10
	      ;; servers, this should not be necessary, because they return
	      ;; a complete merge output.
	      (with-temp-buffer
		(insert-file-contents path)
		(goto-char (point-min))
		(if (re-search-forward "^<<<<<<< " nil t)
		    'CONFLICT 'NEED-MERGE))))
	   (?J 'NEED-MERGE)		;not supported by standard CVS
	   ((?U ?P)
	    (if dont-change-disc 'NEED-UPDATE
	      (cons 'UP-TO-DATE (if (eq code ?U) 'UPDATED 'PATCHED)))))
	 path 'trust)))

     (and
      (cvs-match "pcl-cvs: descending directory \\(.*\\)$" (dir 1))
      (setq cvs-current-subdir dir))

     ;; A special cvs message
     (and
      (let ((case-fold-search t))
	(cvs-match "cvs[.a-z]* [a-z]+: "))
      (cvs-or

       ;; CVS is descending a subdirectory
       ;; (status says `examining' while update says `updating')
       (and
	(cvs-match "\\(Examining\\|Updating\\) \\(.*\\)$" (dir 2))
	(let ((dir (if (string= "." dir) "" (file-name-as-directory dir))))
	  (cvs-parsed-fileinfo 'DIRCHANGE "." dir)))

       ;; [-n update] A new (or pruned) directory appeared but isn't traversed
       (and
	(cvs-match "New directory `\\(.*\\)' -- ignored$" (dir 1))
	;; (cvs-parsed-fileinfo 'MESSAGE " " (file-name-as-directory dir))
	(cvs-parsed-fileinfo '(NEED-UPDATE . NEW-DIR) dir))

       ;; File removed, since it is removed (by third party) in repository.
       (and
	(cvs-or
	 (cvs-match "warning: \\(.*\\) is not (any longer) pertinent$" (file 1))
	 (cvs-match "\\(.*\\) is no longer in the repository$" (file 1)))
	(cvs-parsed-fileinfo 'DEAD file))

       ;; [add]
       (and
	(cvs-or
	 (cvs-match "scheduling file `\\(.*\\)' for addition.*$" (path 1))
	 (cvs-match "re-adding file \\(.*\\) (in place of .*)$" (path 1)))
	(cvs-parsed-fileinfo 'ADDED path))

       ;; [add] this will also show up as a `U <file>'
       (and
	(cvs-match "\\(.*\\), version \\(.*\\), resurrected$"
		   (path 1) (base-rev 2))
	;; FIXME: resurrection only brings back the original version,
	;; not the latest on the branch, so `up-to-date' is not always
	;; what we want.
	(cvs-parsed-fileinfo '(UP-TO-DATE . RESURRECTED) path nil
			     :base-rev base-rev))

       ;; [remove]
       (and
	(cvs-match "removed `\\(.*\\)'$" (path 1))
	(cvs-parsed-fileinfo 'DEAD path))

       ;; [remove,merge]
       (and
	(cvs-match "scheduling `\\(.*\\)' for removal$" (file 1))
	(cvs-parsed-fileinfo 'REMOVED file))

       ;; [update] File removed by you, but not cvs rm'd
       (and
	(cvs-match "warning: \\(.*\\) was lost$" (path 1))
	(cvs-match (concat "U " (regexp-quote path) "$"))
	(cvs-parsed-fileinfo (if dont-change-disc
				 'MISSING
			       '(UP-TO-DATE . UPDATED))
			     path))
     
       ;; Mode conflicts (rather than contents)
       (and
	(cvs-match "conflict: ")
	(cvs-or
	 (cvs-match "removed \\(.*\\) was modified by second party$"
		    (path 1) (subtype 'REMOVED))
	 (cvs-match "\\(.*\\) created independently by second party$"
		    (path 1) (subtype 'ADDED))
	 (cvs-match "\\(.*\\) is modified but no longer in the repository$"
		    (path 1) (subtype 'MODIFIED)))
	(cvs-match (concat "C " (regexp-quote path)))
	(cvs-parsed-fileinfo (cons 'CONFLICT subtype) path))

       ;; Messages that should be shown to the user
       (and
	(cvs-or
	 (cvs-match "move away \\(.*\\); it is in the way$" (file 1))
	 (cvs-match "warning: new-born \\(.*\\) has disappeared$" (file 1))
	 (cvs-match "sticky tag .* for file `\\(.*\\)' is not a branch$"
		    (file 1)))
	(cvs-parsed-fileinfo 'MESSAGE file))
     
       ;; File unknown.
       (and (cvs-match "use `.+ add' to create an entry for \\(.*\\)$" (path 1))
	    (cvs-parsed-fileinfo 'UNKNOWN path))

       ;; [commit]
       (and (cvs-match "Up-to-date check failed for `\\(.+\\)'$" (file 1))
	    (cvs-parsed-fileinfo 'NEED-MERGE file))

       ;; We use cvs-execute-multi-dir but cvs can't handle it
       ;; Probably because the cvs-client can but the cvs-server can't
       (and (cvs-match ".* files with '?/'? in their name.*$")
	    (not cvs-execute-single-dir)
	    (setq cvs-execute-single-dir t)
	    (cvs-create-fileinfo
	     'MESSAGE "" " "
	     "*** Add (setq cvs-execute-single-dir t) to your .emacs ***
	See the FAQ file or the variable's documentation for more info."))
       
       ;; Cvs waits for a lock.  Ignored: already handled by the process filter
       (cvs-match "\\[..:..:..\\] \\(waiting for\\|obtained\\) .*lock in .*$")
       ;; File you removed still exists.  Ignore (will be noted as removed).
       (cvs-match ".* should be removed and is still there$")
       ;; just a note
       (cvs-match "use '.+ commit' to \\sw+ th\\sw+ files? permanently$")
       ;; [add,status] followed by a more complete status description anyway
       (and (cvs-match "nothing known about \\(.*\\)$" (path 1))
	    (cvs-parsed-fileinfo 'DEAD path 'trust))
       ;; [update] problem with patch
       (cvs-match "checksum failure after patch to .*; will refetch$")
       (cvs-match "refetching unpatchable files$")
       ;; [commit]
       (cvs-match "Rebuilding administrative file database$")
       ;; ???
       (cvs-match "--> Using per-directory sticky tag `.*'")
     
       ;; CVS is running a *info program.
       (and
	(cvs-match "Executing.*$")
	;; Skip by any output the program may generate to stdout.
	;; Note that pcl-cvs will get seriously confused if the
	;; program prints anything to stderr.
	(re-search-forward cvs-update-prog-output-skip-regexp))))

     (and
      (cvs-match "cvs[.ex]* \\[[a-z]+ aborted\\]:.*$")
      (cvs-parsed-fileinfo 'MESSAGE ""))
     
     ;; sadly you can't do much with these since the path is in the repository
     (cvs-match "Directory .* added to the repository$")
     )))


(defun cvs-parse-merge ()
  (let (path base-rev head-rev handled type)
    ;; A merge (maybe with a conflict).
    (and
     (cvs-match "RCS file: .*$")
     ;; Squirrel away info about the files that were retrieved for merging
     (cvs-match "retrieving revision \\([0-9.]+\\)$" (base-rev 1))
     (cvs-match "retrieving revision \\([0-9.]+\\)$" (head-rev 1))
     (cvs-match "Merging differences between [0-9.]+ and [0-9.]+ into \\(.*\\)$"
		(path 1))

     ;; eat up potential conflict warnings
     (cvs-or (cvs-match "\\(rcs\\)?merge:?\\( warning\\)?: \\(overlaps\\|conflicts\\) \\(or other problems \\)?during merge$" (type 'CONFLICT)) t)
     (cvs-or
      (and
       (cvs-match "cvs[.ex]* [a-z]+: ")
       (cvs-or
	(cvs-match "conflicts found in \\(.*\\)$" (path 1) (type 'CONFLICT))
	(cvs-match "could not merge .*$")
	(cvs-match "restoring \\(.*\\) from backup file .*$" (path 1))))
      t)

     ;; Is it a succesful merge?
     ;; Figure out result of merging (ie, was there a conflict?)
     (let ((qfile (regexp-quote path)))
       (cvs-or
	;; Conflict
	(and
	 (cvs-match (concat "C \\(.*" qfile "\\)$") (path 1) (type 'CONFLICT))
	 ;; C might be followed by a "suprious" U for non-mergeable files
	 (cvs-or (cvs-match (concat "U \\(.*" qfile "\\)$")) t))
	;; Successful merge
	(cvs-match (concat "M \\(.*" qfile "\\)$") (path 1))
	;; The file already contained the modifications
	(cvs-match (concat "^\\(.*" qfile
			   "\\) already contains the differences between .*$")
		   (path 1) (type '(UP-TO-DATE . MERGED)))
	t)
       ;; FIXME: PATH might not be set yet.  Sometimes the only path
       ;; information is in `RCS file: ...' (yuck!!).
       (cvs-parsed-fileinfo (if dont-change-disc 'NEED-MERGE
			      (or type '(MODIFIED . MERGED))) path nil
			    :merge (cons base-rev head-rev))))))

(defun cvs-parse-status ()
  (let (nofile path base-rev head-rev type)
    (and
     (cvs-match
      "===================================================================$")
     (cvs-match "File: \\(no file \\)?\\(.*[^ \t]\\)[ \t]+Status: "
		(nofile 1) (path 2))
     (cvs-or
      (cvs-match "Needs \\(Checkout\\|Patch\\)$"
		 (type (if nofile 'MISSING 'NEED-UPDATE)))
      (cvs-match "Up-to-date$"
		 (type (if nofile '(UP-TO-DATE . REMOVED) 'UP-TO-DATE)))
      (cvs-match "File had conflicts on merge$" (type 'MODIFIED))
      (cvs-match ".*[Cc]onflict.*$"	(type 'CONFLICT))
      (cvs-match "Locally Added$"		(type 'ADDED))
      (cvs-match "Locally Removed$"	(type 'REMOVED))
      (cvs-match "Locally Modified$"	(type 'MODIFIED))
      (cvs-match "Needs Merge$"		(type 'NEED-MERGE))
      (cvs-match "Entry Invalid"	(type '(NEED-MERGE . REMOVED)))
      (cvs-match "Unknown$"		(type 'UNKNOWN)))
     (cvs-match "$")
     (cvs-or
      (cvs-match " *Version:[ \t]*\\([0-9.]+\\).*$" (base-rev 1))
      ;; NOTE: there's no date on the end of the following for server mode...
      (cvs-match " *Working revision:[ \t]*-?\\([0-9.]+\\).*$" (base-rev 1))
      ;; Let's not get all worked up if the format changes a bit
      (cvs-match " *Working revision:.*$"))
     (cvs-or
      (cvs-match " *RCS Version:[ \t]*\\([0-9.]+\\)[ \t]*.*$" (head-rev 1))
      (cvs-match " *Repository revision:[ \t]*\\([0-9.]+\\)[ \t]*\\(.*\\)$"
		 (head-rev 1))
      (cvs-match " *Repository revision:.*"))
     (cvs-or
      (and;;sometimes those fields are missing
       (cvs-match " *Sticky Tag:[ \t]*\\(.*\\)$") ; FIXME: use it
       (cvs-match " *Sticky Date:[ \t]*\\(.*\\)$") ; FIXME: use it
       (cvs-match " *Sticky Options:[ \t]*\\(.*\\)$")) ; FIXME: use it
      t)
     (cvs-match "$")
     ;; ignore the tags-listing in the case of `status -v'
     (cvs-or (cvs-match " *Existing Tags:\n\\(\t.*\n\\)*$") t)
     (cvs-parsed-fileinfo type path nil
			  :base-rev base-rev
			  :head-rev head-rev))))

(defun cvs-parse-commit ()
  (let (path base-rev subtype)
    (cvs-or

     (and
      (cvs-match "\\(Checking in\\|Removing\\) \\(.*\\);$" (path 2))
      (cvs-match ".*,v  <--  .*$")
      (cvs-or
       ;; deletion
       (cvs-match "new revision: delete; previous revision: \\([0-9.]*\\)$"
		  (subtype 'REMOVED) (base-rev 1))
       ;; addition
       (cvs-match "initial revision: \\([0-9.]*\\)$"
		  (subtype 'ADDED) (base-rev 1))
       ;; update
       (cvs-match "new revision: \\([0-9.]*\\); previous revision: .*$"
		  (subtype 'COMMITTED) (base-rev 1)))
      (cvs-match "done$")
      (progn
	;; Try to remove the temp files used by VC.
	(vc-delete-automatic-version-backups (expand-file-name path))
	;; it's important here not to rely on the default directory management
	;; because `cvs commit' might begin by a series of Examining messages
	;; so the processing of the actual checkin messages might begin with
	;; a `current-dir' set to something different from ""
	(cvs-parsed-fileinfo (cons 'UP-TO-DATE subtype) path 'trust
			     :base-rev base-rev)))
     
     ;; useless message added before the actual addition: ignored
     (cvs-match "RCS file: .*\ndone$"))))


(provide 'pcvs-parse)

;;; pcvs-parse.el ends here