home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / pcl-cvs / pcl-cvs.el < prev    next >
Encoding:
Text File  |  1995-03-21  |  76.1 KB  |  2,233 lines

  1. ;;; @(#) Id: pcl-cvs.el,v 1.93 1993/05/31 22:44:00 ceder Exp 
  2. ;;; pcl-cvs.el -- A Front-end to CVS 1.3 or later.  Release 1.05.
  3. ;;; Copyright (C) 1991, 1992, 1993  Per Cederqvist
  4. ;;;
  5. ;;; This program is free software; you can redistribute it and/or modify
  6. ;;; it under the terms of the GNU General Public License as published by
  7. ;;; the Free Software Foundation; either version 2 of the License, or
  8. ;;; (at your option) any later version.
  9. ;;;
  10. ;;; This program is distributed in the hope that it will be useful,
  11. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;;; GNU General Public License for more details.
  14. ;;;
  15. ;;; You should have received a copy of the GNU General Public License
  16. ;;; along with this program; if not, write to the Free Software
  17. ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. ;;;; See below for installation instructions.
  20. ;;;;
  21. ;;;; There is an TeXinfo file that describes this package.  The GNU
  22. ;;;; General Public License is included in that file.  You should read
  23. ;;;; it to get the most from this package.
  24.  
  25. ;;;; Send bug reports and improvements to ceder@lysator.liu.se or
  26. ;;;; ceder@signum.se.  Talk some about Signum Support here. +++FIXME
  27.  
  28. ;;; Don't try to use this with CVS 1.2 or earlier. It won't work. Get
  29. ;;; CVS 1.3. This package works together with RCS 5.6 and probably 5.5
  30. ;;; as well.
  31.  
  32. ;;; Mail questions and bug reports to ceder@lysator.liu.se.
  33.  
  34. (require 'cookie)
  35. (provide 'pcl-cvs)
  36.  
  37. ;;; -------------------------------------------------------
  38. ;;;        START OF THINGS TO CHECK WHEN INSTALLING
  39.  
  40. (defvar cvs-program "/usr/gnu/bin/cvs"
  41.   "*Full path to the cvs executable.")
  42.  
  43. (defvar cvs-diff-program "/usr/gnu/bin/diff"
  44.   "*Full path to the diff program.")
  45.  
  46. (defvar cvs-rmdir-program "/usr/gnu/bin/rmdir"
  47.   "*Full path to the rmdir program. Typically /bin/rmdir.")
  48.  
  49. ;; Uncomment the following line if you are running on 18.57 or earlier.
  50. ;(setq delete-exited-processes nil)
  51. ;; Emacs version 18.57 and earlier is likely to crash if
  52. ;; delete-exited-processes is t, since the sentinel uses lots of
  53. ;; memory, and 18.57 forgets to GCPROT a variable if
  54. ;; delete-exited-processes is t.
  55.  
  56. (defvar cvs-shell "/bin/sh"
  57.   "*Full path to a shell that can do redirection on stdout.")
  58.  
  59. ;;;         END OF THINGS TO CHECK WHEN INSTALLING
  60. ;;; --------------------------------------------------------
  61.  
  62. (defvar cvs-cvsroot nil
  63.   "*Specifies where the (current) cvs master repository is.
  64. Overrides the $CVSROOT variable by sending \" -d dir\" to all cvs commands.
  65. This switch is useful if you have multiple CVS repositories.")
  66.  
  67. (defvar cvs-stdout-file nil
  68.   "Name of the file that holds the output that CVS sends to stdout.
  69. This variable is buffer local.")
  70.  
  71. (defvar cvs-lock-file nil
  72.   "Full path to a lock file that CVS is waiting for (or was waiting for).")
  73.  
  74. (defvar cvs-bakprefix ".#"
  75.   "The prefix that CVS prepends to files when rcsmerge'ing.")
  76.  
  77. (defvar cvs-erase-input-buffer nil
  78.   "*Non-nil if input buffers should be cleared before asking for new info.")
  79.  
  80. (defvar cvs-auto-remove-handled nil
  81.   "*Non-nil if cvs-mode-remove-handled should be called automatically.
  82. If this is set to any non-nil value entries that does not need to be
  83. checked in will be removed from the *cvs* buffer after every cvs-mode-commit
  84. command.")
  85.  
  86. (defvar cvs-sort-ignore-file t
  87.   "*Non-nil if cvs-mode-ignore should sort the .cvsignore automatically.")
  88.  
  89. (defvar cvs-auto-revert-after-commit t
  90.   "*Non-nil if committed buffers should be automatically reverted.")
  91.  
  92. (defconst cvs-cursor-column 14
  93.   "Column to position cursor in in cvs-mode.
  94. Column 0 is left-most column.")
  95.  
  96. (defvar cvs-mode-map nil
  97.   "Keymap for the cvs mode.")
  98.  
  99. (defvar cvs-edit-mode-map nil
  100.   "Keymap for the cvs edit mode (used when editing cvs log messages).")
  101.  
  102. (defvar cvs-buffer-name "*cvs*"
  103.   "Name of the cvs buffer.")
  104.  
  105. (defvar cvs-commit-prompt-buffer "*cvs-commit-message*"
  106.   "Name of buffer in which the user is prompted for a log message when
  107. committing files.")
  108.  
  109. (defvar cvs-commit-buffer-require-final-newline t
  110.   "*t says silently put a newline at the end of commit log messages.
  111. Non-nil but not t says ask user whether to add a newline in each such case.
  112. nil means don't add newlines.")
  113.  
  114. (defvar cvs-temp-buffer-name "*cvs-tmp*"
  115.   "*Name of the cvs temporary buffer.
  116. Output from cvs is placed here by synchronous commands.")
  117.  
  118. (defvar cvs-diff-ignore-marks nil
  119.   "*Non-nil if cvs-diff and cvs-mode-diff-backup should ignore any marked files.
  120. Normally they run diff on the files that are marked (with cvs-mode-mark),
  121. or the file under the cursor if no files are marked.  If this variable
  122. is set to a non-nil value they will always run diff on the file on the
  123. current line.")
  124.  
  125. (defvar cvs-status-flags nil
  126.   "*List of strings to pass to ``cvs status''.")
  127.  
  128. (defvar cvs-log-flags nil
  129.   "*List of strings to pass to ``cvs log''.")
  130.  
  131. (defvar cvs-diff-flags nil
  132.   "*List of strings to use as flags to pass to ``diff'' and ``cvs diff''.
  133. Used by cvs-mode-diff-cvs and cvs-mode-diff-backup.
  134. Set this to '(\"-u\") to get a Unidiff format, or '(\"-c\") to get context diffs.")
  135.  
  136. (defvar cvs-update-prog-output-skip-regexp "$"
  137.   "*A regexp that matches the end of the output from all cvs update programs.
  138. That is, output from any programs that are run by CVS (by the flag -u
  139. in the `modules' file - see cvs(5)) when `cvs update' is performed should
  140. terminate with a line that this regexp matches.  It is enough that
  141. some part of the line is matched.
  142.  
  143. The default (a single $) fits programs without output.")
  144.  
  145. ;; The variables below are used internally by pcl-cvs. You should
  146. ;; never change them.
  147.  
  148. (defvar cvs-buffers-to-delete nil
  149.   "List of temporary buffers that should be discarded as soon as possible.
  150. Due to a bug in emacs 18.57 the sentinel can't discard them reliably.")
  151.  
  152. ;; You are NOT allowed to disable this message by default.  However, you
  153. ;; are encouraged to inform your users that by adding
  154. ;;    (setq cvs-inhibit-copyright-message t)
  155. ;; to their .emacs they can get rid of it.  Just don't add that line
  156. ;; to your default.el!
  157. (defvar cvs-inhibit-copyright-message nil
  158.   "*Non-nil means don't display a Copyright message in the ``*cvs*'' buffer.")
  159.  
  160. (defconst pcl-cvs-version "1.05"
  161.   "A string denoting the current release version of pcl-cvs.")
  162.  
  163. (defconst cvs-startup-message
  164.   (if cvs-inhibit-copyright-message
  165.       "PCL-CVS release 1.05"
  166.     "PCL-CVS release 1.05.  Copyright (C) 1992, 1993 Per Cederqvist
  167. Pcl-cvs comes with absolutely no warranty; for details consult the manual.
  168. This is free software, and you are welcome to redistribute it under certain
  169. conditions; again, consult the TeXinfo manual for details.")
  170.   "*Startup message for CVS.")
  171.  
  172. (defvar cvs-update-running nil
  173.   "This is set to nil when no process is running, and to
  174. the process when a cvs update process is running.")
  175.  
  176. (defvar cvs-cookie-handle nil
  177.   "Handle for the cookie structure that is displayed in the *cvs* buffer.")
  178.  
  179. (defvar cvs-mode-commit nil
  180.   "Used internally by pcl-cvs.")
  181.  
  182. ;;; The cvs data structure:
  183. ;;;
  184. ;;; When the `cvs update' is ready we parse the output. Every file
  185. ;;; that is affected in some way is added as a cookie of fileinfo
  186. ;;; (as defined below).
  187. ;;;
  188.  
  189. ;;; cvs-fileinfo
  190. ;;;
  191. ;;;  marked         t/nil
  192. ;;;  type         One of
  193. ;;;               UPDATED    - file copied from repository
  194. ;;;               MODIFIED   - modified by you, unchanged in
  195. ;;;                    repository
  196. ;;;               ADDED      - added by you, not yet committed
  197. ;;;               REMOVED    - removed by you, not yet committed
  198. ;;;               CVS-REMOVED- removed, since file no longer exists
  199. ;;;                    in the repository.
  200. ;;;               MERGED     - successful merge
  201. ;;;               CONFLICT   - conflict when merging
  202. ;;;               REM-CONFLICT-removed in repository, changed locally.
  203. ;;;               MOD-CONFLICT-removed locally, changed in repository.
  204. ;;;                        REM-EXIST  -removed locally, but still exists.
  205. ;;;               DIRCHANGE  - A change of directory.
  206. ;;;               UNKNOWN    - An unknown file.
  207. ;;;               MOVE-AWAY  - A file that is in the way.
  208. ;;;               REPOS-MISSING- The directory is removed from the
  209. ;;;                      repository. Go fetch a backup.
  210. ;;;                        MESSAGE    - This is a special fileinfo that is used
  211. ;;;                            to display a text that should be in
  212. ;;;                                       full-log.
  213. ;;;  dir         Directory the file resides in. Should not end with
  214. ;;;             slash.
  215. ;;;  file-name         The file name.
  216. ;;;  base-revision       The revision that the working file was based on.
  217. ;;;                      Onlyy valid for MERGED and CONFLICT files.
  218. ;;;  cvs-diff-buffer     A buffer that contains a 'cvs diff file'.
  219. ;;;  backup-diff-buffer     A buffer that contains a 'diff file backup-file'.
  220. ;;;  full-log         The output from cvs, unparsed.
  221. ;;;  mod-time         Modification time of file used for *-diff-buffer.
  222. ;;;  handled         True if this file doesn't require further action.
  223. ;;; 
  224. ;;; Constructor:
  225.  
  226. ;;; cvs-fileinfo
  227.  
  228. ;;; Constructor:
  229.  
  230. (defun cvs-create-fileinfo (type
  231.                 dir
  232.                 file-name
  233.                 full-log)
  234.   "Create a fileinfo from all parameters.
  235. Arguments: TYPE DIR FILE-NAME FULL-LOG.
  236. A fileinfo has the following fields:
  237.  
  238.   marked        t/nil
  239.   type              One of
  240.             UPDATED       - file copied from repository
  241.             MODIFIED   - modified by you, unchanged in
  242.                      repository
  243.             ADDED       - added by you, not yet committed
  244.             REMOVED       - removed by you, not yet committed
  245.             CVS-REMOVED- removed, since file no longer exists
  246.                      in the repository.
  247.             MERGED       - successful merge
  248.             CONFLICT   - conflict when merging
  249.             REM-CONFLICT-removed in repository, but altered
  250.                      locally.
  251.             MOD-CONFLICT-removed locally, changed in repository.
  252.                         REM-EXIST  - removed locally, but still exists.
  253.             DIRCHANGE  - A change of directory.
  254.             UNKNOWN       - An unknown file.
  255.             MOVE-AWAY  - A file that is in the way.
  256.             REPOS-MISSING- The directory has vanished from the
  257.                        repository.
  258.                         MESSAGE    - This is a special fileinfo that is used
  259.                          to display a text that should be in
  260.                                        full-log.
  261.   dir              Directory the file resides in. Should not end with slash.
  262.   file-name          The file name.
  263.   backup-file          Name of the backup file if MERGED or CONFLICT.
  264.   cvs-diff-buffer     A buffer that contains a 'cvs diff file'.
  265.   backup-diff-buffer  A buffer that contains a 'diff file backup-file'.
  266.   full-log          The output from cvs, unparsed.
  267.   mod-time          Modification time of file used for *-diff-buffer.
  268.   handled          True if this file doesn't require further action."
  269.   (cons
  270.    'CVS-FILEINFO
  271.    (vector nil nil type dir file-name nil nil nil full-log nil)))
  272.  
  273.  
  274. ;;; Selectors:
  275.  
  276. (defun cvs-fileinfo->handled (cvs-fileinfo)
  277.   "Get the  `handled' field from CVS-FILEINFO."
  278.   (elt (cdr cvs-fileinfo) 0))
  279.  
  280. (defun cvs-fileinfo->marked (cvs-fileinfo)
  281.   "Check if CVS-FILEINFO is marked."
  282.   (elt (cdr cvs-fileinfo) 1))
  283.  
  284. (defun cvs-fileinfo->type (cvs-fileinfo)
  285.   "Get type from CVS-FILEINFO.
  286. Type is one of UPDATED, MODIFIED, ADDED, REMOVED, CVS-REMOVED, MERGED,
  287. CONFLICT, REM-CONFLICT, MOD-CONFLICT, REM-EXIST, DIRCHANGE, UNKNOWN, MOVE-AWAY,
  288. REPOS-MISSING or MESSAGE."
  289.   (elt (cdr cvs-fileinfo) 2))
  290.  
  291. (defun cvs-fileinfo->dir (cvs-fileinfo)
  292.   "Get dir from CVS-FILEINFO.
  293. The directory name does not end with a slash. "
  294.   (elt (cdr cvs-fileinfo) 3))
  295.  
  296. (defun cvs-fileinfo->file-name (cvs-fileinfo)
  297.   "Get file-name from CVS-FILEINFO."
  298.   (elt (cdr cvs-fileinfo) 4))
  299.  
  300. (defun cvs-fileinfo->base-revision (cvs-fileinfo)
  301.   "Get the base revision from CVS-FILEINFO."
  302.   (elt (cdr cvs-fileinfo) 5))
  303.  
  304. (defun cvs-fileinfo->cvs-diff-buffer (cvs-fileinfo)
  305.   "Get cvs-diff-buffer from CVS-FILEINFO."
  306.   (elt (cdr cvs-fileinfo) 6))
  307.  
  308. (defun cvs-fileinfo->backup-diff-buffer (cvs-fileinfo)
  309.   "Get backup-diff-buffer from CVS-FILEINFO."
  310.   (elt (cdr cvs-fileinfo) 7))
  311.  
  312. (defun cvs-fileinfo->full-log (cvs-fileinfo)
  313.   "Get full-log from CVS-FILEINFO."
  314.   (elt (cdr cvs-fileinfo) 8))
  315.  
  316. (defun cvs-fileinfo->mod-time (cvs-fileinfo)
  317.   "Get mod-time from CVS-FILEINFO."
  318.   (elt (cdr cvs-fileinfo) 9))
  319.  
  320. ;;; Modifiers:
  321.  
  322. (defun cvs-set-fileinfo->handled (cvs-fileinfo newval)
  323.   "Set handled in CVS-FILEINFO to NEWVAL."
  324.   (aset (cdr cvs-fileinfo) 0 newval))
  325.  
  326. (defun cvs-set-fileinfo->marked (cvs-fileinfo newval)
  327.   "Set marked in CVS-FILEINFO to NEWVAL."
  328.   (aset (cdr cvs-fileinfo) 1 newval))
  329.  
  330. (defun cvs-set-fileinfo->type (cvs-fileinfo newval)
  331.   "Set type in CVS-FILEINFO to NEWVAL."
  332.   (aset (cdr cvs-fileinfo) 2 newval))
  333.  
  334. (defun cvs-set-fileinfo->dir (cvs-fileinfo newval)
  335.   "Set dir in CVS-FILEINFO to NEWVAL.
  336. The directory should now end with a slash."
  337.   (aset (cdr cvs-fileinfo) 3 newval))
  338.  
  339. (defun cvs-set-fileinfo->file-name (cvs-fileinfo newval)
  340.   "Set file-name in CVS-FILEINFO to NEWVAL."
  341.   (aset (cdr cvs-fileinfo) 4 newval))
  342.  
  343. (defun cvs-set-fileinfo->base-revision (cvs-fileinfo newval)
  344.   "Set base-revision in CVS-FILEINFO to NEWVAL."
  345.   (aset (cdr cvs-fileinfo) 5 newval))
  346.  
  347. (defun cvs-set-fileinfo->cvs-diff-buffer (cvs-fileinfo newval)
  348.   "Set cvs-diff-buffer in CVS-FILEINFO to NEWVAL."
  349.   (aset (cdr cvs-fileinfo) 6 newval))
  350.  
  351. (defun cvs-set-fileinfo->backup-diff-buffer (cvs-fileinfo newval)
  352.   "Set backup-diff-buffer in CVS-FILEINFO to NEWVAL."
  353.   (aset (cdr cvs-fileinfo) 7 newval))
  354.  
  355. (defun cvs-set-fileinfo->full-log (cvs-fileinfo newval)
  356.   "Set full-log in CVS-FILEINFO to NEWVAL."
  357.   (aset (cdr cvs-fileinfo) 8 newval))
  358.  
  359. (defun cvs-set-fileinfo->mod-time (cvs-fileinfo newval)
  360.   "Set full-log in CVS-FILEINFO to NEWVAL."
  361.   (aset (cdr cvs-fileinfo) 9 newval))
  362.  
  363.  
  364.  
  365. ;;; Predicate:
  366.  
  367. (defun cvs-fileinfo-p (object)
  368.   "Return t if OBJECT is a cvs-fileinfo."
  369.   (eq (car-safe object) 'CVS-FILEINFO))
  370.  
  371. ;;;; End of types.
  372.  
  373. (defun cvs-use-temp-buffer ()
  374.   "Display a temporary buffer in another window and select it.
  375. The selected window will not be changed.  The temporary buffer will
  376. be erased and writable."
  377.  
  378.   (let ((dir default-directory))
  379.     (display-buffer (get-buffer-create cvs-temp-buffer-name))
  380.     (set-buffer cvs-temp-buffer-name)
  381.     (setq buffer-read-only nil)
  382.     (setq default-directory dir)
  383.     (erase-buffer)))
  384.  
  385. ; Too complicated to handle all the cases that are generated.
  386. ; Maybe later.
  387. ;(defun cvs-examine (directory &optional local)
  388. ;  "Run a 'cvs -n update' in the current working directory.
  389. ;That is, check what needs to be done, but don't change the disc.
  390. ;Feed the output to a *cvs* buffer and run cvs-mode on it.
  391. ;If optional prefix argument LOCAL is non-nil, 'cvs update -l' is run."
  392. ;  (interactive (list (read-file-name "CVS Update (directory): "
  393. ;                     nil default-directory nil)
  394. ;             current-prefix-arg))
  395. ;  (cvs-do-update directory local 'noupdate))
  396.  
  397. ;;;###autoload
  398. (defun cvs-update (directory &optional local)
  399.   "Run a 'cvs update' in the current working directory. Feed the
  400. output to a *cvs* buffer and run cvs-mode on it.
  401. If optional prefix argument LOCAL is non-nil, 'cvs update -l' is run."
  402.   (interactive (list (read-file-name "CVS Update (directory): "
  403.                      nil default-directory nil)
  404.              current-prefix-arg))
  405.   (cvs-do-update directory local nil)
  406.   (switch-to-buffer cvs-buffer-name))            
  407.  
  408. ;;;###autoload
  409. (defun cvs-update-other-window (directory &optional local)
  410.   "Run a 'cvs update' in the current working directory. Feed the
  411. output to a *cvs* buffer, display it in the other window, and run
  412. cvs-mode on it.
  413.  
  414. If optional prefix argument LOCAL is non-nil, 'cvs update -l' is run."
  415.   (interactive (list (read-file-name "CVS Update other window (directory): "
  416.                      nil default-directory nil)
  417.              current-prefix-arg))
  418.   (cvs-do-update directory local nil)
  419.   (switch-to-buffer-other-window cvs-buffer-name))
  420.  
  421. (defun cvs-filter (predicate list &rest extra-args)
  422.   "Apply PREDICATE to each element on LIST.
  423. Args: PREDICATE LIST &rest EXTRA-ARGS.
  424. Return a new list consisting of those elements that PREDICATE
  425. returns non-nil for.
  426.  
  427. If more than two arguments are given the remaining args are
  428. passed to PREDICATE."
  429.   ;; Avoid recursion - this should work for LONG lists also!
  430.   (let* ((head (cons 'dummy-header nil))
  431.      (tail head))
  432.     (while list
  433.       (if (apply predicate (car list) extra-args)
  434.       (setq tail (setcdr tail (list (car list)))))
  435.       (setq list (cdr list)))
  436.     (cdr head)))
  437.  
  438. (defun cvs-mode-update-no-prompt ()
  439.   "Run cvs update in current directory."
  440.   (interactive)
  441.   (cvs-do-update default-directory nil nil))
  442.  
  443. (defun cvs-do-update (directory local dont-change-disc)
  444.   "Do a 'cvs update' in DIRECTORY.
  445. Args: DIRECTORY LOCAL DONT-CHANGE-DISC &optional NOTTHISWINDOW.
  446. If LOCAL is non-nil 'cvs update -l' is executed.
  447. If DONT-CHANGE-DISC is non-nil 'cvs -n update' is executed.
  448. Both LOCAL and DONT-CHANGE-DISC may be non-nil simultaneously.
  449.  
  450. *Note*: DONT-CHANGE-DISC does not yet work. The parser gets confused."
  451.   (save-some-buffers)
  452.   (if (not (file-exists-p cvs-program))
  453.       (error "%s: file not found (check setting of cvs-program)"
  454.          cvs-program))
  455.   (if (not (or (getenv "CVSROOT") cvs-cvsroot))
  456.       (error "Both cvs-cvsroot and environment variable CVSROOT unset."))
  457.   (let* ((this-dir (file-name-as-directory (expand-file-name directory)))
  458.      (update-buffer (generate-new-buffer
  459.              (concat (file-name-nondirectory
  460.                   (substring this-dir 0 -1))
  461.                  "-update")))
  462.      (temp-name (make-temp-name
  463.              (concat (file-name-as-directory
  464.                   (or (getenv "TMPDIR") "/tmp"))
  465.                  "pcl-cvs.")))
  466.      (args nil))
  467.  
  468.     ;; Check that this-dir exists and is a directory that is under CVS contr.
  469.  
  470.     (if (not (file-directory-p this-dir))
  471.     (error "%s is not a directory." this-dir))
  472.     (if (not (file-directory-p (concat this-dir "CVS")))
  473.     (error "%s does not contain CVS controlled files." this-dir))
  474.  
  475.     ;; Check that at most one `cvs update' is run at any time.
  476.  
  477.     (if (and cvs-update-running (process-status cvs-update-running)
  478.          (or (eq (process-status cvs-update-running) 'run)
  479.          (eq (process-status cvs-update-running) 'stop)))
  480.     (error "Can't run two `cvs update' simultaneously."))
  481.  
  482.     ;; Generate "-d /master -n update -l".
  483.     (setq args (concat (if cvs-cvsroot (concat " -d " cvs-cvsroot))
  484.                (if dont-change-disc " -n ")
  485.                " update "
  486.                (if local " -l ")))
  487.  
  488.     ;; Set up the buffer that receives the stderr output from "cvs update".
  489.     (set-buffer update-buffer)
  490.     (setq default-directory this-dir)
  491.     (make-local-variable 'cvs-stdout-file)
  492.     (setq cvs-stdout-file temp-name)
  493.  
  494.     (setq cvs-update-running
  495.       (let ((process-connection-type nil)) ; Use a pipe, not a pty.
  496.         (start-process "cvs" update-buffer cvs-shell "-c"
  497.                (concat cvs-program " " args " > " temp-name))))
  498.  
  499.     (setq mode-line-process
  500.       (concat ": "
  501.           (symbol-name (process-status cvs-update-running))))
  502.     (set-buffer-modified-p (buffer-modified-p))    ; Update the mode line.
  503.     (set-process-sentinel cvs-update-running 'cvs-sentinel)
  504.     (set-process-filter cvs-update-running 'cvs-update-filter)
  505.     (set-marker (process-mark cvs-update-running) (point-min))
  506.  
  507.     (save-excursion
  508.       (set-buffer (get-buffer-create cvs-buffer-name))
  509.       (setq buffer-read-only nil)
  510.       (erase-buffer)
  511.       (cvs-mode))
  512.       
  513.     (setq cvs-cookie-handle
  514.       (collection-create
  515.        cvs-buffer-name 'cvs-pp
  516.        cvs-startup-message        ;Se comment above cvs-startup-message.
  517.        "---------- End -----"))
  518.  
  519.     (cookie-enter-first
  520.      cvs-cookie-handle
  521.      (cvs-create-fileinfo
  522.       'MESSAGE nil nil (concat "\n    Running `cvs " args "' in " this-dir
  523.                    "...\n")))
  524.  
  525.     (save-excursion
  526.       (set-buffer cvs-buffer-name)
  527.       (setq mode-line-process
  528.         (concat ": "
  529.             (symbol-name (process-status cvs-update-running))))
  530.       (set-buffer-modified-p (buffer-modified-p))    ; Update the mode line.
  531.       (setq buffer-read-only t))
  532.  
  533.     ;; Work around a bug in emacs 18.57 and earlier.
  534.     (setq cvs-buffers-to-delete
  535.       (cvs-delete-unused-temporary-buffers cvs-buffers-to-delete)))
  536.  
  537.   ;; The following line is said to improve display updates on some
  538.   ;; emacses. It shouldn't be needed, but it does no harm.
  539.   (sit-for 0))
  540.  
  541.  
  542. (defun cvs-delete-unused-temporary-buffers (list)
  543.   "Delete all buffers on LIST that is not visible.
  544. Return a list of all buffers that still is alive."
  545.  
  546.   (cond
  547.    ((null list) nil)
  548.    ((get-buffer-window (car list))
  549.     (cons (car list)
  550.       (cvs-delete-unused-temporary-buffers (cdr list))))
  551.    (t
  552.     (kill-buffer (car list))
  553.     (cvs-delete-unused-temporary-buffers (cdr list)))))
  554.  
  555.  
  556. (put 'cvs-mode 'mode-class 'special)
  557.  
  558. (defun cvs-mode ()
  559.   "\\<cvs-mode-map>Mode used for pcl-cvs, a frontend to CVS.
  560.  
  561. To get the *cvs* buffer you should use ``\\[cvs-update]''.
  562.  
  563. Full documentation is in the Texinfo file.  These are the most useful commands:
  564.  
  565. \\[cvs-mode-previous-line] Move up.                    \\[cvs-mode-next-line] Move down.
  566. \\[cvs-mode-commit]   Commit file.                \\[cvs-mode-update-no-prompt]   Reupdate directory.
  567. \\[cvs-mode-mark]   Mark file/dir.              \\[cvs-mode-unmark]   Unmark file/dir.
  568. \\[cvs-mode-mark-all-files]   Mark all files.             \\[cvs-mode-unmark-all-files]   Unmark all files.
  569. \\[cvs-mode-find-file]   Edit file/run Dired.        \\[cvs-mode-find-file-other-window]   Find file or run Dired in other window.
  570. \\[cvs-mode-remove-handled]   Remove processed entries.   \\[cvs-mode-add-change-log-entry-other-window]   Write ChangeLog in other window.
  571. \\[cvs-mode-add]   Add to repository.          \\[cvs-mode-remove-file]   Remove file.
  572. \\[cvs-mode-diff-cvs]   Diff between base revision. \\[cvs-mode-diff-backup]   Diff backup file.
  573. \\[cvs-mode-emerge]   Run emerge on base revision/backup file.
  574. \\[cvs-mode-acknowledge] Delete line from buffer.    \\[cvs-mode-ignore]   Add file to the .cvsignore file.
  575. \\[cvs-mode-log]   Run ``cvs log''.            \\[cvs-mode-status]   Run ``cvs status''.
  576. \\[cvs-mode-undo-local-changes]  Revert the last checked in version - discard your changes to the file.
  577.  
  578. Entry to this mode runs cvs-mode-hook.
  579. This description is updated for release 1.05 of pcl-cvs.
  580.  
  581. All bindings:
  582. \\{cvs-mode-map}"
  583.   (interactive)
  584.   (setq major-mode 'cvs-mode)
  585.   (setq mode-name "CVS")
  586.   (setq mode-line-process nil)
  587.   (buffer-flush-undo (current-buffer))
  588.   (make-local-variable 'goal-column)
  589.   (setq goal-column cvs-cursor-column)
  590.   (use-local-map cvs-mode-map)
  591.   (run-hooks 'cvs-mode-hook))
  592.  
  593. (defun cvs-sentinel (proc msg)
  594.   "Sentinel for the cvs update process.
  595. This is responsible for parsing the output from the cvs update when
  596. it is finished."
  597.   (cond
  598.    ((null (buffer-name (process-buffer proc)))
  599.     ;; buffer killed
  600.     (set-process-buffer proc nil))
  601.    ((memq (process-status proc) '(signal exit))
  602.     (let* ((obuf (current-buffer))
  603.        (omax (point-max))
  604.        (opoint (point)))
  605.       ;; save-excursion isn't the right thing if
  606.       ;;  process-buffer is current-buffer
  607.       (unwind-protect
  608.       (progn
  609.         (set-buffer (process-buffer proc))
  610.         (setq mode-line-process
  611.           (concat ": "
  612.               (symbol-name (process-status proc))))
  613.         (let* ((out-file cvs-stdout-file)
  614.            (stdout-buffer (find-file-noselect out-file)))
  615.           (cvs-parse-update stdout-buffer (process-buffer proc))
  616.           (setq cvs-buffers-to-delete
  617.             (cons (process-buffer proc)
  618.               (cons stdout-buffer
  619.                 cvs-buffers-to-delete)))
  620.           (delete-file out-file)))
  621.     (message "CVS update process has completed.")    ; XEmacs
  622.     (set-buffer-modified-p (buffer-modified-p))
  623.     (setq cvs-update-running nil))
  624.       (if (equal obuf (process-buffer proc))
  625.       nil
  626.     (set-buffer (process-buffer proc))
  627.     (if (< opoint omax)
  628.         (goto-char opoint))
  629.     (set-buffer obuf))))))
  630.  
  631. (defun cvs-update-filter (proc string)
  632.   "Filter function for pcl-cvs.
  633. This function gets the output that CVS sends to stderr. It inserts it
  634. into (process-buffer proc) but it also checks if CVS is waiting for a
  635. lock file. If so, it inserts a message cookie in the *cvs* buffer."
  636.   (let ((old-buffer (current-buffer))
  637.     (data (match-data)))
  638.     (unwind-protect
  639.     (progn
  640.            (set-buffer (process-buffer proc))
  641.            (save-excursion
  642.              ;; Insert the text, moving the process-marker.
  643.              (goto-char (process-mark proc))
  644.              (insert string)
  645.              (set-marker (process-mark proc) (point))
  646.         ;; Delete any old lock message
  647.         (if (tin-nth cvs-cookie-handle 1)
  648.         (tin-delete cvs-cookie-handle
  649.                 (tin-nth cvs-cookie-handle 1)))
  650.         ;; Check if CVS is waiting for a lock.
  651.         (beginning-of-line 0)    ;Move to beginning of last
  652.                     ;complete line.
  653.         (cond
  654.          ((looking-at
  655.            "^cvs update: \\[..:..:..\\] waiting \
  656. for \\(.*\\)lock in \\(.*\\)$")
  657.           (setq cvs-lock-file (buffer-substring (match-beginning 2)
  658.                             (match-end 2)))
  659.           (cookie-enter-last
  660.            cvs-cookie-handle
  661.            (cvs-create-fileinfo
  662.         'MESSAGE nil nil
  663.         (concat "\tWaiting for "
  664.             (buffer-substring (match-beginning 1)
  665.                       (match-end 1))
  666.             "lock in " cvs-lock-file
  667.             ".\n\t (type M-x cvs-delete-lock to delete it)"))))
  668.          (t
  669.           ;; Hack by jwz to display some status in the *cvs* buffer...
  670.           (let ((s (buffer-substring (point)
  671.                      (progn (end-of-line) (point)))))
  672.         (save-excursion
  673.           (set-buffer cvs-buffer-name)
  674.           (goto-char (point-min))
  675.           (let ((buffer-read-only nil))
  676.             (if (re-search-forward "^[ \t]*Status: .*\n" nil t)
  677.             (delete-region (match-beginning 0) (match-end 0)))
  678.             (goto-char (point-min))
  679.             (re-search-forward "^[ \t]" nil t)
  680.             (forward-line 1)
  681.             (insert "    Status: " s "\n")
  682.             ))))
  683.          )))
  684.       (store-match-data data)
  685.       (set-buffer old-buffer))))
  686.  
  687. (defun cvs-delete-lock ()
  688.   "Delete the lock file that CVS is waiting for.
  689. Note that this can be dangerous.  You should only do this
  690. if you are convinced that the process that created the lock is dead."
  691.   (interactive)
  692.   (cond
  693.    ((not (or (file-exists-p
  694.           (concat (file-name-as-directory cvs-lock-file) "#cvs.lock"))
  695.          (cvs-filter (function cvs-lock-file-p)
  696.              (directory-files cvs-lock-file))))
  697.     (error "No lock files found."))
  698.    ((yes-or-no-p (concat "Really delete locks in " cvs-lock-file "? "))
  699.     ;; Re-read the directory -- the locks might have disappeared.
  700.     (let ((locks (cvs-filter (function cvs-lock-file-p)
  701.                  (directory-files cvs-lock-file))))
  702.       (while locks
  703.     (delete-file (concat (file-name-as-directory cvs-lock-file)
  704.                  (car locks)))
  705.     (setq locks (cdr locks)))
  706.       (cvs-remove-directory
  707.        (concat (file-name-as-directory cvs-lock-file) "#cvs.lock"))))))
  708.  
  709. (defun cvs-remove-directory (dir)
  710.   "Remove a directory."
  711.   (if (file-directory-p dir)
  712.       (call-process cvs-rmdir-program nil nil nil dir)
  713.     (error "Not a directory: %s" dir))
  714.   (if (file-exists-p dir)
  715.       (error "Could not remove directory %s" dir)))
  716.  
  717. (defun cvs-lock-file-p (file)
  718.   "Return true if FILE looks like a CVS lock file."
  719.   (or
  720.    (string-match "^#cvs.tfl.[0-9]+$" file)
  721.    (string-match "^#cvs.rfl.[0-9]+$" file)
  722.    (string-match "^#cvs.wfl.[0-9]+$" file)))
  723.  
  724. (defun cvs-skip-line (stdout stderr regexp &optional arg)
  725.   "Like forward-line, but check that the skipped line matches REGEXP.
  726. Args: STDOUT STDERR REGEXP &optional ARG.
  727.  
  728. If it doesn't match REGEXP a bug report is generated and displayed.
  729. STDOUT and STDERR is only used to do that.
  730.  
  731. If optional ARG, a number, is given the ARGth parenthesized expression
  732. in the REGEXP is returned as a string.
  733. Point should be in column 1 when this function is called."
  734.   (cond
  735.    ((looking-at regexp)
  736.     (forward-line 1)
  737.     (if arg
  738.     (buffer-substring (match-beginning arg)
  739.               (match-end arg))))
  740.    (t
  741.     (cvs-parse-error stdout stderr
  742.              (if (eq (current-buffer) stdout) 'STDOUT 'STDERR)
  743.              (point)))))
  744.  
  745. (defun cvs-get-current-dir (root-dir dirname)
  746.   "Return current working directory, suitable for cvs-parse-update.
  747. Args: ROOT-DIR DIRNAME.
  748. Concatenates ROOT-DIR and DIRNAME to form an absolute path."
  749.   (if (string= "." dirname)
  750.       (substring root-dir 0 -1)
  751.     (concat root-dir dirname)))
  752.  
  753. (defun cvs-compare-fileinfos (a b)
  754.   "Compare fileinfo A with fileinfo B and return t if A is `less'."
  755.   (cond
  756.    ;; Sort acording to directories.
  757.    ((string< (cvs-fileinfo->dir a) (cvs-fileinfo->dir b)) t)
  758.    ((not (string= (cvs-fileinfo->dir a) (cvs-fileinfo->dir b))) nil)
  759.    
  760.    ;; The DIRCHANGE entry is always first within the directory.
  761.    ((and (eq (cvs-fileinfo->type a) 'DIRCHANGE)
  762.      (not (eq (cvs-fileinfo->type b) 'DIRCHANGE))) t)
  763.    ((and (eq (cvs-fileinfo->type b) 'DIRCHANGE)
  764.      (not (eq (cvs-fileinfo->type a) 'DIRCHANGE))) nil)
  765.    ;; All files are sorted by file name.
  766.    ((string< (cvs-fileinfo->file-name a) (cvs-fileinfo->file-name b)))))
  767.  
  768. (defun cvs-parse-error (stdout-buffer stderr-buffer err-buf pos)
  769.   "Handle a parse error when parsing the output from cvs.
  770. Args: STDOUT-BUFFER STDERR-BUFFER ERR-BUF POS.
  771. ERR-BUF should be 'STDOUT or 'STDERR."
  772.   (setq pos (1- pos))
  773.   (set-buffer cvs-buffer-name)
  774.   (setq buffer-read-only nil)
  775.   (erase-buffer)
  776.   (insert "To: ceder@lysator.liu.se\n")
  777.   (insert "Subject: pcl-cvs " pcl-cvs-version " parse error.\n")
  778.   (insert "--text follows this line--\n\n")
  779.   (insert "This bug report is automatically generated by pcl-cvs\n")
  780.   (insert "because it doesn't understand some output from CVS.  Below\n")
  781.   (insert "is detailed information about the error.  Please send\n")
  782.   (insert "this, together with any information you think might be\n")
  783.   (insert "useful for me to fix the bug, to the address above.  But\n")
  784.   (insert "please check the \"known problems\" section of the\n")
  785.   (insert "documentation first.  Note that this buffer contains\n")
  786.   (insert "information that you might consider confidential.  You\n")
  787.   (insert "are encouraged to read through it before sending it.\n")
  788.   (insert "\n")
  789.   (insert "Press C-c C-c to send this email.\n\n")
  790.   (insert "Please state the version of these programs you are using:\n")
  791.   (insert "RCS:  \ndiff: \n\n")
  792.  
  793.   (let* ((stdout (save-excursion (set-buffer stdout-buffer) (buffer-string)))
  794.      (stderr (save-excursion (set-buffer stderr-buffer) (buffer-string)))
  795.      (errstr (if (eq err-buf 'STDOUT) stdout stderr))
  796.      (errline-end (string-match "\n" errstr pos))
  797.      (errline (substring errstr pos errline-end)))
  798.     (insert (format "Offending line (%d chars): >" (- errline-end pos)))
  799.     (insert errline)
  800.     (insert "<\n")
  801.     (insert "Sent to " (symbol-name err-buf) " at pos " (format "%d\n" pos))
  802.     (insert "Emacs-version: " (emacs-version) "\n")
  803.     (insert "Pcl-cvs $" "Id:" "$" ": " "Id: pcl-cvs.el,v 1.93 1993/05/31 22:44:00 ceder Exp \n")
  804.     (insert "\n")
  805.     (insert (format "--- Contents of stdout buffer (%d chars) ---\n"
  806.             (length stdout)))
  807.     (insert stdout)
  808.     (insert "--- End of stdout buffer ---\n")
  809.     (insert (format "--- Contents of stderr buffer (%d chars) ---\n"
  810.             (length stderr)))
  811.     (insert stderr)
  812.     (insert "--- End of stderr buffer ---\n")
  813.     (insert "End of bug report.\n")
  814.     (require 'sendmail)
  815.     (mail-mode)
  816.     (error "CVS parse error - please report this bug.")))
  817.       
  818. (defun cvs-parse-update (stdout-buffer stderr-buffer)
  819.   "Parse the output from `cvs update'.
  820.  
  821. Args: STDOUT-BUFFER STDERR-BUFFER.
  822.  
  823. This functions parses the from `cvs update' (which should be
  824. separated in its stdout- and stderr-components) and prints a
  825. pretty representation of it in the *cvs* buffer.
  826.  
  827. Signals an error if unexpected output was detected in the buffer."
  828.   (let* ((head (cons 'dummy nil))
  829.      (tail (cvs-parse-stderr stdout-buffer stderr-buffer
  830.                  head default-directory))
  831.      (root-dir default-directory))
  832.     (cvs-parse-stdout stdout-buffer stderr-buffer tail root-dir)
  833.     (setq head (sort (cdr head) (function cvs-compare-fileinfos)))
  834.  
  835.     (collection-clear cvs-cookie-handle)
  836.     (collection-append-cookies cvs-cookie-handle head)
  837.     (cvs-remove-stdout-shadows)
  838.     (cvs-remove-empty-directories)
  839.     (set-buffer cvs-buffer-name)
  840.     (cvs-mode)
  841.     ;; XEmacs - tedium should let you know when it's ended...
  842.     (if (pos-visible-in-window-p (point-min))
  843.     nil                ; assume that the user will see it...
  844.       (ding t 'ready)
  845.       (message "CVS update is ready."))
  846.     (goto-char (point-min))
  847.     (tin-goto-previous cvs-cookie-handle (point-min) 1)
  848.     (setq default-directory root-dir)))
  849.  
  850. (defun cvs-remove-stdout-shadows ()
  851.   "Remove entries in the *cvs* buffer that comes from both stdout and stderr.
  852. If there is two entries for a single file the second one should be
  853. deleted. (Remember that sort uses a stable sort algorithm, so one can
  854. be sure that the stderr entry is always first)."
  855.   (collection-filter-tins cvs-cookie-handle
  856.           (function
  857.            (lambda (tin)
  858.          (not (cvs-shadow-entry-p tin))))))
  859.  
  860. (defun cvs-shadow-entry-p (tin)
  861.   "Return non-nil if TIN is a shadow entry.
  862. Args: TIN.
  863. A TIN is a shadow entry if the previous tin contains the same file."
  864.   (let* ((previous-tin (tin-previous cvs-cookie-handle tin))
  865.      (curr (tin-cookie cvs-cookie-handle tin))
  866.      (prev (and previous-tin
  867.             (tin-cookie cvs-cookie-handle previous-tin))))
  868.     (and
  869.      prev curr
  870.      (string= (cvs-fileinfo->file-name prev) (cvs-fileinfo->file-name curr))
  871.      (string= (cvs-fileinfo->dir prev)       (cvs-fileinfo->dir curr))
  872.      (or
  873.       (and (eq (cvs-fileinfo->type prev) 'CONFLICT)
  874.        (eq (cvs-fileinfo->type curr) 'CONFLICT))
  875.       (and (eq (cvs-fileinfo->type prev) 'MERGED)
  876.        (eq (cvs-fileinfo->type curr) 'MODIFIED))
  877.       (and (eq (cvs-fileinfo->type prev) 'REM-EXIST)
  878.        (eq (cvs-fileinfo->type curr) 'REMOVED))))))
  879.  
  880.  
  881. (defun cvs-parse-stderr (stdout-buffer stderr-buffer head dir)
  882.   "Parse the output from CVS that is written to stderr.
  883. Args: STDOUT-BUFFER STDERR-BUFFER HEAD DIR
  884. STDOUT-BUFFER holds the output that cvs sent to stdout. It is only
  885. used to create a bug report in case there is a parse error.
  886. STDERR-BUFFER is the buffer that holds the output to parse.
  887. HEAD is a cons-cell, the head of the list that is built.
  888. DIR is the directory the `cvs update' was run in.
  889.  
  890. This function returns the last cons-cell in the list that is built."
  891.  
  892.   (save-window-excursion
  893.     (set-buffer stderr-buffer)
  894.     (goto-char (point-min))
  895.     (let ((current-dir dir)
  896.       (root-dir dir))
  897.  
  898.       (while (< (point) (point-max))
  899.     (cond
  900.  
  901.      ;; RCVS support (for now, we simply ignore any output from
  902.      ;; RCVS, including error messages!)
  903.  
  904.      ((looking-at "updating of .* finished$")
  905.       (forward-line 1))
  906.  
  907.      ((looking-at "REMOTE FOLDER:.*")
  908.       (forward-line 1)
  909.       (while (and (< (point) (point-max)) (not (looking-at "phase 2.*")))
  910.         (forward-line 1))
  911.       (forward-line 2))
  912.  
  913.      ((looking-at "turn on remote mode$")
  914.       (forward-line 1)
  915.       (while (and (< (point) (point-max)) (not (looking-at "phase 2.*")))
  916.         (forward-line 1))
  917.       (forward-line 2))
  918.  
  919.      ((looking-at "phase 3.*")
  920.       (goto-char (point-max)))
  921.  
  922.      ;; End of RCVS stuff.
  923.  
  924.      ;; CVS is descending a subdirectory.
  925.      
  926.      ((looking-at "cvs update: Updating \\(.*\\)$")
  927.       (setq current-dir
  928.         (cvs-get-current-dir
  929.          root-dir
  930.          (buffer-substring (match-beginning 1) (match-end 1))))
  931.       (setcdr head (list (cvs-create-fileinfo
  932.                   'DIRCHANGE current-dir
  933.                   nil (buffer-substring (match-beginning 0)
  934.                             (match-end 0)))))
  935.       (setq head (cdr head))
  936.       (forward-line 1))
  937.  
  938.      ;; File removed, since it is removed (by third party) in repository.
  939.        
  940.      ((or (looking-at
  941.            "cvs update: warning: \\(.*\\) is not (any longer) pertinent")
  942.           (looking-at
  943.            "cvs update: \\(.*\\) is no longer in the repository"))
  944.  
  945.       (setcdr head (list (cvs-create-fileinfo
  946.                   'CVS-REMOVED current-dir
  947.                   (file-name-nondirectory
  948.                    (buffer-substring (match-beginning 1)
  949.                          (match-end 1)))
  950.                   (buffer-substring (match-beginning 0)
  951.                         (match-end 0)))))
  952.       (setq head (cdr head))
  953.       (forward-line 1))
  954.  
  955.      ;; File removed by you, but recreated by cvs. Ignored.
  956.  
  957.      ((looking-at "cvs update: warning: .* was lost$")
  958.       (forward-line 1))
  959.  
  960.      ;; A file that has been created by you, but added to the cvs
  961.      ;; repository by another.
  962.  
  963.      ((looking-at "^cvs update: move away \\(.*\\); it is in the way$")
  964.       (setcdr head (list (cvs-create-fileinfo
  965.                   'MOVE-AWAY current-dir
  966.                   (file-name-nondirectory
  967.                    (buffer-substring (match-beginning 1)
  968.                          (match-end 1)))
  969.                   (buffer-substring (match-beginning 0)
  970.                         (match-end 0)))))
  971.       (setq head (cdr head))
  972.       (forward-line 1))
  973.  
  974.      ;; Empty line. Probably inserted by mistake by user (or developer :-)
  975.      ;; Ignore.
  976.  
  977.      ((looking-at "^$")
  978.       (forward-line 1))
  979.  
  980.      ;; Cvs waits for a lock. Ignore.
  981.  
  982.      ((looking-at
  983.        "^cvs update: \\[..:..:..\\] waiting for .*lock in ")
  984.       (forward-line 1))
  985.  
  986.      ;; File removed in repository, but edited by you.
  987.  
  988.      ((looking-at
  989.        "cvs update: conflict: \\(.*\\) is modified but no longer \
  990. in the repository$")
  991.       (setcdr head (list
  992.             (cvs-create-fileinfo
  993.              'REM-CONFLICT current-dir
  994.              (file-name-nondirectory
  995.               (buffer-substring (match-beginning 1) (match-end 1)))
  996.              (buffer-substring (match-beginning 0)
  997.                        (match-end 0)))))
  998.       (setq head (cdr head))
  999.       (forward-line 1))
  1000.  
  1001.      ((looking-at
  1002.        "cvs update: conflict: removed \\(.*\\) was modified by \
  1003. second party")
  1004.       (setcdr head
  1005.           (list
  1006.            (cvs-create-fileinfo
  1007.             'MOD-CONFLICT current-dir
  1008.             (buffer-substring (match-beginning 1) (match-end 1))
  1009.             (buffer-substring (match-beginning 0) (match-end 0)))))
  1010.       (setq head (cdr head))
  1011.       (forward-line 1))
  1012.  
  1013.      ((looking-at
  1014.        "cvs update: \\(.*\\) should be removed and is still there")
  1015.       (setcdr head
  1016.           (list
  1017.            (cvs-create-fileinfo
  1018.             'REM-EXIST current-dir
  1019.             (buffer-substring (match-beginning 1) (match-end 1))
  1020.             (buffer-substring (match-beginning 0) (match-end 0)))))
  1021.       (setq head (cdr head))
  1022.       (forward-line 1))
  1023.  
  1024.      ((looking-at "cvs update: in directory ")
  1025.       (let ((start (point)))
  1026.         (forward-line 1)
  1027.         (cvs-skip-line
  1028.          stdout-buffer stderr-buffer
  1029.          (regexp-quote "cvs [update aborted]: there is no repository "))
  1030.         (setcdr head (list
  1031.               (cvs-create-fileinfo
  1032.                'REPOS-MISSING current-dir
  1033.                nil
  1034.                (buffer-substring start (point)))))
  1035.         (setq head (cdr head))))
  1036.  
  1037.        (t
  1038.  
  1039.     ;; CVS has decided to merge someone elses changes into this
  1040.     ;; document. This leads to a lot of garbage being printed.
  1041.     ;; First there is two lines that contains no information
  1042.     ;; that we skip (but we check that we recognize them).
  1043.  
  1044.     (let ((complex-start (point))
  1045.           initial-revision filename)
  1046.  
  1047.       (cvs-skip-line stdout-buffer stderr-buffer "^RCS file: .*$")
  1048.       (setq initial-revision
  1049.         (cvs-skip-line stdout-buffer stderr-buffer
  1050.                    "^retrieving revision \\(.*\\)$" 1))
  1051.       (cvs-skip-line stdout-buffer stderr-buffer
  1052.              "^retrieving revision .*$")
  1053.  
  1054.       ;; Get the file name from the next line.
  1055.  
  1056.       (setq
  1057.        filename
  1058.        (cvs-skip-line
  1059.         stdout-buffer stderr-buffer
  1060.         "^Merging differences between [0-9.]+ and [0-9.]+ into \\(.*\\)$"
  1061.         1))
  1062.  
  1063.       (cond
  1064.        ;; Was it a conflict?
  1065.        ((looking-at
  1066.          ;; Allow both RCS 5.5 and 5.6. (5.6 prints "rcs" and " warning").
  1067.          "^\\(rcs\\)?merge\\( warning\\)?: overlaps during merge$")
  1068.  
  1069.         ;; Yes, this is a conflict.
  1070.         (cvs-skip-line
  1071.          stdout-buffer stderr-buffer
  1072.          "^\\(rcs\\)?merge\\( warning\\)?: overlaps during merge$")
  1073.  
  1074.         (cvs-skip-line stdout-buffer stderr-buffer
  1075.                "^cvs update: conflicts found in ")
  1076.  
  1077.         (let ((fileinfo
  1078.            (cvs-create-fileinfo
  1079.             'CONFLICT current-dir
  1080.             filename
  1081.             (buffer-substring complex-start (point)))))
  1082.  
  1083.           (cvs-set-fileinfo->base-revision fileinfo initial-revision)
  1084.  
  1085.           (setcdr head (list fileinfo))
  1086.           (setq head (cdr head))))
  1087.  
  1088.        ;; Was it a conflict, and was RCS compiled without DIFF3_BIN?
  1089.  
  1090.        ((looking-at
  1091.          ;; Allow both RCS 5.5 and 5.6. (5.6 prints "rcs" and " warning").
  1092.          "^\\(rcs\\)?merge\\( warning\\)?: overlaps or other probl\
  1093. ems during merge$")
  1094.  
  1095.         ;; Yes, this is a conflict.
  1096.         (cvs-skip-line
  1097.          stdout-buffer stderr-buffer
  1098.          "^\\(rcs\\)?merge\\( warning\\)?: overlaps .*during merge$")
  1099.  
  1100.         (cvs-skip-line stdout-buffer stderr-buffer
  1101.                "^cvs update: could not merge ")
  1102.         (cvs-skip-line stdout-buffer stderr-buffer
  1103.                "^cvs update: restoring .* from backup file ")
  1104.  
  1105.         (let ((fileinfo
  1106.            (cvs-create-fileinfo
  1107.             'CONFLICT current-dir
  1108.             filename
  1109.             (buffer-substring complex-start (point)))))
  1110.  
  1111.           (setcdr head (list fileinfo))
  1112.           (setq head (cdr head))))       
  1113.  
  1114.        (t
  1115.         ;; Not a conflict; it must be a succesful merge.
  1116.         (let ((fileinfo
  1117.            (cvs-create-fileinfo
  1118.             'MERGED current-dir
  1119.             filename
  1120.             (buffer-substring complex-start (point)))))
  1121.           (cvs-set-fileinfo->base-revision fileinfo initial-revision)
  1122.           (setcdr head (list fileinfo))
  1123.           (setq head (cdr head)))))))))))
  1124.   head)
  1125.  
  1126.  
  1127. (defun cvs-parse-stdout (stdout-buffer stderr-buffer head root-dir)
  1128.   "Parse the output from CVS that is written to stderr.
  1129. Args: STDOUT-BUFFER STDERR-BUFFER HEAD ROOT-DIR
  1130. STDOUT-BUFFER is the buffer that holds the output to parse.
  1131. STDERR-BUFFER holds the output that cvs sent to stderr. It is only
  1132. used to create a bug report in case there is a parse error.
  1133.  
  1134. HEAD is a cons-cell, the head of the list that is built.
  1135. ROOT-DIR is the directory the `cvs update' was run in.
  1136.  
  1137. This function doesn't return anything particular."
  1138.   (save-window-excursion
  1139.     (set-buffer stdout-buffer)
  1140.     (goto-char (point-min))
  1141.     (while (< (point) (point-max))
  1142.       (cond
  1143.  
  1144.        ;; M: The file is modified by the user, and untouched in the repository.
  1145.        ;; A: The file is "cvs add"ed, but not "cvs ci"ed.
  1146.        ;; R: The file is "cvs remove"ed, but not "cvs ci"ed.
  1147.        ;; C: Conflict
  1148.        ;; U: The file is copied from the repository.
  1149.        ;; ?: Unknown file.
  1150.  
  1151.  
  1152.        ((looking-at "\\([MARCU?]\\) \\(.*\\)$")
  1153.     (let*
  1154.         ((c         (char-after (match-beginning 1)))
  1155.          (full-path
  1156.           (concat (file-name-as-directory root-dir)
  1157.               (buffer-substring (match-beginning 2) (match-end 2))))
  1158.          (fileinfo (cvs-create-fileinfo
  1159.             (cond ((eq c ?M) 'MODIFIED)
  1160.                   ((eq c ?A) 'ADDED)
  1161.                   ((eq c ?R) 'REMOVED)
  1162.                   ((eq c ?C) 'CONFLICT)
  1163.                   ((eq c ?U) 'UPDATED)
  1164.                   ((eq c ??) 'UNKNOWN))
  1165.             (substring (file-name-directory full-path) 0 -1)
  1166.             (file-name-nondirectory full-path)
  1167.             (buffer-substring (match-beginning 0) (match-end 0)))))
  1168.       ;; Updated files require no further action.
  1169.       (if (eq c ?U)
  1170.           (cvs-set-fileinfo->handled fileinfo t))
  1171.  
  1172.       ;; Link this last on the list.
  1173.       (setcdr head (list fileinfo))
  1174.       (setq head (cdr head))
  1175.       (forward-line 1)))
  1176.  
  1177.        ;; Executing a program because of the -u option in modules.
  1178.        ((looking-at "cvs update: Executing")
  1179.     ;; Skip by any output the program may generate to stdout.
  1180.     ;; Note that pcl-cvs will get seriously confused if the
  1181.     ;; program prints anything to stderr.
  1182.     (re-search-forward cvs-update-prog-output-skip-regexp)
  1183.     (forward-line 1))
  1184.  
  1185.        (t (cvs-parse-error stdout-buffer stderr-buffer 'STDOUT (point)))))))
  1186.  
  1187. (defun cvs-pp (fileinfo)
  1188.   "Pretty print FILEINFO.  Insert a printed representation in current buffer.
  1189. For use by the cookie package."
  1190.  
  1191.   (let ((a (cvs-fileinfo->type fileinfo))
  1192.         (s (if (cvs-fileinfo->marked fileinfo)
  1193.                "*" " "))
  1194.         (f (cvs-fileinfo->file-name fileinfo))
  1195.         (ci (if (cvs-fileinfo->handled fileinfo)
  1196.                 "  " "ci")))
  1197.     (insert
  1198.      (cond
  1199.       ((eq a 'UPDATED)
  1200.        (format "%s Updated     %s" s f))
  1201.       ((eq a 'MODIFIED)
  1202.        (format "%s Modified %s %s" s ci f))
  1203.       ((eq a 'MERGED)
  1204.        (format "%s Merged   %s %s" s ci f))
  1205.       ((eq a 'CONFLICT)
  1206.        (format "%s Conflict    %s" s f))
  1207.       ((eq a 'ADDED)
  1208.        (format "%s Added    %s %s" s ci f))
  1209.       ((eq a 'REMOVED)
  1210.        (format "%s Removed  %s %s" s ci f))
  1211.       ((eq a 'UNKNOWN)
  1212.        (format "%s Unknown     %s" s f))
  1213.       ((eq a 'CVS-REMOVED)
  1214.        (format "%s Removed from repository:  %s" s f))
  1215.       ((eq a 'REM-CONFLICT)
  1216.        (format "%s Conflict: Removed from repository, changed by you: %s" s f))
  1217.       ((eq a 'MOD-CONFLICT)
  1218.        (format "%s Conflict: Removed by you, changed in repository: %s" s f))
  1219.       ((eq a 'REM-EXIST)
  1220.        (format "%s Conflict: Removed by you, but still exists: %s" s f))
  1221.       ((eq a 'DIRCHANGE)
  1222.        (format "\nIn directory %s:"
  1223.            (cvs-fileinfo->dir fileinfo)))
  1224.       ((eq a 'MOVE-AWAY)
  1225.        (format "%s Move away %s - it is in the way" s f))
  1226.       ((eq a 'REPOS-MISSING)
  1227.        (format "  This repository is missing! Remove this dir manually."))
  1228.       ((eq a 'MESSAGE)
  1229.        (cvs-fileinfo->full-log fileinfo))
  1230.       (t
  1231.        (format "%s Internal error! %s" s f))))))
  1232.  
  1233.  
  1234. ;;; You can define your own keymap in .emacs. pcl-cvs.el won't overwrite it.
  1235.  
  1236. (if cvs-mode-map
  1237.     nil
  1238.   (setq cvs-mode-map (make-keymap))
  1239.   (suppress-keymap cvs-mode-map)
  1240.   (define-key cvs-mode-map " "    'cvs-mode-next-line)
  1241.   (define-key cvs-mode-map "?"    'describe-mode)
  1242.   (define-key cvs-mode-map "A"    'cvs-mode-add-change-log-entry-other-window)
  1243.   (define-key cvs-mode-map "M"    'cvs-mode-mark-all-files)
  1244.   (define-key cvs-mode-map "R"    'cvs-mode-revert-updated-buffers)
  1245.   (define-key cvs-mode-map "U"    'cvs-mode-undo-local-changes)
  1246.   (define-key cvs-mode-map "\C-?"  'cvs-mode-unmark-up)
  1247.   (define-key cvs-mode-map "\C-k"  'cvs-mode-acknowledge)
  1248.   (define-key cvs-mode-map "\C-n"  'cvs-mode-next-line)
  1249.   (define-key cvs-mode-map "\C-p"  'cvs-mode-previous-line)
  1250.   (define-key cvs-mode-map "\M-\C-?" 'cvs-mode-unmark-all-files)
  1251.   (define-key cvs-mode-map "a"    'cvs-mode-add)
  1252.   (define-key cvs-mode-map "b"    'cvs-mode-diff-backup)
  1253.   (define-key cvs-mode-map "c"    'cvs-mode-commit)
  1254.   (define-key cvs-mode-map "d"    'cvs-mode-diff-cvs)
  1255. ;;  This binding is intolerable. -jwz
  1256. ;;  (define-key cvs-mode-map "e"    'cvs-mode-emerge)
  1257.   (define-key cvs-mode-map "e"    'cvs-mode-find-file)
  1258.   (define-key cvs-mode-map "f"    'cvs-mode-find-file)
  1259.   (define-key cvs-mode-map "g"    'cvs-mode-update-no-prompt)
  1260.   (define-key cvs-mode-map "i"    'cvs-mode-ignore)
  1261.   (define-key cvs-mode-map "l"    'cvs-mode-log)
  1262.   (define-key cvs-mode-map "m"    'cvs-mode-mark)
  1263.   (define-key cvs-mode-map "n"    'cvs-mode-next-line)
  1264.   (define-key cvs-mode-map "o"    'cvs-mode-find-file-other-window)
  1265.   (define-key cvs-mode-map "p"    'cvs-mode-previous-line)
  1266.   (define-key cvs-mode-map "q"    'bury-buffer)
  1267.   (define-key cvs-mode-map "r"    'cvs-mode-remove-file)
  1268.   (define-key cvs-mode-map "s"    'cvs-mode-status)
  1269.   (define-key cvs-mode-map "x"    'cvs-mode-remove-handled)
  1270.   (define-key cvs-mode-map "u"    'cvs-mode-unmark))
  1271.  
  1272.  
  1273. (defun cvs-get-marked (&optional ignore-marks)
  1274.   "Return a list of all selected tins.
  1275. If there are any marked tins, and IGNORE-MARKS is nil, return them.
  1276. Otherwise, if the cursor selects a directory, return all files in it.
  1277. Otherwise return (a list containing) the file the cursor points to, or
  1278. an empty list if it doesn't point to a file at all.
  1279.  
  1280. Args: &optional IGNORE-MARKS."
  1281.     
  1282.   (cond
  1283.    ;; Any marked cookies?
  1284.    ((and (not ignore-marks)
  1285.      (collection-collect-tin cvs-cookie-handle 'cvs-fileinfo->marked)))
  1286.    ;; Nope.
  1287.    (t
  1288.     (let ((sel (tin-locate cvs-cookie-handle (point))))
  1289.       (cond
  1290.        ;; If a directory is selected, all it members are returned.
  1291.        ((and sel (eq (cvs-fileinfo->type
  1292.             (tin-cookie cvs-cookie-handle sel))
  1293.                'DIRCHANGE))
  1294.     (collection-collect-tin
  1295.      cvs-cookie-handle 'cvs-dir-member-p
  1296.      (cvs-fileinfo->dir (tin-cookie cvs-cookie-handle sel))))
  1297.        (t
  1298.     (list sel)))))))
  1299.  
  1300.  
  1301. (defun cvs-dir-member-p (fileinfo dir)
  1302.   "Return true if FILEINFO represents a file in directory DIR."
  1303.   (and (not (eq (cvs-fileinfo->type fileinfo) 'DIRCHANGE))
  1304.        (string= (cvs-fileinfo->dir fileinfo) dir)))
  1305.  
  1306. (defun cvs-dir-empty-p (tin)
  1307.   "Return non-nil if TIN is a directory that is empty.
  1308. Args: CVS-BUF TIN."
  1309.   (and (eq (cvs-fileinfo->type (tin-cookie cvs-cookie-handle tin)) 'DIRCHANGE)
  1310.        (or (not (tin-next cvs-cookie-handle tin))
  1311.        (eq (cvs-fileinfo->type
  1312.         (tin-cookie cvs-cookie-handle
  1313.                     (tin-next cvs-cookie-handle tin)))
  1314.            'DIRCHANGE))))
  1315.  
  1316. (defun cvs-mode-revert-updated-buffers ()
  1317.   "Revert any buffers that are UPDATED, MERGED or CONFLICT."
  1318.   (interactive)
  1319.   (cookie-map (function cvs-revert-fileinfo) cvs-cookie-handle))
  1320.  
  1321. (defun cvs-revert-fileinfo (fileinfo)
  1322.   "Revert the buffer that holds the file in FILEINFO if it has changed,
  1323. and if the type is UPDATED, MERGED or CONFLICT."
  1324.   (let* ((type (cvs-fileinfo->type fileinfo))
  1325.      (file (cvs-fileinfo->full-path fileinfo))
  1326.      (buffer (get-file-buffer file)))
  1327.     ;; For a revert to happen...
  1328.     (cond
  1329.      ((and
  1330.        ;; ...the type must be one that justifies a revert...
  1331.        (or (eq type 'UPDATED)
  1332.        (eq type 'MERGED)
  1333.        (eq type 'CONFLICT))
  1334.        ;; ...and the user must be editing the file...
  1335.        buffer)
  1336.       (save-excursion
  1337.     (set-buffer buffer)
  1338.     (cond
  1339.      ((buffer-modified-p)
  1340.       (error "%s: edited since last cvs-update."
  1341.          (buffer-file-name)))
  1342.      ;; Go ahead and revert the file.
  1343.      (t (revert-buffer 'dont-use-auto-save-file 'dont-ask))))))))
  1344.  
  1345.  
  1346. (defun cvs-mode-remove-handled ()
  1347.   "Remove all lines that are handled.
  1348. Empty directories are removed."
  1349.   (interactive)
  1350.   ;; Pass one: remove files that are handled.
  1351.   (collection-filter-cookies cvs-cookie-handle
  1352.          (function
  1353.           (lambda (fileinfo) (not (cvs-fileinfo->handled fileinfo)))))
  1354.   ;; Pass two: remove empty directories.
  1355.   (cvs-remove-empty-directories))
  1356.  
  1357.  
  1358. (defun cvs-remove-empty-directories ()
  1359.   "Remove empty directories in the *cvs* buffer."
  1360.   (collection-filter-tins cvs-cookie-handle
  1361.              (function
  1362.               (lambda (tin)
  1363.             (not (cvs-dir-empty-p tin))))))
  1364.  
  1365. (defun cvs-mode-mark (pos)
  1366.   "Mark a fileinfo. Args: POS.
  1367. If the fileinfo is a directory, all the contents of that directory are
  1368. marked instead. A directory can never be marked.
  1369. POS is a buffer position."
  1370.  
  1371.   (interactive "d")
  1372.  
  1373.   (let* ((tin (tin-locate cvs-cookie-handle pos))
  1374.      (sel (tin-cookie cvs-cookie-handle tin)))
  1375.  
  1376.     (cond
  1377.      ;; Does POS point to a directory? If so, mark all files in that directory.
  1378.      ((eq (cvs-fileinfo->type sel) 'DIRCHANGE)
  1379.       (cookie-map
  1380.        (function (lambda (f dir)
  1381.            (cond
  1382.             ((cvs-dir-member-p f dir)
  1383.              (cvs-set-fileinfo->marked f t)
  1384.              t))))        ;Tell cookie to redisplay this cookie.
  1385.        cvs-cookie-handle
  1386.        (cvs-fileinfo->dir sel)))
  1387.      (t
  1388.       (cvs-set-fileinfo->marked sel t)
  1389.       (tin-invalidate cvs-cookie-handle tin)
  1390.       (tin-goto-next cvs-cookie-handle pos 1)))))
  1391.   
  1392.  
  1393. (defun cvs-committable (tin)
  1394.   "Check if the TIN is committable.
  1395. It is committable if it
  1396.    a) is not handled and
  1397.    b) is either MODIFIED, ADDED, REMOVED, MERGED or CONFLICT."
  1398.   (let* ((fileinfo (tin-cookie cvs-cookie-handle tin))
  1399.      (type (cvs-fileinfo->type fileinfo)))
  1400.     (and (not (cvs-fileinfo->handled fileinfo))
  1401.      (or (eq type 'MODIFIED)
  1402.          (eq type 'ADDED)
  1403.          (eq type 'REMOVED)
  1404.          (eq type 'MERGED)
  1405.          (eq type 'CONFLICT)))))
  1406.  
  1407. (defun cvs-mode-commit ()
  1408.  
  1409.   "Check in all marked files, or the current file.
  1410. The user will be asked for a log message in a buffer.
  1411. If cvs-erase-input-buffer is non-nil that buffer will be erased.
  1412. Otherwise mark and point will be set around the entire contents of the
  1413. buffer so that it is easy to kill the contents of the buffer with \\[kill-region]."
  1414.  
  1415.   (interactive)
  1416.  
  1417.   (let* ((cvs-buf (current-buffer))
  1418.      (marked (cvs-filter (function cvs-committable)
  1419.                  (cvs-get-marked))))
  1420.     (if (null marked)
  1421.     (error "Nothing to commit!")
  1422.       (pop-to-buffer (get-buffer-create cvs-commit-prompt-buffer))
  1423.       (goto-char (point-min))
  1424.  
  1425.       (if cvs-erase-input-buffer
  1426.       (erase-buffer)
  1427.     (push-mark (point-max)))
  1428.       (cvs-edit-mode)
  1429.       (make-local-variable 'cvs-commit-list)
  1430.       (setq cvs-commit-list marked)
  1431.       (message "Press C-c C-c when you are done editing."))))
  1432.  
  1433.  
  1434. (defun cvs-edit-done ()
  1435.   "Commit the files to the repository."
  1436.   (interactive)
  1437.   (if (null cvs-commit-list)
  1438.       (error "You have already commited the files"))
  1439.   (if (and (> (point-max) 1)
  1440.        (/= (char-after (1- (point-max))) ?\n)
  1441.        (or (eq cvs-commit-buffer-require-final-newline t)
  1442.            (and cvs-commit-buffer-require-final-newline
  1443.             (yes-or-no-p
  1444.              (format "Buffer %s does not end in newline.  Add one? "
  1445.                  (buffer-name))))))
  1446.       (save-excursion
  1447.     (goto-char (point-max))
  1448.     (insert ?\n)))
  1449.   (save-some-buffers)
  1450.   (let ((cc-list cvs-commit-list)
  1451.     (cc-buffer (get-buffer cvs-buffer-name))
  1452.     (msg-buffer (current-buffer))
  1453.     (msg (buffer-substring (point-min) (point-max))))
  1454.     (pop-to-buffer cc-buffer)
  1455.     (bury-buffer msg-buffer)
  1456.     (cvs-use-temp-buffer)
  1457.     (message "Committing...")
  1458.     (if (cvs-execute-list cc-list cvs-program
  1459.               (if cvs-cvsroot
  1460.                   (list "-d" cvs-cvsroot "commit" "-m" msg)
  1461.                 (list "commit" "-m" msg)))
  1462.     (error "Something went wrong. Check the %s buffer carefully."
  1463.            cvs-temp-buffer-name))
  1464.     (let ((ccl cc-list))
  1465.       (while ccl
  1466.     (cvs-after-commit-function (tin-cookie cvs-cookie-handle (car ccl)))
  1467.     (setq ccl (cdr ccl))))
  1468.     (apply 'tin-invalidate cvs-cookie-handle cc-list)
  1469.     (set-buffer msg-buffer)
  1470.     (setq cvs-commit-list nil)
  1471.     (set-buffer cc-buffer)
  1472.     (if cvs-auto-remove-handled
  1473.     (cvs-mode-remove-handled)))
  1474.   
  1475.   (message "Committing... Done."))
  1476.  
  1477. (defun cvs-after-commit-function (fileinfo)
  1478.   "Do everything that needs to be done when FILEINFO has been commited.
  1479. The fileinfo->handle is set, and if the buffer is present it is reverted."
  1480.   (cvs-set-fileinfo->handled fileinfo t)
  1481.   (if cvs-auto-revert-after-commit
  1482.       (let* ((file (cvs-fileinfo->full-path fileinfo))
  1483.          (buffer (get-file-buffer file)))
  1484.     ;; For a revert to happen...
  1485.     (if buffer
  1486.         ;; ...the user must be editing the file...
  1487.         (save-excursion
  1488.           (set-buffer buffer)
  1489.           (if (not (buffer-modified-p))
  1490.           ;; ...but it must be unmodified.
  1491.           (revert-buffer 'dont-use-auto-save-file 'dont-ask)))))))
  1492.  
  1493.  
  1494. (defun cvs-execute-list (tin-list program constant-args)
  1495.   "Run PROGRAM on all elements on TIN-LIST.
  1496. Args: TIN-LIST PROGRAM CONSTANT-ARGS
  1497. The PROGRAM will be called with pwd set to the directory the
  1498. files reside in. CONSTANT-ARGS should be a list of strings. The
  1499. arguments given to the program will be CONSTANT-ARGS followed by all
  1500. the files (from TIN-LIST) that resides in that directory. If the files
  1501. in TIN-LIST resides in different directories the PROGRAM will be run
  1502. once for each directory (if all files in the same directory appears
  1503. after each other).
  1504.  
  1505. Any output from PROGRAM will be inserted in the current buffer.
  1506.  
  1507. This function return nil if all went well, or the numerical exit
  1508. status or a signal name as a string. Note that PROGRAM might be called
  1509. several times. This will return non-nil if something goes wrong, but
  1510. there is no way to know which process that failed."
  1511.  
  1512.   (let ((exitstatus nil))
  1513.     (while tin-list
  1514.       (let ((current-dir (cvs-fileinfo->dir
  1515.               (tin-cookie cvs-cookie-handle
  1516.                      (car tin-list))))
  1517.         arg-list arg-str)
  1518.  
  1519.     ;; Collect all marked files in this directory.
  1520.  
  1521.     (while (and tin-list
  1522.             (string=
  1523.              current-dir
  1524.              (cvs-fileinfo->dir
  1525.               (tin-cookie cvs-cookie-handle (car tin-list)))))
  1526.       (setq arg-list
  1527.         (cons (cvs-fileinfo->file-name
  1528.                (tin-cookie cvs-cookie-handle (car tin-list)))
  1529.               arg-list))
  1530.       (setq tin-list (cdr tin-list)))
  1531.  
  1532.     (setq arg-list (nreverse arg-list))
  1533.  
  1534.     ;; Execute the command on all the files that were collected.
  1535.  
  1536.     (setq default-directory (file-name-as-directory current-dir))
  1537.     (insert (format "=== cd %s\n" default-directory))
  1538.     (insert (format "=== %s %s\n\n"
  1539.             program
  1540.             (mapconcat '(lambda (foo) foo)
  1541.                    (nconc (copy-sequence constant-args)
  1542.                       arg-list)
  1543.                    " ")))
  1544.     (let ((res (apply 'call-process program nil t t
  1545.               (nconc (copy-sequence constant-args) arg-list))))
  1546.       ;; Remember the first, or highest, exitstatus.
  1547.       (if (and (not (and (integerp res) (zerop res)))
  1548.            (or (null exitstatus)
  1549.                (and (integerp exitstatus) (= 1 exitstatus))))
  1550.           (setq exitstatus res)))
  1551.     (goto-char (point-max))))
  1552.     exitstatus))
  1553.  
  1554.  
  1555. (defun cvs-execute-single-file-list (tin-list extractor program constant-args)
  1556.   "Run PROGRAM on all elements on TIN-LIST.
  1557.  
  1558. Args: TIN-LIST EXTRACTOR PROGRAM CONSTANT-ARGS
  1559.  
  1560. The PROGRAM will be called with pwd set to the directory the files
  1561. reside in.  CONSTANT-ARGS is a list of strings to pass as arguments to
  1562. PROGRAM.  The arguments given to the program will be CONSTANT-ARGS
  1563. followed by the list that EXTRACTOR returns.
  1564.  
  1565. EXTRACTOR will be called once for each file on TIN-LIST.  It is given
  1566. one argument, the cvs-fileinfo.  It can return t, which means ignore
  1567. this file, or a list of arguments to send to the program."
  1568.  
  1569.     (while tin-list
  1570.       (let ((default-directory (file-name-as-directory
  1571.                 (cvs-fileinfo->dir
  1572.                  (tin-cookie cvs-cookie-handle
  1573.                         (car tin-list)))))
  1574.         (arg-list
  1575.          (funcall extractor
  1576.               (tin-cookie cvs-cookie-handle (car tin-list)))))
  1577.  
  1578.     ;; Execute the command unless extractor returned t.
  1579.  
  1580.     (if (eq arg-list t)
  1581.         nil
  1582.       (insert (format "=== cd %s\n" default-directory))
  1583.       (insert (format "=== %s %s\n\n"
  1584.               program
  1585.               (mapconcat '(lambda (foo) foo)
  1586.                      (nconc (copy-sequence constant-args)
  1587.                         arg-list)
  1588.                      " ")))
  1589.       (apply 'call-process program nil t t
  1590.          (nconc (copy-sequence constant-args) arg-list))
  1591.       (goto-char (point-max))))
  1592.       (setq tin-list (cdr tin-list))))
  1593.  
  1594.  
  1595. (defun cvs-edit-mode ()
  1596.   "\\<cvs-edit-mode-map>Mode for editing cvs log messages.
  1597. Commands:
  1598. \\[cvs-edit-done] checks in the file when you are ready.
  1599. This mode is based on fundamental mode."
  1600.   (interactive)
  1601.   (use-local-map cvs-edit-mode-map)
  1602.   (setq major-mode 'cvs-edit-mode)
  1603.   (setq mode-name "CVS Log")
  1604.   (auto-fill-mode 1))
  1605.  
  1606.  
  1607. (if cvs-edit-mode-map
  1608.     nil
  1609.   (setq cvs-edit-mode-map (make-sparse-keymap))
  1610.   (define-prefix-command 'cvs-control-c-prefix)
  1611.   (define-key cvs-edit-mode-map "\C-c" 'cvs-control-c-prefix)
  1612.   (define-key cvs-edit-mode-map "\C-c\C-c" 'cvs-edit-done))
  1613.  
  1614.  
  1615. (defun cvs-diffable (tins)
  1616.   "Return a list of all tins on TINS that it makes sense to run
  1617. ``cvs diff'' on."
  1618.   ;; +++ There is an unnecessary (nreverse) here. Get the list the
  1619.   ;; other way around instead!
  1620.   (let ((result nil))
  1621.     (while tins
  1622.       (let ((type (cvs-fileinfo->type
  1623.            (tin-cookie cvs-cookie-handle (car tins)))))
  1624.     (if (or (eq type 'MODIFIED)
  1625.         (eq type 'UPDATED)
  1626.         (eq type 'MERGED)
  1627.         (eq type 'CONFLICT)
  1628.         (eq type 'REMOVED)    ;+++Does this line make sense?
  1629.         (eq type 'ADDED))    ;+++Does this line make sense?
  1630.         (setq result (cons (car tins) result)))
  1631.     (setq tins (cdr tins))))
  1632.     (nreverse result)))
  1633.       
  1634.                      
  1635. (defun cvs-mode-diff-cvs (&optional ignore-marks)
  1636.   "Diff the selected files against the repository.
  1637. The flags in the variable cvs-diff-flags (which should be a list
  1638. of strings) will be passed to ``cvs diff''.  If the variable
  1639. cvs-diff-ignore-marks is non-nil any marked files will not be
  1640. considered to be selected.  An optional prefix argument will invert
  1641. the influence from cvs-diff-ignore-marks."
  1642.  
  1643.   (interactive "P")
  1644.  
  1645.   (if (not (listp cvs-diff-flags))
  1646.       (error "cvs-diff-flags should be a list of strings"))
  1647.  
  1648.   (save-some-buffers)
  1649.   (let ((marked (cvs-diffable
  1650.          (cvs-get-marked
  1651.           (or (and ignore-marks (not cvs-diff-ignore-marks))
  1652.               (and (not ignore-marks) cvs-diff-ignore-marks))))))
  1653.     (cvs-use-temp-buffer)
  1654.     (message "cvsdiffing...")
  1655.     ;; Don't care much about the exit status since it is the _sum_ of
  1656.     ;; the status codes from the different files (not the _max_ as it
  1657.     ;; should be).
  1658.     (if (cvs-execute-list marked cvs-program
  1659.               (if cvs-cvsroot
  1660.                   (cons "-d" (cons cvs-cvsroot
  1661.                            (cons "diff" cvs-diff-flags)))
  1662.                 (cons "diff" cvs-diff-flags)))
  1663.     (message "cvsdiffing... Done.")
  1664.       (message "cvsdiffing... No differences found."))))
  1665.  
  1666.  
  1667. (defun cvs-backup-diffable (tin)
  1668.   "Check if the TIN is backup-diffable.
  1669. It must have a backup file to be diffable."
  1670.   (let ((file (cvs-fileinfo->backup-file (tin-cookie cvs-cookie-handle tin))))
  1671.     (and file (file-readable-p file))))
  1672.  
  1673. (defun cvs-mode-diff-backup (&optional ignore-marks)
  1674.   "Diff the files against the backup file.
  1675. This command can be used on files that are marked with \"Merged\"
  1676. or \"Conflict\" in the *cvs* buffer.
  1677.  
  1678. If the variable cvs-diff-ignore-marks is non-nil any marked files will
  1679. not be considered to be selected.  An optional prefix argument will
  1680. invert the influence from cvs-diff-ignore-marks.
  1681.  
  1682. The flags in cvs-diff-flags will be passed to ``diff''."
  1683.  
  1684.   (interactive "P")
  1685.  
  1686.   (if (not (listp cvs-diff-flags))
  1687.       (error "cvs-diff-flags should be a list of strings."))
  1688.  
  1689.   (save-some-buffers)
  1690.   (let ((marked (cvs-filter
  1691.          (function cvs-backup-diffable)
  1692.          (cvs-get-marked
  1693.           (or
  1694.            (and ignore-marks (not cvs-diff-ignore-marks))
  1695.            (and (not ignore-marks) cvs-diff-ignore-marks))))))
  1696.     (if (null marked)
  1697.     (error "No ``Conflict'' or ``Merged'' file selected!"))
  1698.     (cvs-use-temp-buffer)
  1699.     (message "diffing...")
  1700.     (cvs-execute-single-file-list
  1701.      marked 'cvs-diff-backup-extractor cvs-diff-program cvs-diff-flags))
  1702.   (message "diffing... Done."))
  1703.  
  1704.  
  1705. (defun cvs-diff-backup-extractor (fileinfo)
  1706.   "Return the filename and the name of the backup file as a list.
  1707. Signal an error if there is no backup file."
  1708.   (if (not (file-readable-p (cvs-fileinfo->backup-file fileinfo)))
  1709.       (error "%s has no backup file."
  1710.          (concat
  1711.           (file-name-as-directory (cvs-fileinfo->dir fileinfo))
  1712.           (cvs-fileinfo->file-name fileinfo))))
  1713.   (list    (cvs-fileinfo->backup-file fileinfo)
  1714.      (cvs-fileinfo->file-name fileinfo)))
  1715.  
  1716. (defun cvs-mode-find-file-other-window (pos)
  1717.   "Select a buffer containing the file in another window.
  1718. Args: POS"
  1719.   (interactive "d")
  1720.   (let ((tin (tin-locate cvs-cookie-handle pos)))
  1721.     (if tin
  1722.     (let ((type (cvs-fileinfo->type (tin-cookie cvs-cookie-handle
  1723.                                 tin))))
  1724.       (cond
  1725.        ((or (eq type 'REMOVED)
  1726.         (eq type 'CVS-REMOVED))
  1727.         (error "Can't visit a removed file."))
  1728.        ((eq type 'DIRCHANGE)
  1729.         (let ((obuf (current-buffer))
  1730.           (odir default-directory))
  1731.           (setq default-directory
  1732.             (file-name-as-directory
  1733.              (cvs-fileinfo->dir
  1734.               (tin-cookie cvs-cookie-handle tin))))
  1735.           (dired-other-window default-directory)
  1736.           (set-buffer obuf)
  1737.           (setq default-directory odir)))
  1738.        (t
  1739.         (find-file-other-window (cvs-full-path tin)))))
  1740.       (error "There is no file to find."))))
  1741.  
  1742. (defun cvs-fileinfo->full-path (fileinfo)
  1743.   "Return the full path for the file that is described in FILEINFO."
  1744.   (concat
  1745.    (file-name-as-directory
  1746.     (cvs-fileinfo->dir fileinfo))
  1747.    (cvs-fileinfo->file-name fileinfo)))
  1748.  
  1749. (defun cvs-full-path (tin)
  1750.   "Return the full path for the file that is described in TIN."
  1751.   (cvs-fileinfo->full-path (tin-cookie cvs-cookie-handle tin)))
  1752.  
  1753. (defun cvs-mode-find-file (pos)
  1754.   "Select a buffer containing the file in another window.
  1755. Args: POS"
  1756.   (interactive "d")
  1757.   (let* ((cvs-buf (current-buffer))
  1758.      (tin (tin-locate cvs-cookie-handle pos)))
  1759.     (if tin
  1760.     (let* ((fileinfo (tin-cookie cvs-cookie-handle tin))
  1761.            (type (cvs-fileinfo->type fileinfo)))
  1762.       (cond
  1763.        ((or (eq type 'REMOVED)
  1764.         (eq type 'CVS-REMOVED))
  1765.         (error "Can't visit a removed file."))
  1766.        ((eq type 'DIRCHANGE)
  1767.         (let ((odir default-directory))
  1768.           (setq default-directory
  1769.             (file-name-as-directory (cvs-fileinfo->dir fileinfo)))
  1770.           (dired default-directory)
  1771.           (set-buffer cvs-buf)
  1772.           (setq default-directory odir))) 
  1773.        (t
  1774.         (find-file (cvs-full-path tin)))))
  1775.       (error "There is no file to find."))))
  1776.  
  1777. (defun cvs-mode-mark-all-files ()
  1778.   "Mark all files.
  1779. Directories are not marked."
  1780.   (interactive)
  1781.   (cookie-map (function (lambda (cookie)
  1782.               (cond
  1783.                ((not (eq (cvs-fileinfo->type cookie) 'DIRCHANGE))
  1784.                 (cvs-set-fileinfo->marked cookie t)
  1785.                 t))))
  1786.           cvs-cookie-handle))
  1787.  
  1788.  
  1789. (defun cvs-mode-unmark (pos)
  1790.   "Unmark a fileinfo. Args: POS."
  1791.   (interactive "d")
  1792.  
  1793.   (let* ((tin (tin-locate cvs-cookie-handle pos))
  1794.      (sel (tin-cookie cvs-cookie-handle tin)))
  1795.  
  1796.     (cond
  1797.      ((eq (cvs-fileinfo->type sel) 'DIRCHANGE)
  1798.       (cookie-map
  1799.        (function (lambda (f dir)
  1800.            (cond
  1801.             ((cvs-dir-member-p f dir)
  1802.              (cvs-set-fileinfo->marked f nil)
  1803.              t))))
  1804.        cvs-cookie-handle
  1805.        (cvs-fileinfo->dir sel)))
  1806.      (t
  1807.       (cvs-set-fileinfo->marked sel nil)
  1808.       (tin-invalidate cvs-cookie-handle tin)
  1809.       (tin-goto-next cvs-cookie-handle pos 1)))))
  1810.  
  1811. (defun cvs-mode-unmark-all-files ()
  1812.   "Unmark all files.
  1813. Directories are also unmarked, but that doesn't matter, since
  1814. they should always be unmarked."
  1815.   (interactive)
  1816.   (cookie-map (function (lambda (cookie)
  1817.               (cvs-set-fileinfo->marked cookie nil)
  1818.               t))
  1819.           cvs-cookie-handle))
  1820.  
  1821.  
  1822. (defun cvs-do-removal (tins)
  1823.   "Remove files.
  1824. Args: TINS.
  1825. TINS is a list of tins that the
  1826. user wants to delete. The files are deleted. If the type of
  1827. the tin is 'UNKNOWN the tin is removed from the buffer. If it
  1828. is anything else the file is added to a list that should be
  1829. `cvs remove'd and the tin is changed to be of type 'REMOVED.
  1830.  
  1831. Returns a list of tins files that should be `cvs remove'd."
  1832.   (cvs-use-temp-buffer)
  1833.   (mapcar 'cvs-insert-full-path tins)
  1834.   (cond
  1835.    ((and tins (yes-or-no-p (format "Delete %d files? " (length tins))))
  1836.     (let (files-to-remove)
  1837.       (while tins
  1838.     (let* ((tin (car tins))
  1839.            (fileinfo (tin-cookie cvs-cookie-handle tin))
  1840.            (type (cvs-fileinfo->type fileinfo)))
  1841.       (if (not (or (eq type 'REMOVED) (eq type 'CVS-REMOVED)))
  1842.           (progn
  1843.         (delete-file (cvs-full-path tin))
  1844.         (cond
  1845.          ((or (eq type 'UNKNOWN) (eq type 'MOVE-AWAY))
  1846.           (tin-delete cvs-cookie-handle tin))
  1847.          (t
  1848.           (setq files-to-remove (cons tin files-to-remove))
  1849.           (cvs-set-fileinfo->type fileinfo 'REMOVED)
  1850.           (cvs-set-fileinfo->handled fileinfo nil)
  1851.           (tin-invalidate cvs-cookie-handle tin))))))
  1852.     (setq tins (cdr tins)))
  1853.       files-to-remove))
  1854.    (t nil)))
  1855.  
  1856.  
  1857.  
  1858. (defun cvs-mode-remove-file ()
  1859.   "Remove all marked files."
  1860.   (interactive)
  1861.   (let ((files-to-remove (cvs-do-removal (cvs-get-marked))))
  1862.     (if (null files-to-remove)
  1863.     nil
  1864.       (cvs-use-temp-buffer)
  1865.       (message "removing from repository...")
  1866.       (if (cvs-execute-list files-to-remove cvs-program
  1867.                 (if cvs-cvsroot
  1868.                 (list "-d" cvs-cvsroot "remove")
  1869.                   '("remove")))
  1870.       (error "CVS exited with non-zero exit status.")
  1871.     (message "removing from repository... done.")))))
  1872.  
  1873. (defun cvs-mode-undo-local-changes ()
  1874.   "Undo local changes to all marked files.
  1875. The file is removed and `cvs update FILE' is run."
  1876.   (interactive)
  1877.   (let ((tins-to-undo (cvs-get-marked)))
  1878.     (cvs-use-temp-buffer)
  1879.     (mapcar 'cvs-insert-full-path tins-to-undo)
  1880.     (cond
  1881.      ((and tins-to-undo (yes-or-no-p (format "Undo changes to %d files? "
  1882.                          (length tins-to-undo))))
  1883.       (let (files-to-update)
  1884.     (while tins-to-undo
  1885.       (let* ((tin (car tins-to-undo))
  1886.          (fileinfo (tin-cookie cvs-cookie-handle tin))
  1887.          (type (cvs-fileinfo->type fileinfo)))
  1888.         (cond
  1889.          ((or
  1890.            (eq type 'UPDATED) (eq type 'MODIFIED) (eq type 'MERGED)
  1891.            (eq type 'CONFLICT) (eq type 'CVS-REMOVED)
  1892.            (eq type 'REM-CONFLICT) (eq type 'MOVE-AWAY)
  1893.            (eq type 'REMOVED))
  1894.           (if (not (eq type 'REMOVED))
  1895.           (delete-file (cvs-full-path tin)))
  1896.           (setq files-to-update (cons tin files-to-update))
  1897.           (cvs-set-fileinfo->type fileinfo 'UPDATED)
  1898.           (cvs-set-fileinfo->handled fileinfo t)
  1899.           (tin-invalidate cvs-cookie-handle tin))
  1900.  
  1901.          ((eq type 'MOD-CONFLICT)
  1902.           (error "Use cvs-mode-add instead on %s."
  1903.              (cvs-fileinfo->file-name fileinfo)))
  1904.  
  1905.          ((eq type 'REM-CONFLICT)
  1906.           (error "Can't deal with a file you have removed and recreated."))
  1907.  
  1908.          ((eq type 'DIRCHANGE)
  1909.           (error "Undo on directories not supported (yet)."))
  1910.  
  1911.          ((eq type 'ADDED)
  1912.           (error "There is no old revision to get for %s"
  1913.              (cvs-fileinfo->file-name fileinfo)))
  1914.          (t (error "cvs-mode-undo-local-changes: can't handle an %s"
  1915.                type)))
  1916.  
  1917.         (setq tins-to-undo (cdr tins-to-undo))))
  1918.     (cvs-use-temp-buffer)
  1919.     (message "Regetting files from repository...")
  1920.     (if (cvs-execute-list files-to-update cvs-program
  1921.                   (if cvs-cvsroot
  1922.                   (list "-d" cvs-cvsroot "update")
  1923.                 '("update")))
  1924.         (error "CVS exited with non-zero exit status.")
  1925.       (message "Regetting files from repository... done.")))))))
  1926.  
  1927. (defun cvs-mode-acknowledge ()
  1928.   "Remove all marked files from the buffer."
  1929.   (interactive)
  1930.  
  1931.   (mapcar (function (lambda (tin)
  1932.               (tin-delete cvs-cookie-handle tin)))
  1933.       (cvs-get-marked)))
  1934.  
  1935.  
  1936. (defun cvs-mode-unmark-up (pos)
  1937.   "Unmark the file on the previous line.
  1938. Takes one argument POS, a buffer position."
  1939.   (interactive "d")
  1940.   (let ((tin (tin-goto-previous cvs-cookie-handle pos 1)))
  1941.     (cond
  1942.      (tin
  1943.       (cvs-set-fileinfo->marked (tin-cookie cvs-cookie-handle tin)
  1944.                 nil)
  1945.       (tin-invalidate cvs-cookie-handle tin)))))
  1946.  
  1947. (defun cvs-mode-previous-line (arg)
  1948.   "Go to the previous line.
  1949. If a prefix argument is given, move by that many lines."
  1950.   (interactive "p")
  1951.   (tin-goto-previous cvs-cookie-handle (point) arg))
  1952.  
  1953. (defun cvs-mode-next-line (arg)
  1954.   "Go to the next line.
  1955. If a prefix argument is given, move by that many lines."
  1956.   (interactive "p")
  1957.   (tin-goto-next cvs-cookie-handle (point) arg))
  1958.  
  1959. (defun cvs-add-file-update-buffer (tin)
  1960.   "Subfunction to cvs-mode-add. Internal use only.
  1961. Update the display. Return non-nil if `cvs add' should be called on this
  1962. file. Args: TIN.
  1963. Returns 'ADD or 'RESURRECT."
  1964.   (let ((fileinfo (tin-cookie cvs-cookie-handle tin)))
  1965.     (cond
  1966.      ((eq (cvs-fileinfo->type fileinfo) 'UNKNOWN)
  1967.       (cvs-set-fileinfo->type fileinfo 'ADDED)
  1968.       (tin-invalidate cvs-cookie-handle tin)
  1969.       'ADD)
  1970.      ((eq (cvs-fileinfo->type fileinfo) 'REMOVED)
  1971.       (cvs-set-fileinfo->type fileinfo 'UPDATED)
  1972.       (cvs-set-fileinfo->handled fileinfo t)
  1973.       (tin-invalidate cvs-cookie-handle tin)
  1974.       'RESURRECT))))
  1975.  
  1976. (defun cvs-add-sub (cvs-buf candidates)
  1977.   "Internal use only.
  1978. Args: CVS-BUF CANDIDATES.
  1979. CANDIDATES is a list of tins. Updates the CVS-BUF and returns a pair of lists.
  1980. The first list is unknown tins that shall be `cvs add -m msg'ed.
  1981. The second list is removed files that shall be `cvs add'ed (resurrected)."
  1982.   (let (add resurrect)
  1983.     (while candidates
  1984.       (let ((type (cvs-add-file-update-buffer (car candidates))))
  1985.     (cond ((eq type 'ADD)
  1986.            (setq add (cons (car candidates) add)))
  1987.           ((eq type 'RESURRECT)
  1988.            (setq resurrect (cons (car candidates) resurrect)))))
  1989.       (setq candidates (cdr candidates)))
  1990.     (cons add resurrect)))
  1991.  
  1992. (defun cvs-mode-add ()
  1993.   "Add marked files to the cvs repository."
  1994.   (interactive)
  1995.  
  1996.   (let* ((buf (current-buffer))
  1997.      (result (cvs-add-sub buf (cvs-get-marked)))
  1998.      (added (car result))
  1999.      (resurrect (cdr result))
  2000.      (msg (if added (read-from-minibuffer "Enter description: "))))
  2001.  
  2002.     (if (or resurrect added)
  2003.     (cvs-use-temp-buffer))
  2004.  
  2005.     (cond (resurrect
  2006.        (message "Resurrecting files from repository...")
  2007.        (if (cvs-execute-list resurrect cvs-program
  2008.                  (if cvs-cvsroot
  2009.                      (list "-d" cvs-cvsroot "add")
  2010.                    '("add")))
  2011.            (error "CVS exited with non-zero exit status.")
  2012.          (message "Done."))))
  2013.  
  2014.     (cond (added
  2015.        (message "Adding new files to repository...")
  2016.        (if (cvs-execute-list added cvs-program
  2017.                  (if cvs-cvsroot
  2018.                      (list "-d" cvs-cvsroot "add" "-m" msg)
  2019.                    (list "add" "-m" msg)))
  2020.            (error "CVS exited with non-zero exit status.")
  2021.          (message "Done."))))))
  2022.  
  2023. (defun cvs-mode-ignore ()
  2024.   "Arrange so that CVS ignores the selected files.
  2025. This command ignores files that are not flagged as `Unknown'."
  2026.   (interactive)
  2027.  
  2028.   (mapcar (function (lambda (tin)
  2029.               (cond
  2030.                ((eq (cvs-fileinfo->type
  2031.                  (tin-cookie cvs-cookie-handle tin))
  2032.                 'UNKNOWN)
  2033.             (cvs-append-to-ignore
  2034.              (tin-cookie cvs-cookie-handle tin))
  2035.             (tin-delete cvs-cookie-handle tin)))))
  2036.       (cvs-get-marked)))
  2037.  
  2038. (defun cvs-append-to-ignore (fileinfo)
  2039.   "Append the file in fileinfo to the .cvsignore file"
  2040.   (save-window-excursion
  2041.     (set-buffer (find-file-noselect (concat (file-name-as-directory
  2042.                          (cvs-fileinfo->dir fileinfo))
  2043.                         ".cvsignore")))
  2044.     (goto-char (point-max))
  2045.     (if (not (zerop (current-column)))
  2046.     (insert "\n"))
  2047.     (insert (cvs-fileinfo->file-name fileinfo) "\n")
  2048.     (if cvs-sort-ignore-file
  2049.     (sort-lines nil (point-min) (point-max)))
  2050.     (save-buffer)))
  2051.  
  2052. (defun cvs-mode-status ()
  2053.   "Show cvs status for all marked files."
  2054.   (interactive)
  2055.  
  2056.   (save-some-buffers)
  2057.   (let ((marked (cvs-get-marked)))
  2058.     (cvs-use-temp-buffer)
  2059.     (message "Running cvs status ...")
  2060.     (if (cvs-execute-list
  2061.      marked cvs-program
  2062.      (if cvs-cvsroot
  2063.          (cons "-d" (cons cvs-cvsroot (cons "status" cvs-status-flags)))
  2064.        (cons "status" cvs-status-flags)))
  2065.     (error "CVS exited with non-zero exit status.")
  2066.       (message "Running cvs status ... Done."))))
  2067.  
  2068. (defun cvs-mode-log ()
  2069.   "Display the cvs log of all selected files."
  2070.   (interactive)
  2071.  
  2072.   (let ((marked (cvs-get-marked)))
  2073.     (cvs-use-temp-buffer)
  2074.     (message "Running cvs log ...")
  2075.     (if (cvs-execute-list marked cvs-program
  2076.               (if cvs-cvsroot
  2077.                   (cons "-d" (cons cvs-cvsroot
  2078.                            (cons "log" cvs-log-flags)))
  2079.                 (cons "log" cvs-log-flags)))
  2080.     (error "CVS exited with non-zero exit status.")
  2081.       (message "Running cvs log ... Done."))))
  2082.  
  2083. (defun cvs-byte-compile-files ()
  2084.   "Run byte-compile-file on all selected files that end in '.el'."
  2085.   (interactive)
  2086.   (let ((marked (cvs-get-marked)))
  2087.     (while marked
  2088.       (let ((filename (cvs-full-path (car marked))))
  2089.     (if (string-match "\\.el$" filename)
  2090.         (byte-compile-file filename)))
  2091.       (setq marked (cdr marked)))))
  2092.  
  2093. (defun cvs-insert-full-path (tin)
  2094.   "Insert full path to the file described in TIN in the current buffer."
  2095.   (insert (format "%s\n" (cvs-full-path tin))))
  2096.  
  2097.  
  2098. (defun cvs-mode-add-change-log-entry-other-window (pos)
  2099.   "Add a ChangeLog entry in the ChangeLog of the current directory.
  2100. Args: POS."
  2101.   (interactive "d")
  2102.   (let* ((cvs-buf (current-buffer))
  2103.      (odir default-directory))
  2104.     (setq default-directory
  2105.       (file-name-as-directory
  2106.        (cvs-fileinfo->dir
  2107.         (tin-cookie
  2108.          cvs-cookie-handle
  2109.          (tin-locate cvs-cookie-handle pos)))))
  2110.     (if (not default-directory)        ;In case there was no entries.
  2111.     (setq default-directory odir))
  2112.     (add-change-log-entry-other-window)
  2113.     (set-buffer cvs-buf)
  2114.     (setq default-directory odir)))
  2115.  
  2116.  
  2117. (defun print-cvs-tin (foo)
  2118.   "Debug utility."
  2119.   (let ((cookie (tin-cookie cvs-cookie-handle foo))
  2120.     (stream (get-buffer-create "debug")))
  2121.     (princ "==============\n" stream)
  2122.     (princ (cvs-fileinfo->file-name cookie) stream)
  2123.     (princ "\n" stream)
  2124.     (princ (cvs-fileinfo->dir cookie) stream)
  2125.     (princ "\n" stream)
  2126.     (princ (cvs-fileinfo->full-log cookie) stream)
  2127.     (princ "\n" stream)
  2128.     (princ (cvs-fileinfo->marked cookie) stream)
  2129.     (princ "\n" stream)))
  2130.  
  2131. (defun cvs-mode-emerge (pos)
  2132.   "Emerge appropriate revisions of the selected file.
  2133. Args: POS"
  2134.   (interactive "d")
  2135.   (let* ((cvs-buf (current-buffer))
  2136.      (tin (tin-locate cvs-cookie-handle pos)))
  2137.     (if tin
  2138.     (let* ((fileinfo (tin-cookie cvs-cookie-handle tin))
  2139.            (type (cvs-fileinfo->type fileinfo)))
  2140.       (cond
  2141.        ((eq type 'MODIFIED)
  2142.         (require 'emerge)
  2143.         (let ((tmp-file
  2144.            (cvs-retrieve-revision-to-tmpfile fileinfo)))
  2145.           (unwind-protect
  2146.           (if (not (emerge-files
  2147.                 t
  2148.                 (cvs-fileinfo->full-path fileinfo)
  2149.                 tmp-file
  2150.                 (cvs-fileinfo->full-path fileinfo)))
  2151.               (error "Emerge session failed"))
  2152.         (delete-file tmp-file))))
  2153.  
  2154.        ((or (eq type 'MERGED)
  2155.         (eq type 'CONFLICT))
  2156.         (require 'emerge)
  2157.         (let ((tmp-file
  2158.            (cvs-retrieve-revision-to-tmpfile
  2159.             fileinfo))
  2160.           (ancestor-file
  2161.            (cvs-retrieve-revision-to-tmpfile
  2162.             fileinfo
  2163.             (cvs-fileinfo->base-revision fileinfo))))
  2164.           (unwind-protect
  2165.           (if (not (emerge-files-with-ancestor
  2166.                 t
  2167.                 (cvs-fileinfo->backup-file fileinfo)
  2168.                 tmp-file
  2169.                 ancestor-file
  2170.                 (cvs-fileinfo->full-path fileinfo)))
  2171.               (error "Emerge session failed"))
  2172.         (delete-file tmp-file)
  2173.         (delete-file ancestor-file))))
  2174.        (t
  2175.         (error "Can only emerge \"Modified\", \"Merged\" or \"Conflict\"%s"
  2176.            " files"))))
  2177.       (error "There is no file to emerge."))))
  2178.  
  2179. (defun cvs-retrieve-revision-to-tmpfile (fileinfo &optional revision)
  2180.   "Retrieve the latest revision of the file in FILEINFO to a temporary file.
  2181. If second optional argument REVISION is given, retrieve that revision instead."
  2182.   (let
  2183.       ((temp-name (make-temp-name
  2184.            (concat (file-name-as-directory
  2185.                 (or (getenv "TMPDIR") "/tmp"))
  2186.                "pcl-cvs." revision))))
  2187.     (cvs-kill-buffer-visiting temp-name)
  2188.     (if revision
  2189.     (message "Retrieving revision %s..." revision)
  2190.       (message "Retrieving latest revision..."))
  2191.     (let ((res (call-process cvs-shell nil nil nil "-c"
  2192.                  (concat cvs-program " update -p "
  2193.                      (if revision
  2194.                      (concat "-r " revision " ")
  2195.                        "")
  2196.                      (cvs-fileinfo->full-path fileinfo)
  2197.                      " > " temp-name))))
  2198.       (if (and res (not (and (integerp res) (zerop res))))
  2199.       (error "Something went wrong: %s" res))
  2200.  
  2201.       (if revision
  2202.       (message "Retrieving revision %s... Done." revision)
  2203.     (message "Retrieving latest revision... Done."))
  2204.       (find-file-noselect temp-name)
  2205.       temp-name)))
  2206.  
  2207. (defun cvs-fileinfo->backup-file (fileinfo)
  2208.   "Construct the file name of the backup file for FILEINFO."
  2209.   (if (cvs-fileinfo->base-revision fileinfo)
  2210.       (concat cvs-bakprefix (cvs-fileinfo->file-name fileinfo)
  2211.           "." (cvs-fileinfo->base-revision fileinfo))))
  2212.  
  2213. (defun cvs-kill-buffer-visiting (filename)
  2214.   "If there is any buffer visiting FILENAME, kill it (without confirmation)."
  2215.   (let ((l (buffer-list)))
  2216.     (while l
  2217.       (if (string= (buffer-file-name (car l)) filename)
  2218.       (kill-buffer (car l)))
  2219.       (setq l (cdr l)))))
  2220.  
  2221. (defun cvs-change-cvsroot (newroot)
  2222.   "Change the cvsroot."
  2223.   (interactive "DNew repository: ")
  2224.   (if (or (file-directory-p (expand-file-name "CVSROOT" newroot))
  2225.       (y-or-n-p (concat "Warning: no CVSROOT found inside repository."
  2226.                 " Change cvs-cvsroot anyhow?")))
  2227.       (setq cvs-cvsroot newroot)))
  2228.  
  2229. (if (string-match "XEmacs" emacs-version)
  2230.     (progn
  2231.       (autoload 'pcl-cvs-fontify "pcl-cvs-lucid")
  2232.       (add-hook 'cvs-mode-hook 'pcl-cvs-fontify)))
  2233.