(defconst rcsid-pcl-cvs-parse "$Id$")
;; Copyright (C) 1991-1999 Per Cederqvist
;; This program 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 of the License, or
;; (at your option) any later version.
;; This program 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 this program; if not, write to the Free Software
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;; 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."
:type '(regexp :value "$"))
'("Executing ssh-askpass to query the password.*$")
"*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
:type '(repeat regexp))
;; a few more defvars just to shut up the compiler
;;;; The parser
(defun cvs-parse-buffer (parse-spec dont-change-disc &optional subdir)
"Parse data from BUFFER according to PARSE-SPEC.
Args: BUFFER PARSE-SPEC
Return a list of collected entries, or t if an error occured.
See parse-once for further documentation."
(let ((fileinfos ())
(cvs-current-subdir (or subdir "")))
(while (not (or (eobp) (eq fileinfos t)))
(let ((ret (cvs-run-parse-table parse-spec)))
;; it matched a known information message
((cvs-fileinfo-p ret) (push ret fileinfos))
;; it didn't match anything at all (impossible)
((null ret) (setq fileinfos t))
;; it matched something that should be ignored
;; All those parsing macros/functions should return a success indicator
(defsubst 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 REGEXP (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 re (mapcar (lambda (match)
`(cons (quote ,(first match)) ,(second match)))
(defun cvs-do-REGEXP (re &rest matches)
"Internal function for the REGEXP macro."
;; Is it a match? (The REGEXP must be anchored at the end of a line).
(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 ((var (car match))
(val (cdr match)))
(if (integerp val)
(let ((beg (match-beginning val)))
(if beg (buffer-substring beg (match-end val))))
(defmacro ALT (&rest alts)
"The meat of these parser macros/functions."
`(let ((current-point (point)))
(mapcar (lambda (es)
(progn (goto-char current-point)
;; This is how parser tables should be executed
(defun cvs-run-parse-table (parse-spec)
"Wrapper for parser-table."
(let ((cvs-start (point)))
(dolist (re cvs-parse-ignored-messages)
(when (cvs-do-REGEXP re) (return t)))
;; This is a parse error. Create a message-type fileinfo.
(cvs-create-fileinfo 'MESSAGE cvs-current-dir " "
(concat " Parser Error: '" (MSG) "'"))))))
(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."
(multiple-value-bind (dir file)
;; if the directory is a string, trust it
(if (stringp directory) (values directory path)
;; else, if the directory is true, the path should be trusted
(values (or (file-name-directory path) (if directory ""))
(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 (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 head-rev base-rev nofile subtype)
;; The full report for a given file from 'cvs status'...
;; Is it a merge ?
;; is it a commit ?
;; this is not necessary because the fileinfo merging will remove
;; such duplicate info and luckily the second info is the one we want.
;; (SEQ (REGEXP "M \\(.*\\)$" (path 1))
;; (cvs-merge-parse-table path))
;; Normal file state indicator.
(REGEXP "\\([MARCUPN?]\\) \\(.*\\)$" (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
(?C (if dont-change-disc 'NEED-MERGE 'CONFLICT))
(if (eq code ?U) 'UPDATED 'PATCHED)))))
(REGEXP "pcl-cvs: descending directory \\(.*\\)$" (dir 1))
(setq cvs-current-subdir dir))
;; A special cvs message
(REGEXP "cvs[.ex]* [a-z]+: ")
;; CVS is descending a subdirectory
;; (status says `examining' while update says `updating')
(REGEXP "\\(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
(REGEXP "New directory `\\(.*\\)' -- ignored$" (dir 1))
(cvs-parsed-fileinfo 'MESSAGE " " (file-name-as-directory dir)))
;; File removed, since it is removed (by third party) in repository.
(REGEXP "warning: \\(.*\\) is not (any longer) pertinent$" (file 1))
(REGEXP "\\(.*\\) is no longer in the repository$" (file 1)))
(cvs-parsed-fileinfo 'DEAD file))
(REGEXP "scheduling file `\\(.*\\)' for addition\\( on branch .*\\)?$" (path 1))
(REGEXP "re-adding file \\(.*\\) (in place of .*)$" (path 1)))
(cvs-parsed-fileinfo 'ADDED path))
;; [add] this will also show up as a `U <file>' so it's ignored here
(REGEXP "\\(.*\\), version \\(.*\\), resurrected$" (path 1) (base-rev 2))
(cvs-parsed-fileinfo '(UP-TO-DATE . RESURRECTED) path nil
(REGEXP "removed `\\(.*\\)'$" (path 1))
(cvs-parsed-fileinfo 'DEAD path))
(REGEXP "scheduling `\\(.*\\)' for removal$" (file 1))
(cvs-parsed-fileinfo 'REMOVED file))
;; [update] File removed by you, but not cvs rm'd
(REGEXP "warning: \\(.*\\) was lost$" (path 1))
(REGEXP (concat "U " (regexp-quote path) "$"))
(cvs-parsed-fileinfo (if dont-change-disc
'(UP-TO-DATE . UPDATED))
;; File removed in repository, but edited by you.
(REGEXP "conflict: \\(.*\\) is modified but no longer in the repository$"
(REGEXP "sticky tag .* for file `\\(.*\\)' is not a branch$" (file 1)))
(cvs-parsed-fileinfo 'MESSAGE file))
;; A removed file modified by someone else
(REGEXP "conflict: removed \\(.*\\) was modified by second party$"
(cvs-parsed-fileinfo 'MOD-CONFLICT file))
;; File unknown.
(SEQ (REGEXP "use `.+ add' to create an entry for \\(.*\\)$" (path 1))
(cvs-parsed-fileinfo 'UNKNOWN path))
;; We use cvs-execute-multi-dir but cvs can't handle it
;; Probably because the cvs-client can but the cvs-server can't
(SEQ (REGEXP ".* files with '?/'? in their name.*$")
(cvs-create-fileinfo 'MESSAGE "" " "
"*** Add (setq cvs-execute-single-dir t) to your .emacs ***"))
;; Cvs waits for a lock. Ignored: already handled by the process filter
(REGEXP "\\[..:..:..\\] \\(waiting for\\|obtained\\) .*lock in .*$")
;; File you removed still exists. Ignore (will be noted as removed).
(REGEXP ".* should be removed and is still there$")
;; just a note
(REGEXP "use '.+ commit' to \\(add\\|remove\\) th\\(is\\|ese\\) files? permanently$")
;; [add,status] followed by a more complete status description anyway
(REGEXP "nothing known about .*$")
;; [update] problem with patch
(REGEXP "checksum failure after patch to .*; will refetch$")
(REGEXP "refetching unpatchable files$")
(REGEXP "Rebuilding administrative file database$")
;; CVS is running a *info program.
;; 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.
(REGEXP "cvs[.ex]* \\[[a-z]+ aborted\\]:.*$")
(cvs-parsed-fileinfo 'MESSAGE nil))
;; sadly you can't do much with these since the path is in the repository
(REGEXP "Directory .* added to the repository$")
;; Patch informational message with CVS client.
;; Ignore, since this simply tells us that the patch in question
;; already has been applied to the file.
(REGEXP "^.* already contains the differences between .* and .*$"))))
(defun cvs-merge-parse-table ()
(let (path base-rev head-rev handled type)
;; A merge (maybe with a conflict).
(REGEXP "RCS file: .*$")
;; Squirrel away info about the files that were retrieved for merging
(REGEXP "retrieving revision \\([0-9.]+\\)$" (base-rev 1))
(REGEXP "retrieving revision \\([0-9.]+\\)$" (head-rev 1))
(REGEXP "Merging differences between [0-9.]+ and [0-9.]+ into \\(.*\\)$"
;; eat up potential conflict warnings
(ALT (REGEXP "\\(rcs\\)?merge:?\\( warning\\)?: \\(overlaps\\|conflicts\\) \\(or other problems \\)?during merge$" (type 'CONFLICT)) t)
(REGEXP "cvs[.ex]* [a-z]+: ")
(ALT (REGEXP "conflicts found in \\(.*\\)$" (path 1) (type 'CONFLICT))
(REGEXP "could not merge .*$")
(REGEXP "restoring \\(.*\\) from backup file .*$" (path 1))))
;; Is it a succesful merge?
;; Figure out result of merging (ie, was there a conflict?)
(let ((qfile (regexp-quote path)))
(REGEXP (concat "^C \\(.*" qfile "\\)$") (path 1) (type 'CONFLICT))
;; Successful merge
(REGEXP (concat "^M \\(.*" qfile "\\)$") (path 1))
;; The file already contained the modifications
(REGEXP (concat "^\\(.*" qfile
"\\) already contains the differences between .* and .*$")
(cvs-parsed-fileinfo (or type '(MODIFIED . MERGED)) path nil
:merge (cons base-rev head-rev))))))
(defun cvs-status-parse-table ()
(let (nofile path base-rev head-rev type)
(REGEXP "File: \\(no file \\)?\\([^ \t]*\\)[ \t]+Status: "
(nofile 1) (path 2))
(REGEXP "Needs \\(Checkout\\|Patch\\)$"
(type (if nofile 'NEED-REMOVE 'NEED-UPDATE)))
(REGEXP ".*[Cc]onflict.*$" (type 'CONFLICT))
(REGEXP "Locally Added$" (type 'ADDED))
(REGEXP "Locally Removed$" (type 'REMOVED))
(REGEXP "Locally Modified$" (type 'MODIFIED))
(REGEXP "Up-to-date$" (type 'UP-TO-DATE))
(REGEXP "Needs Merge$" (type 'NEED-MERGE))
(REGEXP "Unknown$" (type 'UNKNOWN)))
(REGEXP " *Version:[ \t]*\\([0-9.]+\\)[ \t]*.*$" (base-rev 1))
;; NOTE: there's no date on the end of the following for server mode...
(REGEXP " *Working revision:[ \t]*-?\\([0-9.]+\\)[ \t]*.*$" (base-rev 1))
;; Let's not get all worked up if the format changes a bit
(REGEXP " *Working revision:.*$"))
(REGEXP " *RCS Version:[ \t]*\\([0-9.]+\\)[ \t]*.*$" (head-rev 1))
(REGEXP " *Repository revision:[ \t]*\\([0-9.]+\\)[ \t]*\\(.*\\)$"
(REGEXP " *Repository revision:.*"))
(SEQ;;sometimes those fields are missing
(REGEXP " *Sticky Tag:[ \t]*\\(.*\\)$") ; FIXME: use it
(REGEXP " *Sticky Date:[ \t]*\\(.*\\)$") ; FIXME: use it
(REGEXP " *Sticky Options:[ \t]*\\(.*\\)$")) ; FIXME: use it
(cvs-parsed-fileinfo type path nil
(defun cvs-commit-parse-table ()
(let (path base-rev type)
(REGEXP "\\(Checking in\\|Removing\\) \\(.*\\);$" (path 2))
(REGEXP ".*,v <-- .*$")
(REGEXP "new revision: delete; previous revision: .*$" (type 'DEAD))
(REGEXP "initial revision: \\([0-9.]*\\)$"
(type '(UP-TO-DATE . ADDED)) (base-rev 1))
(REGEXP "new revision: \\([0-9.]*\\); previous revision: .*$"
(type '(UP-TO-DATE . COMMITTED)) (base-rev 1)))
;; 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 type path 'trust :base-rev base-rev))
;; useless message added before the actual addition: ignored
(REGEXP "RCS file: .*\ndone$"))))
;;; Provide this package
;;; pcl-cvs-parse.el ends here