home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / cvs-1.8.7-src.tgz / tar.out / fsf / cvs / tools / pcl-cvs / pcl-cvs.el < prev    next >
Lisp/Scheme  |  1996-09-28  |  122KB  |  3,451 lines

  1. ;;;
  2. ;;;#ident "@(#)OrigId: pcl-cvs.el,v 1.93 1993/05/31 22:44:00 ceder Exp "
  3. ;;;
  4. ;;;#ident "@(#)cvs/contrib/pcl-cvs:$Name:  $:$Id: pcl-cvs.el,v 1.3 1996/08/09 14:45:20 jimb Exp $"
  5. ;;;
  6. ;;; pcl-cvs.el -- A Front-end to CVS 1.3 or later.
  7. ;;; Release 1.05-CVS-$Name:  $.
  8. ;;; Copyright (C) 1991, 1992, 1993  Per Cederqvist
  9.  
  10. ;;; This program is free software; you can redistribute it and/or modify
  11. ;;; it under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 2 of the License, or
  13. ;;; (at your option) any later version.
  14. ;;;
  15. ;;; This program is distributed in the hope that it will be useful,
  16. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ;;; GNU General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with this program; if not, write to the Free Software
  22. ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. ;;; See below for installation instructions.
  25.  
  26. ;;; This package requires ELIB-1.0 to run.  Elib is included in the
  27. ;;; CVS distribution in the contrib/elib/ subdirectory, but you can
  28. ;;; also download it at the following URL:
  29. ;;;
  30. ;;;       ftp://ftp.lysator.liu.se/pub/emacs/elib-1.0.tar.gz
  31. ;;;
  32.  
  33. ;;; There is an TeXinfo file that describes this package.  You should read it
  34. ;;; to get the most from this package.
  35.  
  36. ;;; Mail questions and bug reports regarding this version (as included in
  37. ;;; CVS-1.7 or newer) to the pcl-cvs support team at <pcl-cvs@cyclic.com>.
  38.  
  39. ;;; Don't try to use this with CVS 1.2 or earlier.  It won't work.  Get CVS 1.7
  40. ;;; or newer.  Use the version of RCS best suited for the version of CVS you're
  41. ;;; using.
  42.  
  43. (require 'cookie)            ; from ELIB-1.0
  44. (require 'add-log)            ; for all the ChangeLog goodies
  45.  
  46. ;;; -------------------------------------------------------
  47. ;;;        START OF THINGS TO CHECK WHEN INSTALLING
  48.  
  49. ;; also use $GNU here, since may folks might install CVS as a GNU package
  50. ;;
  51. (defvar local-path (cond
  52.               ((getenv "LOCAL")
  53.                (getenv "LOCAL"))
  54.               ((getenv "GNU")
  55.                (getenv "GNU"))
  56.               (t
  57.                "/usr/local"))
  58.   "*Path prefix for most locally installed things.")
  59.  
  60. ;; this isn't likely to be right all the time....
  61. ;;
  62. (defvar local-gnu-path (cond
  63.               ((getenv "GNU")
  64.                (getenv "GNU"))
  65.               (t
  66.                "/usr/local"))    ; or "/usr/gnu"?
  67.   "*Path prefix for locally installed GNU software.")
  68.  
  69. (defvar cvs-program (concat local-path "/bin/cvs")
  70.   "*Full path to the cvs executable.")
  71.  
  72. ;; SunOS-4.1.1_U1 has "diff.c 1.12 88/08/04 SMI; from UCB 4.6 86/04/03"
  73. ;;
  74. (defvar cvs-diff-program (concat local-gnu-path "/bin/diff")
  75.   "*Full path to the best diff program you've got.
  76. NOTE:  there are some nasty bugs in the context diff variants of some vendor
  77. versions, such as the one in SunOS-4.1.1_U1")
  78.  
  79. (defvar cvs-rmdir-program "/bin/rmdir"
  80.   "*Full path to the rmdir program.  Typically /bin/rmdir.")
  81.  
  82. (defvar cvs-shell "/bin/sh"
  83.   "*Full path to a shell that can do redirection on stdout.")
  84.  
  85. ;;; Options to control various features:
  86.  
  87. (defvar cvs-changelog-full-paragraphs t
  88.   "If non-nil, include full ChangeLog paragraphs in the CVS log.
  89. This may be set in the ``local variables'' section of a ChangeLog, to
  90. indicate the policy for that ChangeLog.
  91.  
  92. A ChangeLog paragraph is a bunch of log text containing no blank lines;
  93. a paragraph usually describes a set of changes with a single purpose,
  94. but perhaps spanning several functions in several files.  Changes in
  95. different paragraphs are unrelated.
  96.  
  97. You could argue that the CVS log entry for a file should contain the
  98. full ChangeLog paragraph mentioning the change to the file, even though
  99. it may mention other files, because that gives you the full context you
  100. need to understand the change.  This is the behaviour you get when this
  101. variable is set to t.
  102.  
  103. On the other hand, you could argue that the CVS log entry for a change
  104. should contain only the text for the changes which occurred in that
  105. file, because the CVS log is per-file.  This is the behaviour you get
  106. when this variable is set to nil.")
  107.  
  108. (defvar cvs-cvsroot-required nil
  109.   "*Specifies whether CVS needs to be told where the repository is.
  110.  
  111. In CVS 1.3, if your CVSROOT environment variable is not set, and you
  112. do not set the `cvs-cvsroot' lisp variable, CVS will have no idea
  113. where to find the repository, and refuse to run.  CVS 1.4 and later
  114. store the repository path with the working directories, so most
  115. operations don't need to be told where the repository is.
  116.  
  117. If you work with multiple repositories with CVS 1.4, it's probably
  118. advisable to leave your CVSROOT environment variable unset, set this
  119. variable to nil, and let CVS figure out where the repository is for
  120. itself.")
  121.  
  122. (defvar cvs-cvsroot nil
  123.   "*Specifies where the (current) cvs master repository is.
  124. Overrides the $CVSROOT variable by sending \" -d dir\" to all cvs commands.
  125. This switch is useful if you have multiple CVS repositories, and are not using
  126. a modern version of CVS that stores the current repository in CVS/Root.")
  127.  
  128. ;; Uncomment the following line if you are running on 18.57 or earlier.
  129. ;(setq delete-exited-processes nil)
  130. ;; Emacs version 18.57 and earlier is likely to crash if
  131. ;; delete-exited-processes is t, since the sentinel uses lots of
  132. ;; memory, and 18.57 forgets to GCPROT a variable if
  133. ;; delete-exited-processes is t.
  134.  
  135. ;;;         END OF THINGS TO CHECK WHEN INSTALLING
  136. ;;; --------------------------------------------------------
  137.  
  138. (defconst pcl-cvs-version "1.05-CVS-$Name:  $"
  139.   "A string denoting the current release version of pcl-cvs.")
  140.  
  141. ;; You are NOT allowed to disable this message by default.  However, you
  142. ;; are encouraged to inform your users that by adding
  143. ;;    (setq cvs-inhibit-copyright-message t)
  144. ;; to their .emacs they can get rid of it.  Just don't add that line
  145. ;; to your default.el!
  146. (defvar cvs-inhibit-copyright-message nil
  147.   "*Non-nil means don't display a Copyright message in the ``*cvs*'' buffer.")
  148.  
  149. (defconst cvs-startup-message
  150.   (if cvs-inhibit-copyright-message
  151.       "PCL-CVS release 1.05-CVS-$Name:  $"
  152.     "PCL-CVS release 1.05 from CVS release $Name:  $.
  153. Copyright (C) 1992, 1993 Per Cederqvist
  154. Pcl-cvs comes with absolutely no warranty; for details consult the manual.
  155. This is free software, and you are welcome to redistribute it under certain
  156. conditions; again, consult the TeXinfo manual for details.")
  157.   "*Startup message for CVS.")
  158.  
  159. (defconst pcl-cvs-bugs-address "pcl-cvs-auto-bugs@cyclic.com"
  160.   "The destination address used for the default bug report form.")
  161.  
  162. (defvar cvs-stdout-file nil
  163.   "Name of the file that holds the output that CVS sends to stdout.
  164. This variable is buffer local.")
  165.  
  166. (defvar cvs-lock-file nil
  167.   "Full path to a lock file that CVS is waiting for (or was waiting for).")
  168.  
  169. (defvar cvs-bakprefix ".#"
  170.   "The prefix that CVS prepends to files when rcsmerge'ing.")
  171.  
  172. (defvar cvs-erase-input-buffer nil
  173.   "*Non-nil if input buffers should be cleared before asking for new info.")
  174.  
  175. (defvar cvs-auto-remove-handled nil
  176.   "*Non-nil if cvs-mode-remove-handled should be called automatically.
  177. If this is set to any non-nil value, entries that do not need to be checked in
  178. will be removed from the *cvs* buffer after every cvs-mode-commit command.")
  179.  
  180. (defvar cvs-auto-remove-handled-directories nil
  181.   "*Non-nil if cvs-mode-remove-handled and cvs-update should automatically
  182. remove empty directories.
  183. If this is set to any non-nil value, directories that do not contain any files
  184. to be checked in will be removed from the *cvs* buffer.")
  185.  
  186. (defvar cvs-sort-ignore-file t
  187.   "*Non-nil if cvs-mode-ignore should sort the .cvsignore automatically.")
  188.  
  189. (defvar cvs-auto-revert-after-commit t
  190.   "*Non-nil if committed buffers should be automatically reverted.")
  191.  
  192. (defconst cvs-cursor-column 14
  193.   "Column to position cursor in in cvs-mode.
  194. Column 0 is left-most column.")
  195.  
  196. (defvar cvs-mode-map nil
  197.   "Keymap for the cvs mode.")
  198.  
  199. (defvar cvs-edit-mode-map nil
  200.   "Keymap for the cvs edit mode (used when editing cvs log messages).")
  201.  
  202. (defvar cvs-buffer-name "*cvs*"
  203.   "Name of the cvs buffer.")
  204.  
  205. (defvar cvs-commit-prompt-buffer "*cvs-commit-message*"
  206.   "Name of buffer in which the user is prompted for a log message when
  207. committing files.")
  208.  
  209. (defvar cvs-commit-buffer-require-final-newline t
  210.   "*t says silently put a newline at the end of commit log messages.
  211. Non-nil but not t says ask user whether to add a newline in each such case.
  212. nil means don't add newlines.")
  213.  
  214. (defvar cvs-temp-buffer-name "*cvs-tmp*"
  215.   "*Name of the cvs temporary buffer.
  216. Output from cvs is placed here by synchronous commands.")
  217.  
  218. (defvar cvs-diff-ignore-marks nil
  219.   "*Non-nil if cvs-diff and cvs-mode-diff-backup should ignore any marked files.
  220. Normally they run diff on the files that are marked (with cvs-mode-mark),
  221. or the file under the cursor if no files are marked.  If this variable
  222. is set to a non-nil value they will always run diff on the file on the
  223. current line.")
  224.  
  225. ;;; (setq cvs-status-flags '("-v"))
  226. (defvar cvs-status-flags '("-v")
  227.   "*List of flags to pass to ``cvs status''.  Default is \"-v\".")
  228.  
  229. ;;; (setq cvs-log-flags nil)
  230. (defvar cvs-log-flags nil
  231.   "*List of flags to pass to ``cvs log''.  Default is none.")
  232.  
  233. ;;; (setq cvs-tag-flags nil)
  234. (defvar cvs-tag-flags nil
  235.   "*List of extra flags to pass to ``cvs tag''.  Default is none.")
  236.  
  237. ;;; (setq cvs-rtag-flags nil)
  238. (defvar cvs-rtag-flags nil
  239.   "*List of extra flags to pass to ``cvs rtag''.  Default is none.")
  240.  
  241. ;;; (setq cvs-diff-flags '("-u"))
  242. (defvar cvs-diff-flags '("-u")
  243.   "*List of flags to use as flags to pass to ``diff'' and ``cvs diff''.
  244. Used by cvs-mode-diff-cvs and cvs-mode-diff-backup.  Default is \"-u\".
  245.  
  246. Set this to \"-u\" to get a Unidiff format, or \"-c\" to get context diffs.")
  247.  
  248. ;;; (setq cvs-update-optional-flags nil)
  249. (defvar cvs-update-optional-flags nil
  250.   "*List of strings to use as optional flags to pass to ``cvs update''.  Used
  251. by cvs-do-update, called by cvs-update, cvs-update-other-window,
  252. cvs-mode-update-no-prompt, and cvs-examine.  Default is none.
  253.  
  254. For example set this to \"-j VENDOR_PREV_RELEASE -j VENDOR_TOP_RELEASE\" to
  255. perform an update after a new vendor release has been imported.
  256.  
  257. To restrict the update to the current working directory, set this to \"-l\".")
  258.  
  259. (defvar cvs-update-prog-output-skip-regexp "$"
  260.   "*A regexp that matches the end of the output from all cvs update programs.
  261. That is, output from any programs that are run by CVS (by the flag -u in the
  262. `modules' file - see cvs(5)) when `cvs update' is performed should terminate
  263. with a line that this regexp matches.  It is enough that some part of the line
  264. is matched.
  265.  
  266. The default (a single $) fits programs without output.")
  267.  
  268. ;;; --------------------------------------------------------
  269. ;;; The variables below are used internally by pcl-cvs.  You should
  270. ;;; never change them.
  271.  
  272. (defvar cvs-buffers-to-delete nil
  273.   "List of temporary buffers that should be discarded as soon as possible.
  274. Due to a bug in emacs 18.57 the sentinel can't discard them reliably.")
  275.  
  276. (defvar cvs-update-running nil
  277.   "This is set to nil when no process is running, and to
  278. the process when a cvs update process is running.")
  279.  
  280. (defvar cvs-cookie-handle nil
  281.   "Handle for the cookie structure that is displayed in the *cvs* buffer.")
  282.  
  283. (defvar cvs-commit-list nil
  284.   "Used internally by pcl-cvs.")
  285.  
  286. ;;; The cvs data structure:
  287. ;;;
  288. ;;; When the `cvs update' is ready we parse the output.  Every file
  289. ;;; that is affected in some way is added as a cookie of fileinfo
  290. ;;; (as defined below).
  291. ;;;
  292.  
  293. ;;; cvs-fileinfo
  294.  
  295. ;;; Constructor:
  296.  
  297. (defun cvs-create-fileinfo (type
  298.                 dir
  299.                 file-name
  300.                 full-log)
  301.   "Create a fileinfo from all parameters.
  302. Arguments:  TYPE DIR FILE-NAME FULL-LOG.
  303. A fileinfo is a vector with the following fields:
  304.  
  305. [0]  handled          True if this file doesn't require further action.
  306. [1]  marked          t/nil
  307. [2]  type          One of
  308.             UPDATED       - file copied from repository
  309.             PATCHED       - file update with patch from repository
  310.             MODIFIED   - modified by you, unchanged in
  311.                      repository
  312.             ADDED       - added by you, not yet committed
  313.             REMOVED       - removed by you, not yet committed
  314.             CVS-REMOVED- removed, since file no longer exists
  315.                      in the repository.
  316.             MERGED       - successful merge
  317.             CONFLICT   - conflict when merging (if pcl-cvs did it)
  318.             REM-CONFLICT-removed in repository, but altered
  319.                      locally.
  320.             MOD-CONFLICT-removed locally, changed in repository.
  321.                         REM-EXIST  - removed locally, but still exists.
  322.             DIRCHANGE  - A change of directory.
  323.             UNKNOWN       - An unknown file.
  324.             UNKNOWN-DIR- An unknown directory.
  325.             MOVE-AWAY  - A file that is in the way.
  326.             REPOS-MISSING- The directory has vanished from the
  327.                        repository.
  328.                         MESSAGE    - This is a special fileinfo that is used
  329.                          to display a text that should be in
  330.                                        full-log.
  331. [3]  dir          Directory the file resides in.  Should not end with slash.
  332. [4]  file-name          The file name.
  333. [5]  backup-file      The name of a backup file created during a merge.
  334.                         Only valid for MERGED and CONFLICT files.
  335. [6]  base-revision    The revision that the working file was based on.
  336.                         Only valid for MERGED and CONFLICT files.
  337. [7]  head-revision    The revision that the newly merged changes came from
  338.                         Only valid for MERGED and CONFLICT files.
  339. [8]  backup-revision  The revision of the cvs backup file (original working rev.)
  340.                         Only valid for MERGED and CONFLICT files.
  341. [9]  cvs-diff-buffer  A buffer that contains a 'cvs diff file'.
  342. [10] vendor-diff-buffer  A buffer that contains a 'diff base-file head-file'.
  343. [11] backup-diff-buffer  A buffer that contains a 'diff file backup-file'.
  344. [12] full-log          The output from cvs, unparsed.
  345. [13] mod-time          Modification time of file used for *-diff-buffer."
  346.  
  347.   (cons
  348.    'CVS-FILEINFO
  349.    (vector nil nil type dir file-name nil nil nil nil nil nil nil full-log nil nil)))
  350.  
  351. ;;; Selectors:
  352.  
  353. (defun cvs-fileinfo->handled (cvs-fileinfo)
  354.   "Get the  `handled' field from CVS-FILEINFO."
  355.   (elt (cdr cvs-fileinfo) 0))
  356.  
  357. (defun cvs-fileinfo->marked (cvs-fileinfo)
  358.   "Check if CVS-FILEINFO is marked."
  359.   (elt (cdr cvs-fileinfo) 1))
  360.  
  361. (defun cvs-fileinfo->type (cvs-fileinfo)
  362.   "Get type from CVS-FILEINFO.
  363. Type is one of UPDATED, PATCHED, MODIFIED, ADDED, REMOVED, CVS-REMOVED, MERGED,
  364. CONFLICT, REM-CONFLICT, MOD-CONFLICT, REM-EXIST, DIRCHANGE, UNKNOWN,
  365. UNKNOWN-DIR, MOVE-AWAY, REPOS-MISSING or MESSAGE."
  366.   (elt (cdr cvs-fileinfo) 2))
  367.  
  368. (defun cvs-fileinfo->dir (cvs-fileinfo)
  369.   "Get dir from CVS-FILEINFO.
  370. The directory name does not end with a slash."
  371.   (elt (cdr cvs-fileinfo) 3))
  372.  
  373. (defun cvs-fileinfo->file-name (cvs-fileinfo)
  374.   "Get file-name from CVS-FILEINFO."
  375.   (elt (cdr cvs-fileinfo) 4))
  376.  
  377. (defun cvs-fileinfo->backup-file (cvs-fileinfo)
  378.   "Get backup-file from CVS-FILEINFO."
  379.   (elt (cdr cvs-fileinfo) 5))
  380.  
  381. (defun cvs-fileinfo->base-revision (cvs-fileinfo)
  382.   "Get the base revision from CVS-FILEINFO."
  383.   (elt (cdr cvs-fileinfo) 6))
  384.  
  385. (defun cvs-fileinfo->head-revision (cvs-fileinfo)
  386.   "Get the head revision from CVS-FILEINFO."
  387.   (elt (cdr cvs-fileinfo) 7))
  388.  
  389. (defun cvs-fileinfo->backup-revision (cvs-fileinfo)
  390.   "Get the backup revision from CVS-FILEINFO."
  391.   (elt (cdr cvs-fileinfo) 8))
  392.  
  393. (defun cvs-fileinfo->cvs-diff-buffer (cvs-fileinfo)
  394.   "Get cvs-diff-buffer from CVS-FILEINFO."
  395.   (elt (cdr cvs-fileinfo) 9))
  396.  
  397. (defun cvs-fileinfo->vendor-diff-buffer (cvs-fileinfo)
  398.   "Get backup-diff-buffer from CVS-FILEINFO."
  399.   (elt (cdr cvs-fileinfo) 10))
  400.  
  401. (defun cvs-fileinfo->backup-diff-buffer (cvs-fileinfo)
  402.   "Get backup-diff-buffer from CVS-FILEINFO."
  403.   (elt (cdr cvs-fileinfo) 11))
  404.  
  405. (defun cvs-fileinfo->full-log (cvs-fileinfo)
  406.   "Get full-log from CVS-FILEINFO."
  407.   (elt (cdr cvs-fileinfo) 12))
  408.  
  409. (defun cvs-fileinfo->mod-time (cvs-fileinfo)
  410.   "Get mod-time from CVS-FILEINFO."
  411.   (elt (cdr cvs-fileinfo) 13))
  412.  
  413. ;;; Modifiers:
  414.  
  415. (defun cvs-set-fileinfo->handled (cvs-fileinfo newval)
  416.   "Set handled in CVS-FILEINFO to NEWVAL."
  417.   (aset (cdr cvs-fileinfo) 0 newval))
  418.  
  419. (defun cvs-set-fileinfo->marked (cvs-fileinfo newval)
  420.   "Set marked in CVS-FILEINFO to NEWVAL."
  421.   (aset (cdr cvs-fileinfo) 1 newval))
  422.  
  423. (defun cvs-set-fileinfo->type (cvs-fileinfo newval)
  424.   "Set type in CVS-FILEINFO to NEWVAL."
  425.   (aset (cdr cvs-fileinfo) 2 newval))
  426.  
  427. (defun cvs-set-fileinfo->dir (cvs-fileinfo newval)
  428.   "Set dir in CVS-FILEINFO to NEWVAL.
  429. The directory should now end with a slash."
  430.   (aset (cdr cvs-fileinfo) 3 newval))
  431.  
  432. (defun cvs-set-fileinfo->file-name (cvs-fileinfo newval)
  433.   "Set file-name in CVS-FILEINFO to NEWVAL."
  434.   (aset (cdr cvs-fileinfo) 4 newval))
  435.  
  436. (defun cvs-set-fileinfo->backup-file (cvs-fileinfo newval)
  437.   "Set backup-file in CVS-FILEINFO to NEWVAL."
  438.   (aset (cdr cvs-fileinfo) 5 newval))
  439.  
  440. (defun cvs-set-fileinfo->base-revision (cvs-fileinfo newval)
  441.   "Set base-revision in CVS-FILEINFO to NEWVAL."
  442.   (aset (cdr cvs-fileinfo) 6 newval))
  443.  
  444. (defun cvs-set-fileinfo->head-revision (cvs-fileinfo newval)
  445.   "Set head-revision in CVS-FILEINFO to NEWVAL."
  446.   (aset (cdr cvs-fileinfo) 7 newval))
  447.  
  448. (defun cvs-set-fileinfo->backup-revision (cvs-fileinfo newval)
  449.   "Set backup-revision in CVS-FILEINFO to NEWVAL."
  450.   (aset (cdr cvs-fileinfo) 8 newval))
  451.  
  452. (defun cvs-set-fileinfo->cvs-diff-buffer (cvs-fileinfo newval)
  453.   "Set cvs-diff-buffer in CVS-FILEINFO to NEWVAL."
  454.   (aset (cdr cvs-fileinfo) 9 newval))
  455.  
  456. (defun cvs-set-fileinfo->vendor-diff-buffer (cvs-fileinfo newval)
  457.   "Set vendor-diff-buffer in CVS-FILEINFO to NEWVAL."
  458.   (aset (cdr cvs-fileinfo) 10 newval))
  459.  
  460. (defun cvs-set-fileinfo->backup-diff-buffer (cvs-fileinfo newval)
  461.   "Set backup-diff-buffer in CVS-FILEINFO to NEWVAL."
  462.   (aset (cdr cvs-fileinfo) 11 newval))
  463.  
  464. (defun cvs-set-fileinfo->full-log (cvs-fileinfo newval)
  465.   "Set full-log in CVS-FILEINFO to NEWVAL."
  466.   (aset (cdr cvs-fileinfo) 12 newval))
  467.  
  468. (defun cvs-set-fileinfo->mod-time (cvs-fileinfo newval)
  469.   "Set full-log in CVS-FILEINFO to NEWVAL."
  470.   (aset (cdr cvs-fileinfo) 13 newval))
  471.  
  472. ;;; Predicate:
  473.  
  474. (defun cvs-fileinfo-p (object)
  475.   "Return t if OBJECT is a cvs-fileinfo."
  476.   (eq (car-safe object) 'CVS-FILEINFO))
  477.  
  478. ;;;; End of types.
  479.  
  480. ;;----------
  481. (defun cvs-use-temp-buffer ()
  482.   "Display a temporary buffer in another window and select it.
  483. The selected window will not be changed.  The temporary buffer will
  484. be erased and writable."
  485.  
  486.   (let ((dir default-directory))
  487.     (display-buffer (get-buffer-create cvs-temp-buffer-name))
  488.     (set-buffer cvs-temp-buffer-name)
  489.     (setq buffer-read-only nil)
  490.     (setq default-directory dir)
  491.     (erase-buffer)))
  492.  
  493. ;;----------
  494. (defun cvs-examine (directory &optional local)
  495.   "Run a 'cvs -n update' in the current working directory.
  496. That is, check what needs to be done, but don't change the disc.
  497. Feed the output to a *cvs* buffer and run cvs-mode on it.
  498. If optional prefix argument LOCAL is non-nil, 'cvs update -l' is run.
  499. WARNING:  this doesn't work very well yet...."
  500.  
  501.   ;; TODO:  this should do everything cvs-update does...
  502.   ;; for example, for CONFLICT files, it should setup fileinfo appropriately
  503.  
  504.   (interactive (list (read-file-name "CVS Update (directory): "
  505.                      nil default-directory nil)
  506.              current-prefix-arg))
  507.   (cvs-do-update directory local 'noupdate))
  508.  
  509. ;;----------
  510. (defun cvs-update (directory &optional local)
  511.   "Run a 'cvs update' in the current working directory.  Feed the
  512. output to a *cvs* buffer and run cvs-mode on it.
  513. If optional prefix argument LOCAL is non-nil, 'cvs update -l' is run."
  514.  
  515.   (interactive (list (read-file-name "CVS Update (directory): "
  516.                      nil default-directory nil)
  517.              current-prefix-arg))
  518.   (cvs-do-update directory local nil)
  519.   (switch-to-buffer cvs-buffer-name))
  520.  
  521. ;;----------
  522. (defun cvs-update-other-window (directory &optional local)
  523.   "Run a 'cvs update' in the current working directory.  Feed the
  524. output to a *cvs* buffer, display it in the other window, and run
  525. cvs-mode on it.
  526.  
  527. If optional prefix argument LOCAL is non-nil, 'cvs update -l' is run."
  528.  
  529.   (interactive (list (read-file-name "CVS Update other window (directory): "
  530.                      nil default-directory nil)
  531.              current-prefix-arg))
  532.   (cvs-do-update directory local nil)
  533.   (switch-to-buffer-other-window cvs-buffer-name))
  534.  
  535. ;;----------
  536. (defun cvs-filter (predicate list &rest extra-args)
  537.   "Apply PREDICATE to each element on LIST.
  538. Args:  PREDICATE LIST &rest EXTRA-ARGS.
  539.  
  540. Return a new list consisting of those elements that PREDICATE
  541. returns non-nil for.
  542.  
  543. If more than two arguments are given the remaining args are
  544. passed to PREDICATE."
  545.  
  546.   ;; Avoid recursion - this should work for LONG lists also!
  547.   (let* ((head (cons 'dummy-header nil))
  548.      (tail head))
  549.     (while list
  550.       (if (apply predicate (car list) extra-args)
  551.       (setq tail (setcdr tail (list (car list)))))
  552.       (setq list (cdr list)))
  553.     (cdr head)))
  554.  
  555. ;;----------
  556. (defun cvs-mode-update-no-prompt ()
  557.   "Run cvs update in current directory."
  558.  
  559.   (interactive)
  560.   (cvs-do-update default-directory nil nil))
  561.  
  562. ;;----------
  563. (defun cvs-do-update (directory local dont-change-disc)
  564.   "Do a 'cvs update' in DIRECTORY.
  565. Args:  DIRECTORY LOCAL DONT-CHANGE-DISC.
  566.  
  567. If LOCAL is non-nil 'cvs update -l' is executed.
  568. If DONT-CHANGE-DISC is non-nil 'cvs -n update' is executed.
  569. Both LOCAL and DONT-CHANGE-DISC may be non-nil simultaneously.
  570.  
  571. *Note*:  DONT-CHANGE-DISC does not yet work.  The parser gets confused."
  572.  
  573.   (save-some-buffers)
  574.   ;; Ensure that it is safe to do an update.  If not, ask user
  575.   ;; for confirmation.
  576.   (if (and (boundp 'cvs-cookie-handle) (collection-buffer cvs-cookie-handle))
  577.       (if (collection-collect-tin
  578.        cvs-cookie-handle
  579.        '(lambda (cookie) (eq (cvs-fileinfo->type cookie) 'CONFLICT)))
  580.       (if (not
  581.            (yes-or-no-p
  582.         "Only update if conflicts have been resolved.  Continue? "))
  583.           (error "Update aborted by user request."))))
  584.   (if (not (file-exists-p cvs-program))
  585.       (error "%s: file not found (check setting of cvs-program)"
  586.          cvs-program))
  587.   (let* ((this-dir (file-name-as-directory (expand-file-name directory)))
  588.      (update-buffer (generate-new-buffer
  589.              (concat " " (file-name-nondirectory
  590.                       (substring this-dir 0 -1))
  591.                  "-update")))
  592.      (temp-name (make-temp-name
  593.              (concat (file-name-as-directory
  594.                   (or (getenv "TMPDIR") "/tmp"))
  595.                  "pcl-cvs.")))
  596.      (args nil))
  597.  
  598.     ;; Check that this-dir exists and is a directory that is under CVS contr.
  599.  
  600.     (if (not (file-directory-p this-dir))
  601.     (error "%s is not a directory." this-dir))
  602.     (if (not (file-directory-p (concat this-dir "CVS")))
  603.     (error "%s does not contain CVS controlled files." this-dir))
  604.     (if (file-readable-p (concat this-dir "CVS/Root"))
  605.     (save-excursion        ; read CVS/Root into cvs-cvsroot
  606.       (find-file (concat this-dir "CVS/Root"))
  607.       (goto-char (point-min))
  608.       (setq cvs-cvsroot (buffer-substring (point)
  609.                           (progn (end-of-line) (point))))
  610.       (if (not cvs-cvsroot)
  611.           (error "Invalid contents of %sCVS/Root" this-dir))
  612.       (kill-buffer (current-buffer)))
  613.       (if (and cvs-cvsroot-required
  614.            (not (or (getenv "CVSROOT") cvs-cvsroot)))
  615.       (error "Both cvs-cvsroot and environment variable CVSROOT are unset, and no CVS/Root.")))
  616.  
  617.     ;; Check that at most one `cvs update' is run at any time.
  618.  
  619.     (if (and cvs-update-running (process-status cvs-update-running)
  620.          (or (eq (process-status cvs-update-running) 'run)
  621.          (eq (process-status cvs-update-running) 'stop)))
  622.     (error "Can't run two `cvs update' simultaneously."))
  623.  
  624.     (if (not (listp cvs-update-optional-flags))
  625.     (error "cvs-update-optional-flags should be set using cvs-set-update-optional-flags"))
  626.  
  627.     ;; Generate "-d /master -n update -l".
  628.     (setq args (concat (if cvs-cvsroot (concat " -d " cvs-cvsroot))
  629.                (if dont-change-disc " -n ")
  630.                " update "
  631.                (if local " -l ")
  632.                (if cvs-update-optional-flags
  633.                (mapconcat 'identity
  634.                       (copy-sequence cvs-update-optional-flags)
  635.                       " "))))
  636.  
  637.     ;; Set up the buffer that receives the stderr output from "cvs update".
  638.     (set-buffer update-buffer)
  639.     (setq default-directory this-dir)
  640.     (make-local-variable 'cvs-stdout-file)
  641.     (setq cvs-stdout-file temp-name)
  642.  
  643.     (setq cvs-update-running
  644.       (let ((process-connection-type nil)) ; Use a pipe, not a pty.
  645.         (start-process "cvs" update-buffer cvs-shell "-c"
  646.                (concat cvs-program " " args " > " temp-name))))
  647.  
  648.     (setq mode-line-process
  649.       (concat ": "
  650.           (symbol-name (process-status cvs-update-running))))
  651.     (set-buffer-modified-p (buffer-modified-p))    ; Update the mode line.
  652.     (set-process-sentinel cvs-update-running 'cvs-sentinel)
  653.     (set-process-filter cvs-update-running 'cvs-update-filter)
  654.     (set-marker (process-mark cvs-update-running) (point-min))
  655.  
  656.     (save-excursion
  657.       (set-buffer (get-buffer-create cvs-buffer-name))
  658.       (setq buffer-read-only nil)
  659.       (erase-buffer)
  660.       (cvs-mode))
  661.       
  662.     (setq cvs-cookie-handle
  663.       (collection-create
  664.        cvs-buffer-name 'cvs-pp
  665.        cvs-startup-message        ;See comment above cvs-startup-message.
  666.        "---------- End -----"))
  667.  
  668.     (cookie-enter-first
  669.      cvs-cookie-handle
  670.      (cvs-create-fileinfo
  671.       'MESSAGE nil nil (concat "\n    Running `cvs " args "' in " this-dir
  672.                    "...\n")))
  673.  
  674.     (save-excursion
  675.       (set-buffer cvs-buffer-name)
  676.       (setq mode-line-process
  677.         (concat ": "
  678.             (symbol-name (process-status cvs-update-running))))
  679.       (set-buffer-modified-p (buffer-modified-p))    ; Update the mode line.
  680.       (setq buffer-read-only t))
  681.  
  682.     ;; Work around a bug in emacs 18.57 and earlier.
  683.     (setq cvs-buffers-to-delete
  684.       (cvs-delete-unused-temporary-buffers cvs-buffers-to-delete)))
  685.  
  686.   ;; The following line is said to improve display updates on some
  687.   ;; emacses.  It shouldn't be needed, but it does no harm.
  688.   (sit-for 0))
  689.  
  690. ;;----------
  691. (defun cvs-delete-unused-temporary-buffers (list)
  692.   "Delete all buffers on LIST that is not visible.
  693. Return a list of all buffers that still is alive."
  694.  
  695.   (cond
  696.    ((null list) nil)
  697.    ((get-buffer-window (car list))
  698.     (cons (car list)
  699.       (cvs-delete-unused-temporary-buffers (cdr list))))
  700.    (t
  701.     (kill-buffer (car list))
  702.     (cvs-delete-unused-temporary-buffers (cdr list)))))
  703.  
  704. ;;----------
  705. (put 'cvs-mode 'mode-class 'special)
  706.  
  707. ;;----------
  708. (defun cvs-mode ()
  709.   "\\<cvs-mode-map>Mode used for pcl-cvs, a front-end to CVS.
  710.  
  711. To get to the \"*cvs*\" buffer you should use ``\\[execute-extended-command] cvs-update''.
  712.  
  713. Full documentation is in the Texinfo file.  Here are the most useful commands:
  714.  
  715. \\[cvs-mode-previous-line] Move up.                    \\[cvs-mode-next-line] Move down.
  716. \\[cvs-mode-commit]   Commit file.                \\[cvs-mode-update-no-prompt]   Re-update directory.
  717. \\[cvs-mode-mark]   Mark file/dir.              \\[cvs-mode-unmark]   Unmark file/dir.
  718. \\[cvs-mode-mark-all-files]   Mark all files.             \\[cvs-mode-unmark-all-files]   Unmark all files.
  719. \\[cvs-mode-find-file]   Edit file/run Dired.        \\[cvs-mode-find-file-other-window]   Find file or run Dired in other window.
  720. \\[cvs-mode-ignore]   Add file to ./.cvsignore.   \\[cvs-mode-add-change-log-entry-other-window]   Write ChangeLog in other window.
  721. \\[cvs-mode-add]   Add to repository.          \\[cvs-mode-remove-file]   Remove file.
  722. \\[cvs-mode-diff-cvs]   Diff with base revision.    \\[cvs-mode-diff-backup]   Diff backup file.
  723. \\[cvs-mode-ediff]   Ediff base rev & backup.    \\[cvs-mode-diff-vendor]   Show merge from vendor branch.
  724. \\[cvs-mode-emerge]   Emerge base rev & backup.   \\[cvs-mode-diff-backup]   Diff backup file.
  725. \\[cvs-mode-acknowledge] Delete line from buffer.    \\[cvs-mode-remove-handled]   Remove processed entries.   
  726. \\[cvs-mode-log]   Run ``cvs log''.            \\[cvs-mode-status]   Run ``cvs status''.
  727. \\[cvs-mode-tag]   Run ``cvs tag''.            \\[cvs-mode-rtag]   Run ``cvs rtag''.
  728. \\[cvs-mode-changelog-commit]   Like \\[cvs-mode-commit], but get default log text from ChangeLog.
  729. \\[cvs-mode-undo-local-changes]   Revert the last checked in version - discard your changes to the file.
  730.  
  731. Entry to this mode runs cvs-mode-hook.
  732. This description is updated for release 1.05-CVS-$Name:  $ of pcl-cvs.
  733.  
  734. All bindings:
  735. \\{cvs-mode-map}"
  736.  
  737.   (interactive)
  738.   (setq major-mode 'cvs-mode)
  739.   (setq mode-name "CVS")
  740.   (setq mode-line-process nil)
  741. ;; for older v18 emacs
  742. ;;(buffer-flush-undo (current-buffer))
  743.   (buffer-disable-undo (current-buffer))
  744.   (make-local-variable 'goal-column)
  745.   (setq goal-column cvs-cursor-column)
  746.   (use-local-map cvs-mode-map)
  747.   (run-hooks 'cvs-mode-hook))
  748.  
  749. ;;----------
  750. (defun cvs-sentinel (proc msg)
  751.   "Sentinel for the cvs update process.
  752. This is responsible for parsing the output from the cvs update when
  753. it is finished."
  754.  
  755.   (cond
  756.    ((null (buffer-name (process-buffer proc)))
  757.     ;; buffer killed
  758.     (set-process-buffer proc nil))
  759.    ((memq (process-status proc) '(signal exit))
  760.     (let* ((obuf (current-buffer))
  761.        (omax (point-max))
  762.        (opoint (point)))
  763.       ;; save-excursion isn't the right thing if
  764.       ;;  process-buffer is current-buffer
  765.       (unwind-protect
  766.       (progn
  767.         (set-buffer (process-buffer proc))
  768.         (setq mode-line-process
  769.           (concat ": "
  770.               (symbol-name (process-status proc))))
  771.         (let* ((out-file cvs-stdout-file)
  772.            (stdout-buffer (find-file-noselect out-file)))
  773.           (save-excursion
  774.         (set-buffer stdout-buffer)
  775.         (rename-buffer (concat " "
  776.                        (file-name-nondirectory out-file)) t))
  777.           (cvs-parse-update stdout-buffer (process-buffer proc))
  778.           (setq cvs-buffers-to-delete
  779.             (cons (process-buffer proc)
  780.               (cons stdout-buffer
  781.                 cvs-buffers-to-delete)))
  782.           (delete-file out-file)))
  783.     (set-buffer-modified-p (buffer-modified-p))
  784.     (setq cvs-update-running nil))
  785.       (if (equal obuf (process-buffer proc))
  786.       nil
  787.     (set-buffer (process-buffer proc))
  788.     (if (< opoint omax)
  789.         (goto-char opoint))
  790.     (set-buffer obuf))))))
  791.  
  792. ;;----------
  793. (defun cvs-update-filter (proc string)
  794.   "Filter function for pcl-cvs.
  795. This function gets the output that CVS sends to stderr.  It inserts it
  796. into (process-buffer proc) but it also checks if CVS is waiting for a
  797. lock file.  If so, it inserts a message cookie in the *cvs* buffer."
  798.  
  799.   (let ((old-buffer (current-buffer))
  800.     (data (match-data)))
  801.     (unwind-protect
  802.     (progn
  803.            (set-buffer (process-buffer proc))
  804.            (save-excursion
  805.              ;; Insert the text, moving the process-marker.
  806.              (goto-char (process-mark proc))
  807.              (insert string)
  808.              (set-marker (process-mark proc) (point))
  809.         ;; Delete any old lock message
  810.         (if (tin-nth cvs-cookie-handle 1)
  811.         (tin-delete cvs-cookie-handle
  812.                 (tin-nth cvs-cookie-handle 1)))
  813.         ;; Check if CVS is waiting for a lock.
  814.         (beginning-of-line 0)    ;Move to beginning of last
  815.                     ;complete line.
  816.         (cond
  817.          ((looking-at
  818.            "^cvs \\(update\\|server\\): \\[..:..:..\\] waiting for \\(.*\\)lock in \\(.*\\)$")
  819.           (setq cvs-lock-file (buffer-substring (match-beginning 3)
  820.                             (match-end 3)))
  821.           (cookie-enter-last
  822.            cvs-cookie-handle
  823.            (cvs-create-fileinfo
  824.         'MESSAGE nil nil
  825.         (concat "\tWaiting for "
  826.             (buffer-substring (match-beginning 2)
  827.                       (match-end 2))
  828.             "lock in " cvs-lock-file
  829.             ".\n\t (type M-x cvs-delete-lock to delete it)")))))))
  830.       (store-match-data data)
  831.       (set-buffer old-buffer))))
  832.  
  833. ;;----------
  834. (defun cvs-delete-lock ()
  835.   "Delete the lock file that CVS is waiting for.
  836. Note that this can be dangerous.  You should only do this
  837. if you are convinced that the process that created the lock is dead."
  838.  
  839.   (interactive)
  840.   (cond
  841.    ((not (or (file-exists-p
  842.           (concat (file-name-as-directory cvs-lock-file) "#cvs.lock"))
  843.          (cvs-filter (function cvs-lock-file-p)
  844.              (directory-files cvs-lock-file))))
  845.     (error "No lock files found."))
  846.    ((yes-or-no-p (concat "Really delete locks in " cvs-lock-file "? "))
  847.     ;; Re-read the directory -- the locks might have disappeared.
  848.     (let ((locks (cvs-filter (function cvs-lock-file-p)
  849.                  (directory-files cvs-lock-file))))
  850.       (while locks
  851.     (delete-file (concat (file-name-as-directory cvs-lock-file)
  852.                  (car locks)))
  853.     (setq locks (cdr locks)))
  854.       (cvs-remove-directory
  855.        (concat (file-name-as-directory cvs-lock-file) "#cvs.lock"))))))
  856.  
  857. ;;----------
  858. (defun cvs-remove-directory (dir)
  859.   "Remove a directory."
  860.  
  861.   (if (file-directory-p dir)
  862.       (call-process cvs-rmdir-program nil nil nil dir)
  863.     (error "Not a directory: %s" dir))
  864.   (if (file-exists-p dir)
  865.       (error "Could not remove directory %s" dir)))
  866.  
  867. ;;----------
  868. (defun cvs-lock-file-p (file)
  869.   "Return true if FILE looks like a CVS lock file."
  870.  
  871.   (or
  872.    (string-match "^#cvs.tfl.[0-9]+$" file)
  873.    (string-match "^#cvs.rfl.[0-9]+$" file)
  874.    (string-match "^#cvs.wfl.[0-9]+$" file)))
  875.  
  876. ;;----------
  877. (defun cvs-quote-multiword-string (str)
  878.   "Return STR surrounded in single quotes if it contains whitespace."
  879.   (cond ((string-match "[ \t\n]" str)
  880.      (concat "'" str "'"))
  881.     (t
  882.      str)))
  883.  
  884. ;;----------
  885. ;; this should be in subr.el or some similar place....
  886. (defun parse-string (str &optional regexp)
  887.   "Explode the string STR into a list of words ala strtok(3).  Optional REGEXP
  888. defines regexp matching word separator, which defaults to \"[ \\t\\n]+\"."
  889.   (let (str-list            ; new list
  890.     str-token            ; "index" of next token
  891.     (str-start 0)            ; "index" of current token
  892.     (str-sep (if regexp
  893.              regexp
  894.            "[ \t\n]+")))
  895.     (while (setq str-token (string-match str-sep str str-start))
  896.       (setq str-list
  897.         (nconc str-list
  898.            (list (substring str str-start str-token))))
  899.       (setq str-start (match-end 0)))
  900.     ;; tag on the remainder as the final item
  901.     (if (not (>= str-start (length str)))
  902.     (setq str-list
  903.           (nconc str-list
  904.              (list (substring str str-start)))))
  905.     str-list))
  906.  
  907. ;;----------
  908. (defun cvs-make-list (str)
  909.   "Return list of words made from the string STR."
  910.   (cond ((string-match "[ \t\n]+" str)
  911.      (let ((new-str (parse-string str "[ \t\n]+")))
  912.        ;; this is ugly, but assume if the first element is empty, there are
  913.        ;; no more elements.
  914.        (cond ((string= (car new-str) "")
  915.           nil)
  916.          (t
  917.           new-str))))
  918.     ((string= str "")
  919.      nil)
  920.     (t
  921.      (list str))))
  922.  
  923. ;;----------
  924. (defun cvs-skip-line (stdout stderr regexp &optional arg)
  925.   "Like forward-line, but check that the skipped line matches REGEXP.
  926. Args:  STDOUT STDERR REGEXP &optional ARG.
  927.  
  928. If it doesn't match REGEXP a bug report is generated and displayed.
  929. STDOUT and STDERR is only used to do that.
  930.  
  931. If optional ARG, a number, is given the ARGth parenthesized expression
  932. in the REGEXP is returned as a string.
  933. Point should be in column 1 when this function is called."
  934.  
  935.   (cond
  936.    ((looking-at regexp)
  937.     (forward-line 1)
  938.     (if arg
  939.     (buffer-substring (match-beginning arg)
  940.               (match-end arg))))
  941.    (t
  942.     (cvs-parse-error stdout
  943.              stderr
  944.              (if (eq (current-buffer) stdout)
  945.              'STDOUT
  946.                'STDERR)
  947.              (point)
  948.              regexp))))
  949.  
  950. ;;----------
  951. (defun cvs-get-current-dir (root-dir dirname)
  952.   "Return current working directory, suitable for cvs-parse-update.
  953. Args:  ROOT-DIR DIRNAME.
  954.  
  955. Concatenates ROOT-DIR and DIRNAME to form an absolute path."
  956.  
  957.   (if (string= "." dirname)
  958.       (substring root-dir 0 -1)
  959.     (concat root-dir dirname)))
  960.  
  961. ;;----------
  962. (defun cvs-compare-fileinfos (a b)
  963.   "Compare fileinfo A with fileinfo B and return t if A is `less'."
  964.  
  965.   (cond
  966.    ;; Sort acording to directories.
  967.    ((string< (cvs-fileinfo->dir a) (cvs-fileinfo->dir b)) t)
  968.    ((not (string= (cvs-fileinfo->dir a) (cvs-fileinfo->dir b))) nil)
  969.    ;; The DIRCHANGE entry is always first within the directory.
  970.    ((and (eq (cvs-fileinfo->type a) 'DIRCHANGE)
  971.      (not (eq (cvs-fileinfo->type b) 'DIRCHANGE))) t)
  972.    ((and (eq (cvs-fileinfo->type b) 'DIRCHANGE)
  973.      (not (eq (cvs-fileinfo->type a) 'DIRCHANGE))) nil)
  974.    ;; All files are sorted by file name.
  975.    ((string< (cvs-fileinfo->file-name a) (cvs-fileinfo->file-name b)))))
  976.  
  977. ;;----------
  978. (defun cvs-parse-error (stdout-buffer stderr-buffer err-buf pos &optional indicator)
  979.   "Handle a parse error when parsing the output from cvs.
  980. Args:  STDOUT-BUFFER STDERR-BUFFER ERR-BUF POS &optional INDICATOR.
  981.  
  982. ERR-BUF should be 'STDOUT or 'STDERR."
  983.  
  984.   (setq pos (1- pos))
  985.   (set-buffer cvs-buffer-name)
  986.   (setq buffer-read-only nil)
  987.   (erase-buffer)
  988.   (insert "To: " pcl-cvs-bugs-address "\n")
  989.   (insert "Subject: pcl-cvs release" pcl-cvs-version " parse error.\n")
  990.   (insert (concat mail-header-separator "\n"))
  991.   (insert "This bug report is automatically generated by pcl-cvs\n")
  992.   (insert "because it doesn't understand some output from CVS.  Below\n")
  993.   (insert "is detailed information about the error.  Please send\n")
  994.   (insert "this, together with any information you think might be\n")
  995.   (insert "useful for me to fix the bug, to the address above.  But\n")
  996.   (insert "please check the \"known problems\" section of the\n")
  997.   (insert "documentation first.  Note that this buffer contains\n")
  998.   (insert "information that you might consider confidential.  You\n")
  999.   (insert "are encouraged to read through it before sending it.\n")
  1000.   (insert "\n")
  1001.   (insert "Press C-c C-c to send this email.\n\n")
  1002.   (insert "Please state the version of these programs you are using:\n\n")
  1003.   (insert "RCS:  \ndiff: \n\n")
  1004.  
  1005.   (let* ((stdout (save-excursion (set-buffer stdout-buffer) (buffer-string)))
  1006.      (stderr (save-excursion (set-buffer stderr-buffer) (buffer-string)))
  1007.      (errstr (if (eq err-buf 'STDOUT) stdout stderr))
  1008.      (errline-end (string-match "\n" errstr pos))
  1009.      (errline (substring errstr pos errline-end)))
  1010.     (insert (format "Offending line (%d chars): >" (- errline-end pos)))
  1011.     (insert errline)
  1012.     (insert "<\n")
  1013.     (insert "Sent to " (symbol-name err-buf) " at pos " (format "%d\n" pos))
  1014.     (if indicator
  1015.     (insert "Optional args: \"" indicator "\".\n"))
  1016.     (insert "\nEmacs-version: " (emacs-version) "\n")
  1017.     (insert "Pcl-cvs Version: "
  1018.         "@(#)OrigId: pcl-cvs.el,v 1.93 1993/05/31 22:44:00 ceder Exp\n")
  1019.     (insert "CVS Version: "
  1020.         "@(#)cvs/contrib/pcl-cvs:$Name:  $:$Id: pcl-cvs.el,v 1.3 1996/08/09 14:45:20 jimb Exp $\n\n")
  1021.     (insert (format "--- Contents of stdout buffer (%d chars) ---\n"
  1022.             (length stdout)))
  1023.     (insert stdout)
  1024.     (insert "--- End of stdout buffer ---\n")
  1025.     (insert (format "--- Contents of stderr buffer (%d chars) ---\n"
  1026.             (length stderr)))
  1027.     (insert stderr)
  1028.     (insert "--- End of stderr buffer ---\n")
  1029.     (insert "\nEnd of bug report.\n")
  1030.     (require 'sendmail)
  1031.     (mail-mode)
  1032.     (error "CVS parse error - please report this bug.")))
  1033.       
  1034. ;;----------
  1035. (defun cvs-parse-update (stdout-buffer stderr-buffer)
  1036.   "Parse the output from `cvs update'.
  1037.  
  1038. Args:  STDOUT-BUFFER STDERR-BUFFER.
  1039.  
  1040. This functions parses the from `cvs update' (which should be
  1041. separated in its stdout- and stderr-components) and prints a
  1042. pretty representation of it in the *cvs* buffer.
  1043.  
  1044. Signals an error if unexpected output was detected in the buffer."
  1045.  
  1046.   (let* ((head (cons 'dummy nil))
  1047.      (tail (cvs-parse-stderr stdout-buffer stderr-buffer
  1048.                  head default-directory))
  1049.      (root-dir default-directory))
  1050.     (cvs-parse-stdout stdout-buffer stderr-buffer tail root-dir)
  1051.     (setq head (sort (cdr head) (function cvs-compare-fileinfos)))
  1052.     (collection-clear cvs-cookie-handle)
  1053.     (collection-append-cookies cvs-cookie-handle head)
  1054.     (cvs-remove-stdout-shadows)
  1055.     (if cvs-auto-remove-handled-directories
  1056.     (cvs-remove-empty-directories))
  1057.     (set-buffer cvs-buffer-name)
  1058.     (cvs-mode)
  1059.     (goto-char (point-min))
  1060.     (tin-goto-previous cvs-cookie-handle (point-min) 1)
  1061.     (setq default-directory root-dir)))
  1062.  
  1063. ;;----------
  1064. (defun cvs-remove-stdout-shadows ()
  1065.   "Remove entries in the *cvs* buffer that comes from both stdout and stderr.
  1066. If there is two entries for a single file the second one should be
  1067. deleted.  (Remember that sort uses a stable sort algorithm, so one can
  1068. be sure that the stderr entry is always first)."
  1069.  
  1070.   (collection-filter-tins cvs-cookie-handle
  1071.               (function
  1072.                (lambda (tin)
  1073.                  (not (cvs-shadow-entry-p tin))))))
  1074.  
  1075. ;;----------
  1076. (defun cvs-shadow-entry-p (tin)
  1077.   "Return non-nil if TIN is a shadow entry.
  1078. Args:  TIN.
  1079.  
  1080. A TIN is a shadow entry if the previous tin contains the same file."
  1081.  
  1082.   (let* ((previous-tin (tin-previous cvs-cookie-handle tin))
  1083.      (curr (tin-cookie cvs-cookie-handle tin))
  1084.      (prev (and previous-tin
  1085.             (tin-cookie cvs-cookie-handle previous-tin))))
  1086.     (and
  1087.      prev curr
  1088.      (string= (cvs-fileinfo->file-name prev)
  1089.           (cvs-fileinfo->file-name curr))
  1090.      (string= (cvs-fileinfo->dir prev)
  1091.           (cvs-fileinfo->dir curr))
  1092.      (or
  1093.       (and (eq (cvs-fileinfo->type prev) 'CONFLICT)
  1094.        (eq (cvs-fileinfo->type curr) 'CONFLICT))
  1095.       (and (eq (cvs-fileinfo->type prev) 'MERGED)
  1096.        (eq (cvs-fileinfo->type curr) 'MODIFIED))
  1097.       (and (eq (cvs-fileinfo->type prev) 'REM-EXIST)
  1098.        (eq (cvs-fileinfo->type curr) 'REMOVED))))))
  1099.  
  1100. ;;----------
  1101. (defun cvs-find-backup-file (filename &optional dirname)
  1102.   "Look for a backup file for FILENAME, optionally in directory DIRNAME, and if
  1103. there is one, return the name of the first file found as a string."
  1104.  
  1105.   (if (eq dirname nil)
  1106.       (setq dirname default-directory))
  1107.   (car (directory-files dirname nil (concat "^\\" cvs-bakprefix filename
  1108.                         "\\."))))
  1109.  
  1110. ;;----------
  1111. (defun cvs-find-backup-revision (filename)
  1112.   "Take FILENAME as the name of a cvs backup file and return the revision of
  1113. that file as a string."
  1114.  
  1115.     (substring filename
  1116.            (+ 1 (string-match "\\.\\([0-9.]+\\)$" filename))))
  1117.  
  1118. ;;----------
  1119. (defun cvs-parse-stderr (stdout-buffer stderr-buffer head dir)
  1120.   "Parse the output from CVS that is written to stderr.
  1121. Args:  STDOUT-BUFFER STDERR-BUFFER HEAD DIR
  1122.  
  1123. STDOUT-BUFFER holds the output that cvs sent to stdout.  It is only
  1124. used to create a bug report in case there is a parse error.
  1125. STDERR-BUFFER is the buffer that holds the output to parse.
  1126. HEAD is a cons-cell, the head of the list that is built.
  1127. DIR is the directory the `cvs update' was run in.
  1128.  
  1129. This function returns the last cons-cell in the list that is built."
  1130.  
  1131.   (save-window-excursion
  1132.     (set-buffer stderr-buffer)
  1133.     (goto-char (point-min))
  1134.     (let ((current-dir dir)
  1135.       (root-dir dir))
  1136.  
  1137.       (while (< (point) (point-max))
  1138.     (cond
  1139.  
  1140.      ;; CVS is descending a subdirectory.
  1141.  
  1142.      ((looking-at
  1143.        "^cvs \\(server\\|update\\): Updating \\(.*\\)$")
  1144.       (setq current-dir
  1145.         (cvs-get-current-dir
  1146.          root-dir
  1147.          (buffer-substring (match-beginning 2) (match-end 2))))
  1148.       (setcdr head (list (cvs-create-fileinfo
  1149.                   'DIRCHANGE
  1150.                   current-dir
  1151.                   "."    ; the old version had nil here???
  1152.                   (buffer-substring (match-beginning 0)
  1153.                         (match-end 0)))))
  1154.       (setq head (cdr head))
  1155.       (forward-line 1))
  1156.  
  1157.      ;; File removed, since it is removed (by third party) in repository.
  1158.        
  1159.      ((or (looking-at
  1160.            "^cvs \\(update\\|server\\): warning: \\(.*\\) is not (any longer) pertinent")
  1161.           (looking-at
  1162.            "^cvs \\(update\\|server\\): \\(.*\\) is no longer in the repository"))
  1163.  
  1164.       (setcdr head (list (cvs-create-fileinfo
  1165.                   'CVS-REMOVED
  1166.                   current-dir
  1167.                   (file-name-nondirectory
  1168.                    (buffer-substring (match-beginning 2)
  1169.                          (match-end 2)))
  1170.                   (buffer-substring (match-beginning 0)
  1171.                         (match-end 0)))))
  1172.       (setq head (cdr head))
  1173.       (forward-line 1))
  1174.  
  1175.      ;; File removed by you, but recreated by cvs.  Ignored.  Will say
  1176.      ;; "Updated" on the next line.
  1177.  
  1178.      ((looking-at
  1179.        "^cvs \\(update\\|server\\): warning: .* was lost$")
  1180.       (forward-line 1))
  1181.  
  1182.      ;; File unknown for some reason.
  1183.      ;; FIXME:  is it really a good idea to add this as unknown here?
  1184.  
  1185.      ((looking-at
  1186.        "cvs \\(update\\|server\\): nothing known about \\(.*\\)$")
  1187.       (let ((filename (buffer-substring (match-beginning 2)
  1188.                         (match-end 2))))
  1189.         (if (file-directory-p filename)
  1190.         (setcdr head (list (cvs-create-fileinfo
  1191.                     'UNKNOWN-DIR
  1192.                     current-dir
  1193.                     "."
  1194.                     (buffer-substring (match-beginning 0)
  1195.                               (match-end 0)))))
  1196.           (setcdr head (list (cvs-create-fileinfo
  1197.                   'UNKNOWN
  1198.                   current-dir
  1199.                   (file-name-nondirectory filename)
  1200.                   (buffer-substring (match-beginning 0)
  1201.                             (match-end 0)))))))
  1202.       (setq head (cdr head))
  1203.       (forward-line 1))
  1204.  
  1205.      ;; A file that has been created by you, but added to the cvs
  1206.      ;; repository by another.
  1207.  
  1208.      ((looking-at
  1209.        "^cvs \\(update\\|server\\): move away \\(.*\\); it is in the way$")
  1210.       (setcdr head (list (cvs-create-fileinfo
  1211.                   'MOVE-AWAY
  1212.                   current-dir
  1213.                   (file-name-nondirectory
  1214.                    (buffer-substring (match-beginning 2)
  1215.                          (match-end 2)))
  1216.                   (buffer-substring (match-beginning 0)
  1217.                         (match-end 0)))))
  1218.       (setq head (cdr head))
  1219.       (forward-line 1))
  1220.  
  1221.      ;; Cvs waits for a lock.  Ignore.
  1222.  
  1223.      ((looking-at
  1224.        "^cvs \\(update\\|server\\): \\[..:..:..\\] waiting for .*lock in ")
  1225.       (forward-line 1))
  1226.  
  1227.      ;; File removed in repository, but edited by you.
  1228.  
  1229.      ((looking-at
  1230.        "^cvs \\(update\\|server\\): conflict: \\(.*\\) is modified but no longer in the repository$")
  1231.       (setcdr head (list
  1232.             (cvs-create-fileinfo
  1233.              'REM-CONFLICT
  1234.              current-dir
  1235.              (file-name-nondirectory
  1236.               (buffer-substring (match-beginning 2)
  1237.                         (match-end 2)))
  1238.              (buffer-substring (match-beginning 0)
  1239.                        (match-end 0)))))
  1240.       (setq head (cdr head))
  1241.       (forward-line 1))
  1242.  
  1243.      ;; File removed in repository, but edited by someone else.
  1244.  
  1245.      ((looking-at
  1246.        "^cvs \\(update\\|server\\): conflict: removed \\(.*\\) was modified by second party")
  1247.       (setcdr head
  1248.           (list
  1249.            (cvs-create-fileinfo
  1250.             'MOD-CONFLICT
  1251.             current-dir
  1252.             (buffer-substring (match-beginning 1)
  1253.                       (match-end 1))
  1254.             (buffer-substring (match-beginning 0)
  1255.                       (match-end 0)))))
  1256.       (setq head (cdr head))
  1257.       (forward-line 1))
  1258.  
  1259.      ;; File removed in repository, but not in local directory.
  1260.  
  1261.      ((looking-at
  1262.        "^cvs \\(update\\|server\\): \\(.*\\) should be removed and is still there")
  1263.       (setcdr head
  1264.           (list
  1265.            (cvs-create-fileinfo
  1266.             'REM-EXIST
  1267.             current-dir
  1268.             (buffer-substring (match-beginning 2)
  1269.                       (match-end 2))
  1270.             (buffer-substring (match-beginning 0)
  1271.                       (match-end 0)))))
  1272.       (setq head (cdr head))
  1273.       (forward-line 1))
  1274.  
  1275.      ;; Error searching for repository
  1276.  
  1277.      ((looking-at
  1278.        "^cvs \\(update\\|server\\): in directory ")
  1279.       (let ((start (point)))
  1280.         (forward-line 1)
  1281.         (cvs-skip-line stdout-buffer stderr-buffer
  1282.                (regexp-quote "cvs [update aborted]: there is no repository "))
  1283.         (setcdr head (list (cvs-create-fileinfo
  1284.                 'REPOS-MISSING
  1285.                 current-dir
  1286.                 nil
  1287.                 (buffer-substring start (point)))))
  1288.         (setq head (cdr head))))
  1289.  
  1290.      ;; Silly warning from attempted conflict resolution.  Ignored.
  1291.      ;; FIXME:  Should it be?
  1292.      ;; eg.:  "cvs update: cannot find revision APC-web-update in file .cvsignore"
  1293.      ;;
  1294.      ((looking-at
  1295.        "^cvs \\(update\\|server\\): cannot find revision \\(.*\\) in file \\(.*\\)$")
  1296.       (forward-line 1)
  1297.       (message "%s" (buffer-substring (match-beginning 0) (match-end 0))))
  1298.  
  1299.      ;; CVS has decided to merge someone elses changes into this document.
  1300.      ;; About to start an rcsmerge operation...
  1301.      ;;
  1302.      ((looking-at
  1303.        "^RCS file: ")
  1304.  
  1305.       ;; skip the "RCS file:" line...
  1306.       (forward-line 1)
  1307.  
  1308.       (let ((complex-start (point))
  1309.         base-revision        ; the first revision retrieved to merge from
  1310.         head-revision        ; the second revision retrieved to merge from
  1311.         filename        ; the name of the file being merged
  1312.         backup-file        ; the name of the backup of the working file
  1313.         backup-revision)    ; the revision of the original working file
  1314.  
  1315.         (setq base-revision
  1316.           (cvs-skip-line stdout-buffer stderr-buffer
  1317.                  "^retrieving revision \\(.*\\)$"
  1318.                  1))
  1319.         (setq head-revision
  1320.           (cvs-skip-line stdout-buffer stderr-buffer
  1321.                  "^retrieving revision \\(.*\\)$"
  1322.                  1))
  1323.         (setq filename
  1324.           (cvs-skip-line stdout-buffer stderr-buffer
  1325.                  "^Merging differences between [0-9.]+ and [0-9.]+ into \\(.*\\)$"
  1326.                  1))
  1327.         (setq backup-file
  1328.           (cvs-find-backup-file filename current-dir))
  1329.         (setq backup-revision
  1330.           (cvs-find-backup-revision backup-file))
  1331.  
  1332.          ;; Was there a conflict during the merge?
  1333.  
  1334.         (cond
  1335.  
  1336.          ;;;; From CVS-1.3 & RCS-5.6.0.1 with GNU-Diffutils-2.5:
  1337.          ;;;; "cvs update -j OLD-REV -j NEW-REV ."
  1338.          ;;
  1339.          ;; RCS file: /big/web-CVS/apc/cmd/Main/logout.sh,v
  1340.          ;; retrieving revision 1.1.1.1
  1341.          ;; retrieving revision 1.1.1.2
  1342.          ;; Merging differences between 1.1.1.1 and 1.1.1.2 into logout.sh
  1343.          ;; rcsmerge warning: overlaps during merge
  1344.  
  1345.          ((looking-at
  1346.            ;; Allow both RCS 5.5 and 5.6.  (5.6 prints "rcs" and " warning").
  1347.            "^\\(rcs\\)?merge[:]*\\( warning\\)?: \\(overlaps\\|conflicts\\) during merge$")
  1348.  
  1349.           ;; Yes, this is a conflict.
  1350.           (cvs-skip-line stdout-buffer stderr-buffer
  1351.                  "^\\(rcs\\)?merge[:]*\\( warning\\)?: \\(overlaps\\|conflicts\\) during merge$")
  1352.  
  1353.           ;; this line doesn't seem to appear in all cases -- perhaps only
  1354.           ;; in "-j A -j B" usage, in which case this indicates ????
  1355.           (cvs-skip-line stdout-buffer stderr-buffer
  1356.                  "^cvs \\(update\\|server\\): conflicts found in ")
  1357.  
  1358.           (let ((fileinfo
  1359.              (cvs-create-fileinfo
  1360.               'CONFLICT current-dir
  1361.               filename
  1362.               (buffer-substring complex-start (point)))))
  1363.  
  1364.         ;; squirrel away info about the files that were retrieved for merging
  1365.         (cvs-set-fileinfo->base-revision fileinfo base-revision)
  1366.         (cvs-set-fileinfo->head-revision fileinfo head-revision)
  1367.         (cvs-set-fileinfo->backup-revision fileinfo backup-revision)
  1368.         (cvs-set-fileinfo->backup-file fileinfo backup-file)
  1369.  
  1370.         (setcdr head (list fileinfo))
  1371.         (setq head (cdr head))))
  1372.  
  1373.          ;; Was it a conflict, and was RCS compiled without DIFF3_BIN, in
  1374.          ;; which case this is a failed conflict resolution?
  1375.  
  1376.          ((looking-at
  1377.            ;; Allow both RCS 5.5 and 5.6.  (5.6 prints "rcs" and " warning").
  1378.            "^\\(rcs\\)?merge\\( warning\\)?: overlaps or other problems during merge$")
  1379.  
  1380.           (cvs-skip-line stdout-buffer stderr-buffer
  1381.                  "^\\(rcs\\)?merge\\( warning\\)?: overlaps or other problems during merge$")
  1382.           (cvs-skip-line stdout-buffer stderr-buffer
  1383.                  "^cvs update: could not merge ")
  1384.           (cvs-skip-line stdout-buffer stderr-buffer
  1385.                  "^cvs update: restoring .* from backup file ")
  1386.           (let ((fileinfo
  1387.              (cvs-create-fileinfo
  1388.               'CONFLICT current-dir
  1389.               filename
  1390.               (buffer-substring complex-start (point)))))
  1391.         (setcdr head (list fileinfo))
  1392.         (setq head (cdr head))))       
  1393.  
  1394.          ;; Not a conflict; it must be a succesful merge.
  1395.  
  1396.          (t
  1397.           (let ((fileinfo
  1398.              (cvs-create-fileinfo
  1399.               'MERGED current-dir
  1400.               filename
  1401.               (buffer-substring complex-start (point)))))
  1402.         (cvs-set-fileinfo->base-revision fileinfo base-revision)
  1403.         (cvs-set-fileinfo->head-revision fileinfo head-revision)
  1404.         (cvs-set-fileinfo->backup-revision fileinfo backup-revision)
  1405.         (cvs-set-fileinfo->backup-file fileinfo backup-file)
  1406.         (setcdr head (list fileinfo))
  1407.         (setq head (cdr head)))))))
  1408.  
  1409.      ;; Error messages from CVS (incomplete)
  1410.  
  1411.      ((looking-at
  1412.        "^cvs \\(update\\|server\\): \\(invalid option .*\\)$")
  1413.       (error "Interface problem with CVS: %s"
  1414.          (buffer-substring (match-beginning 2) (match-end 2))))
  1415.  
  1416.      ;; network errors
  1417.  
  1418.      ;; Kerberos connection attempted but failed.  This is not
  1419.          ;; really an error, as CVS will automatically fall back to
  1420.          ;; rsh.  Plus it tries kerberos, if available, even when rsh
  1421.          ;; is what you really wanted.
  1422.  
  1423.      ((looking-at
  1424.        "^cvs update: kerberos connect:.*$")
  1425.       (forward-line 1)
  1426.       (message "Remote CVS: %s"
  1427.            (buffer-substring (match-beginning 0) (match-end 0))))
  1428.  
  1429.          ;; And when kerberos *does* fail, cvs prints out some stuff
  1430.          ;; as it tries rsh.  Ignore that stuff too.
  1431.  
  1432.      ((looking-at
  1433.        "^cvs update: trying to start server using rsh$")
  1434.       (forward-line 1))
  1435.  
  1436.      ((looking-at
  1437.        "^\\([^:]*\\) Connection timed out")
  1438.       (error "Remote CVS: %s"
  1439.            (buffer-substring (match-beginning 0) (match-end 0))))
  1440.  
  1441.      ((looking-at
  1442.        "^Permission denied.")
  1443.       (error "Remote CVS: %s"
  1444.          (buffer-substring (match-beginning 0) (match-end 0))))
  1445.  
  1446.      ((looking-at
  1447.        "^cvs \\[update aborted\\]: premature end of file from server")
  1448.       (error "Remote CVS: %s"
  1449.          (buffer-substring (match-beginning 0) (match-end 0))))
  1450.  
  1451.      ;; Empty line.  Probably inserted by mistake by user (or developer :-)
  1452.      ;; Ignore.
  1453.  
  1454.      ((looking-at
  1455.        "^$")
  1456.       (forward-line 1))
  1457.  
  1458.      ;; top-level parser (cond) default clause
  1459.  
  1460.      (t
  1461.       (cvs-skip-line stdout-buffer stderr-buffer
  1462.              "^UN-MATCHABLE-OUTPUT"))))))
  1463.  
  1464.   ;; cause this function to return the head of the parser output list
  1465.   head)
  1466.  
  1467. ;;----------
  1468. (defun cvs-parse-stdout (stdout-buffer stderr-buffer head root-dir)
  1469.   "Parse the output from CVS that is written to stderr.
  1470. Args:  STDOUT-BUFFER STDERR-BUFFER HEAD ROOT-DIR
  1471.  
  1472. STDOUT-BUFFER is the buffer that holds the output to parse.
  1473. STDERR-BUFFER holds the output that cvs sent to stderr.  It is only
  1474. used to create a bug report in case there is a parse error.
  1475.  
  1476. HEAD is a cons-cell, the head of the list that is built.
  1477. ROOT-DIR is the directory the `cvs update' was run in.
  1478.  
  1479. This function doesn't return anything particular."
  1480.  
  1481.   (save-window-excursion
  1482.     (set-buffer stdout-buffer)
  1483.     (goto-char (point-min))
  1484.     (while (< (point) (point-max))
  1485.       (cond
  1486.  
  1487.        ;; M:  The file is modified by the user, and untouched in the repository.
  1488.        ;; A:  The file is "cvs add"ed, but not "cvs ci"ed.
  1489.        ;; R:  The file is "cvs remove"ed, but not "cvs ci"ed.
  1490.        ;; C:  Conflict (only useful if a join was done and stderr has info...)
  1491.        ;; U:  The file is copied from the repository.
  1492.        ;; ?:  Unknown file or directory.
  1493.  
  1494.        ((looking-at
  1495.      "^\\([MARCUP?]\\) \\(.*\\)$")
  1496.     (let*
  1497.         ((c (char-after (match-beginning 1)))
  1498.          (full-path (concat (file-name-as-directory root-dir)
  1499.                 (buffer-substring (match-beginning 2)
  1500.                           (match-end 2))))
  1501.          (isdir (file-directory-p full-path))
  1502.          (fileinfo (cvs-create-fileinfo
  1503.             (cond ((eq c ?M) 'MODIFIED)
  1504.                   ((eq c ?A) 'ADDED)
  1505.                   ((eq c ?R) 'REMOVED)
  1506.                   ((eq c ?C) 'CONFLICT)
  1507.                   ((eq c ?U) 'UPDATED)
  1508.                   ((eq c ?P) 'PATCHED)
  1509.                   ((eq c ??) (if isdir
  1510.                          'UNKNOWN-DIR
  1511.                        'UNKNOWN)))
  1512.             (substring (file-name-directory full-path) 0 -1)
  1513.             (file-name-nondirectory full-path)
  1514.             (buffer-substring (match-beginning 0) (match-end 0)))))
  1515.       ;; Updated and Patched files require no further action.
  1516.       (if (memq c '(?U ?P))
  1517.           (cvs-set-fileinfo->handled fileinfo t))
  1518.  
  1519.       ;; Link this last on the list.
  1520.       (setcdr head (list fileinfo))
  1521.       (setq head (cdr head))
  1522.       (forward-line 1)))
  1523.  
  1524.        ;; Executing a program because of the -u option in modules.
  1525.        ((looking-at
  1526.      "^cvs \\(update\\|server\\): Executing")
  1527.     ;; Skip by any output the program may generate to stdout.
  1528.     ;; Note that pcl-cvs will get seriously confused if the
  1529.     ;; program prints anything to stderr.
  1530.     (re-search-forward cvs-update-prog-output-skip-regexp)
  1531.     (forward-line 1))
  1532.  
  1533.        (t
  1534.     (cvs-parse-error stdout-buffer stderr-buffer 'STDOUT (point)
  1535.              "cvs-parse-stdout"))))))
  1536.  
  1537. ;;----------
  1538. (defun cvs-pp (fileinfo)
  1539.   "Pretty print FILEINFO.  Insert a printed representation in current buffer.
  1540. For use by the cookie package."
  1541.  
  1542.   (let ((a (cvs-fileinfo->type fileinfo))
  1543.         (s (if (cvs-fileinfo->marked fileinfo)
  1544.                "*" " "))
  1545.         (f (cvs-fileinfo->file-name fileinfo))
  1546.         (ci (if (cvs-fileinfo->handled fileinfo)
  1547.                 "  " "ci")))
  1548.     (insert
  1549.      (cond
  1550.       ((eq a 'UPDATED)
  1551.        (format "%s Updated     %s" s f))
  1552.       ((eq a 'PATCHED)
  1553.        (format "%s Patched     %s" s f))
  1554.       ((eq a 'MODIFIED)
  1555.        (format "%s Modified %s %s" s ci f))
  1556.       ((eq a 'MERGED)
  1557.        (format "%s Merged   %s %s" s ci f))
  1558.       ((eq a 'CONFLICT)
  1559.        (format "%s Conflict    %s" s f))
  1560.       ((eq a 'ADDED)
  1561.        (format "%s Added    %s %s" s ci f))
  1562.       ((eq a 'REMOVED)
  1563.        (format "%s Removed  %s %s" s ci f))
  1564.       ((eq a 'UNKNOWN)
  1565.        (format "%s Unknown     %s" s f))
  1566.       ((eq a 'UNKNOWN-DIR)
  1567.        (format "%s Unknown dir %s" s f))
  1568.       ((eq a 'CVS-REMOVED)
  1569.        (format "%s Removed from repository:  %s" s f))
  1570.       ((eq a 'REM-CONFLICT)
  1571.        (format "%s Conflict: Removed from repository, changed by you: %s" s f))
  1572.       ((eq a 'MOD-CONFLICT)
  1573.        (format "%s Conflict: Removed by you, changed in repository: %s" s f))
  1574.       ((eq a 'REM-EXIST)
  1575.        (format "%s Conflict: Removed by you, but still exists: %s" s f))
  1576.       ((eq a 'DIRCHANGE)
  1577.        (format "\nIn directory %s:" (cvs-fileinfo->dir fileinfo)))
  1578.       ((eq a 'MOVE-AWAY)
  1579.        (format "%s Move away %s - it is in the way" s f))
  1580.       ((eq a 'REPOS-MISSING)
  1581.        (format "  This repository directory is missing!  Remove this directory manually."))
  1582.       ((eq a 'MESSAGE)
  1583.        (cvs-fileinfo->full-log fileinfo))
  1584.       (t
  1585.        (format "%s Internal error!  %s" s f))))))
  1586.  
  1587.  
  1588. ;;; You can define your own keymap in .emacs.  pcl-cvs.el won't overwrite it.
  1589.  
  1590. (if cvs-mode-map
  1591.     nil
  1592.   (setq cvs-mode-map (make-keymap))
  1593.   (suppress-keymap cvs-mode-map)
  1594.   (define-prefix-command 'cvs-mode-map-control-c-prefix)
  1595.   (define-key cvs-mode-map "\C-?"    'cvs-mode-unmark-up)
  1596.   (define-key cvs-mode-map "\C-k"    'cvs-mode-acknowledge)
  1597.   (define-key cvs-mode-map "\C-n"    'cvs-mode-next-line)
  1598.   (define-key cvs-mode-map "\C-p"    'cvs-mode-previous-line)
  1599.   ;; ^C- keys are used to set various flags to control CVS features
  1600.   (define-key cvs-mode-map "\C-c"    'cvs-mode-map-control-c-prefix)
  1601.   (define-key cvs-mode-map "\C-c\C-c"    'cvs-change-cvsroot)
  1602.   (define-key cvs-mode-map "\C-c\C-d"    'cvs-set-diff-flags)
  1603.   (define-key cvs-mode-map "\C-c\C-l"    'cvs-set-log-flags)
  1604.   (define-key cvs-mode-map "\C-c\C-s"    'cvs-set-status-flags)
  1605.   (define-key cvs-mode-map "\C-c\C-u"    'cvs-set-update-optional-flags)
  1606.   ;; M- keys are usually those that operate on modules
  1607.   (define-key cvs-mode-map "\M-\C-?"    'cvs-mode-unmark-all-files)
  1608.   (define-key cvs-mode-map "\M-C"    'cvs-mode-rcs2log) ; i.e. "Create a ChangeLog"
  1609.   (define-key cvs-mode-map "\M-a"    'cvs-mode-admin)
  1610.   (define-key cvs-mode-map "\M-c"    'cvs-mode-checkout)
  1611.   (define-key cvs-mode-map "\M-o"    'cvs-mode-checkout-other-window)
  1612.   (define-key cvs-mode-map "\M-p"    'cvs-mode-rdiff) ; i.e. "create a Patch"
  1613.   (define-key cvs-mode-map "\M-r"    'cvs-mode-release)
  1614.   (define-key cvs-mode-map "\M-t"    'cvs-mode-rtag)
  1615.   ;; keys that operate on files
  1616.   (define-key cvs-mode-map " "    'cvs-mode-next-line)
  1617.   (define-key cvs-mode-map "?"    'describe-mode)
  1618.   (define-key cvs-mode-map "A"    'cvs-mode-add-change-log-entry-other-window)
  1619.   (define-key cvs-mode-map "B"    'cvs-mode-byte-compile-files)
  1620.   (define-key cvs-mode-map "C"  'cvs-mode-changelog-commit)
  1621.   (define-key cvs-mode-map "E"    'cvs-mode-emerge)
  1622.   (define-key cvs-mode-map "G"    'cvs-update)
  1623.   (define-key cvs-mode-map "M"    'cvs-mode-mark-all-files)
  1624.   (define-key cvs-mode-map "Q"    'cvs-examine)
  1625.   (define-key cvs-mode-map "R"    'cvs-mode-revert-updated-buffers)
  1626.   (define-key cvs-mode-map "U"    'cvs-mode-undo-local-changes)
  1627.   (define-key cvs-mode-map "a"    'cvs-mode-add)
  1628.   (define-key cvs-mode-map "b"    'cvs-mode-diff-backup)
  1629.   (define-key cvs-mode-map "c"    'cvs-mode-commit)
  1630.   (define-key cvs-mode-map "d"    'cvs-mode-diff-cvs)
  1631.   (define-key cvs-mode-map "e"    'cvs-mode-ediff)
  1632.   (define-key cvs-mode-map "f"    'cvs-mode-find-file)
  1633.   (define-key cvs-mode-map "g"    'cvs-mode-update-no-prompt)
  1634.   (define-key cvs-mode-map "i"    'cvs-mode-ignore)
  1635.   (define-key cvs-mode-map "l"    'cvs-mode-log)
  1636.   (define-key cvs-mode-map "m"    'cvs-mode-mark)
  1637.   (define-key cvs-mode-map "n"    'cvs-mode-next-line)
  1638.   (define-key cvs-mode-map "o"    'cvs-mode-find-file-other-window)
  1639.   (define-key cvs-mode-map "p"    'cvs-mode-previous-line)
  1640.   (define-key cvs-mode-map "q"    'bury-buffer)
  1641.   (define-key cvs-mode-map "r"    'cvs-mode-remove-file)
  1642.   (define-key cvs-mode-map "s"    'cvs-mode-status)
  1643.   (define-key cvs-mode-map "t"    'cvs-mode-tag)
  1644.   (define-key cvs-mode-map "u"    'cvs-mode-unmark)
  1645.   (define-key cvs-mode-map "v"    'cvs-mode-diff-vendor)
  1646.   (define-key cvs-mode-map "x"    'cvs-mode-remove-handled))
  1647.  
  1648. ;;----------
  1649. (defun cvs-get-marked (&optional ignore-marks ignore-contents)
  1650.   "Return a list of all selected tins.
  1651. Args:  &optional IGNORE-MARKS IGNORE-CONTENTS.
  1652.  
  1653. If there are any marked tins, and IGNORE-MARKS is nil, return them.  Otherwise,
  1654. if the cursor selects a directory, return all files in it, unless there are
  1655. none, in which case just return the directory; or unless IGNORE-CONTENTS is not
  1656. nil, in which case also just return the directory.  Otherwise return (a list
  1657. containing) the file the cursor points to, or an empty list if it doesn't point
  1658. to a file at all."
  1659.  
  1660.   (cond
  1661.    ;; Any marked cookies?
  1662.    ((and (not ignore-marks)
  1663.      (collection-collect-tin cvs-cookie-handle 'cvs-fileinfo->marked)))
  1664.    ;; Nope.
  1665.    ((and (not ignore-contents)
  1666.      (let ((sel (tin-locate cvs-cookie-handle (point))))
  1667.        (cond
  1668.         ;; If a directory is selected, all it members are returned.
  1669.         ((and sel (eq (cvs-fileinfo->type (tin-cookie cvs-cookie-handle
  1670.                               sel))
  1671.               'DIRCHANGE))
  1672.          (let ((retsel
  1673.             (collection-collect-tin cvs-cookie-handle
  1674.                         'cvs-dir-member-p
  1675.                         (cvs-fileinfo->dir (tin-cookie
  1676.                                 cvs-cookie-handle sel)))))
  1677.            (if retsel
  1678.            retsel
  1679.          (list sel))))
  1680.         (t
  1681.          (list sel))))))
  1682.    (t
  1683.     (list (tin-locate cvs-cookie-handle (point))))))
  1684.  
  1685. ;;----------
  1686. (defun cvs-dir-member-p (fileinfo dir)
  1687.   "Return true if FILEINFO represents a file in directory DIR."
  1688.  
  1689.   (and (not (eq (cvs-fileinfo->type fileinfo) 'DIRCHANGE))
  1690.        (string= (cvs-fileinfo->dir fileinfo) dir)))
  1691.  
  1692. ;;----------
  1693. (defun cvs-dir-empty-p (tin)
  1694.   "Return non-nil if TIN is a directory that is empty.
  1695. Args:  CVS-BUF TIN."
  1696.  
  1697.   (and (eq (cvs-fileinfo->type (tin-cookie cvs-cookie-handle tin)) 'DIRCHANGE)
  1698.        (or (not (tin-next cvs-cookie-handle tin))
  1699.        (eq (cvs-fileinfo->type
  1700.         (tin-cookie cvs-cookie-handle
  1701.                     (tin-next cvs-cookie-handle tin)))
  1702.            'DIRCHANGE))))
  1703.  
  1704. ;;----------
  1705. (defun cvs-mode-revert-updated-buffers ()
  1706.   "Revert any buffers that are UPDATED, PATCHED, MERGED or CONFLICT."
  1707.  
  1708.   (interactive)
  1709.   (cookie-map (function cvs-revert-fileinfo) cvs-cookie-handle))
  1710.  
  1711. ;;----------
  1712. (defun cvs-revert-fileinfo (fileinfo)
  1713.   "Revert the buffer that holds the file in FILEINFO if it has changed,
  1714. and if the type is UPDATED, PATCHED, MERGED or CONFLICT."
  1715.  
  1716.   (let* ((type (cvs-fileinfo->type fileinfo))
  1717.      (file (cvs-fileinfo->full-path fileinfo))
  1718.      (buffer (get-file-buffer file)))
  1719.     ;; For a revert to happen...
  1720.     (cond
  1721.      ((and
  1722.        ;; ...the type must be one that justifies a revert...
  1723.        (or (eq type 'UPDATED)
  1724.        (eq type 'PATCHED)
  1725.        (eq type 'MERGED)
  1726.        (eq type 'CONFLICT))
  1727.        ;; ...and the user must be editing the file...
  1728.        buffer)
  1729.       (save-excursion
  1730.     (set-buffer buffer)
  1731.     (cond
  1732.      ((buffer-modified-p)
  1733.       (error "%s: edited since last cvs-update."
  1734.          (buffer-file-name)))
  1735.      ;; Go ahead and revert the file.
  1736.      (t (revert-buffer 'dont-use-auto-save-file 'dont-ask))))))))
  1737.  
  1738. ;;----------
  1739. (defun cvs-mode-remove-handled ()
  1740.   "Remove all lines that are handled.
  1741. Empty directories are removed."
  1742.  
  1743.   (interactive)
  1744.   ;; Pass one:  remove files that are handled.
  1745.   (collection-filter-cookies cvs-cookie-handle
  1746.                  (function
  1747.                   (lambda (fileinfo)
  1748.                 (not (cvs-fileinfo->handled fileinfo)))))
  1749.   ;; Pass two:  remove empty directories.
  1750.   (if cvs-auto-remove-handled-directories
  1751.       (cvs-remove-empty-directories)))
  1752.  
  1753. ;;----------
  1754. (defun cvs-remove-empty-directories ()
  1755.   "Remove empty directories in the *cvs* buffer."
  1756.  
  1757.   (collection-filter-tins cvs-cookie-handle
  1758.               (function
  1759.                (lambda (tin)
  1760.                  (not (cvs-dir-empty-p tin))))))
  1761.  
  1762. ;;----------
  1763. (defun cvs-mode-mark (pos)
  1764.   "Mark a fileinfo.
  1765. Args:  POS.
  1766.  
  1767. If the fileinfo is a directory, all the contents of that directory are marked
  1768. instead.  A directory can never be marked.  POS is a buffer position."
  1769.  
  1770.   (interactive "d")
  1771.   (let* ((tin (tin-locate cvs-cookie-handle pos))
  1772.      (sel (tin-cookie cvs-cookie-handle tin)))
  1773.     (cond
  1774.      ;; Does POS point to a directory?  If so, mark all files in that directory.
  1775.      ((eq (cvs-fileinfo->type sel) 'DIRCHANGE)
  1776.       (cookie-map
  1777.        (function (lambda (f dir)
  1778.            (cond
  1779.             ((cvs-dir-member-p f dir)
  1780.              (cvs-set-fileinfo->marked f t)
  1781.              t))))        ; Tell cookie to redisplay this cookie.
  1782.        cvs-cookie-handle
  1783.        (cvs-fileinfo->dir sel)))
  1784.      (t
  1785.       (cvs-set-fileinfo->marked sel t)
  1786.       (tin-invalidate cvs-cookie-handle tin)
  1787.       (tin-goto-next cvs-cookie-handle pos 1)))))
  1788.   
  1789. ;;----------
  1790. (defun cvs-committable (tin)
  1791.   "Check if the TIN is committable.
  1792. It is committable if it
  1793.    a) is not handled and
  1794.    b) is either MODIFIED, ADDED, REMOVED, MERGED or CONFLICT."
  1795.  
  1796.   (let* ((fileinfo (tin-cookie cvs-cookie-handle tin))
  1797.      (type (cvs-fileinfo->type fileinfo)))
  1798.     (and (not (cvs-fileinfo->handled fileinfo))
  1799.      (or (eq type 'MODIFIED)
  1800.          (eq type 'ADDED)
  1801.          (eq type 'REMOVED)
  1802.          (eq type 'MERGED)
  1803.          (eq type 'CONFLICT)))))
  1804.  
  1805. ;;----------
  1806. (defun cvs-mode-commit ()
  1807.   "Check in all marked files, or the current file.
  1808. The user will be asked for a log message in a buffer.
  1809. If cvs-erase-input-buffer is non-nil that buffer will be erased.
  1810. Otherwise mark and point will be set around the entire contents of the
  1811. buffer so that it is easy to kill the contents of the buffer with \\[kill-region]."
  1812.  
  1813.   (interactive)
  1814.   (let* ((cvs-buf (current-buffer))
  1815.      (marked (cvs-filter (function cvs-committable)
  1816.                  (cvs-get-marked))))
  1817.     (if (null marked)
  1818.     (error "Nothing to commit!")
  1819.       (pop-to-buffer (get-buffer-create cvs-commit-prompt-buffer))
  1820.       (goto-char (point-min))
  1821.  
  1822.       (if cvs-erase-input-buffer
  1823.       (erase-buffer)
  1824.     (push-mark (point-max)))
  1825.       (cvs-edit-mode)
  1826.       (make-local-variable 'cvs-commit-list)
  1827.       (setq cvs-commit-list marked)
  1828.       (message "Press C-c C-c when you are done editing."))))
  1829.  
  1830. ;;----------
  1831. (defun cvs-edit-done ()
  1832.   "Commit the files to the repository."
  1833.  
  1834.   (interactive)
  1835.   (if (null cvs-commit-list)
  1836.       (error "You have already committed the files"))
  1837.   (if (and (> (point-max) 1)
  1838.        (/= (char-after (1- (point-max))) ?\n)
  1839.        (or (eq cvs-commit-buffer-require-final-newline t)
  1840.            (and cvs-commit-buffer-require-final-newline
  1841.             (yes-or-no-p
  1842.              (format "Buffer %s does not end in newline.  Add one? "
  1843.                  (buffer-name))))))
  1844.       (save-excursion
  1845.     (goto-char (point-max))
  1846.     (insert ?\n)))
  1847.   (save-some-buffers)
  1848.   (let ((cc-list cvs-commit-list)
  1849.     (cc-buffer (get-buffer cvs-buffer-name))
  1850.     (msg-buffer (current-buffer))
  1851.     (msg (buffer-substring (point-min) (point-max))))
  1852.     (pop-to-buffer cc-buffer)
  1853.     (bury-buffer msg-buffer)
  1854.     (cvs-use-temp-buffer)
  1855.     (message "Committing...")
  1856.     (if (cvs-execute-list cc-list cvs-program
  1857.               (if cvs-cvsroot
  1858.                   (list "-d" cvs-cvsroot "commit" "-m" msg)
  1859.                 (list "commit" "-m" msg))
  1860.               "Committing %s...")
  1861.     (error "Something went wrong.  Check the %s buffer carefully."
  1862.            cvs-temp-buffer-name))
  1863.     ;; FIXME: don't do any of this if the commit fails.
  1864.     (let ((ccl cc-list))
  1865.       (while ccl
  1866.     (cvs-after-commit-function (tin-cookie cvs-cookie-handle (car ccl)))
  1867.     (setq ccl (cdr ccl))))
  1868.     (apply 'tin-invalidate cvs-cookie-handle cc-list)
  1869.     (set-buffer msg-buffer)
  1870.     (setq cvs-commit-list nil)
  1871.     (set-buffer cc-buffer)
  1872.     (if cvs-auto-remove-handled
  1873.     (cvs-mode-remove-handled)))
  1874.   
  1875.   (message "Committing... Done."))
  1876.  
  1877. ;;----------
  1878. (defun cvs-after-commit-function (fileinfo)
  1879.   "Do everything that needs to be done when FILEINFO has been committed.
  1880. The fileinfo->handle is set, and if the buffer is present it is reverted."
  1881.  
  1882.   (cvs-set-fileinfo->handled fileinfo t)
  1883.   (if cvs-auto-revert-after-commit
  1884.       (let* ((file (cvs-fileinfo->full-path fileinfo))
  1885.          (buffer (get-file-buffer file)))
  1886.     ;; For a revert to happen...
  1887.     (if buffer
  1888.         ;; ...the user must be editing the file...
  1889.         (save-excursion
  1890.           (set-buffer buffer)
  1891.           (if (not (buffer-modified-p))
  1892.           ;; ...but it must be unmodified.
  1893.           (revert-buffer 'dont-use-auto-save-file 'dont-ask)))))))
  1894.  
  1895. ;;----------
  1896. (defun cvs-execute-list (tin-list program constant-args &optional message-fmt)
  1897.   "Run PROGRAM on all elements on TIN-LIST.
  1898. Args:  TIN-LIST PROGRAM CONSTANT-ARGS.
  1899.  
  1900. The PROGRAM will be called with pwd set to the directory the files reside
  1901. in.  CONSTANT-ARGS should be a list of strings.  The arguments given to the
  1902. program will be CONSTANT-ARGS followed by all the files (from TIN-LIST) that
  1903. resides in that directory.  If the files in TIN-LIST resides in different
  1904. directories the PROGRAM will be run once for each directory (if all files in
  1905. the same directory appears after each other).
  1906.  
  1907. Any output from PROGRAM will be inserted in the current buffer.
  1908.  
  1909. This function return nil if all went well, or the numerical exit status or a
  1910. signal name as a string.  Note that PROGRAM might be called several times.  This
  1911. will return non-nil if something goes wrong, but there is no way to know which
  1912. process that failed.
  1913.  
  1914. If MESSAGE-FMT is not nil, then message is called to display progress with
  1915. MESSAGE-FMT as the string.  MESSAGE-FMT should contain one %s for the arg-list
  1916. being passed to PROGRAM."
  1917.  
  1918.   ;; FIXME:  something seems wrong with the error checking here....
  1919.  
  1920.   (let ((exitstatus nil))
  1921.     (while tin-list
  1922.       (let ((current-dir (cvs-fileinfo->dir (tin-cookie cvs-cookie-handle
  1923.                             (car tin-list))))
  1924.         arg-list
  1925.         arg-str)
  1926.  
  1927.     ;; Collect all marked files in this directory.
  1928.  
  1929.     (while (and tin-list
  1930.             (string= current-dir
  1931.                  (cvs-fileinfo->dir (tin-cookie cvs-cookie-handle
  1932.                                 (car tin-list)))))
  1933.       (setq arg-list
  1934.         (cons (cvs-fileinfo->file-name
  1935.                (tin-cookie cvs-cookie-handle (car tin-list)))
  1936.               arg-list))
  1937.       (setq tin-list (cdr tin-list)))
  1938.  
  1939.     (setq arg-list (nreverse arg-list))
  1940.  
  1941.     ;; Execute the command on all the files that were collected.
  1942.  
  1943.     (if message-fmt
  1944.         (message message-fmt
  1945.              (mapconcat 'cvs-quote-multiword-string
  1946.                 arg-list
  1947.                 " ")))
  1948.     (setq default-directory (file-name-as-directory current-dir))
  1949.     (insert (format "=== cd %s\n" default-directory))
  1950.     (insert (format "=== %s %s\n\n"
  1951.             program
  1952.             (mapconcat 'cvs-quote-multiword-string
  1953.                    (nconc (copy-sequence constant-args)
  1954.                       arg-list)
  1955.                    " ")))
  1956.     (let ((res (apply 'call-process program nil t t
  1957.               (nconc (copy-sequence constant-args) arg-list))))
  1958.       ;; Remember the first, or highest, exitstatus.
  1959.       (if (and (not (and (integerp res) (zerop res)))
  1960.            (or (null exitstatus)
  1961.                (and (integerp exitstatus) (= 1 exitstatus))))
  1962.           (setq exitstatus res)))
  1963.     (goto-char (point-max))
  1964.     (if message-fmt
  1965.         (message message-fmt
  1966.              (mapconcat 'cvs-quote-multiword-string
  1967.                 (nconc (copy-sequence arg-list) '("Done."))
  1968.                 " ")))
  1969.     exitstatus))))
  1970.  
  1971. ;;----------
  1972. ;;;; +++ not currently used!
  1973. (defun cvs-execute-single-file-list (tin-list extractor program constant-args
  1974.                           &optional cleanup message-fmt)
  1975.   "Run PROGRAM on all elements on TIN-LIST.
  1976. Args:  TIN-LIST EXTRACTOR PROGRAM CONSTANT-ARGS &optional CLEANUP.
  1977.  
  1978. The PROGRAM will be called with pwd set to the directory the files
  1979. reside in.  CONSTANT-ARGS is a list of strings to pass as arguments to
  1980. PROGRAM.  The arguments given to the program will be CONSTANT-ARGS
  1981. followed by the list that EXTRACTOR returns.
  1982.  
  1983. EXTRACTOR will be called once for each file on TIN-LIST.  It is given
  1984. one argument, the cvs-fileinfo.  It can return t, which means ignore
  1985. this file, or a list of arguments to send to the program.
  1986.  
  1987. If CLEANUP is not nil, the filenames returned by EXTRACTOR are deleted.
  1988.  
  1989. If MESSAGE-FMT is not nil, then message is called to display progress with
  1990. MESSAGE-FMT as the string.  MESSAGE-FMT should contain one %s for the arg-list
  1991. being passed to PROGRAM."
  1992.  
  1993.     (while tin-list
  1994.       (let ((current-dir (file-name-as-directory
  1995.               (cvs-fileinfo->dir
  1996.                (tin-cookie cvs-cookie-handle
  1997.                        (car tin-list)))))
  1998.         (arg-list
  1999.          (funcall extractor
  2000.               (tin-cookie cvs-cookie-handle (car tin-list)))))
  2001.  
  2002.     ;; Execute the command unless extractor returned t.
  2003.  
  2004.     (if (eq arg-list t)
  2005.         nil
  2006.       (setq default-directory current-dir)
  2007.       (insert (format "=== cd %s\n" default-directory))
  2008.       (insert (format "=== %s %s\n\n"
  2009.               program
  2010.               (mapconcat 'cvs-quote-multiword-string
  2011.                      (nconc (copy-sequence constant-args)
  2012.                         arg-list)
  2013.                      " ")))
  2014.       (if message-fmt
  2015.           (message message-fmt (mapconcat 'cvs-quote-multiword-string
  2016.                           arg-list
  2017.                           " ")))
  2018.       (apply 'call-process program nil t t
  2019.          (nconc (copy-sequence constant-args) arg-list))
  2020.       (goto-char (point-max))
  2021.       (if message-fmt
  2022.           (message message-fmt (mapconcat 'cvs-quote-multiword-string
  2023.                           (nconc arg-list '("Done."))
  2024.                           " ")))
  2025.       (if cleanup
  2026.           (while arg-list
  2027. ;;;;        (kill-buffer ?????)
  2028.         (delete-file (car arg-list))
  2029.         (setq arg-list (cdr arg-list))))))
  2030.       (setq tin-list (cdr tin-list))))
  2031.  
  2032. ;;----------
  2033. (defun cvs-edit-mode ()
  2034.   "\\<cvs-edit-mode-map>Mode for editing cvs log messages.
  2035. Commands:
  2036. \\[cvs-edit-done] checks in the file when you are ready.
  2037. This mode is based on fundamental mode."
  2038.  
  2039.   (interactive)
  2040.   (use-local-map cvs-edit-mode-map)
  2041.   (setq major-mode 'cvs-edit-mode)
  2042.   (setq mode-name "CVS Log")
  2043.   (auto-fill-mode 1))
  2044.  
  2045. ;;----------
  2046. (if cvs-edit-mode-map
  2047.     nil
  2048.   (setq cvs-edit-mode-map (make-sparse-keymap))
  2049.   (define-prefix-command 'cvs-edit-mode-control-c-prefix)
  2050.   (define-key cvs-edit-mode-map "\C-c" 'cvs-edit-mode-control-c-prefix)
  2051.   (define-key cvs-edit-mode-map "\C-c\C-c" 'cvs-edit-done))
  2052.  
  2053. ;;----------
  2054. (defun cvs-diffable (tins)
  2055.   "Return a list of all tins on TINS that it makes sense to run
  2056. ``cvs diff'' on."
  2057.  
  2058.   ;; +++ There is an unnecessary (nreverse) here.  Get the list the
  2059.   ;; other way around instead!
  2060.   (let ((result nil))
  2061.     (while tins
  2062.       (let ((type (cvs-fileinfo->type
  2063.            (tin-cookie cvs-cookie-handle (car tins)))))
  2064.     (if (or (eq type 'MODIFIED)
  2065.         (eq type 'UPDATED)
  2066.         (eq type 'PATCHED)
  2067.         (eq type 'MERGED)
  2068.         (eq type 'CONFLICT)
  2069.         (eq type 'REMOVED)    ;+++Does this line make sense?
  2070.         (eq type 'ADDED))    ;+++Does this line make sense?
  2071.         (setq result (cons (car tins) result)))
  2072.     (setq tins (cdr tins))))
  2073.     (nreverse result)))
  2074.       
  2075. ;;----------
  2076. (defun cvs-mode-diff-cvs (&optional ignore-marks)
  2077.   "Diff the selected files against the head revisions in the repository.
  2078.  
  2079. If the variable cvs-diff-ignore-marks is non-nil any marked files will not be
  2080. considered to be selected.  An optional prefix argument will invert the
  2081. influence from cvs-diff-ignore-marks.
  2082.  
  2083. The flags in the variable cvs-diff-flags will be passed to ``cvs diff''.
  2084.  
  2085. The resulting diffs are placed in the cvs-fileinfo->cvs-diff-buffer."
  2086.  
  2087.   (interactive "P")
  2088.   (if (not (listp cvs-diff-flags))
  2089.       (error "cvs-diff-flags should be set using cvs-set-diff-flags."))
  2090.   (save-some-buffers)
  2091.   (message "cvsdiffing...")
  2092.   (let ((marked-file-list (cvs-diffable
  2093.          (cvs-get-marked
  2094.           (or (and ignore-marks (not cvs-diff-ignore-marks))
  2095.               (and (not ignore-marks) cvs-diff-ignore-marks))))))
  2096.     (while marked-file-list
  2097.       (let ((fileinfo-to-diff (tin-cookie cvs-cookie-handle
  2098.                       (car marked-file-list)))
  2099.         (local-def-directory (file-name-as-directory
  2100.                   (cvs-fileinfo->dir
  2101.                    (tin-cookie cvs-cookie-handle
  2102.                            (car marked-file-list))))))
  2103.     (message "cvsdiffing %s..."
  2104.          (cvs-fileinfo->file-name fileinfo-to-diff))
  2105.  
  2106.     ;; FIXME:  this seems messy to test and set buffer name at this point....
  2107.     (if (not (cvs-fileinfo->cvs-diff-buffer fileinfo-to-diff))
  2108.         (cvs-set-fileinfo->cvs-diff-buffer fileinfo-to-diff
  2109.                            (concat "*cvs-diff-"
  2110.                                (cvs-fileinfo->file-name
  2111.                             fileinfo-to-diff)
  2112.                                "-in-"
  2113.                                local-def-directory
  2114.                                "*")))
  2115.     (display-buffer (get-buffer-create
  2116.              (cvs-fileinfo->cvs-diff-buffer fileinfo-to-diff)))
  2117.     (set-buffer (cvs-fileinfo->cvs-diff-buffer fileinfo-to-diff))
  2118.     (setq buffer-read-only nil)
  2119.     (setq default-directory local-def-directory)
  2120.     (erase-buffer)
  2121.     (insert (format "=== cd %s\n" default-directory))
  2122.     (insert (format "=== cvs %s\n\n"
  2123.             (mapconcat 'cvs-quote-multiword-string
  2124.                    (nconc (if cvs-cvsroot
  2125.                           (list "-d" cvs-cvsroot "diff")
  2126.                         '("diff"))
  2127.                       (copy-sequence cvs-diff-flags)
  2128.                       (list (cvs-fileinfo->file-name
  2129.                          fileinfo-to-diff)))
  2130.                    " ")))
  2131.     (if (apply 'call-process cvs-program nil t t
  2132.            (nconc (if cvs-cvsroot
  2133.                   (list "-d" cvs-cvsroot "diff")
  2134.                 '("diff"))
  2135.               (copy-sequence cvs-diff-flags)
  2136.               (list (cvs-fileinfo->file-name fileinfo-to-diff))))
  2137.         (message "cvsdiffing %s... Done."
  2138.              (cvs-fileinfo->file-name fileinfo-to-diff))
  2139.       (message "cvsdiffing %s... No differences found."
  2140.            (cvs-fileinfo->file-name fileinfo-to-diff)))
  2141.     (goto-char (point-max))
  2142.     (setq marked-file-list (cdr marked-file-list)))))
  2143.   (message "cvsdiffing... Done."))
  2144.  
  2145. ;;----------
  2146. (defun cvs-mode-diff-backup (&optional ignore-marks)
  2147.   "Diff the files against the backup file.
  2148. This command can be used on files that are marked with \"Merged\"
  2149. or \"Conflict\" in the *cvs* buffer.
  2150.  
  2151. If the variable cvs-diff-ignore-marks is non-nil any marked files will
  2152. not be considered to be selected.  An optional prefix argument will
  2153. invert the influence from cvs-diff-ignore-marks.
  2154.  
  2155. The flags in cvs-diff-flags will be passed to ``diff''.
  2156.  
  2157. The resulting diffs are placed in the cvs-fileinfo->backup-diff-buffer."
  2158.  
  2159.   (interactive "P")
  2160.   (if (not (listp cvs-diff-flags))
  2161.       (error "cvs-diff-flags should be set using cvs-set-diff-flags."))
  2162.   (save-some-buffers)
  2163.   (let ((marked-file-list (cvs-filter
  2164.                (function cvs-backup-diffable)
  2165.                (cvs-get-marked
  2166.                 (or
  2167.                  (and ignore-marks (not cvs-diff-ignore-marks))
  2168.                  (and (not ignore-marks) cvs-diff-ignore-marks))))))
  2169.     (if (null marked-file-list)
  2170.     (error "No ``Conflict'' or ``Merged'' file selected!"))
  2171.     (message "backup diff...")
  2172.     (while marked-file-list
  2173.       (let ((fileinfo-to-diff (tin-cookie cvs-cookie-handle
  2174.                       (car marked-file-list)))
  2175.         (local-def-directory (file-name-as-directory
  2176.                   (cvs-fileinfo->dir
  2177.                    (tin-cookie cvs-cookie-handle
  2178.                            (car marked-file-list)))))
  2179.         (backup-temp-files (cvs-diff-backup-extractor
  2180.                 (tin-cookie cvs-cookie-handle
  2181.                         (car marked-file-list)))))
  2182.     (message "backup diff %s..."
  2183.          (cvs-fileinfo->file-name fileinfo-to-diff))
  2184.  
  2185.     ;; FIXME:  this seems messy to test and set buffer name at this point....
  2186.     (if (not (cvs-fileinfo->backup-diff-buffer fileinfo-to-diff))
  2187.         (cvs-set-fileinfo->backup-diff-buffer fileinfo-to-diff
  2188.                           (concat "*cvs-diff-"
  2189.                               (cvs-fileinfo->backup-file
  2190.                                fileinfo-to-diff)
  2191.                               "-to-"
  2192.                               (cvs-fileinfo->file-name
  2193.                                fileinfo-to-diff)
  2194.                               "-in"
  2195.                               local-def-directory
  2196.                               "*")))
  2197.     (display-buffer (get-buffer-create
  2198.              (cvs-fileinfo->backup-diff-buffer fileinfo-to-diff)))
  2199.     (set-buffer (cvs-fileinfo->backup-diff-buffer fileinfo-to-diff))
  2200.     (setq buffer-read-only nil)
  2201.     (setq default-directory local-def-directory)
  2202.     (erase-buffer)
  2203.     (insert (format "=== cd %s\n" default-directory))
  2204.     (insert (format "=== %s %s\n\n"
  2205.             cvs-diff-program
  2206.             (mapconcat 'cvs-quote-multiword-string
  2207.                    (nconc (copy-sequence cvs-diff-flags)
  2208.                       backup-temp-files)
  2209.                    " ")))
  2210.     (apply 'call-process cvs-diff-program nil t t
  2211.            (nconc (copy-sequence cvs-diff-flags) backup-temp-files))
  2212.     (goto-char (point-max))
  2213.     (message "backup diff %s... Done."
  2214.          (cvs-fileinfo->file-name fileinfo-to-diff))
  2215.     (setq marked-file-list (cdr marked-file-list)))))
  2216.   (message "backup diff... Done."))
  2217.  
  2218. ;;----------
  2219. (defun cvs-mode-diff-vendor (&optional ignore-marks)
  2220.   "Diff the revisions merged into the current file.  I.e. show what changes
  2221. were merged in.
  2222.  
  2223. This command can be used on files that are marked with \"Merged\"
  2224. or \"Conflict\" in the *cvs* buffer.
  2225.  
  2226. If the variable cvs-diff-ignore-marks is non-nil any marked files will
  2227. not be considered to be selected.  An optional prefix argument will
  2228. invert the influence from cvs-diff-ignore-marks.
  2229.  
  2230. The flags in cvs-diff-flags will be passed to ``diff''.
  2231.  
  2232. The resulting diffs are placed in the cvs-fileinfo->vendor-diff-buffer."
  2233.  
  2234.   (interactive "P")
  2235.   (if (not (listp cvs-diff-flags))
  2236.       (error "cvs-diff-flags should be set using cvs-set-diff-flags."))
  2237.   (save-some-buffers)
  2238.   (let ((marked-file-list (cvs-filter
  2239.                (function cvs-vendor-diffable)
  2240.                (cvs-get-marked
  2241.                 (or
  2242.                  (and ignore-marks (not cvs-diff-ignore-marks))
  2243.                  (and (not ignore-marks) cvs-diff-ignore-marks))))))
  2244.     (if (null marked-file-list)
  2245.     (error "No ``Conflict'' or ``Merged'' file selected!"))
  2246.     (message "vendor diff...")
  2247.     (while marked-file-list
  2248.       (let ((fileinfo-to-diff (tin-cookie cvs-cookie-handle
  2249.                       (car marked-file-list)))
  2250.         (local-def-directory (file-name-as-directory
  2251.                   (cvs-fileinfo->dir
  2252.                    (tin-cookie cvs-cookie-handle
  2253.                            (car marked-file-list)))))
  2254.         (vendor-temp-files (cvs-diff-vendor-extractor
  2255.                 (tin-cookie cvs-cookie-handle
  2256.                         (car marked-file-list)))))
  2257.     (message "vendor diff %s..."
  2258.              (cvs-fileinfo->file-name fileinfo-to-diff))
  2259.     (if (not (cvs-fileinfo->vendor-diff-buffer fileinfo-to-diff))
  2260.         (cvs-set-fileinfo->vendor-diff-buffer fileinfo-to-diff
  2261.                           (concat "*cvs-diff-"
  2262.                               (cvs-fileinfo->file-name
  2263.                                fileinfo-to-diff)
  2264.                               "-of-"
  2265.                               (cvs-fileinfo->base-revision
  2266.                                fileinfo-to-diff)
  2267.                               "-to-"
  2268.                               (cvs-fileinfo->head-revision
  2269.                                fileinfo-to-diff)
  2270.                               "-in-"
  2271.                               local-def-directory
  2272.                               "*")))
  2273.     (display-buffer (get-buffer-create
  2274.              (cvs-fileinfo->vendor-diff-buffer fileinfo-to-diff)))
  2275.     (set-buffer (cvs-fileinfo->vendor-diff-buffer fileinfo-to-diff))
  2276.     (setq buffer-read-only nil)
  2277.     (setq default-directory local-def-directory)
  2278.     (erase-buffer)
  2279.     (insert (format "=== cd %s\n" default-directory))
  2280.     (insert (format "=== %s %s\n\n"
  2281.             cvs-diff-program
  2282.             (mapconcat 'cvs-quote-multiword-string
  2283.                    (nconc (copy-sequence cvs-diff-flags)
  2284.                       vendor-temp-files)
  2285.                    " ")))
  2286.     (apply 'call-process cvs-diff-program nil t t
  2287.            (nconc (copy-sequence cvs-diff-flags) vendor-temp-files))
  2288.     (goto-char (point-max))
  2289.     (message "vendor diff %s... Done."
  2290.              (cvs-fileinfo->file-name fileinfo-to-diff))
  2291.     (while vendor-temp-files
  2292.       (cvs-kill-buffer-visiting (car vendor-temp-files))
  2293.       (delete-file (car vendor-temp-files))
  2294.       (setq vendor-temp-files (cdr vendor-temp-files)))
  2295.     (setq marked-file-list (cdr marked-file-list)))))
  2296.   (message "vendor diff... Done."))
  2297.  
  2298. ;;----------
  2299. (defun cvs-backup-diffable (tin)
  2300.   "Check if the TIN is backup-diffable.
  2301. It must have a backup file to be diffable."
  2302.  
  2303.   (file-readable-p
  2304.    (cvs-fileinfo->backup-file (tin-cookie cvs-cookie-handle tin))))
  2305.  
  2306. ;;----------
  2307. (defun cvs-vendor-diffable (tin)
  2308.   "Check if the TIN is vendor-diffable.
  2309. It must have head and base revision info to be diffable."
  2310.  
  2311.   (and
  2312.    (cvs-fileinfo->base-revision (tin-cookie cvs-cookie-handle tin))
  2313.    (cvs-fileinfo->head-revision (tin-cookie cvs-cookie-handle tin))))
  2314.  
  2315. ;;----------
  2316. (defun cvs-diff-backup-extractor (fileinfo)
  2317.   "Return the filename and the name of the backup file as a list.
  2318. Signal an error if there is no backup file."
  2319.  
  2320.   (if (not (file-readable-p (cvs-fileinfo->backup-file fileinfo)))
  2321.       (error "%s has no backup file."
  2322.          (concat
  2323.           (file-name-as-directory (cvs-fileinfo->dir fileinfo))
  2324.           (cvs-fileinfo->file-name fileinfo))))
  2325.   (list    (cvs-fileinfo->backup-file fileinfo)
  2326.      (cvs-fileinfo->file-name fileinfo)))
  2327.  
  2328. ;;----------
  2329. (defun cvs-diff-vendor-extractor (fileinfo)
  2330.   "Retrieve and return the filenames of the vendor branch revisions as a list.
  2331. Signal an error if there is no info for the vendor revisions."
  2332.  
  2333.   (list (cvs-retrieve-revision-to-tmpfile fileinfo
  2334.                       (cvs-fileinfo->base-revision
  2335.                        fileinfo))
  2336.     (cvs-retrieve-revision-to-tmpfile fileinfo
  2337.                       (cvs-fileinfo->head-revision
  2338.                        fileinfo))))
  2339.  
  2340. ;;----------
  2341. (defun cvs-mode-find-file-other-window (pos)
  2342.   "Select a buffer containing the file in another window.
  2343. Args:  POS."
  2344.  
  2345.   (interactive "d")
  2346.   (let ((tin (tin-locate cvs-cookie-handle pos)))
  2347.     (if tin
  2348.     (let ((type (cvs-fileinfo->type (tin-cookie cvs-cookie-handle tin))))
  2349.       (cond
  2350.        ((or (eq type 'REMOVED)
  2351.         (eq type 'CVS-REMOVED))
  2352.         (error "Can't visit a removed file."))
  2353.        ((eq type 'DIRCHANGE)
  2354.         (let ((obuf (current-buffer))
  2355.           (odir default-directory))
  2356.           (setq default-directory
  2357.             (file-name-as-directory
  2358.              (cvs-fileinfo->dir
  2359.               (tin-cookie cvs-cookie-handle tin))))
  2360.           (dired-other-window default-directory)
  2361.           (set-buffer obuf)
  2362.           (setq default-directory odir)))
  2363.        (t
  2364.         (find-file-other-window (cvs-full-path tin)))))
  2365.       (error "There is no file to find."))))
  2366.  
  2367. ;;----------
  2368. (defun cvs-fileinfo->full-path (fileinfo)
  2369.   "Return the full path for the file that is described in FILEINFO."
  2370.  
  2371.   (concat
  2372.    (file-name-as-directory
  2373.     (cvs-fileinfo->dir fileinfo))
  2374.    (cvs-fileinfo->file-name fileinfo)))
  2375.  
  2376. ;;----------
  2377. (defun cvs-full-path (tin)
  2378.   "Return the full path for the file that is described in TIN."
  2379.  
  2380.   (cvs-fileinfo->full-path (tin-cookie cvs-cookie-handle tin)))
  2381.  
  2382. ;;----------
  2383. (defun cvs-mode-find-file (pos)
  2384.   "Select a buffer containing the file in another window.
  2385. Args:  POS."
  2386.  
  2387.   (interactive "d")
  2388.   (let* ((cvs-buf (current-buffer))
  2389.      (tin (tin-locate cvs-cookie-handle pos)))
  2390.     (if tin
  2391.     (let* ((fileinfo (tin-cookie cvs-cookie-handle tin))
  2392.            (type (cvs-fileinfo->type fileinfo)))
  2393.       (cond
  2394.        ((or (eq type 'REMOVED)
  2395.         (eq type 'CVS-REMOVED))
  2396.         (error "Can't visit a removed file."))
  2397.        ((eq type 'DIRCHANGE)
  2398.         (let ((odir default-directory))
  2399.           (setq default-directory
  2400.             (file-name-as-directory (cvs-fileinfo->dir fileinfo)))
  2401.           (dired default-directory)
  2402.           (set-buffer cvs-buf)
  2403.           (setq default-directory odir))) 
  2404.        (t
  2405.         (find-file (cvs-full-path tin)))))
  2406.       (error "There is no file to find."))))
  2407.  
  2408. ;;----------
  2409. (defun cvs-mode-mark-all-files ()
  2410.   "Mark all files.
  2411. Directories are not marked."
  2412.  
  2413.   (interactive)
  2414.   (cookie-map (function (lambda (cookie)
  2415.               (cond
  2416.                ((not (eq (cvs-fileinfo->type cookie) 'DIRCHANGE))
  2417.                 (cvs-set-fileinfo->marked cookie t)
  2418.                 t))))
  2419.           cvs-cookie-handle))
  2420.  
  2421. ;;----------
  2422. (defun cvs-mode-unmark (pos)
  2423.   "Unmark a fileinfo.
  2424. Args:  POS."
  2425.  
  2426.   (interactive "d")
  2427.   (let* ((tin (tin-locate cvs-cookie-handle pos))
  2428.      (sel (tin-cookie cvs-cookie-handle tin)))
  2429.     (cond
  2430.      ((eq (cvs-fileinfo->type sel) 'DIRCHANGE)
  2431.       (cookie-map
  2432.        (function (lambda (f dir)
  2433.            (cond
  2434.             ((cvs-dir-member-p f dir)
  2435.              (cvs-set-fileinfo->marked f nil)
  2436.              t))))
  2437.        cvs-cookie-handle
  2438.        (cvs-fileinfo->dir sel)))
  2439.      (t
  2440.       (cvs-set-fileinfo->marked sel nil)
  2441.       (tin-invalidate cvs-cookie-handle tin)
  2442.       (tin-goto-next cvs-cookie-handle pos 1)))))
  2443.  
  2444. ;;----------
  2445. (defun cvs-mode-unmark-all-files ()
  2446.   "Unmark all files.
  2447. Directories are also unmarked, but that doesn't matter, since
  2448. they should always be unmarked."
  2449.  
  2450.   (interactive)
  2451.   (cookie-map (function (lambda (cookie)
  2452.               (cvs-set-fileinfo->marked cookie nil)
  2453.               t))
  2454.           cvs-cookie-handle))
  2455.  
  2456. ;;----------
  2457. (defun cvs-do-removal (tins)
  2458.   "Remove files.
  2459. Args:  TINS.
  2460.  
  2461. TINS is a list of tins that the user wants to delete.  The files are deleted.
  2462. If the type of the tin is 'UNKNOWN or 'UNKNOWN-DIR the tin is removed from the
  2463. buffer.  If it is anything else the file is added to a list that should be `cvs
  2464. remove'd and the tin is changed to be of type 'REMOVED.
  2465.  
  2466. Returns a list of tins files that should be `cvs remove'd."
  2467.  
  2468.   (cvs-use-temp-buffer)
  2469.   (mapcar 'cvs-insert-full-path tins)
  2470.   (cond
  2471.    ((and tins (yes-or-no-p (format "Delete %d files? " (length tins))))
  2472.     (let (files-to-remove)
  2473.       (while tins
  2474.     (let* ((tin (car tins))
  2475.            (fileinfo (tin-cookie cvs-cookie-handle tin))
  2476.            (filepath (cvs-full-path tin))
  2477.            (type (cvs-fileinfo->type fileinfo)))
  2478.       (if (or (eq type 'REMOVED)
  2479.           (eq type 'CVS-REMOVED))
  2480.           nil
  2481.         ;; if it doesn't exist, as a file or directory, ignore it
  2482.         (cond ((file-directory-p filepath)
  2483.            (call-process cvs-rmdir-program nil nil nil filepath))
  2484.           ((file-exists-p filepath)
  2485.            (delete-file filepath)))
  2486.         (if (or (eq type 'UNKNOWN)
  2487.              (eq type 'UNKNOWN-DIR)
  2488.              (eq type 'MOVE-AWAY))
  2489.         (tin-delete cvs-cookie-handle tin)
  2490.           (setq files-to-remove (cons tin files-to-remove))
  2491.           (cvs-set-fileinfo->type fileinfo 'REMOVED)
  2492.           (cvs-set-fileinfo->handled fileinfo nil)
  2493.           (tin-invalidate cvs-cookie-handle tin))))
  2494.     (setq tins (cdr tins)))
  2495.       files-to-remove))
  2496.    (t nil)))
  2497.  
  2498. ;;----------
  2499. (defun cvs-mode-remove-file ()
  2500.   "Remove all marked files."
  2501.  
  2502.   (interactive)
  2503.   (let ((files-to-remove (cvs-do-removal (cvs-get-marked))))
  2504.     (if (null files-to-remove)
  2505.     nil
  2506.       (cvs-use-temp-buffer)
  2507.       (message "removing from repository...")
  2508.       (if (cvs-execute-list files-to-remove cvs-program
  2509.                 (if cvs-cvsroot
  2510.                 (list "-d" cvs-cvsroot "remove")
  2511.                   '("remove"))
  2512.                 "removing %s from repository...")
  2513.       (error "CVS exited with non-zero exit status.")
  2514.     (message "removing from repository... Done.")))))
  2515.  
  2516. ;;----------
  2517. (defun cvs-mode-undo-local-changes ()
  2518.   "Undo local changes to all marked files.
  2519. The file is removed and `cvs update FILE' is run."
  2520.  
  2521.   (interactive)
  2522.   (let ((tins-to-undo (cvs-get-marked)))
  2523.     (cvs-use-temp-buffer)
  2524.     (mapcar 'cvs-insert-full-path tins-to-undo)
  2525.     (cond
  2526.      ((and tins-to-undo (yes-or-no-p (format "Undo changes to %d files? "
  2527.                          (length tins-to-undo))))
  2528.       (let (files-to-update)
  2529.     (while tins-to-undo
  2530.       (let* ((tin (car tins-to-undo))
  2531.          (fileinfo (tin-cookie cvs-cookie-handle tin))
  2532.          (type (cvs-fileinfo->type fileinfo)))
  2533.         (cond
  2534.          ((or
  2535.            (eq type 'UPDATED)
  2536.            (eq type 'PATCHED)
  2537.            (eq type 'MODIFIED)
  2538.            (eq type 'MERGED)
  2539.            (eq type 'CONFLICT)
  2540.            (eq type 'CVS-REMOVED)
  2541.            (eq type 'REM-CONFLICT)
  2542.            (eq type 'MOVE-AWAY)
  2543.            (eq type 'REMOVED))
  2544.           (if (not (eq type 'REMOVED))
  2545.           (delete-file (cvs-full-path tin)))
  2546.           (setq files-to-update (cons tin files-to-update))
  2547.           (cvs-set-fileinfo->type fileinfo 'UPDATED)
  2548.           (cvs-set-fileinfo->handled fileinfo t)
  2549.           (tin-invalidate cvs-cookie-handle tin))
  2550.  
  2551.          ((eq type 'MOD-CONFLICT)
  2552.           (error "Use cvs-mode-add instead on %s."
  2553.              (cvs-fileinfo->file-name fileinfo)))
  2554.  
  2555.          ((eq type 'REM-CONFLICT)
  2556.           (error "Can't deal with a file you have removed and recreated."))
  2557.  
  2558.          ((eq type 'DIRCHANGE)
  2559.           (error "Undo on directories not supported (yet)."))
  2560.  
  2561.          ((eq type 'ADDED)
  2562.           (error "There is no old revision to get for %s"
  2563.              (cvs-fileinfo->file-name fileinfo)))
  2564.          (t (error "cvs-mode-undo-local-changes: can't handle an %s"
  2565.                type)))
  2566.  
  2567.         (setq tins-to-undo (cdr tins-to-undo))))
  2568.     (cvs-use-temp-buffer)
  2569.     (message "Re-getting files from repository...")
  2570.     (if (cvs-execute-list files-to-update cvs-program
  2571.                   (if cvs-cvsroot
  2572.                   (list "-d" cvs-cvsroot "update")
  2573.                 '("update"))
  2574.                   "Re-getting %s from repository...")
  2575.         (error "CVS exited with non-zero exit status.")
  2576.       (message "Re-getting files from repository... Done.")))))))
  2577.  
  2578. ;;----------
  2579. (defun cvs-mode-acknowledge ()
  2580.   "Remove all marked files from the buffer."
  2581.  
  2582.   (interactive)
  2583.   (mapcar (function (lambda (tin)
  2584.               (tin-delete cvs-cookie-handle tin)))
  2585.       (cvs-get-marked)))
  2586.  
  2587. ;;----------
  2588. (defun cvs-mode-unmark-up (pos)
  2589.   "Unmark the file on the previous line.
  2590. Takes one argument POS, a buffer position."
  2591.  
  2592.   (interactive "d")
  2593.   (let ((tin (tin-goto-previous cvs-cookie-handle pos 1)))
  2594.     (cond
  2595.      (tin
  2596.       (cvs-set-fileinfo->marked (tin-cookie cvs-cookie-handle tin)
  2597.                 nil)
  2598.       (tin-invalidate cvs-cookie-handle tin)))))
  2599.  
  2600. ;;----------
  2601. (defun cvs-mode-previous-line (arg)
  2602.   "Go to the previous line.
  2603. If a prefix argument is given, move by that many lines."
  2604.  
  2605.   (interactive "p")
  2606.   (tin-goto-previous cvs-cookie-handle (point) arg))
  2607.  
  2608. ;;----------
  2609. (defun cvs-mode-next-line (arg)
  2610.   "Go to the next line.
  2611. If a prefix argument is given, move by that many lines."
  2612.  
  2613.   (interactive "p")
  2614.   (tin-goto-next cvs-cookie-handle (point) arg))
  2615.  
  2616. ;;----------
  2617. (defun cvs-add-file-update-buffer (tin)
  2618.   "Sub-function to cvs-mode-add.  Internal use only.  Update the display.  Return
  2619. non-nil if `cvs add' should be called on this file.
  2620. Args:  TIN.
  2621.  
  2622. Returns 'DIR, 'ADD, 'ADD-DIR, or 'RESURRECT."
  2623.  
  2624.   (let ((fileinfo (tin-cookie cvs-cookie-handle tin)))
  2625.     (cond
  2626.      ((eq (cvs-fileinfo->type fileinfo) 'UNKNOWN-DIR)
  2627.       (cvs-set-fileinfo->full-log fileinfo "new directory added with cvs-mode-add")
  2628.       'ADD-DIR)
  2629.      ((eq (cvs-fileinfo->type fileinfo) 'UNKNOWN)
  2630.       (cvs-set-fileinfo->type fileinfo 'ADDED)
  2631.       (cvs-set-fileinfo->full-log fileinfo "new file added with cvs-mode-add")
  2632.       (tin-invalidate cvs-cookie-handle tin)
  2633.       'ADD)
  2634.      ((eq (cvs-fileinfo->type fileinfo) 'REMOVED)
  2635.       (cvs-set-fileinfo->type fileinfo 'UPDATED)
  2636.       (cvs-set-fileinfo->full-log fileinfo "file resurrected with cvs-mode-add")
  2637.       (cvs-set-fileinfo->handled fileinfo t)
  2638.       (tin-invalidate cvs-cookie-handle tin)
  2639.       'RESURRECT))))
  2640.  
  2641. ;;----------
  2642. (defun cvs-add-sub (cvs-buf candidates)
  2643.   "Internal use only.
  2644. Args:  CVS-BUF CANDIDATES.
  2645.  
  2646. CANDIDATES is a list of tins.  Updates the CVS-BUF and returns a list of lists.
  2647. The first list is unknown tins that shall be `cvs add -m msg'ed.
  2648. The second list is unknown directory tins that shall be `cvs add -m msg'ed.
  2649. The third list is removed files that shall be `cvs add'ed (resurrected)."
  2650.  
  2651.   (let (add add-dir resurrect)
  2652.     (while candidates
  2653.       (let ((type (cvs-add-file-update-buffer (car candidates))))
  2654.     (cond ((eq type 'ADD)
  2655.            (setq add (cons (car candidates) add)))
  2656.           ((eq type 'ADD-DIR)
  2657.            (setq add-dir (cons (car candidates) add-dir)))
  2658.           ((eq type 'RESURRECT)
  2659.            (setq resurrect (cons (car candidates) resurrect)))))
  2660.       (setq candidates (cdr candidates)))
  2661.     (list add add-dir resurrect)))
  2662.  
  2663. ;;----------
  2664. (defun cvs-mode-add ()
  2665.   "Add marked files to the cvs repository."
  2666.  
  2667.   (interactive)
  2668.   (let* ((buf (current-buffer))
  2669.      (marked (cvs-get-marked))
  2670.      (result (cvs-add-sub buf marked))
  2671.      (added (car result))
  2672.      (newdirs (car (cdr result)))
  2673.      (resurrect (car (cdr (cdr result))))
  2674.      (msg (if (or added newdirs)
  2675.           (read-from-minibuffer "Enter description: "))))
  2676.  
  2677.     (if (or resurrect (or added newdirs))
  2678.     (cvs-use-temp-buffer))
  2679.  
  2680.     (cond (resurrect
  2681.        (message "Resurrecting files from repository...")
  2682.        (if (cvs-execute-list resurrect
  2683.                  cvs-program
  2684.                  (if cvs-cvsroot
  2685.                      (list "-d" cvs-cvsroot "add")
  2686.                    '("add"))
  2687.                  "Resurrecting %s from repository...")
  2688.            (error "CVS exited with non-zero exit status.")
  2689.          (message "Resurrecting files from repository... Done."))))
  2690.  
  2691.     (cond (added
  2692.        (message "Adding new files to repository...")
  2693.        (if (cvs-execute-list added
  2694.                  cvs-program
  2695.                  (if cvs-cvsroot
  2696.                      (list "-d" cvs-cvsroot "add" "-m" msg)
  2697.                    (list "add" "-m" msg))
  2698.                  "Adding %s to repository...")
  2699.            (error "CVS exited with non-zero exit status.")
  2700.          (message "Adding new files to repository... Done."))))
  2701.  
  2702.     (cond (newdirs
  2703.        (message "Adding new directories to repository...")
  2704.        (if (cvs-execute-list newdirs
  2705.                  cvs-program
  2706.                  (if cvs-cvsroot
  2707.                      (list "-d" cvs-cvsroot "add" "-m" msg)
  2708.                    (list "add" "-m" msg))
  2709.                  "Adding %s to repository...")
  2710.            (error "CVS exited with non-zero exit status.")
  2711.          (while newdirs
  2712.            (let* ((tin (car newdirs))
  2713.               (fileinfo (tin-cookie cvs-cookie-handle tin))
  2714.               (newdir (cvs-fileinfo->file-name fileinfo)))
  2715.          (cvs-set-fileinfo->dir fileinfo
  2716.                     (concat (cvs-fileinfo->dir fileinfo)
  2717.                         "/"
  2718.                         newdir))
  2719.          (cvs-set-fileinfo->type fileinfo 'DIRCHANGE)
  2720.          (cvs-set-fileinfo->file-name fileinfo ".")
  2721.          (tin-invalidate cvs-cookie-handle tin)
  2722.          (setq newdirs (cdr newdirs))))
  2723.          ;; FIXME: this should really run cvs-update-no-prompt on the
  2724.          ;; subdir and insert everthing in the current list.
  2725.          (message "You must re-update to visit the new directories."))))))
  2726.  
  2727. ;;----------
  2728. (defun cvs-mode-ignore ()
  2729.   "Arrange so that CVS ignores the selected files and directories.
  2730. This command ignores files/dirs that are flagged as `Unknown'."
  2731.  
  2732.   (interactive)
  2733.   (mapcar (function (lambda (tin)
  2734.               (let* ((fileinfo (tin-cookie cvs-cookie-handle tin))
  2735.                  (type (cvs-fileinfo->type fileinfo)))
  2736.             (cond ((or (eq type 'UNKNOWN)
  2737.                    (eq type 'UNKNOWN-DIR))
  2738.                    (cvs-append-to-ignore fileinfo)
  2739.                    (tin-delete cvs-cookie-handle tin))))))
  2740.       (cvs-get-marked)))
  2741.  
  2742. ;;----------
  2743. (defun cvs-append-to-ignore (fileinfo)
  2744.   "Append the file in fileinfo to the .cvsignore file"
  2745.  
  2746.   (save-window-excursion
  2747.     (set-buffer (find-file-noselect (concat (file-name-as-directory
  2748.                          (cvs-fileinfo->dir fileinfo))
  2749.                         ".cvsignore")))
  2750.     (goto-char (point-max))
  2751.     (if (not (zerop (current-column)))
  2752.     (insert "\n"))
  2753.     (insert (cvs-fileinfo->file-name fileinfo) "\n")
  2754.     (if cvs-sort-ignore-file
  2755.     (sort-lines nil (point-min) (point-max)))
  2756.     (save-buffer)))
  2757.  
  2758. ;;----------
  2759. (defun cvs-mode-status ()
  2760.   "Show cvs status for all marked files."
  2761.  
  2762.   (interactive)
  2763.   (save-some-buffers)
  2764.   (if (not (listp cvs-status-flags))
  2765.       (error "cvs-status-flags should be set using cvs-set-status-flags."))
  2766.   (let ((marked (cvs-get-marked nil t)))
  2767.     (cvs-use-temp-buffer)
  2768.     (message "Running cvs status ...")
  2769.     (if (cvs-execute-list marked
  2770.               cvs-program
  2771.               (append (if cvs-cvsroot (list "-d" cvs-cvsroot))
  2772.                   (list "-Q" "status")
  2773.                   cvs-status-flags)
  2774.               "Running cvs -Q status %s...")
  2775.     (error "CVS exited with non-zero exit status.")
  2776.       (message "Running cvs -Q status ... Done."))))
  2777.  
  2778. ;;----------
  2779. (defun cvs-mode-log ()
  2780.   "Display the cvs log of all selected files."
  2781.  
  2782.   (interactive)
  2783.   (if (not (listp cvs-log-flags))
  2784.       (error "cvs-log-flags should be set using cvs-set-log-flags."))
  2785.   (let ((marked (cvs-get-marked nil t)))
  2786.     (cvs-use-temp-buffer)
  2787.     (message "Running cvs log ...")
  2788.     (if (cvs-execute-list marked
  2789.               cvs-program
  2790.               (append (if cvs-cvsroot (list "-d" cvs-cvsroot))
  2791.                   (list "log")
  2792.                   cvs-log-flags)
  2793.               "Running cvs log %s...")
  2794.     (error "CVS exited with non-zero exit status.")
  2795.       (message "Running cvs log ... Done."))))
  2796.  
  2797. ;;----------
  2798. (defun cvs-mode-tag ()
  2799.   "Run 'cvs tag' on all selected files."
  2800.  
  2801.   (interactive)
  2802.   (if (not (listp cvs-tag-flags))
  2803.       (error "cvs-tag-flags should be set using cvs-set-tag-flags."))
  2804.   (let ((marked (cvs-get-marked nil t))
  2805.     (tag-args (cvs-make-list (read-string "Tag name (and flags): "))))
  2806.     (cvs-use-temp-buffer)
  2807.     (message "Running cvs tag ...")
  2808.     (if (cvs-execute-list marked
  2809.               cvs-program
  2810.               (append (if cvs-cvsroot (list "-d" cvs-cvsroot))
  2811.                   (list "tag")
  2812.                   cvs-tag-flags
  2813.                   tag-args)
  2814.               "Running cvs tag %s...")
  2815.     (error "CVS exited with non-zero exit status.")
  2816.       (message "Running cvs tag ... Done."))))
  2817.  
  2818. ;;----------
  2819. (defun cvs-mode-rtag ()
  2820.   "Run 'cvs rtag' on all selected files."
  2821.  
  2822.   (interactive)
  2823.   (if (not (listp cvs-rtag-flags))
  2824.       (error "cvs-rtag-flags should be set using cvs-set-rtag-flags."))
  2825.   (let ((marked (cvs-get-marked nil t))
  2826.     ;; FIXME:  should give selection from the modules file
  2827.     (module-name (read-string "Module name: "))
  2828.     ;; FIXME:  should also ask for an existing tag *or* date
  2829.     (rtag-args (cvs-make-list (read-string "Tag name (and flags): "))))
  2830.     (cvs-use-temp-buffer)
  2831.     (message "Running cvs rtag ...")
  2832.     (if (cvs-execute-list marked
  2833.               cvs-program
  2834.               (append (if cvs-cvsroot (list "-d" cvs-cvsroot)) 
  2835.                   (list "rtag")
  2836.                   cvs-rtag-flags
  2837.                   rtag-args
  2838.                   (list module-name))
  2839.               "Running cvs rtag %s...")
  2840.     (error "CVS rtag exited with non-zero exit status.")
  2841.       (message "Running cvs rtag ... Done."))))
  2842.  
  2843. ;;----------
  2844. (defun cvs-mode-byte-compile-files ()
  2845.   "Run byte-compile-file on all selected files that end in '.el'."
  2846.  
  2847.   (interactive)
  2848.   (let ((marked (cvs-get-marked)))
  2849.     (while marked
  2850.       (let ((filename (cvs-full-path (car marked))))
  2851.     (if (string-match "\\.el$" filename)
  2852.         (byte-compile-file filename)))
  2853.       (setq marked (cdr marked)))))
  2854.  
  2855. ;;----------
  2856. (defun cvs-insert-full-path (tin)
  2857.   "Insert full path to the file described in TIN in the current buffer."
  2858.  
  2859.   (insert (format "%s\n" (cvs-full-path tin))))
  2860.  
  2861. ;;----------
  2862. (defun cvs-mode-add-change-log-entry-other-window (pos)
  2863.   "Add a ChangeLog entry in the ChangeLog of the current directory.
  2864. Args:  POS."
  2865.  
  2866.   (interactive "d")
  2867.   (let* ((cvs-buf (current-buffer))
  2868.      (odir default-directory)
  2869.      (obfname buffer-file-name)
  2870.      (tin (tin-locate cvs-cookie-handle pos))
  2871.      (fileinfo (tin-cookie cvs-cookie-handle tin))
  2872.      (fname (cvs-fileinfo->file-name fileinfo))
  2873.      (dname (file-name-as-directory (cvs-fileinfo->dir fileinfo))))
  2874.     (setq change-log-default-name nil)    ; this rarely correct in 19.28
  2875.     (setq buffer-file-name (cond (fname
  2876.                    fname)
  2877.                   (t
  2878.                    nil)))
  2879.     (setq default-directory (cond (dname
  2880.                     dname)
  2881.                    (t
  2882.                     odir)))
  2883.     (add-change-log-entry-other-window)
  2884.     (set-buffer cvs-buf)
  2885.     (setq default-directory odir)
  2886.     (setq buffer-file-name obfname)))
  2887.  
  2888. ;;----------
  2889. (defun print-cvs-tin (foo)
  2890.   "Debug utility."
  2891.  
  2892.   (let ((cookie (tin-cookie cvs-cookie-handle foo))
  2893.     (stream (get-buffer-create "pcl-cvs-debug")))
  2894.     (princ "==============\n" stream)
  2895.     (princ (cvs-fileinfo->file-name cookie) stream)
  2896.     (princ "\n" stream)
  2897.     (princ (cvs-fileinfo->dir cookie) stream)
  2898.     (princ "\n" stream)
  2899.     (princ (cvs-fileinfo->full-log cookie) stream)
  2900.     (princ "\n" stream)
  2901.     (princ (cvs-fileinfo->marked cookie) stream)
  2902.     (princ "\n" stream)))
  2903.  
  2904. ;;----------
  2905. ;; NOTE: the variable cvs-emerge-tmp-head-file will be "free" when compiling
  2906. (defun cvs-mode-emerge (pos)
  2907.   "Emerge appropriate revisions of the selected file.
  2908. Args:  POS."
  2909.  
  2910.   (interactive "d")
  2911.   (let* ((cvs-buf (current-buffer))
  2912.      (tin (tin-locate cvs-cookie-handle pos)))
  2913.     (if (boundp 'cvs-emerge-tmp-head-file)
  2914.     (error "There can only be one emerge session active at a time."))
  2915.     (if tin
  2916.     (let* ((fileinfo (tin-cookie cvs-cookie-handle tin))
  2917.            (type (cvs-fileinfo->type fileinfo)))
  2918.       (cond
  2919.        ((eq type 'MODIFIED)        ; merge repository head rev. with working file
  2920.         (require 'emerge)
  2921.         (setq cvs-emerge-tmp-head-file ; trick to prevent multiple runs
  2922.           (cvs-retrieve-revision-to-tmpfile fileinfo))
  2923.         (unwind-protect
  2924.         (if (not (emerge-files
  2925.               t                        ; arg
  2926.               (cvs-fileinfo->full-path fileinfo)         ; file-A
  2927.               ;; this is an un-avoidable compiler reference to a free variable
  2928.               cvs-emerge-tmp-head-file            ; file-B
  2929.               (cvs-fileinfo->full-path fileinfo)        ; file-out
  2930.               nil                        ; start-hooks
  2931.               '(lambda ()                    ; quit-hooks
  2932.                  (delete-file cvs-emerge-tmp-head-file)
  2933.                  (makunbound 'cvs-emerge-tmp-head-file))))
  2934.             (error "Emerge session failed"))))
  2935.  
  2936.        ;; re-do the same merge rcsmerge supposedly just did....
  2937.        ((or (eq type 'MERGED)
  2938.         (eq type 'CONFLICT))    ; merge backup-working=A, head=B, base=ancestor
  2939.         (require 'emerge)
  2940.         (setq cvs-emerge-tmp-head-file ; trick to prevent multiple runs
  2941.           (cvs-retrieve-revision-to-tmpfile fileinfo
  2942.                             (cvs-fileinfo->head-revision
  2943.                              fileinfo)))
  2944.         (let ((cvs-emerge-tmp-backup-working-file
  2945.            (cvs-fileinfo->backup-file fileinfo))
  2946.           (cvs-emerge-tmp-ancestor-file
  2947.            (cvs-retrieve-revision-to-tmpfile fileinfo
  2948.                              (cvs-fileinfo->base-revision
  2949.                               fileinfo))))
  2950.           (unwind-protect
  2951.           (if (not (emerge-files-with-ancestor
  2952.                 t                        ; arg
  2953.                 cvs-emerge-tmp-backup-working-file        ; file-A
  2954.                 ;; this is an un-avoidable compiler reference to a free variable
  2955.                 cvs-emerge-tmp-head-file            ; file-B
  2956.                 cvs-emerge-tmp-ancestor-file        ; file-ancestor
  2957.                 (cvs-fileinfo->full-path fileinfo)        ; file-out
  2958.                 nil                        ; start-hooks
  2959.                 '(lambda ()                    ; quit-hooks
  2960.                    (delete-file cvs-emerge-tmp-backup-file)
  2961.                    (delete-file cvs-emerge-tmp-ancestor-file)
  2962.                    (delete-file cvs-emerge-tmp-head-file)
  2963.                    (makunbound 'cvs-emerge-tmp-head-file))))
  2964.               (error "Emerge session failed")))))
  2965.        (t
  2966.         (error "Can only e-merge \"Modified\", \"Merged\" or \"Conflict\" files"))))
  2967.       (error "There is no file to e-merge."))))
  2968.  
  2969. ;;----------
  2970. ;; NOTE: the variable ediff-version may be "free" when compiling
  2971. (defun cvs-mode-ediff (pos)
  2972.   "Ediff appropriate revisions of the selected file.
  2973. Args:  POS."
  2974.  
  2975.   (interactive "d")
  2976.   (if (boundp 'cvs-ediff-tmp-head-file)
  2977.       (error "There can only be one ediff session active at a time."))
  2978.   (require 'ediff)
  2979.   (if (and (boundp 'ediff-version)
  2980.        (>= (string-to-number ediff-version) 2.0)) ; FIXME real number?
  2981.       (run-ediff-from-cvs-buffer pos)
  2982.     (cvs-old-ediff-interface pos)))
  2983.  
  2984. (defun cvs-old-ediff-interface (pos)
  2985.   "Emerge like interface for older ediffs.
  2986. Args:  POS"
  2987.  
  2988.   (let* ((cvs-buf (current-buffer))
  2989.      (tin (tin-locate cvs-cookie-handle pos)))
  2990.     (if tin
  2991.     (let* ((fileinfo (tin-cookie cvs-cookie-handle tin))
  2992.            (type (cvs-fileinfo->type fileinfo)))
  2993.       (cond
  2994.        ((eq type 'MODIFIED)        ; diff repository head rev. with working file
  2995.         ;; should this be inside the unwind-protect, and should the
  2996.         ;; makeunbound be an unwindform?
  2997.         (setq cvs-ediff-tmp-head-file ; trick to prevent multiple runs
  2998.           (cvs-retrieve-revision-to-tmpfile fileinfo))
  2999.         (unwind-protect
  3000.         (if (not (ediff-files    ; check correct ordering of args
  3001.               (cvs-fileinfo->full-path fileinfo)         ; file-A
  3002.               ;; this is an un-avoidable compiler reference to a free variable
  3003.               cvs-ediff-tmp-head-file            ; file-B
  3004.               '(lambda ()                    ; startup-hooks
  3005.                  (make-local-hook 'ediff-cleanup-hooks)
  3006.                  (add-hook 'ediff-cleanup-hooks
  3007.                        '(lambda ()
  3008.                       (ediff-janitor)
  3009.                       (delete-file cvs-ediff-tmp-head-file)
  3010.                       (makunbound 'cvs-ediff-tmp-head-file))
  3011.                        nil t))))
  3012.             (error "Ediff session failed"))))
  3013.  
  3014.        ;; look at the merge rcsmerge supposedly just did....
  3015.        ((or (eq type 'MERGED)
  3016.         (eq type 'CONFLICT))    ; diff backup-working=A, head=B, base=ancestor
  3017.         (if (not (boundp 'ediff-version))
  3018.         (error "ediff version way too old for 3-way diff"))
  3019.         (if (<= (string-to-number ediff-version) 1.9) ; FIXME real number?
  3020.         (error "ediff version %s too old for 3-way diff" ediff-version))
  3021.         (setq cvs-ediff-tmp-head-file ; trick to prevent multiple runs
  3022.           (cvs-retrieve-revision-to-tmpfile fileinfo
  3023.                             (cvs-fileinfo->head-revision
  3024.                              fileinfo)))
  3025.         (let ((cvs-ediff-tmp-backup-working-file
  3026.            (cvs-fileinfo->backup-file fileinfo))
  3027.           (cvs-ediff-tmp-ancestor-file
  3028.            (cvs-retrieve-revision-to-tmpfile fileinfo
  3029.                              (cvs-fileinfo->base-revision
  3030.                               fileinfo))))
  3031.           (unwind-protect
  3032.           (if (not (ediff-files3 ; check correct ordering of args
  3033.                 cvs-ediff-tmp-backup-working-file        ; file-A
  3034.                 ;; this is an un-avoidable compiler reference to a free variable
  3035.                 cvs-ediff-tmp-head-file            ; file-B
  3036.                 cvs-ediff-tmp-ancestor-file            ; file-ancestor
  3037.                 '(lambda ()                    ; start-hooks
  3038.                    (make-local-hook 'ediff-cleanup-hooks)
  3039.                    (add-hook 'ediff-cleanup-hooks
  3040.                      '(lambda ()
  3041.                         (ediff-janitor)
  3042.                         (delete-file cvs-ediff-tmp-backup-file)
  3043.                         (delete-file cvs-ediff-tmp-ancestor-file)
  3044.                         (delete-file cvs-ediff-tmp-head-file)
  3045.                         (makunbound 'cvs-ediff-tmp-head-file))
  3046.                      nil t))))
  3047.               (error "Ediff session failed")))))
  3048.  
  3049.        ((not (or (eq type 'UNKNOWN)
  3050.              (eq type 'UNKNOWN-DIR))) ; i.e. UPDATED or PATCHED ????
  3051.         ;; this should really diff the current working file with the previous
  3052.         ;; rev. on the current branch (i.e. not the head, since that's what
  3053.         ;; the current file should be)
  3054.         (setq cvs-ediff-tmp-head-file ; trick to prevent multiple runs
  3055.           (cvs-retrieve-revision-to-tmpfile fileinfo
  3056.                             (read-string "Rev #/tag to diff against: "
  3057.                                  (cvs-fileinfo->head-revision
  3058.                                   fileinfo))))
  3059.         (unwind-protect
  3060.         (if (not (ediff-files    ; check correct ordering of args
  3061.               (cvs-fileinfo->full-path fileinfo)         ; file-A
  3062.               ;; this is an un-avoidable compiler reference to a free variable
  3063.               cvs-ediff-tmp-head-file            ; file-B
  3064.               '(lambda ()                    ; startup-hooks
  3065.                  (make-local-hook 'ediff-cleanup-hooks)
  3066.                  (add-hook 'ediff-cleanup-hooks
  3067.                        '(lambda ()
  3068.                       (ediff-janitor)
  3069.                       (delete-file cvs-ediff-tmp-head-file)
  3070.                       (makunbound 'cvs-ediff-tmp-head-file))
  3071.                        nil t))))
  3072.             (error "Ediff session failed"))))
  3073.        (t
  3074.         (error "Can not ediff \"Unknown\" files"))))
  3075.       (error "There is no file to ediff."))))
  3076.  
  3077. ;;----------
  3078. (defun cvs-retrieve-revision-to-tmpfile (fileinfo &optional revision)
  3079.   "Retrieve the latest revision of the file in FILEINFO to a temporary file.
  3080. If second optional argument REVISION is given, retrieve that revision instead."
  3081.  
  3082.   (let
  3083.       ((temp-name (make-temp-name
  3084.            (concat (file-name-as-directory
  3085.                 (or (getenv "TMPDIR") "/tmp"))
  3086.                "pcl-cvs." revision))))
  3087.     (cvs-kill-buffer-visiting temp-name)
  3088.     (if (and revision
  3089.          (stringp revision)
  3090.          (not (string= revision "")))
  3091.     (message "Retrieving revision %s..." revision)
  3092.       (message "Retrieving latest revision..."))
  3093.     (let ((res (call-process cvs-shell nil nil nil "-c"
  3094.                  (concat cvs-program " update -p "
  3095.                      (if (and revision
  3096.                           (stringp revision)
  3097.                           (not (string= revision "")))
  3098.                      (concat "-r " revision " ")
  3099.                        "")
  3100.                      (cvs-fileinfo->full-path fileinfo)
  3101.                      " > " temp-name))))
  3102.       (if (and res (not (and (integerp res) (zerop res))))
  3103.       (error "Something went wrong retrieving revision %s: %s"
  3104.          revision res))
  3105.  
  3106.       (if revision
  3107.       (message "Retrieving revision %s... Done." revision)
  3108.     (message "Retrieving latest revision... Done."))
  3109.       (save-excursion
  3110.     (set-buffer (find-file-noselect temp-name))
  3111.     (rename-buffer (concat " " (file-name-nondirectory temp-name)) t))
  3112.       temp-name)))
  3113.  
  3114. ;;----------
  3115. (defun cvs-kill-buffer-visiting (filename)
  3116.   "If there is any buffer visiting FILENAME, kill it (without confirmation)."
  3117.  
  3118.   (let ((l (buffer-list)))
  3119.     (while l
  3120.       (if (string= (buffer-file-name (car l)) filename)
  3121.       (kill-buffer (car l)))
  3122.       (setq l (cdr l)))))
  3123.  
  3124. ;;----------
  3125. (defun cvs-change-cvsroot ()
  3126.   "Ask for a new cvsroot."
  3127.  
  3128.   (interactive)
  3129.   (cvs-set-cvsroot (read-file-name "New CVSROOT: " cvs-cvsroot)))
  3130.  
  3131. ;;----------
  3132. (defun cvs-set-cvsroot (newroot)
  3133.   "Change the cvsroot."
  3134.  
  3135.   (if (or (file-directory-p (expand-file-name "CVSROOT" newroot))
  3136.       (y-or-n-p (concat "Warning:  no CVSROOT found inside repository."
  3137.                 " Change cvs-cvsroot anyhow?")))
  3138.       (setq cvs-cvsroot newroot)))
  3139.  
  3140. ;;----------
  3141. (defun cvs-set-diff-flags ()
  3142.   "Ask for new setting of cvs-diff-flags."
  3143.  
  3144.   (interactive)
  3145.   (let ((old-value (mapconcat 'identity
  3146.                   (copy-sequence cvs-diff-flags) " ")))
  3147.     (setq cvs-diff-flags
  3148.       (cvs-make-list (read-string "Diff flags: " old-value)))))
  3149.  
  3150. ;;----------
  3151. (defun cvs-set-update-optional-flags ()
  3152.   "Ask for new setting of cvs-update-optional-flags."
  3153.   
  3154.   (interactive)
  3155.   (let ((old-value (mapconcat 'identity
  3156.                   (copy-sequence cvs-update-optional-flags) " ")))
  3157.     (setq cvs-update-optional-flags
  3158.       (cvs-make-list (read-string "Update optional flags: " old-value)))))
  3159.  
  3160. ;;----------
  3161. (defun cvs-set-status-flags ()
  3162.   "Ask for new setting of cvs-status-flags."
  3163.  
  3164.   (interactive)
  3165.   (let ((old-value (mapconcat 'identity
  3166.                   (copy-sequence cvs-status-flags) " ")))
  3167.     (setq cvs-status-flags
  3168.       (cvs-make-list (read-string "Status flags: " old-value)))))
  3169.  
  3170. ;;----------
  3171. (defun cvs-set-log-flags ()
  3172.   "Ask for new setting of cvs-log-flags."
  3173.  
  3174.   (interactive)
  3175.   (let ((old-value (mapconcat 'identity
  3176.                   (copy-sequence cvs-log-flags) " ")))
  3177.     (setq cvs-log-flags
  3178.       (cvs-make-list (read-string "Log flags: " old-value)))))
  3179.  
  3180. ;;----------
  3181. (defun cvs-set-tag-flags ()
  3182.   "Ask for new setting of cvs-tag-flags."
  3183.  
  3184.   (interactive)
  3185.   (let ((old-value (mapconcat 'identity
  3186.                   (copy-sequence cvs-tag-flags) " ")))
  3187.     (setq cvs-tag-flags
  3188.       (cvs-make-list (read-string "Tag flags: " old-value)))))
  3189.  
  3190. ;;----------
  3191. (defun cvs-set-rtag-flags ()
  3192.   "Ask for new setting of cvs-rtag-flags."
  3193.  
  3194.   (interactive)
  3195.   (let ((old-value (mapconcat 'identity
  3196.                   (copy-sequence cvs-rtag-flags) " ")))
  3197.     (setq cvs-rtag-flags
  3198.       (cvs-make-list (read-string "Rtag flags: " old-value)))))
  3199.  
  3200. ;;----------
  3201. (if (string-match "Lucid" emacs-version)
  3202.     (progn
  3203.       (autoload 'pcl-cvs-fontify "pcl-cvs-lucid")
  3204.       (add-hook 'cvs-mode-hook 'pcl-cvs-fontify)))
  3205.  
  3206. (defun cvs-changelog-name (directory)
  3207.   "Return the name of the ChangeLog file that handles DIRECTORY.
  3208. This is in DIRECTORY or one of its parents.
  3209. Signal an error if we can't find an appropriate ChangeLog file."
  3210.   (let ((dir (file-name-as-directory directory))
  3211.         file)
  3212.     (while (and dir
  3213.                 (not (file-exists-p 
  3214.                       (setq file (expand-file-name "ChangeLog" dir)))))
  3215.       (let ((last dir))
  3216.         (setq dir (file-name-directory (directory-file-name dir)))
  3217.         (if (equal last dir)
  3218.             (setq dir nil))))
  3219.     (or dir
  3220.         (error "Can't find ChangeLog for %s" directory))
  3221.     file))
  3222.  
  3223. (defun cvs-narrow-changelog ()
  3224.   "Narrow to the top page of the current buffer, a ChangeLog file.
  3225. Actually, the narrowed region doesn't include the date line.
  3226. A \"page\" in a ChangeLog file is the area between two dates."
  3227.   (or (eq major-mode 'change-log-mode)
  3228.       (error "cvs-narrow-changelog: current buffer isn't a ChangeLog"))
  3229.  
  3230.   (goto-char (point-min))
  3231.  
  3232.   ;; Skip date line and subsequent blank lines.
  3233.   (forward-line 1)
  3234.   (if (looking-at "[ \t\n]*\n")
  3235.       (goto-char (match-end 0)))
  3236.  
  3237.   (let ((start (point)))
  3238.     (forward-page 1)
  3239.     (narrow-to-region start (point))
  3240.     (goto-char (point-min))))
  3241.  
  3242. (defun cvs-changelog-paragraph ()
  3243.   "Return the bounds of the ChangeLog paragraph containing point.
  3244. If we are between paragraphs, return the previous paragraph."
  3245.   (save-excursion
  3246.     (beginning-of-line)
  3247.     (if (looking-at "^[ \t]*$")
  3248.         (skip-chars-backward " \t\n" (point-min)))
  3249.     (list (progn
  3250.             (if (re-search-backward "^[ \t]*\n" nil 'or-to-limit)
  3251.                 (goto-char (match-end 0)))
  3252.             (point))
  3253.           (if (re-search-forward "^[ \t\n]*$" nil t)
  3254.               (match-beginning 0)
  3255.             (point)))))
  3256.  
  3257. (defun cvs-changelog-subparagraph ()
  3258.   "Return the bounds of the ChangeLog subparagraph containing point.
  3259. A subparagraph is a block of non-blank lines beginning with an asterisk.
  3260. If we are between sub-paragraphs, return the previous subparagraph."
  3261.   (save-excursion
  3262.     (end-of-line)
  3263.     (if (search-backward "*" nil t)
  3264.         (list (progn (beginning-of-line) (point))
  3265.               (progn 
  3266.                 (forward-line 1)
  3267.                 (if (re-search-forward "^[ \t]*[\n*]" nil t)
  3268.                     (match-beginning 0)
  3269.                   (point-max))))
  3270.       (list (point) (point)))))
  3271.  
  3272. (defun cvs-changelog-entry ()
  3273.   "Return the bounds of the ChangeLog entry containing point.
  3274. The variable `cvs-changelog-full-paragraphs' decides whether an
  3275. \"entry\" is a paragraph or a subparagraph; see its documentation string
  3276. for more details."
  3277.   (if cvs-changelog-full-paragraphs
  3278.       (cvs-changelog-paragraph)
  3279.     (cvs-changelog-subparagraph)))
  3280.  
  3281. ;; NOTE: the variable user-full-name may be "free" when compiling
  3282. (defun cvs-changelog-ours-p ()
  3283.   "See if ChangeLog entry at point is for the current user, today.
  3284. Return non-nil iff it is."
  3285.   ;; Code adapted from add-change-log-entry.
  3286.   (looking-at (concat (regexp-quote (substring (current-time-string)
  3287.                                                0 10))
  3288.                       ".* "
  3289.                       (regexp-quote (substring (current-time-string) -4))
  3290.                       "[ \t]+"
  3291.               (regexp-quote (if (and (boundp 'add-log-full-name)
  3292.                                              add-log-full-name)
  3293.                                         add-log-full-name
  3294.                                       user-full-name))
  3295.                       "  <"
  3296.               (regexp-quote (if (and (boundp 'add-log-mailing-address)
  3297.                          add-log-mailing-address)
  3298.                     add-log-mailing-address
  3299.                       user-mail-address)))))
  3300.  
  3301. (defun cvs-relative-path (base child)
  3302.   "Return a directory path relative to BASE for CHILD.
  3303. If CHILD doesn't seem to be in a subdirectory of BASE, just return 
  3304. the full path to CHILD."
  3305.   (let ((base (file-name-as-directory (expand-file-name base)))
  3306.         (child (expand-file-name child)))
  3307.     (or (string= base (substring child 0 (length base)))
  3308.         (error "cvs-relative-path: %s isn't in %s" child base))
  3309.     (substring child (length base))))
  3310.  
  3311. (defun cvs-changelog-entries (file)
  3312.   "Return the ChangeLog entries for FILE, and the ChangeLog they came from.
  3313. The return value looks like this:
  3314.   (LOGBUFFER (ENTRYSTART . ENTRYEND) ...)
  3315. where LOGBUFFER is the name of the ChangeLog buffer, and each
  3316. \(ENTRYSTART . ENTRYEND\) pair is a buffer region."
  3317.   (save-excursion
  3318.     (set-buffer (find-file-noselect
  3319.                  (cvs-changelog-name
  3320.                   (file-name-directory
  3321.                    (expand-file-name file)))))
  3322.     (or (eq major-mode 'change-log-mode)
  3323.     (change-log-mode))
  3324.     (goto-char (point-min))
  3325.     (if (looking-at "[ \t\n]*\n")
  3326.         (goto-char (match-end 0)))
  3327.     (if (not (cvs-changelog-ours-p))
  3328.         (list (current-buffer))
  3329.       (save-restriction
  3330.         (cvs-narrow-changelog)
  3331.         (goto-char (point-min))
  3332.  
  3333.         ;; Search for the name of FILE relative to the ChangeLog.  If that
  3334.         ;; doesn't occur anywhere, they're not using full relative
  3335.         ;; filenames in the ChangeLog, so just look for FILE; we'll accept
  3336.         ;; some false positives.
  3337.         (let ((pattern (cvs-relative-path
  3338.                         (file-name-directory buffer-file-name) file)))
  3339.           (if (or (string= pattern "")
  3340.                   (not (save-excursion
  3341.                          (search-forward pattern nil t))))
  3342.               (setq pattern file))
  3343.  
  3344.           (let (texts)
  3345.             (while (search-forward pattern nil t)
  3346.               (let ((entry (cvs-changelog-entry)))
  3347.                 (setq texts (cons entry texts))
  3348.                 (goto-char (elt entry 1))))
  3349.  
  3350.             (cons (current-buffer) texts)))))))
  3351.  
  3352. (defun cvs-changelog-insert-entries (buffer regions)
  3353.   "Insert those regions in BUFFER specified in REGIONS.
  3354. Sort REGIONS front-to-back first."
  3355.   (let ((regions (sort regions 'car-less-than-car))
  3356.         (last))
  3357.     (while regions
  3358.       (if (and last (< last (car (car regions))))
  3359.           (newline))
  3360.       (setq last (elt (car regions) 1))
  3361.       (apply 'insert-buffer-substring buffer (car regions))
  3362.       (setq regions (cdr regions)))))
  3363.  
  3364. (defun cvs-union (set1 set2)
  3365.   "Return the union of SET1 and SET2, according to `equal'."
  3366.   (while set2
  3367.     (or (member (car set2) set1)
  3368.         (setq set1 (cons (car set2) set1)))
  3369.     (setq set2 (cdr set2)))
  3370.   set1)
  3371.  
  3372. (defun cvs-insert-changelog-entries (files)
  3373.   "Given a list of files FILES, insert the ChangeLog entries for them."
  3374.   (let ((buffer-entries nil))
  3375.  
  3376.     ;; Add each buffer to buffer-entries, and associate it with the list
  3377.     ;; of entries we want from that file.
  3378.     (while files
  3379.       (let* ((entries (cvs-changelog-entries (car files)))
  3380.              (pair (assq (car entries) buffer-entries)))
  3381.         (if pair
  3382.             (setcdr pair (cvs-union (cdr pair) (cdr entries)))
  3383.           (setq buffer-entries (cons entries buffer-entries))))
  3384.       (setq files (cdr files)))
  3385.  
  3386.     ;; Now map over each buffer in buffer-entries, sort the entries for
  3387.     ;; each buffer, and extract them as strings.
  3388.     (while buffer-entries
  3389.       (cvs-changelog-insert-entries (car (car buffer-entries))
  3390.                                     (cdr (car buffer-entries)))
  3391.       (if (and (cdr buffer-entries) (cdr (car buffer-entries)))
  3392.           (newline))
  3393.       (setq buffer-entries (cdr buffer-entries)))))
  3394.  
  3395. (defun cvs-edit-delete-common-indentation ()
  3396.   "Unindent the current buffer rigidly until at least one line is flush left."
  3397.   (save-excursion
  3398.     (let ((common 100000))
  3399.       (goto-char (point-min))
  3400.       (while (< (point) (point-max))
  3401.         (if (not (looking-at "^[ \t]*$"))
  3402.             (setq common (min common (current-indentation))))
  3403.         (forward-line 1))
  3404.       (indent-rigidly (point-min) (point-max) (- common)))))
  3405.  
  3406. (defun cvs-mode-changelog-commit ()
  3407.   "Check in all marked files, or the current file.
  3408. Ask the user for a log message in a buffer.
  3409.  
  3410. This is just like `\\[cvs-mode-commit]', except that it tries to provide
  3411. appropriate default log messages by looking at the ChangeLog.  The
  3412. idea is to write your ChangeLog entries first, and then use this
  3413. command to commit your changes.
  3414.  
  3415. To select default log text, we:
  3416. - find the ChangeLog entries for the files to be checked in,
  3417. - verify that the top entry in the ChangeLog is on the current date
  3418.   and by the current user; if not, we don't provide any default text,
  3419. - search the ChangeLog entry for paragraphs containing the names of
  3420.   the files we're checking in, and finally
  3421. - use those paragraphs as the log text."
  3422.  
  3423.   (interactive)
  3424.  
  3425.   (let* ((cvs-buf (current-buffer))
  3426.          (marked (cvs-filter (function cvs-committable)
  3427.                              (cvs-get-marked))))
  3428.     (if (null marked)
  3429.         (error "Nothing to commit!")
  3430.       (pop-to-buffer (get-buffer-create cvs-commit-prompt-buffer))
  3431.       (goto-char (point-min))
  3432.  
  3433.       (erase-buffer)
  3434.       (cvs-insert-changelog-entries
  3435.        (mapcar (lambda (tin)
  3436.                  (let ((cookie (tin-cookie cvs-cookie-handle tin)))
  3437.                    (expand-file-name 
  3438.                     (cvs-fileinfo->file-name cookie)
  3439.                     (cvs-fileinfo->dir cookie))))
  3440.                marked))
  3441.       (cvs-edit-delete-common-indentation)
  3442.  
  3443.       (cvs-edit-mode)
  3444.       (make-local-variable 'cvs-commit-list)
  3445.       (setq cvs-commit-list marked)
  3446.       (message "Press C-c C-c when you are done editing."))))
  3447.  
  3448. (provide 'pcl-cvs)
  3449.  
  3450. ;;;; end of file pcl-cvs.el
  3451.