1 ;;; pcvs-parse.el --- the CVS output parser
3 ;; Copyright (C) 1991,92,93,94,95,96,97,98,99,2000,2002
4 ;; Free Software Foundation, Inc.
6 ;; Author: Stefan Monnier <monnier@cs.yale.edu>
8 ;; Revision: $Id: pcvs-parse.el,v 1.12 2002/06/24 22:49:06 monnier Exp $
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
31 ;; - when merging a modified file, if the merge says that the file already
32 ;; contained in the changes, it marks the file as `up-to-date' although
33 ;; it might still contain further changes.
34 ;; Example: merging a zero-change commit.
38 (eval-when-compile (require 'cl
))
43 ;; imported from pcvs.el
44 (defvar cvs-execute-single-dir
)
48 (defcustom cvs-update-prog-output-skip-regexp
"$"
49 "*A regexp that matches the end of the output from all cvs update programs.
50 That is, output from any programs that are run by CVS (by the flag -u
51 in the `modules' file - see cvs(5)) when `cvs update' is performed should
52 terminate with a line that this regexp matches. It is enough that
53 some part of the line is matched.
55 The default (a single $) fits programs without output."
57 :type
'(regexp :value
"$"))
59 (defcustom cvs-parse-ignored-messages
60 '("Executing ssh-askpass to query the password.*$"
61 ".*Remote host denied X11 forwarding.*$")
62 "*A list of regexps matching messages that should be ignored by the parser.
63 Each regexp should match a whole set of lines and should hence be terminated
66 :type
'(repeat regexp
))
68 ;; a few more defvars just to shut up the compiler
70 (defvar cvs-current-dir
)
71 (defvar cvs-current-subdir
)
72 (defvar dont-change-disc
)
76 (defconst cvs-parse-known-commands
77 '("status" "add" "commit" "update" "remove" "checkout" "ci")
78 "List of CVS commands whose output is understood by the parser.")
80 (defun cvs-parse-buffer (parse-spec dont-change-disc
&optional subdir
)
81 "Parse current buffer according to PARSE-SPEC.
82 PARSE-SPEC is a function of no argument advancing the point and returning
83 either a fileinfo or t (if the matched text should be ignored) or
84 nil if it didn't match anything.
85 DONT-CHANGE-DISC just indicates whether the command was changing the disc
86 or not (useful to tell the difference between `cvs-examine' and `cvs-update'
88 The path names should be interpreted as relative to SUBDIR (defaults
89 to the `default-directory').
90 Return a list of collected entries, or t if an error occurred."
91 (goto-char (point-min))
94 (case-fold-search nil
)
95 (cvs-current-subdir (or subdir
"")))
96 (while (not (or (eobp) (eq fileinfos t
)))
97 (let ((ret (cvs-parse-run-table parse-spec
)))
99 ;; it matched a known information message
100 ((cvs-fileinfo-p ret
) (push ret fileinfos
))
101 ;; it didn't match anything at all (impossible)
102 ((and (consp ret
) (cvs-fileinfo-p (car ret
)))
103 (setq fileinfos
(append ret fileinfos
)))
104 ((null ret
) (setq fileinfos t
))
105 ;; it matched something that should be ignored
107 (nreverse fileinfos
)))
110 ;; All those parsing macros/functions should return a success indicator
111 (defsubst cvs-parse-msg
() (buffer-substring cvs-start
(1- (point))))
113 ;;(defsubst COLLECT (exp) (push exp *result*))
114 ;;(defsubst PROG (e) t)
115 ;;(defmacro SEQ (&rest seqs) (cons 'and seqs))
117 (defmacro cvs-match
(re &rest matches
)
118 "Try to match RE and extract submatches.
119 If RE matches, advance the point until the line after the match and
120 then assign the variables as specified in MATCHES (via `setq')."
122 (cons re
(mapcar (lambda (match)
123 `(cons ',(first match
) ,(second match
)))
126 (defun cvs-do-match (re &rest matches
)
127 "Internal function for the `cvs-match' macro.
128 Match RE and if successful, execute MATCHES."
130 (when (looking-at re
)
131 (goto-char (match-end 0))
132 ;; Skip the newline (unless we already are at the end of the buffer).
133 (when (and (eolp) (< (point) (point-max))) (forward-char))
134 ;; assign the matches
135 (dolist (match matches t
)
136 (let ((val (cdr match
)))
137 (set (car match
) (if (integerp val
) (match-string val
) val
))))))
139 (defmacro cvs-or
(&rest alts
)
140 "Try each one of the ALTS alternatives until one matches."
141 `(let ((-cvs-parse-point (point)))
144 `(or ,es
(ignore (goto-char -cvs-parse-point
))))
146 (def-edebug-spec cvs-or t
)
148 ;; This is how parser tables should be executed
149 (defun cvs-parse-run-table (parse-spec)
150 "Run PARSE-SPEC and provide sensible default behavior."
151 (unless (bolp) (forward-line 1)) ;this should never be needed
152 (let ((cvs-start (point)))
156 (dolist (re cvs-parse-ignored-messages
)
157 (when (cvs-match re
) (return t
)))
159 ;; This is a parse error. Create a message-type fileinfo.
162 (cvs-create-fileinfo 'MESSAGE cvs-current-dir
" "
163 ;; (concat " Unknown msg: '"
164 (cvs-parse-msg) ;; "'")
168 (defun cvs-parsed-fileinfo (type path
&optional directory
&rest keys
)
170 TYPE can either be a type symbol or a cons of the form (TYPE . SUBTYPE).
171 PATH is the filename.
172 DIRECTORY influences the way PATH is interpreted:
173 - if it's a string, it denotes the directory in which PATH (which should then be
174 a plain file name with no directory component) resides.
175 - if it's nil, the PATH should not be trusted: if it has a directory
176 component, use it, else, assume it is relative to the current directory.
177 - else, the PATH should be trusted to be relative to the root
178 directory (i.e. if there is no directory component, it means the file
179 is inside the main directory).
180 The remaining KEYS are passed directly to `cvs-create-fileinfo'."
181 (let ((dir directory
)
183 ;; only trust the directory if it's a string
184 (unless (stringp directory
)
185 ;; else, if the directory is true, the path should be trusted
186 (setq dir
(or (file-name-directory path
) (if directory
"")))
187 (setq file
(file-name-nondirectory path
)))
189 (let ((type (if (consp type
) (car type
) type
))
190 (subtype (if (consp type
) (cdr type
))))
191 (when dir
(setq cvs-current-dir dir
))
192 (apply 'cvs-create-fileinfo type
193 (concat cvs-current-subdir
(or dir cvs-current-dir
))
194 file
(cvs-parse-msg) :subtype subtype keys
))))
196 ;;;; CVS Process Parser Tables:
198 ;;;; The table for status and update could actually be merged since they
199 ;;;; don't conflict. But they don't overlap much either.
201 (defun cvs-parse-table ()
202 "Table of message objects for `cvs-parse-process'."
203 (let (c file dir path type base-rev subtype
)
210 ;; this is not necessary because the fileinfo merging will remove
211 ;; such duplicate info and luckily the second info is the one we want.
212 ;; (and (cvs-match "M \\(.*\\)$" (path 1))
213 ;; (cvs-parse-merge path))
215 ;; Normal file state indicator.
217 (cvs-match "\\([MARCUPNJ?]\\) \\(.*\\)$" (c 1) (path 2))
218 ;; M: The file is modified by the user, and untouched in the repository.
219 ;; A: The file is "cvs add"ed, but not "cvs ci"ed.
220 ;; R: The file is "cvs remove"ed, but not "cvs ci"ed.
222 ;; U: The file is copied from the repository.
223 ;; P: The file was patched from the repository.
225 (let ((code (aref c
0)))
233 (if (not dont-change-disc
) 'CONFLICT
234 ;; This is ambiguous. We should look for conflict markers in the
235 ;; file to decide between CONFLICT and NEED-MERGE. With CVS-1.10
236 ;; servers, this should not be necessary, because they return
237 ;; a complete merge output.
239 (insert-file-contents path
)
240 (goto-char (point-min))
241 (if (re-search-forward "^<<<<<<< " nil t
)
242 'CONFLICT
'NEED-MERGE
))))
243 (?J
'NEED-MERGE
) ;not supported by standard CVS
245 (if dont-change-disc
'NEED-UPDATE
246 (cons 'UP-TO-DATE
(if (eq code ?U
) 'UPDATED
'PATCHED
)))))
250 (cvs-match "pcl-cvs: descending directory \\(.*\\)$" (dir 1))
251 (setq cvs-current-subdir dir
))
253 ;; A special cvs message
255 (let ((case-fold-search t
))
256 (cvs-match "cvs[.a-z]* [a-z]+: "))
259 ;; CVS is descending a subdirectory
260 ;; (status says `examining' while update says `updating')
262 (cvs-match "\\(Examining\\|Updating\\) \\(.*\\)$" (dir 2))
263 (let ((dir (if (string= "." dir
) "" (file-name-as-directory dir
))))
264 (cvs-parsed-fileinfo 'DIRCHANGE
"." dir
)))
266 ;; [-n update] A new (or pruned) directory appeared but isn't traversed
268 (cvs-match "New directory `\\(.*\\)' -- ignored$" (dir 1))
269 ;; (cvs-parsed-fileinfo 'MESSAGE " " (file-name-as-directory dir))
270 (cvs-parsed-fileinfo '(NEED-UPDATE . NEW-DIR
) dir
))
272 ;; File removed, since it is removed (by third party) in repository.
275 (cvs-match "warning: \\(.*\\) is not (any longer) pertinent$" (file 1))
276 (cvs-match "\\(.*\\) is no longer in the repository$" (file 1)))
277 (cvs-parsed-fileinfo 'DEAD file
))
282 (cvs-match "scheduling file `\\(.*\\)' for addition.*$" (path 1))
283 (cvs-match "re-adding file \\(.*\\) (in place of .*)$" (path 1)))
284 (cvs-parsed-fileinfo 'ADDED path
))
286 ;; [add] this will also show up as a `U <file>'
288 (cvs-match "\\(.*\\), version \\(.*\\), resurrected$"
289 (path 1) (base-rev 2))
290 ;; FIXME: resurrection only brings back the original version,
291 ;; not the latest on the branch, so `up-to-date' is not always
293 (cvs-parsed-fileinfo '(UP-TO-DATE . RESURRECTED
) path nil
298 (cvs-match "removed `\\(.*\\)'$" (path 1))
299 (cvs-parsed-fileinfo 'DEAD path
))
303 (cvs-match "scheduling `\\(.*\\)' for removal$" (file 1))
304 (cvs-parsed-fileinfo 'REMOVED file
))
306 ;; [update] File removed by you, but not cvs rm'd
308 (cvs-match "warning: \\(.*\\) was lost$" (path 1))
309 (cvs-match (concat "U " (regexp-quote path
) "$"))
310 (cvs-parsed-fileinfo (if dont-change-disc
312 '(UP-TO-DATE . UPDATED
))
315 ;; Mode conflicts (rather than contents)
317 (cvs-match "conflict: ")
319 (cvs-match "removed \\(.*\\) was modified by second party$"
320 (path 1) (subtype 'REMOVED
))
321 (cvs-match "\\(.*\\) created independently by second party$"
322 (path 1) (subtype 'ADDED
))
323 (cvs-match "\\(.*\\) is modified but no longer in the repository$"
324 (path 1) (subtype 'MODIFIED
)))
325 (cvs-match (concat "C " (regexp-quote path
)))
326 (cvs-parsed-fileinfo (cons 'CONFLICT subtype
) path
))
328 ;; Messages that should be shown to the user
331 (cvs-match "move away \\(.*\\); it is in the way$" (file 1))
332 (cvs-match "warning: new-born \\(.*\\) has disappeared$" (file 1))
333 (cvs-match "sticky tag .* for file `\\(.*\\)' is not a branch$"
335 (cvs-parsed-fileinfo 'MESSAGE file
))
338 (and (cvs-match "use `.+ add' to create an entry for \\(.*\\)$" (path 1))
339 (cvs-parsed-fileinfo 'UNKNOWN path
))
342 (and (cvs-match "Up-to-date check failed for `\\(.+\\)'$" (file 1))
343 (cvs-parsed-fileinfo 'NEED-MERGE file
))
345 ;; We use cvs-execute-multi-dir but cvs can't handle it
346 ;; Probably because the cvs-client can but the cvs-server can't
347 (and (cvs-match ".* files with '?/'? in their name.*$")
348 (not cvs-execute-single-dir
)
349 (setq cvs-execute-single-dir t
)
352 "*** Add (setq cvs-execute-single-dir t) to your .emacs ***
353 See the FAQ file or the variable's documentation for more info."))
355 ;; Cvs waits for a lock. Ignored: already handled by the process filter
356 (cvs-match "\\[..:..:..\\] \\(waiting for\\|obtained\\) .*lock in .*$")
357 ;; File you removed still exists. Ignore (will be noted as removed).
358 (cvs-match ".* should be removed and is still there$")
360 (cvs-match "use '.+ commit' to \\sw+ th\\sw+ files? permanently$")
361 ;; [add,status] followed by a more complete status description anyway
362 (and (cvs-match "nothing known about \\(.*\\)$" (path 1))
363 (cvs-parsed-fileinfo 'DEAD path
'trust
))
364 ;; [update] problem with patch
365 (cvs-match "checksum failure after patch to .*; will refetch$")
366 (cvs-match "refetching unpatchable files$")
368 (cvs-match "Rebuilding administrative file database$")
370 (cvs-match "--> Using per-directory sticky tag `.*'")
372 ;; CVS is running a *info program.
374 (cvs-match "Executing.*$")
375 ;; Skip by any output the program may generate to stdout.
376 ;; Note that pcl-cvs will get seriously confused if the
377 ;; program prints anything to stderr.
378 (re-search-forward cvs-update-prog-output-skip-regexp
))))
381 (cvs-match "cvs[.ex]* \\[[a-z]+ aborted\\]:.*$")
382 (cvs-parsed-fileinfo 'MESSAGE
""))
384 ;; sadly you can't do much with these since the path is in the repository
385 (cvs-match "Directory .* added to the repository$")
389 (defun cvs-parse-merge ()
390 (let (path base-rev head-rev handled type
)
391 ;; A merge (maybe with a conflict).
393 (cvs-match "RCS file: .*$")
394 ;; Squirrel away info about the files that were retrieved for merging
395 (cvs-match "retrieving revision \\([0-9.]+\\)$" (base-rev 1))
396 (cvs-match "retrieving revision \\([0-9.]+\\)$" (head-rev 1))
397 (cvs-match "Merging differences between [0-9.]+ and [0-9.]+ into \\(.*\\)$"
400 ;; eat up potential conflict warnings
401 (cvs-or (cvs-match "\\(rcs\\)?merge:?\\( warning\\)?: \\(overlaps\\|conflicts\\) \\(or other problems \\)?during merge$" (type 'CONFLICT
)) t
)
404 (cvs-match "cvs[.ex]* [a-z]+: ")
406 (cvs-match "conflicts found in \\(.*\\)$" (path 1) (type 'CONFLICT
))
407 (cvs-match "could not merge .*$")
408 (cvs-match "restoring \\(.*\\) from backup file .*$" (path 1))))
411 ;; Is it a succesful merge?
412 ;; Figure out result of merging (ie, was there a conflict?)
413 (let ((qfile (regexp-quote path
)))
417 (cvs-match (concat "C \\(.*" qfile
"\\)$") (path 1) (type 'CONFLICT
))
418 ;; C might be followed by a "suprious" U for non-mergeable files
419 (cvs-or (cvs-match (concat "U \\(.*" qfile
"\\)$")) t
))
421 (cvs-match (concat "M \\(.*" qfile
"\\)$") (path 1))
422 ;; The file already contained the modifications
423 (cvs-match (concat "^\\(.*" qfile
424 "\\) already contains the differences between .*$")
425 (path 1) (type '(UP-TO-DATE . MERGED
)))
427 ;; FIXME: PATH might not be set yet. Sometimes the only path
428 ;; information is in `RCS file: ...' (yuck!!).
429 (cvs-parsed-fileinfo (if dont-change-disc
'NEED-MERGE
430 (or type
'(MODIFIED . MERGED
))) path nil
431 :merge
(cons base-rev head-rev
))))))
433 (defun cvs-parse-status ()
434 (let (nofile path base-rev head-rev type
)
437 "===================================================================$")
438 (cvs-match "File: \\(no file \\)?\\(.*[^ \t]\\)[ \t]+Status: "
441 (cvs-match "Needs \\(Checkout\\|Patch\\)$"
442 (type (if nofile
'MISSING
'NEED-UPDATE
)))
443 (cvs-match "Up-to-date$"
444 (type (if nofile
'(UP-TO-DATE . REMOVED
) 'UP-TO-DATE
)))
445 (cvs-match "File had conflicts on merge$" (type 'MODIFIED
))
446 (cvs-match ".*[Cc]onflict.*$" (type 'CONFLICT
))
447 (cvs-match "Locally Added$" (type 'ADDED
))
448 (cvs-match "Locally Removed$" (type 'REMOVED
))
449 (cvs-match "Locally Modified$" (type 'MODIFIED
))
450 (cvs-match "Needs Merge$" (type 'NEED-MERGE
))
451 (cvs-match "Entry Invalid" (type '(NEED-MERGE . REMOVED
)))
452 (cvs-match "Unknown$" (type 'UNKNOWN
)))
455 (cvs-match " *Version:[ \t]*\\([0-9.]+\\).*$" (base-rev 1))
456 ;; NOTE: there's no date on the end of the following for server mode...
457 (cvs-match " *Working revision:[ \t]*-?\\([0-9.]+\\).*$" (base-rev 1))
458 ;; Let's not get all worked up if the format changes a bit
459 (cvs-match " *Working revision:.*$"))
461 (cvs-match " *RCS Version:[ \t]*\\([0-9.]+\\)[ \t]*.*$" (head-rev 1))
462 (cvs-match " *Repository revision:[ \t]*\\([0-9.]+\\)[ \t]*\\(.*\\)$"
464 (cvs-match " *Repository revision:.*"))
466 (and;;sometimes those fields are missing
467 (cvs-match " *Sticky Tag:[ \t]*\\(.*\\)$") ; FIXME: use it
468 (cvs-match " *Sticky Date:[ \t]*\\(.*\\)$") ; FIXME: use it
469 (cvs-match " *Sticky Options:[ \t]*\\(.*\\)$")) ; FIXME: use it
472 ;; ignore the tags-listing in the case of `status -v'
473 (cvs-or (cvs-match " *Existing Tags:\n\\(\t.*\n\\)*$") t
)
474 (cvs-parsed-fileinfo type path nil
476 :head-rev head-rev
))))
478 (defun cvs-parse-commit ()
479 (let (path base-rev subtype
)
483 (cvs-match "\\(Checking in\\|Removing\\) \\(.*\\);$" (path 2))
484 (cvs-match ".*,v <-- .*$")
487 (cvs-match "new revision: delete; previous revision: \\([0-9.]*\\)$"
488 (subtype 'REMOVED
) (base-rev 1))
490 (cvs-match "initial revision: \\([0-9.]*\\)$"
491 (subtype 'ADDED
) (base-rev 1))
493 (cvs-match "new revision: \\([0-9.]*\\); previous revision: .*$"
494 (subtype 'COMMITTED
) (base-rev 1)))
497 ;; Try to remove the temp files used by VC.
498 (vc-delete-automatic-version-backups (expand-file-name path
))
499 ;; it's important here not to rely on the default directory management
500 ;; because `cvs commit' might begin by a series of Examining messages
501 ;; so the processing of the actual checkin messages might begin with
502 ;; a `current-dir' set to something different from ""
503 (cvs-parsed-fileinfo (cons 'UP-TO-DATE subtype
) path
'trust
504 :base-rev base-rev
)))
506 ;; useless message added before the actual addition: ignored
507 (cvs-match "RCS file: .*\ndone$"))))
510 (provide 'pcvs-parse
)
512 ;;; pcvs-parse.el ends here