]> code.delx.au - gnu-emacs/blob - lisp/pcvs.el
(save-abbrevs): Default value is t.
[gnu-emacs] / lisp / pcvs.el
1 ;;; pcvs.el --- a front-end to CVS
2
3 ;; Copyright (C) 1991,92,93,94,95,95,97,98,99,2000 Free Software Foundation, Inc.
4
5 ;; Author: (The PCL-CVS Trust) pcl-cvs@cyclic.com
6 ;; (Per Cederqvist) ceder@lysator.liu.se
7 ;; (Greg A. Woods) woods@weird.com
8 ;; (Jim Blandy) jimb@cyclic.com
9 ;; (Karl Fogel) kfogel@floss.red-bean.com
10 ;; (Jim Kingdon) kingdon@cyclic.com
11 ;; (Stefan Monnier) monnier@cs.yale.edu
12 ;; (Greg Klanderman) greg@alphatech.com
13 ;; (Jari Aalto+mail.emacs) jari.aalto@poboxes.com
14 ;; Maintainer: (Stefan Monnier) monnier+lists/cvs/pcl@flint.cs.yale.edu
15 ;; Keywords: CVS, version control, release management
16 ;; Revision: $Id: pcvs.el,v 1.29 2001/09/22 20:23:16 monnier Exp $
17
18 ;; This file is part of GNU Emacs.
19
20 ;; GNU Emacs is free software; you can redistribute it and/or modify
21 ;; it under the terms of the GNU General Public License as published by
22 ;; the Free Software Foundation; either version 2, or (at your option)
23 ;; any later version.
24
25 ;; GNU Emacs is distributed in the hope that it will be useful,
26 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
27 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ;; GNU General Public License for more details.
29
30 ;; You should have received a copy of the GNU General Public License
31 ;; along with GNU Emacs; see the file COPYING. If not, write to the
32 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
33 ;; Boston, MA 02111-1307, USA.
34
35 ;;; Commentary:
36
37 ;; PCL-CVS is a front-end to the CVS version control system. For people
38 ;; familiar with VC, it is somewhat like VC-dired: it presents the status of
39 ;; all the files in your working area and allows you to commit/update several
40 ;; of them at a time. Compared to VC-dired, it is considerably better and
41 ;; faster (but only for CVS).
42
43 ;; PCL-CVS was originally written by Per Cederqvist many years ago. This
44 ;; version derives from the XEmacs-21 version, itself based on the 2.0b2
45 ;; version (last release from Per). It is a thorough rework.
46
47 ;; Contrary to what you'd expect, PCL-CVS is not a replacement for VC but only
48 ;; for VC-dired. As such, I've tried to make PCL-CVS and VC interoperate
49 ;; seamlessly (I also use VC).
50
51 ;; To use PCL-CVS just use `M-x cvs-examine RET <dir> RET'.
52 ;; There is a TeXinfo manual, which can be helpful to get started.
53
54 ;;; Bugs:
55
56 ;; - Extracting an old version seems not to recognize encoding correctly.
57 ;; That's probably because it's done via a process rather than a file.
58
59 ;;; Todo:
60
61 ;; ******** FIX THE DOCUMENTATION *********
62 ;;
63 ;; - rework the displaying of error messages.
64 ;; - use UP-TO-DATE rather than DEAD when cleaning before `examine'.
65 ;; - allow to flush messages only
66 ;; - allow to protect files like ChangeLog from flushing
67 ;; - automatically cvs-mode-insert files from find-file-hook
68 ;; (and don't flush them as long as they are visited)
69 ;; - query the user for cvs-get-marked (for some cmds or if nothing's selected)
70 ;; - don't return the first (resp last) FI if the cursor is before
71 ;; (resp after) it.
72 ;; - allow cvs-confirm-removals to force always confirmation.
73 ;; - cvs-checkout should ask for a revision (with completion).
74 ;; - removal confirmation should allow specifying another file name.
75 ;;
76 ;; - hide fileinfos without getting rid of them (will require ewok work).
77 ;; - add toolbar entries
78 ;; - marking
79 ;; marking directories should jump to just after the dir.
80 ;; allow (un)marking directories at a time with the mouse.
81 ;; allow cvs-cmd-do to either clear the marks or not.
82 ;; add a "marks active" notion, like transient-mark-mode does.
83 ;; - liveness indicator
84 ;; - indicate in docstring if the cmd understands the `b' prefix(es).
85 ;; - call smerge-mode when opening CONFLICT files.
86 ;; - have vc-checkin delegate to cvs-mode-commit when applicable
87 ;; - higher-level CVS operations
88 ;; cvs-mode-rename
89 ;; cvs-mode-branch
90 ;; - module-level commands
91 ;; add support for parsing 'modules' file ("cvs co -c")
92 ;; cvs-mode-rcs2log
93 ;; cvs-rdiff
94 ;; cvs-release
95 ;; cvs-import
96 ;; C-u M-x cvs-checkout should ask for a cvsroot
97 ;; cvs-mode-handle-new-vendor-version
98 ;; - checks out module, or alternately does update join
99 ;; - does "cvs -n tag LAST_VENDOR" to find old files into *cvs*
100 ;; cvs-export
101 ;; (with completion on tag names and hooks to help generate full releases)
102 ;; - display stickiness information. And current CVS/Tag as well.
103 ;; - write 'cvs-mode-admin' to do arbitrary 'cvs admin' commands
104 ;; Most interesting would be version removal and log message replacement.
105 ;; The last one would be neat when called from log-view-mode.
106 ;; - cvs-mode-incorporate
107 ;; It would merge in the status from one *cvs* buffer into another.
108 ;; This would be used to populate such a buffer that had been created with
109 ;; a `cvs {update,status,checkout} -l'.
110 ;; - cvs-mode-(i)diff-other-{file,buffer,cvs-buffer}
111 ;; - offer the choice to kill the process when the user kills the cvs buffer.
112 ;; right now, it's killed without further ado.
113 ;; - make `cvs-mode-ignore' allow manually entering a pattern.
114 ;; to which dir should it apply ?
115 ;; - cvs-mode-ignore should try to remove duplicate entries.
116 ;; - maybe poll/check CVS/Entries files to react to external `cvs' commands ?
117 ;; - some kind of `cvs annotate' support ?
118 ;; but vc-annotate can be used instead.
119 ;; - proper `g' that passes safe args and uses either cvs-status or cvs-examine
120 ;; maybe also use cvs-update depending on I-don't-know-what.
121 ;; - add message-levels so that we can hide some levels of messages
122
123 ;;; Code:
124
125 (eval-when-compile (require 'cl))
126 (require 'ewoc) ;Ewoc was once cookie
127 (require 'pcvs-defs)
128 (require 'pcvs-util)
129 (require 'pcvs-parse)
130 (require 'pcvs-info)
131
132 \f
133 ;;;;
134 ;;;; global vars
135 ;;;;
136
137 (defvar cvs-cookies) ;;nil
138 ;;"Handle for the cookie structure that is displayed in the *cvs* buffer.")
139 ;;(make-variable-buffer-local 'cvs-cookies)
140
141 ;;;;
142 ;;;; Dynamically scoped variables
143 ;;;;
144
145 (defvar cvs-from-vc nil "Bound to t inside VC advice.")
146
147 ;;;;
148 ;;;; flags variables
149 ;;;;
150
151 (defun cvs-defaults (&rest defs)
152 (let ((defs (cvs-first defs cvs-shared-start)))
153 (append defs
154 (make-list (- cvs-shared-start (length defs)) (car defs))
155 cvs-shared-flags)))
156
157 ;; For cvs flags, we need to add "-f" to override the cvsrc settings
158 ;; we also want to evict the annoying -q and -Q options that hide useful
159 ;; information from pcl-cvs.
160 (cvs-flags-define cvs-cvs-flags '(("-f")))
161
162 (cvs-flags-define cvs-checkout-flags (cvs-defaults '("-P")))
163 (cvs-flags-define cvs-status-flags (cvs-defaults '("-v") nil))
164 (cvs-flags-define cvs-log-flags (cvs-defaults nil))
165 (cvs-flags-define cvs-diff-flags (cvs-defaults '("-u" "-N") '("-c" "-N") '("-u" "-b")))
166 (cvs-flags-define cvs-tag-flags (cvs-defaults nil))
167 (cvs-flags-define cvs-add-flags (cvs-defaults nil))
168 (cvs-flags-define cvs-commit-flags (cvs-defaults nil))
169 (cvs-flags-define cvs-remove-flags (cvs-defaults nil))
170 ;;(cvs-flags-define cvs-undo-flags (cvs-defaults nil))
171 (cvs-flags-define cvs-update-flags (cvs-defaults '("-d" "-P")))
172
173 (defun cvs-reread-cvsrc ()
174 "Reset the default arguments to those in the `cvs-cvsrc-file'."
175 (interactive)
176 (let ((cvsrc (cvs-file-to-string cvs-cvsrc-file)))
177 (when (stringp cvsrc)
178 ;; fetch the values
179 (dolist (cmd '("cvs" "checkout" "status" "log" "diff" "tag"
180 "add" "commit" "remove" "update"))
181 (let* ((sym (intern (concat "cvs-" cmd "-flags")))
182 (val (when (string-match (concat "^" cmd "\\s-\\(.*\\)$") cvsrc)
183 (cvs-string->strings (match-string 1 cvsrc)))))
184 (cvs-flags-set sym 0 val)))
185 ;; ensure that cvs doesn't have -q or -Q
186 (cvs-flags-set 'cvs-cvs-flags 0
187 (cons "-f"
188 (cdr (cvs-partition
189 (lambda (x) (member x '("-q" "-Q")))
190 (cvs-flags-query 'cvs-cvs-flags
191 nil 'noquery))))))))
192
193 ;; initialize to cvsrc's default values
194 (cvs-reread-cvsrc)
195
196 \f
197 ;;;;
198 ;;;; Mouse bindings and mode motion
199 ;;;;
200
201 (defun cvs-menu (e)
202 "Popup the CVS menu."
203 (interactive "e")
204 (let ((cvs-minor-current-files
205 (list (ewoc-data (ewoc-locate
206 cvs-cookies (posn-point (event-end e)))))))
207 (popup-menu cvs-menu e)))
208
209 (defvar cvs-mode-line-process nil
210 "Mode-line control for displaying info on cvs process status.")
211
212
213 ;;;;
214 ;;;; Query-Type-Descriptor for Tags
215 ;;;;
216
217 (autoload 'cvs-status-get-tags "cvs-status")
218 (defun cvs-tags-list ()
219 "Return a list of acceptable tags, ready for completions."
220 (assert (cvs-buffer-p))
221 (let ((marked (cvs-get-marked)))
222 (list* '("BASE") '("HEAD")
223 (when marked
224 (with-temp-buffer
225 (call-process cvs-program
226 nil ;no input
227 t ;output to current-buffer
228 nil ;don't update display while running
229 "status"
230 "-v"
231 (cvs-fileinfo->full-path (car marked)))
232 (goto-char (point-min))
233 (let ((tags (cvs-status-get-tags)))
234 (when (listp tags) tags)))))))
235
236 (defvar cvs-tag-history nil)
237 (defconst cvs-qtypedesc-tag
238 (cvs-qtypedesc-create 'identity 'identity 'cvs-tags-list 'cvs-tag-history))
239
240 ;;;;
241
242 (defun cvs-mode! (&optional -cvs-mode!-fun -cvs-mode!-noerror)
243 "Switch to the *cvs* buffer.
244 If -CVS-MODE!-FUN is provided, it is executed *cvs* being the current buffer
245 and with its window selected. Else, the *cvs* buffer is simply selected.
246 If -CVS-MODE!-NOERROR is non-nil, then failure to find a *cvs* buffer does
247 not generate an error and the current buffer is kept selected.
248 -CVS-MODE!-FUN is called interactively if applicable and else with no argument."
249 (let* ((-cvs-mode!-buf (current-buffer))
250 (cvsbuf (cond ((cvs-buffer-p) (current-buffer))
251 ((and cvs-buffer (cvs-buffer-p cvs-buffer)) cvs-buffer)
252 (-cvs-mode!-noerror (current-buffer))
253 (t (error "can't find the *cvs* buffer"))))
254 (-cvs-mode!-wrapper cvs-minor-wrap-function)
255 (-cvs-mode!-cont (lambda ()
256 (save-current-buffer
257 (if (commandp -cvs-mode!-fun)
258 (call-interactively -cvs-mode!-fun)
259 (funcall -cvs-mode!-fun))))))
260 (if (not -cvs-mode!-fun) (set-buffer cvsbuf)
261 (let ((cvs-mode!-buf (current-buffer))
262 (cvs-mode!-owin (selected-window))
263 (cvs-mode!-nwin (get-buffer-window cvsbuf 'visible)))
264 (unwind-protect
265 (progn
266 (set-buffer cvsbuf)
267 (when cvs-mode!-nwin (select-window cvs-mode!-nwin))
268 (if -cvs-mode!-wrapper
269 (funcall -cvs-mode!-wrapper -cvs-mode!-buf -cvs-mode!-cont)
270 (funcall -cvs-mode!-cont)))
271 (set-buffer cvs-mode!-buf)
272 (when (and cvs-mode!-nwin (eq cvs-mode!-nwin (selected-window)))
273 ;; the selected window has not been changed by FUN
274 (select-window cvs-mode!-owin)))))))
275
276 ;;;;
277 ;;;; Prefixes
278 ;;;;
279
280 (defvar cvs-branches (list cvs-vendor-branch "HEAD" "HEAD"))
281 (cvs-prefix-define cvs-branch-prefix
282 "Current selected branch."
283 "version"
284 (cons cvs-vendor-branch cvs-branches)
285 cvs-qtypedesc-tag)
286
287 (defun cvs-set-branch-prefix (arg)
288 "Set the branch prefix to take action at the next command.
289 See `cvs-prefix-set' for a further the description of the behavior.
290 \\[universal-argument] 1 selects the vendor branch
291 and \\[universal-argument] 2 selects the HEAD."
292 (interactive "P")
293 (cvs-mode!)
294 (cvs-prefix-set 'cvs-branch-prefix arg))
295
296 (defun cvs-add-branch-prefix (flags &optional arg)
297 "Add branch selection argument if the branch prefix was set.
298 The argument is added (or not) to the list of FLAGS and is constructed
299 by appending the branch to ARG which defaults to \"-r\"."
300 (let ((branch (cvs-prefix-get 'cvs-branch-prefix)))
301 ;; deactivate the secondary prefix, even if not used.
302 (cvs-prefix-get 'cvs-secondary-branch-prefix)
303 (if branch (cons (concat (or arg "-r") branch) flags) flags)))
304
305 (cvs-prefix-define cvs-secondary-branch-prefix
306 "Current secondary selected branch."
307 "version"
308 (cons cvs-vendor-branch cvs-branches)
309 cvs-qtypedesc-tag)
310
311 (defun cvs-set-secondary-branch-prefix (arg)
312 "Set the branch prefix to take action at the next command.
313 See `cvs-prefix-set' for a further the description of the behavior.
314 \\[universal-argument] 1 selects the vendor branch
315 and \\[universal-argument] 2 selects the HEAD."
316 (interactive "P")
317 (cvs-mode!)
318 (cvs-prefix-set 'cvs-secondary-branch-prefix arg))
319
320 (defun cvs-add-secondary-branch-prefix (flags &optional arg)
321 "Add branch selection argument if the secondary branch prefix was set.
322 The argument is added (or not) to the list of FLAGS and is constructed
323 by appending the branch to ARG which defaults to \"-r\".
324 Since the `cvs-secondary-branch-prefix' is only active if the primary
325 prefix is active, it is important to read the secondary prefix before
326 the primay since reading the primary can deactivate it."
327 (let ((branch (and (cvs-prefix-get 'cvs-branch-prefix 'read-only)
328 (cvs-prefix-get 'cvs-secondary-branch-prefix))))
329 (if branch (cons (concat (or arg "-r") branch) flags) flags)))
330
331 ;;;;
332
333 (define-minor-mode cvs-minor-mode
334 "This mode is used for buffers related to a main *cvs* buffer.
335 All the `cvs-mode' buffer operations are simply rebound under
336 the \\[cvs-mode-map] prefix."
337 nil " CVS")
338 (put 'cvs-minor-mode 'permanent-local t)
339
340
341 (defvar cvs-temp-buffers nil)
342 (defun cvs-temp-buffer (&optional cmd normal nosetup)
343 "Create a temporary buffer to run CMD in.
344 If CMD is a string, use it to lookup `cvs-buffer-name-alist' to find
345 the buffer name to be used and its `major-mode'.
346
347 The selected window will not be changed. The new buffer will not maintain undo
348 information and will be read-only unless NORMAL is non-nil. It will be emptied
349 \(unless NOSETUP is non-nil\) and its `default-directory' will be inherited
350 from the current buffer."
351 (let* ((cvs-buf (current-buffer))
352 (info (cdr (assoc cmd cvs-buffer-name-alist)))
353 (name (eval (nth 0 info)))
354 (mode (nth 1 info))
355 (dir default-directory)
356 (buf (cond
357 (name (cvs-get-buffer-create name))
358 ((and (bufferp cvs-temp-buffer) (buffer-name cvs-temp-buffer))
359 cvs-temp-buffer)
360 (t
361 (set (make-local-variable 'cvs-temp-buffer)
362 (cvs-get-buffer-create
363 (eval cvs-temp-buffer-name) 'noreuse))))))
364
365 ;; handle the potential pre-existing process
366 (let ((proc (get-buffer-process buf)))
367 (when (and (not normal) (processp proc)
368 (memq (process-status proc) '(run stop)))
369 (error "Can not run two cvs processes simultaneously")))
370
371 (if (not name) (kill-local-variable 'other-window-scroll-buffer)
372 ;; Strangely, if no window is created, `display-buffer' ends up
373 ;; doing a `switch-to-buffer' which does a `set-buffer', hence
374 ;; the need for `save-excursion'.
375 (unless nosetup (save-excursion (display-buffer buf)))
376 ;; FIXME: this doesn't do the right thing if the user later on
377 ;; does a `find-file-other-window' and `scroll-other-window'
378 (set (make-local-variable 'other-window-scroll-buffer) buf))
379
380 (add-to-list 'cvs-temp-buffers buf)
381
382 (with-current-buffer buf
383 (setq buffer-read-only nil)
384 (setq default-directory dir)
385 (unless nosetup (erase-buffer))
386 (set (make-local-variable 'cvs-buffer) cvs-buf)
387 ;;(cvs-minor-mode 1)
388 (let ((lbd list-buffers-directory))
389 (if (fboundp mode) (funcall mode) (fundamental-mode))
390 (when lbd (set (make-local-variable 'list-buffers-directory) lbd)))
391 (cvs-minor-mode 1)
392 ;;(set (make-local-variable 'cvs-buffer) cvs-buf)
393 (unless normal
394 (setq buffer-read-only t)
395 (buffer-disable-undo))
396 buf)))
397
398 (defun cvs-mode-kill-buffers ()
399 "Kill all the \"temporary\" buffers created by the *cvs* buffer."
400 (interactive)
401 (dolist (buf cvs-temp-buffers) (ignore-errors (kill-buffer buf))))
402
403 (defun cvs-make-cvs-buffer (dir &optional new)
404 "Create the *cvs* buffer for directory DIR.
405 If non-nil, NEW means to create a new buffer no matter what."
406 ;; the real cvs-buffer creation
407 (setq dir (cvs-expand-dir-name dir))
408 (let* ((buffer-name (eval cvs-buffer-name))
409 (buffer
410 (or (and (not new)
411 (eq cvs-reuse-cvs-buffer 'current)
412 (cvs-buffer-p) ;reuse the current buffer if possible
413 (current-buffer))
414 ;; look for another cvs buffer visiting the same directory
415 (save-excursion
416 (unless new
417 (dolist (buffer (cons (current-buffer) (buffer-list)))
418 (set-buffer buffer)
419 (and (cvs-buffer-p)
420 (case cvs-reuse-cvs-buffer
421 (always t)
422 (subdir
423 (or (cvs-string-prefix-p default-directory dir)
424 (cvs-string-prefix-p dir default-directory)))
425 (samedir (string= default-directory dir)))
426 (return buffer)))))
427 ;; we really have to create a new buffer:
428 ;; we temporarily bind cwd to "" to prevent
429 ;; create-file-buffer from using directory info
430 ;; unless it is explicitly in the cvs-buffer-name.
431 (cvs-get-buffer-create buffer-name new))))
432 (with-current-buffer buffer
433 (or
434 (and (string= dir default-directory) (cvs-buffer-p)
435 ;; just a refresh
436 (ignore-errors
437 (cvs-cleanup-collection cvs-cookies nil nil t)
438 (current-buffer)))
439 ;; setup from scratch
440 (progn
441 (setq default-directory dir)
442 (setq buffer-read-only nil)
443 (erase-buffer)
444 (insert "\
445 Repository : " (directory-file-name (cvs-get-cvsroot)) "
446 Module : " (cvs-get-module) "
447 Working dir: " (abbreviate-file-name dir) "
448
449 ")
450 (setq buffer-read-only t)
451 (cvs-mode)
452 (set (make-local-variable 'list-buffers-directory) buffer-name)
453 ;;(set (make-local-variable 'cvs-temp-buffer) (cvs-temp-buffer))
454 (let ((cookies (ewoc-create 'cvs-fileinfo-pp "\n" "")))
455 (set (make-local-variable 'cvs-cookies) cookies)
456 (add-hook 'kill-buffer-hook
457 (lambda ()
458 (ignore-errors (kill-buffer cvs-temp-buffer)))
459 nil t)
460 ;;(set-buffer buf)
461 buffer))))))
462
463 (defun* cvs-cmd-do (cmd dir flags fis new
464 &key cvsargs noexist dont-change-disc noshow)
465 (let* ((dir (file-name-as-directory
466 (abbreviate-file-name (expand-file-name dir))))
467 (cvsbuf (cvs-make-cvs-buffer dir new)))
468 ;; Check that dir is under CVS control.
469 (unless (file-directory-p dir)
470 (error "%s is not a directory" dir))
471 (unless (or noexist (file-directory-p (expand-file-name "CVS" dir)))
472 (error "%s does not contain CVS controlled files" dir))
473
474 (set-buffer cvsbuf)
475 (cvs-mode-run cmd flags fis
476 :cvsargs cvsargs :dont-change-disc dont-change-disc)
477
478 (if noshow cvsbuf
479 (let ((pop-up-windows nil)) (pop-to-buffer cvsbuf)))))
480 ;; (funcall (if (and (boundp 'pop-up-frames) pop-up-frames)
481 ;; 'pop-to-buffer 'switch-to-buffer)
482 ;; cvsbuf))))
483
484 (defun cvs-run-process (args fis postprocess &optional single-dir)
485 (assert (cvs-buffer-p cvs-buffer))
486 (save-current-buffer
487 (let ((procbuf (current-buffer))
488 (cvsbuf cvs-buffer)
489 (single-dir (or single-dir (eq cvs-execute-single-dir t))))
490
491 (set-buffer procbuf)
492 (goto-char (point-max))
493 (unless (bolp) (let ((inhibit-read-only t)) (insert "\n")))
494 ;; find the set of files we'll process in this round
495 (let* ((dir+files+rest
496 (if (or (null fis) (not single-dir))
497 ;; not single-dir mode: just process the whole thing
498 (list "" (mapcar 'cvs-fileinfo->full-path fis) nil)
499 ;; single-dir mode: extract the same-dir-elements
500 (let ((dir (cvs-fileinfo->dir (car fis))))
501 ;; output the concerned dir so the parser can translate paths
502 (let ((inhibit-read-only t))
503 (insert "pcl-cvs: descending directory " dir "\n"))
504 ;; loop to find the same-dir-elems
505 (do* ((files () (cons (cvs-fileinfo->file fi) files))
506 (fis fis (cdr fis))
507 (fi (car fis) (car fis)))
508 ((not (and fis (string= dir (cvs-fileinfo->dir fi))))
509 (list dir files fis))))))
510 (dir (nth 0 dir+files+rest))
511 (files (nth 1 dir+files+rest))
512 (rest (nth 2 dir+files+rest)))
513
514 ;; setup the (current) process buffer
515 (set (make-local-variable 'cvs-postprocess)
516 (if (null rest)
517 ;; this is the last invocation
518 postprocess
519 ;; else, we have to register ourselves to be rerun on the rest
520 `(cvs-run-process ',args ',rest ',postprocess ',single-dir)))
521 (add-hook 'kill-buffer-hook
522 (lambda ()
523 (let ((proc (get-buffer-process (current-buffer))))
524 (when (processp proc)
525 (set-process-filter proc nil)
526 (set-process-sentinel proc nil)
527 (delete-process proc))))
528 nil t)
529
530 ;; create the new process and setup the procbuffer correspondingly
531 (let* ((args (append (cvs-flags-query 'cvs-cvs-flags nil 'noquery)
532 (if cvs-cvsroot (list "-d" cvs-cvsroot))
533 args
534 files))
535 (process-connection-type nil) ; Use a pipe, not a pty.
536 (process
537 ;; the process will be run in the selected dir
538 (let ((default-directory (cvs-expand-dir-name dir)))
539 (apply 'start-process "cvs" procbuf cvs-program args))))
540 (set-process-sentinel process 'cvs-sentinel)
541 (set-process-filter process 'cvs-update-filter)
542 (set-marker (process-mark process) (point-max))
543 (ignore-errors (process-send-eof process)) ;close its stdin to avoid hangs
544
545 ;; now finish setting up the cvs-buffer
546 (set-buffer cvsbuf)
547 (setq cvs-mode-line-process (symbol-name (process-status process)))
548 (force-mode-line-update)))))
549
550 ;; The following line is said to improve display updates on some
551 ;; emacsen. It shouldn't be needed, but it does no harm.
552 (sit-for 0))
553
554 (defun cvs-update-header (args fis) ; inline
555 (let* ((lastarg nil)
556 ;; filter out the largish commit message
557 (args (mapcar (lambda (arg)
558 (cond
559 ((and (eq lastarg nil) (string= arg "commit"))
560 (setq lastarg 'commit) arg)
561 ((and (eq lastarg 'commit) (string= arg "-m"))
562 (setq lastarg '-m) arg)
563 ((eq lastarg '-m)
564 (setq lastarg 'done) "<log message>")
565 (t arg)))
566 args))
567 ;; turn them into a string
568 (arg (cvs-strings->string
569 (append (cvs-flags-query 'cvs-cvs-flags nil 'noquery)
570 (if cvs-cvsroot (list "-d" cvs-cvsroot))
571 args
572 (mapcar 'cvs-fileinfo->full-path fis))))
573 (str (if args (concat "-- Running " cvs-program " " arg " ...\n")
574 "\n")))
575 (if nil (insert str) ;inline
576 ;;(with-current-buffer cvs-buffer
577 (let* ((prev-msg (car (ewoc-get-hf cvs-cookies)))
578 (tin (ewoc-nth cvs-cookies 0)))
579 ;; look for the first *real* fileinfo (to determine emptyness)
580 (while
581 (and tin
582 (memq (cvs-fileinfo->type (ewoc-data tin))
583 '(MESSAGE DIRCHANGE)))
584 (setq tin (ewoc-next cvs-cookies tin)))
585 ;; cleanup the prev-msg
586 (when (string-match "Running \\(.*\\) ...\n" prev-msg)
587 (setq prev-msg
588 (concat
589 "-- last cmd: "
590 (match-string 1 prev-msg)
591 " --")))
592 ;; set the new header and footer
593 (ewoc-set-hf cvs-cookies
594 str (concat "\n--------------------- "
595 (if tin "End" "Empty")
596 " ---------------------\n"
597 prev-msg))))))
598
599
600 (defun cvs-sentinel (proc msg)
601 "Sentinel for the cvs update process.
602 This is responsible for parsing the output from the cvs update when
603 it is finished."
604 (when (memq (process-status proc) '(signal exit))
605 (if (null (buffer-name (process-buffer proc)))
606 ;;(set-process-buffer proc nil)
607 (error "cvs' process buffer was killed")
608 (let* ((obuf (current-buffer))
609 (procbuffer (process-buffer proc)))
610 (set-buffer (with-current-buffer procbuffer cvs-buffer))
611 (setq cvs-mode-line-process (symbol-name (process-status proc)))
612 (force-mode-line-update)
613 (set-buffer procbuffer)
614 (let ((cvs-postproc cvs-postprocess))
615 ;; Since the buffer and mode line will show that the
616 ;; process is dead, we can delete it now. Otherwise it
617 ;; will stay around until M-x list-processes.
618 (delete-process proc)
619 (setq cvs-postprocess nil)
620 ;; do the postprocessing like parsing and such
621 (save-excursion (eval cvs-postproc))
622 ;; check whether something is left
623 (unless cvs-postprocess
624 (buffer-enable-undo)
625 (with-current-buffer cvs-buffer
626 (cvs-update-header nil nil) ;FIXME: might need to be inline
627 (message "CVS process has completed"))))
628 ;; This might not even be necessary
629 (set-buffer obuf)))))
630
631 (defun cvs-parse-process (dcd &optional subdir)
632 "FIXME: bad name, no doc."
633 (let* ((from-buf (current-buffer))
634 (fileinfos (cvs-parse-buffer 'cvs-parse-table dcd subdir))
635 (_ (set-buffer cvs-buffer))
636 last
637 (from-pt (point)))
638 ;; add the new fileinfos
639 (dolist (fi fileinfos)
640 (setq last (cvs-addto-collection cvs-cookies fi last)))
641 (cvs-cleanup-collection cvs-cookies
642 (eq cvs-auto-remove-handled t)
643 cvs-auto-remove-directories
644 nil)
645 ;; update the display (might be unnecessary)
646 ;;(ewoc-refresh cvs-cookies)
647 ;; revert buffers if necessary
648 (when (and cvs-auto-revert (not dcd) (not cvs-from-vc))
649 (cvs-revert-if-needed fileinfos))
650 ;; get back to where we were. `save-excursion' doesn't seem to
651 ;; work in this case, probably because the buffer is reconstructed
652 ;; by the cookie code.
653 (goto-char from-pt)
654 (set-buffer from-buf)))
655
656 (defmacro defun-cvs-mode (fun args docstring interact &rest body)
657 "Define a function to be used in a *cvs* buffer.
658 This will look for a *cvs* buffer and execute BODY in it.
659 Since the interactive arguments might need to be queried after
660 switching to the *cvs* buffer, the generic code is rather ugly,
661 but luckily we can often use simpler alternatives.
662
663 FUN can be either a symbol (i.e. STYLE is nil) or a cons (FUN . STYLE).
664 ARGS and DOCSTRING are the normal argument list.
665 INTERACT is the interactive specification or nil for non-commands.
666
667 STYLE can be either SIMPLE, NOARGS or DOUBLE. It's an error for it
668 to have any other value, unless other details of the function make it
669 clear what alternative to use.
670 - SIMPLE will get all the interactive arguments from the original buffer.
671 - NOARGS will get all the arguments from the *cvs* buffer and will
672 always behave as if called interactively.
673 - DOUBLE is the generic case."
674 (let ((style (cvs-cdr fun))
675 (fun (cvs-car fun)))
676 (cond
677 ;; a trivial interaction, no need to move it
678 ((or (eq style 'SIMPLE)
679 (null (nth 1 interact))
680 (stringp (nth 1 interact)))
681 `(defun ,fun ,args ,docstring ,interact
682 (cvs-mode! (lambda () ,@body))))
683
684 ;; fun is only called interactively: move all the args to the inner fun
685 ((eq style 'NOARGS)
686 `(defun ,fun () ,docstring (interactive)
687 (cvs-mode! (lambda ,args ,interact ,@body))))
688
689 ;; bad case
690 ((eq style 'DOUBLE)
691 (string-match ".*" docstring)
692 (let ((line1 (match-string 0 docstring))
693 (restdoc (substring docstring (match-end 0)))
694 (fun-1 (intern (concat (symbol-name fun) "-1"))))
695 `(progn
696 (defun ,fun-1 ,args
697 ,(concat docstring "\nThis function only works within a *cvs* buffer.
698 For interactive use, use `" (symbol-name fun) "' instead.")
699 ,interact
700 ,@body)
701 (defun ,fun ()
702 ,(concat line1 "\nWrapper function that switches to a *cvs* buffer
703 before calling the real function `" (symbol-name fun-1) "'.\n")
704 (interactive)
705 (cvs-mode! ',fun-1)))))
706
707 (t (error "unknown style %s in `defun-cvs-mode'" style)))))
708 (def-edebug-spec defun-cvs-mode (&define sexp lambda-list stringp ("interactive" interactive) def-body))
709
710 (defun-cvs-mode cvs-mode-kill-process ()
711 "Kill the temporary buffer and associated process."
712 (interactive)
713 (when (and (bufferp cvs-temp-buffer) (buffer-name cvs-temp-buffer))
714 (let ((proc (get-buffer-process cvs-temp-buffer)))
715 (when proc (delete-process proc)))))
716
717 ;;
718 ;; Maintaining the collection in the face of updates
719 ;;
720
721 (defun cvs-addto-collection (c fi &optional tin)
722 "Add FI to C and return FI's corresponding tin.
723 FI is inserted in its proper place or maybe even merged with a preexisting
724 fileinfo if applicable.
725 TIN specifies an optional starting point."
726 (unless tin (setq tin (ewoc-nth c 0)))
727 (while (and tin (cvs-fileinfo< fi (ewoc-data tin)))
728 (setq tin (ewoc-prev c tin)))
729 (if (null tin) (ewoc-enter-first c fi) ;empty collection
730 (assert (not (cvs-fileinfo< fi (ewoc-data tin))))
731 (let ((next-tin (ewoc-next c tin)))
732 (while (not (or (null next-tin)
733 (cvs-fileinfo< fi (ewoc-data next-tin))))
734 (setq tin next-tin next-tin (ewoc-next c next-tin)))
735 (if (or (cvs-fileinfo< (ewoc-data tin) fi)
736 (eq (cvs-fileinfo->type fi) 'MESSAGE))
737 ;; tin < fi < next-tin
738 (ewoc-enter-after c tin fi)
739 ;; fi == tin
740 (cvs-fileinfo-update (ewoc-data tin) fi)
741 (ewoc-invalidate c tin)
742 tin))))
743
744 (defcustom cvs-cleanup-functions nil
745 "Functions to tweak the cleanup process.
746 The functions are called with a single argument (a FILEINFO) and should
747 return a non-nil value if that fileinfo should be removed."
748 :group 'pcl-cvs
749 :type '(hook :options (cvs-cleanup-removed)))
750
751 (defun cvs-cleanup-removed (fi)
752 "Non-nil if FI has been cvs-removed but still exists.
753 This is intended for use on `cvs-cleanup-functions' when you have cvs-removed
754 automatically generated files (which should hence not be under CVS control)
755 but can't commit the removal because the repository's owner doesn't understand
756 the problem."
757 (and (or (eq (cvs-fileinfo->type fi) 'REMOVED)
758 (and (eq (cvs-fileinfo->type fi) 'CONFLICT)
759 (eq (cvs-fileinfo->subtype fi) 'REMOVED)))
760 (file-exists-p (cvs-fileinfo->full-path fi))))
761
762 ;; called at the following times:
763 ;; - postparse ((eq cvs-auto-remove-handled t) cvs-auto-remove-directories nil)
764 ;; - pre-run ((eq cvs-auto-remove-handled 'delayed) nil t)
765 ;; - remove-handled (t (or cvs-auto-remove-directories 'handled) t)
766 ;; - cvs-cmd-do (nil nil t)
767 ;; - post-ignore (nil nil nil)
768 ;; - acknowledge (nil nil nil)
769 ;; - remove (nil nil nil)
770 (defun cvs-cleanup-collection (c rm-handled rm-dirs rm-msgs)
771 "Remove undesired entries.
772 C is the collection
773 RM-HANDLED if non-nil means remove handled entries.
774 RM-DIRS behaves like `cvs-auto-remove-directories'.
775 RM-MSGS if non-nil means remove messages."
776 (let (last-fi first-dir (rerun t))
777 (while rerun
778 (setq rerun nil)
779 (setq first-dir t)
780 (setq last-fi (cvs-create-fileinfo 'DEAD "../" "" "")) ;place-holder
781 (ewoc-filter
782 c (lambda (fi)
783 (let* ((type (cvs-fileinfo->type fi))
784 (subtype (cvs-fileinfo->subtype fi))
785 (keep
786 (case type
787 ;; remove temp messages and keep the others
788 (MESSAGE (not (or rm-msgs (eq subtype 'TEMP))))
789 ;; remove entries
790 (DEAD nil)
791 ;; handled also?
792 (UP-TO-DATE (not rm-handled))
793 ;; keep the rest
794 (t (not (run-hook-with-args-until-success
795 'cvs-cleanup-functions fi))))))
796
797 ;; mark dirs for removal
798 (when (and keep rm-dirs
799 (eq (cvs-fileinfo->type last-fi) 'DIRCHANGE)
800 (not (when first-dir (setq first-dir nil) t))
801 (or (eq rm-dirs 'all)
802 (not (cvs-string-prefix-p
803 (cvs-fileinfo->dir last-fi)
804 (cvs-fileinfo->dir fi)))
805 (and (eq type 'DIRCHANGE) (eq rm-dirs 'empty))
806 (eq subtype 'FOOTER)))
807 (setf (cvs-fileinfo->type last-fi) 'DEAD)
808 (setq rerun t))
809 (when keep (setq last-fi fi)))))
810 ;; remove empty last dir
811 (when (and rm-dirs
812 (not first-dir)
813 (eq (cvs-fileinfo->type last-fi) 'DIRCHANGE))
814 (setf (cvs-fileinfo->type last-fi) 'DEAD)
815 (setq rerun t)))))
816
817 (defun cvs-get-cvsroot ()
818 "Gets the CVSROOT for DIR."
819 (let ((cvs-cvsroot-file (expand-file-name "Root" "CVS")))
820 (or (cvs-file-to-string cvs-cvsroot-file t)
821 cvs-cvsroot
822 (getenv "CVSROOT")
823 "?????")))
824
825 (defun cvs-get-module ()
826 "Return the current CVS module.
827 This usually doesn't really work but is a handy initval in a prompt."
828 (let* ((repfile (expand-file-name "Repository" "CVS"))
829 (rep (cvs-file-to-string repfile t)))
830 (cond
831 ((null rep) "")
832 ((not (file-name-absolute-p rep)) rep)
833 (t
834 (let* ((root (cvs-get-cvsroot))
835 (str (concat (file-name-as-directory (or root "/")) " || " rep)))
836 (if (and root (string-match "\\(.*\\) || \\1\\(.*\\)\\'" str))
837 (match-string 2 str)
838 (file-name-nondirectory rep)))))))
839
840
841 \f
842 ;;;;
843 ;;;; running a "cvs checkout".
844 ;;;;
845
846 ;;;###autoload
847 (defun cvs-checkout (modules dir flags)
848 "Run a 'cvs checkout MODULES' in DIR.
849 Feed the output to a *cvs* buffer, display it in the current window,
850 and run `cvs-mode' on it.
851
852 With a prefix argument, prompt for cvs FLAGS to use."
853 (interactive
854 (list (cvs-string->strings (read-string "Module(s): " (cvs-get-module)))
855 (read-file-name "CVS Checkout Directory: "
856 nil default-directory nil)
857 (cvs-add-branch-prefix
858 (cvs-flags-query 'cvs-checkout-flags "cvs checkout flags"))))
859 (when (eq flags t)
860 (setf flags (cvs-flags-query 'cvs-checkout-flags nil 'noquery)))
861 (cvs-cmd-do "checkout" (or dir default-directory)
862 (append flags modules) nil 'new
863 :noexist t))
864
865 \f
866 ;;;;
867 ;;;; The code for running a "cvs update" and friends in various ways.
868 ;;;;
869
870 (defun-cvs-mode (cvs-mode-revert-buffer . SIMPLE)
871 (&optional ignore-auto noconfirm)
872 "Rerun `cvs-examine' on the current directory with the default flags."
873 (interactive)
874 (cvs-examine default-directory t))
875
876 (defun cvs-query-directory (msg)
877 ;; last-command-char = ?\r hints that the command was run via M-x
878 (if (and (cvs-buffer-p)
879 (not current-prefix-arg)
880 (not (eq last-command-char ?\r)))
881 default-directory
882 (read-file-name msg nil default-directory nil)))
883
884 ;;;###autoload
885 (defun cvs-quickdir (dir &optional flags noshow)
886 "Open a *cvs* buffer on DIR without running cvs.
887 With a prefix argument, prompt for a directory to use.
888 A prefix arg >8 (ex: \\[universal-argument] \\[universal-argument]),
889 prevents reuse of an existing *cvs* buffer.
890 Optional argument NOSHOW if non-nil means not to display the buffer.
891 FLAGS is ignored."
892 (interactive (list (cvs-query-directory "CVS quickdir (directory): ")))
893 ;; FIXME: code duplication with cvs-cmd-do and cvs-parse-process
894 (let* ((dir (file-name-as-directory
895 (abbreviate-file-name (expand-file-name dir))))
896 (new (> (prefix-numeric-value current-prefix-arg) 8))
897 (cvsbuf (cvs-make-cvs-buffer dir new))
898 last)
899 ;; Check that dir is under CVS control.
900 (unless (file-directory-p dir)
901 (error "%s is not a directory" dir))
902 (unless (file-directory-p (expand-file-name "CVS" dir))
903 (error "%s does not contain CVS controlled files" dir))
904 (set-buffer cvsbuf)
905 (dolist (fi (cvs-fileinfo-from-entries ""))
906 (setq last (cvs-addto-collection cvs-cookies fi last)))
907 (cvs-cleanup-collection cvs-cookies
908 (eq cvs-auto-remove-handled t)
909 cvs-auto-remove-directories
910 nil)
911 (if noshow cvsbuf
912 (let ((pop-up-windows nil)) (pop-to-buffer cvsbuf)))))
913
914 ;;;###autoload
915 (defun cvs-examine (directory flags &optional noshow)
916 "Run a `cvs -n update' in the specified DIRECTORY.
917 That is, check what needs to be done, but don't change the disc.
918 Feed the output to a *cvs* buffer and run `cvs-mode' on it.
919 With a prefix argument, prompt for a directory and cvs FLAGS to use.
920 A prefix arg >8 (ex: \\[universal-argument] \\[universal-argument]),
921 prevents reuse of an existing *cvs* buffer.
922 Optional argument NOSHOW if non-nil means not to display the buffer."
923 (interactive (list (cvs-query-directory "CVS Examine (directory): ")
924 (cvs-flags-query 'cvs-update-flags "cvs -n update flags")))
925 (when (eq flags t)
926 (setf flags (cvs-flags-query 'cvs-update-flags nil 'noquery)))
927 (cvs-cmd-do "update" directory flags nil
928 (> (prefix-numeric-value current-prefix-arg) 8)
929 :cvsargs '("-n")
930 :noshow noshow
931 :dont-change-disc t))
932
933
934 ;;;###autoload
935 (defun cvs-update (directory flags)
936 "Run a `cvs update' in the current working DIRECTORY.
937 Feed the output to a *cvs* buffer and run `cvs-mode' on it.
938 With a prefix argument, prompt for a directory and cvs FLAGS to use.
939 A prefix arg >8 (ex: \\[universal-argument] \\[universal-argument]),
940 prevents reuse of an existing *cvs* buffer."
941 (interactive (list (cvs-query-directory "CVS Update (directory): ")
942 (cvs-flags-query 'cvs-update-flags "cvs update flags")))
943 (when (eq flags t)
944 (setf flags (cvs-flags-query 'cvs-update-flags nil 'noquery)))
945 (cvs-cmd-do "update" directory flags nil
946 (> (prefix-numeric-value current-prefix-arg) 8)))
947
948
949 ;;;###autoload
950 (defun cvs-status (directory flags &optional noshow)
951 "Run a `cvs status' in the current working DIRECTORY.
952 Feed the output to a *cvs* buffer and run `cvs-mode' on it.
953 With a prefix argument, prompt for a directory and cvs FLAGS to use.
954 A prefix arg >8 (ex: \\[universal-argument] \\[universal-argument]),
955 prevents reuse of an existing *cvs* buffer.
956 Optional argument NOSHOW if non-nil means not to display the buffer."
957 (interactive (list (cvs-query-directory "CVS Status (directory): ")
958 (cvs-flags-query 'cvs-status-flags "cvs status flags")))
959 (when (eq flags t)
960 (setf flags (cvs-flags-query 'cvs-status-flags nil 'noquery)))
961 (cvs-cmd-do "status" directory flags nil
962 (> (prefix-numeric-value current-prefix-arg) 8)
963 :noshow noshow :dont-change-disc t))
964
965 (defun cvs-update-filter (proc string)
966 "Filter function for pcl-cvs.
967 This function gets the output that CVS sends to stdout. It inserts
968 the STRING into (process-buffer PROC) but it also checks if CVS is waiting
969 for a lock file. If so, it inserts a message cookie in the *cvs* buffer."
970 (save-match-data
971 (with-current-buffer (process-buffer proc)
972 (let ((inhibit-read-only t))
973 (save-excursion
974 ;; Insert the text, moving the process-marker.
975 (goto-char (process-mark proc))
976 (insert string)
977 (set-marker (process-mark proc) (point))
978 ;; FIXME: Delete any old lock message
979 ;;(if (tin-nth cookies 1)
980 ;; (tin-delete cookies
981 ;; (tin-nth cookies 1)))
982 ;; Check if CVS is waiting for a lock.
983 (beginning-of-line 0) ;Move to beginning of last complete line.
984 (when (looking-at "^[ a-z]+: \\(.*waiting for .*lock in \\(.*\\)\\)$")
985 (let ((msg (match-string 1))
986 (lock (match-string 2)))
987 (with-current-buffer cvs-buffer
988 (set (make-local-variable 'cvs-lock-file) lock)
989 ;; display the lock situation in the *cvs* buffer:
990 (ewoc-enter-last
991 cvs-cookies
992 (cvs-create-fileinfo
993 'MESSAGE "" " "
994 (concat msg
995 (when (file-exists-p lock)
996 (substitute-command-keys
997 "\n\t(type \\[cvs-mode-delete-lock] to delete it)")))
998 :subtype 'TEMP))
999 (pop-to-buffer (current-buffer))
1000 (goto-char (point-max))
1001 (beep)))))))))
1002
1003 \f
1004 ;;;;
1005 ;;;; The cvs-mode and its associated commands.
1006 ;;;;
1007
1008 (cvs-prefix-define cvs-force-command "" "" '("/F") cvs-qtypedesc-string1)
1009 (defun-cvs-mode cvs-mode-force-command (arg)
1010 "Force the next cvs command to operate on all the selected files.
1011 By default, cvs commands only operate on files on which the command
1012 \"makes sense\". This overrides the safety feature on the next cvs command.
1013 It actually behaves as a toggle. If prefixed by \\[universal-argument] \\[universal-argument],
1014 the override will persist until the next toggle."
1015 (interactive "P")
1016 (cvs-prefix-set 'cvs-force-command arg))
1017
1018 (put 'cvs-mode 'mode-class 'special)
1019 (define-derived-mode cvs-mode fundamental-mode "CVS"
1020 "Mode used for PCL-CVS, a frontend to CVS.
1021 Full documentation is in the Texinfo file."
1022 (setq mode-line-process
1023 '("" cvs-force-command cvs-ignore-marks-modif
1024 ":" (cvs-branch-prefix
1025 ("" cvs-branch-prefix (cvs-secondary-branch-prefix
1026 ("->" cvs-secondary-branch-prefix))))
1027 " " cvs-mode-line-process))
1028 (buffer-disable-undo (current-buffer))
1029 ;;(set (make-local-variable 'goal-column) cvs-cursor-column)
1030 (set (make-local-variable 'revert-buffer-function) 'cvs-mode-revert-buffer)
1031 (setq truncate-lines t)
1032 (cvs-prefix-make-local 'cvs-branch-prefix)
1033 (cvs-prefix-make-local 'cvs-secondary-branch-prefix)
1034 (cvs-prefix-make-local 'cvs-force-command)
1035 (cvs-prefix-make-local 'cvs-ignore-marks-modif)
1036 (make-local-variable 'cvs-mode-line-process)
1037 (make-local-variable 'cvs-temp-buffers))
1038
1039
1040 (defun cvs-buffer-p (&optional buffer)
1041 "Return whether the (by default current) BUFFER is a `cvs-mode' buffer."
1042 (save-excursion
1043 (if buffer (set-buffer buffer))
1044 (and (eq major-mode 'cvs-mode))))
1045
1046 (defun cvs-buffer-check ()
1047 "Check that the current buffer follows cvs-buffer's conventions."
1048 (let ((buf (current-buffer))
1049 (check 'none))
1050 (or (and (setq check 'collection)
1051 (eq (ewoc-buffer cvs-cookies) buf)
1052 (setq check 'cvs-temp-buffer)
1053 (or (null cvs-temp-buffer)
1054 (null (buffer-name cvs-temp-buffer))
1055 (and (eq (with-current-buffer cvs-temp-buffer cvs-buffer) buf)
1056 (equal (with-current-buffer cvs-temp-buffer
1057 default-directory)
1058 default-directory)))
1059 t)
1060 (error "Inconsistent %s in buffer %s" check (buffer-name buf)))))
1061
1062
1063 (defun cvs-mode-quit ()
1064 "Quit PCL-CVS, killing the *cvs* buffer."
1065 (interactive)
1066 (and (y-or-n-p "Quit pcl-cvs? ") (kill-buffer (current-buffer))))
1067
1068 ;; Give help....
1069
1070 (defun cvs-help ()
1071 "Display help for various PCL-CVS commands."
1072 (interactive)
1073 (if (eq last-command 'cvs-help)
1074 (describe-function 'cvs-mode) ; would need minor-mode for log-edit-mode
1075 (message
1076 (substitute-command-keys
1077 "`\\[cvs-help]':help `\\[cvs-mode-add]':add `\\[cvs-mode-commit]':commit \
1078 `\\[cvs-mode-diff-map]':diff* `\\[cvs-mode-log]':log \
1079 `\\[cvs-mode-remove]':remove `\\[cvs-mode-status]':status \
1080 `\\[cvs-mode-undo]':undo"))))
1081
1082 ;; Move around in the buffer
1083
1084 (defun-cvs-mode cvs-mode-previous-line (arg)
1085 "Go to the previous line.
1086 If a prefix argument is given, move by that many lines."
1087 (interactive "p")
1088 (ewoc-goto-prev cvs-cookies arg))
1089
1090 (defun-cvs-mode cvs-mode-next-line (arg)
1091 "Go to the next line.
1092 If a prefix argument is given, move by that many lines."
1093 (interactive "p")
1094 (ewoc-goto-next cvs-cookies arg))
1095
1096 ;;;;
1097 ;;;; Mark handling
1098 ;;;;
1099
1100 (defun-cvs-mode cvs-mode-mark (&optional arg)
1101 "Mark the fileinfo on the current line.
1102 If the fileinfo is a directory, all the contents of that directory are
1103 marked instead. A directory can never be marked."
1104 (interactive)
1105 (let* ((tin (ewoc-locate cvs-cookies))
1106 (fi (ewoc-data tin)))
1107 (if (eq (cvs-fileinfo->type fi) 'DIRCHANGE)
1108 ;; it's a directory: let's mark all files inside
1109 (ewoc-map
1110 (lambda (f dir)
1111 (when (cvs-dir-member-p f dir)
1112 (setf (cvs-fileinfo->marked f)
1113 (not (if (eq arg 'toggle) (cvs-fileinfo->marked f) arg)))
1114 t)) ;Tell cookie to redisplay this cookie.
1115 cvs-cookies
1116 (cvs-fileinfo->dir fi))
1117 ;; not a directory: just do the obvious
1118 (setf (cvs-fileinfo->marked fi)
1119 (not (if (eq arg 'toggle) (cvs-fileinfo->marked fi) arg)))
1120 (ewoc-invalidate cvs-cookies tin)
1121 (cvs-mode-next-line 1))))
1122
1123 (defun cvs-mouse-toggle-mark (e)
1124 "Toggle the mark of the entry under the mouse."
1125 (interactive "e")
1126 (save-excursion
1127 (mouse-set-point e)
1128 (cvs-mode-mark 'toggle)))
1129
1130 (defun-cvs-mode cvs-mode-unmark ()
1131 "Unmark the fileinfo on the current line."
1132 (interactive)
1133 (cvs-mode-mark t))
1134
1135 (defun-cvs-mode cvs-mode-mark-all-files ()
1136 "Mark all files."
1137 (interactive)
1138 (ewoc-map (lambda (cookie)
1139 (unless (eq (cvs-fileinfo->type cookie) 'DIRCHANGE)
1140 (setf (cvs-fileinfo->marked cookie) t)))
1141 cvs-cookies))
1142
1143 (defun-cvs-mode (cvs-mode-mark-on-state . SIMPLE) (state)
1144 "Mark all files in state STATE."
1145 (interactive
1146 (list
1147 (let ((default
1148 (condition-case nil
1149 (downcase
1150 (symbol-name
1151 (cvs-fileinfo->type
1152 (cvs-mode-marked nil nil :read-only t :one t :noquery t))))
1153 (error nil))))
1154 (intern
1155 (upcase
1156 (completing-read
1157 (concat
1158 "Mark files in state" (if default (concat " [" default "]")) ": ")
1159 (mapcar (lambda (x)
1160 (list (downcase (symbol-name (car x)))))
1161 cvs-states)
1162 nil t nil nil default))))))
1163 (ewoc-map (lambda (fi)
1164 (when (eq (cvs-fileinfo->type fi) state)
1165 (setf (cvs-fileinfo->marked fi) t)))
1166 cvs-cookies))
1167
1168 (defun-cvs-mode cvs-mode-mark-matching-files (regex)
1169 "Mark all files matching REGEX."
1170 (interactive "sMark files matching: ")
1171 (ewoc-map (lambda (cookie)
1172 (when (and (not (eq (cvs-fileinfo->type cookie) 'DIRCHANGE))
1173 (string-match regex (cvs-fileinfo->file cookie)))
1174 (setf (cvs-fileinfo->marked cookie) t)))
1175 cvs-cookies))
1176
1177 (defun-cvs-mode cvs-mode-unmark-all-files ()
1178 "Unmark all files.
1179 Directories are also unmarked, but that doesn't matter, since
1180 they should always be unmarked."
1181 (interactive)
1182 (ewoc-map (lambda (cookie)
1183 (setf (cvs-fileinfo->marked cookie) nil)
1184 t)
1185 cvs-cookies))
1186
1187 (defun-cvs-mode cvs-mode-unmark-up ()
1188 "Unmark the file on the previous line."
1189 (interactive)
1190 (let ((tin (ewoc-goto-prev cvs-cookies 1)))
1191 (when tin
1192 (setf (cvs-fileinfo->marked (ewoc-data tin)) nil)
1193 (ewoc-invalidate cvs-cookies tin))))
1194
1195 (defconst cvs-ignore-marks-alternatives
1196 '(("toggle-marks" . "/TM")
1197 ("force-marks" . "/FM")
1198 ("ignore-marks" . "/IM")))
1199
1200 (cvs-prefix-define cvs-ignore-marks-modif
1201 "Prefix to decide whether to ignore marks or not."
1202 "active"
1203 (mapcar 'cdr cvs-ignore-marks-alternatives)
1204 (cvs-qtypedesc-create
1205 (lambda (str) (cdr (assoc str cvs-ignore-marks-alternatives)))
1206 (lambda (obj) (car (rassoc obj cvs-ignore-marks-alternatives)))
1207 (lambda () cvs-ignore-marks-alternatives)
1208 nil t))
1209
1210 (defun-cvs-mode cvs-mode-toggle-marks (arg)
1211 "Toggle whether the next CVS command uses marks.
1212 See `cvs-prefix-set' for further description of the behavior.
1213 \\[universal-argument] 1 selects `force-marks',
1214 \\[universal-argument] 2 selects `ignore-marks',
1215 \\[universal-argument] 3 selects `toggle-marks'."
1216 (interactive "P")
1217 (cvs-prefix-set 'cvs-ignore-marks-modif arg))
1218
1219 (defun cvs-ignore-marks-p (cmd &optional read-only)
1220 (let ((default (if (member cmd cvs-invert-ignore-marks)
1221 (not cvs-default-ignore-marks)
1222 cvs-default-ignore-marks))
1223 (modif (cvs-prefix-get 'cvs-ignore-marks-modif read-only)))
1224 (cond
1225 ((equal modif "/IM") t)
1226 ((equal modif "/TM") (not default))
1227 ((equal modif "/FM") nil)
1228 (t default))))
1229
1230 (defun cvs-mode-mark-get-modif (cmd)
1231 (if (cvs-ignore-marks-p cmd 'read-only) "/IM" "/FM"))
1232
1233 (defvar cvs-minor-current-files)
1234 (defun cvs-get-marked (&optional ignore-marks ignore-contents)
1235 "Return a list of all selected fileinfos.
1236 If there are any marked tins, and IGNORE-MARKS is nil, return them.
1237 Otherwise, if the cursor selects a directory, and IGNORE-CONTENTS is
1238 nil, return all files in it, else return just the directory.
1239 Otherwise return (a list containing) the file the cursor points to, or
1240 an empty list if it doesn't point to a file at all.
1241
1242 Args: &optional IGNORE-MARKS IGNORE-CONTENTS."
1243
1244 (let ((fis nil))
1245 (dolist (fi (if (and (boundp 'cvs-minor-current-files)
1246 (consp cvs-minor-current-files))
1247 (mapcar
1248 (lambda (f)
1249 (if (cvs-fileinfo-p f) f
1250 (let ((f (file-relative-name f)))
1251 (if (file-directory-p f)
1252 (cvs-create-fileinfo
1253 'DIRCHANGE (file-name-as-directory f) "." "")
1254 (let ((dir (file-name-directory f))
1255 (file (file-name-nondirectory f)))
1256 (cvs-create-fileinfo
1257 'UNKNOWN (or dir "") file ""))))))
1258 cvs-minor-current-files)
1259 (or (and (not ignore-marks)
1260 (ewoc-collect cvs-cookies 'cvs-fileinfo->marked))
1261 (list (ewoc-data (ewoc-locate cvs-cookies))))))
1262
1263 (if (or ignore-contents (not (eq (cvs-fileinfo->type fi) 'DIRCHANGE)))
1264 (push fi fis)
1265 ;; If a directory is selected, return members, if any.
1266 (setq fis
1267 (append (ewoc-collect
1268 cvs-cookies 'cvs-dir-member-p (cvs-fileinfo->dir fi))
1269 fis))))
1270 (nreverse fis)))
1271
1272 (defun* cvs-mode-marked (filter &optional cmd
1273 &key read-only one file noquery)
1274 "Get the list of marked FIS.
1275 CMD is used to determine whether to use the marks or not.
1276 Only files for which FILTER is applicable are returned.
1277 If READ-ONLY is non-nil, the current toggling is left intact.
1278 If ONE is non-nil, marks are ignored and a single FI is returned.
1279 If FILE is non-nil, directory entries won't be selected."
1280 (unless cmd (setq cmd (symbol-name filter)))
1281 (let* ((fis (cvs-get-marked (or one (cvs-ignore-marks-p cmd read-only))
1282 (and (not file)
1283 (cvs-applicable-p 'DIRCHANGE filter))))
1284 (force (cvs-prefix-get 'cvs-force-command))
1285 (fis (car (cvs-partition
1286 (lambda (fi) (cvs-applicable-p fi (and (not force) filter)))
1287 fis))))
1288 (when (and (or (null fis) (and one (cdr fis))) (not noquery))
1289 (message (if (null fis)
1290 "`%s' is not applicable to any of the selected files."
1291 "`%s' is only applicable to a single file.") cmd)
1292 (sit-for 1)
1293 (setq fis (list (cvs-insert-file
1294 (read-file-name (format "File to %s: " cmd))))))
1295 (if one (car fis) fis)))
1296
1297 (defun cvs-enabledp (filter)
1298 "Determine whether FILTER applies to at least one of the selected files."
1299 (ignore-errors (cvs-mode-marked filter nil :read-only t :noquery t)))
1300
1301 (defun cvs-mode-files (&rest -cvs-mode-files-args)
1302 (cvs-mode!
1303 (lambda ()
1304 (mapcar 'cvs-fileinfo->full-path
1305 (apply 'cvs-mode-marked -cvs-mode-files-args)))))
1306
1307 ;;
1308 ;; Interface between Log-Edit and PCL-CVS
1309 ;;
1310
1311 (defun cvs-mode-commit-setup ()
1312 "Run `cvs-mode-commit' with setup."
1313 (interactive)
1314 (cvs-mode-commit 'force))
1315
1316 (defcustom cvs-mode-commit-hook nil
1317 "Hook run after setting up the commit buffer."
1318 :type 'hook
1319 :options '(cvs-mode-diff))
1320
1321 (defun cvs-mode-commit (setup)
1322 "Check in all marked files, or the current file.
1323 The user will be asked for a log message in a buffer.
1324 The buffer's mode and name is determined by the \"message\" setting
1325 of `cvs-buffer-name-alist'.
1326 The POSTPROC specified there (typically `log-edit') is then called,
1327 passing it the SETUP argument."
1328 (interactive "P")
1329 ;; It seems that the save-excursion that happens if I use the better
1330 ;; form of `(cvs-mode! (lambda ...))' screws up a couple things which
1331 ;; end up being rather annoying (like log-edit-mode's message being
1332 ;; displayed in the wrong minibuffer).
1333 (cvs-mode!)
1334 (let ((buf (cvs-temp-buffer "message" 'normal 'nosetup))
1335 (lbd list-buffers-directory)
1336 (setupfun (or (nth 2 (cdr (assoc "message" cvs-buffer-name-alist)))
1337 'log-edit)))
1338 (funcall setupfun 'cvs-do-commit setup 'cvs-commit-filelist buf)
1339 (set (make-local-variable 'cvs-minor-wrap-function) 'cvs-commit-minor-wrap)
1340 (set (make-local-variable 'list-buffers-directory) lbd)
1341 (run-hooks 'cvs-mode-commit-hook)))
1342
1343 (defun cvs-commit-minor-wrap (buf f)
1344 (let ((cvs-ignore-marks-modif (cvs-mode-mark-get-modif "commit")))
1345 (funcall f)))
1346
1347 (defun cvs-commit-filelist ()
1348 (cvs-mode-files 'commit nil :read-only t :file t :noquery t))
1349
1350 (defun cvs-do-commit (flags)
1351 "Do the actual commit, using the current buffer as the log message."
1352 (interactive (list (cvs-flags-query 'cvs-commit-flags "cvs commit flags")))
1353 (let ((msg (buffer-substring-no-properties (point-min) (point-max))))
1354 (cvs-mode!)
1355 ;;(pop-to-buffer cvs-buffer)
1356 (cvs-mode-do "commit" (list* "-m" msg flags) 'commit)))
1357
1358
1359 ;;;;
1360 ;;;; CVS Mode commands
1361 ;;;;
1362
1363 (defun-cvs-mode (cvs-mode-insert . NOARGS) (file)
1364 "Insert an entry for a specific file."
1365 (interactive
1366 (list (read-file-name
1367 "File to insert: "
1368 ;; Can't use ignore-errors here because interactive
1369 ;; specs aren't byte-compiled.
1370 (condition-case nil
1371 (file-name-as-directory
1372 (expand-file-name
1373 (cvs-fileinfo->dir
1374 (cvs-mode-marked nil nil :read-only t :one t :noquery t))))
1375 (error nil)))))
1376 (cvs-insert-file file))
1377
1378 (defun cvs-insert-file (file)
1379 "Insert FILE (and its contents if it's a dir) and return its FI."
1380 (let ((file (file-relative-name (directory-file-name file))) last)
1381 (dolist (fi (cvs-fileinfo-from-entries file))
1382 (setq last (cvs-addto-collection cvs-cookies fi last)))
1383 ;; There should have been at least one entry.
1384 (goto-char (ewoc-location last))
1385 (ewoc-data last)))
1386
1387 (defun cvs-mark-fis-dead (fis)
1388 ;; Helper function, introduced because of the need for macro-expansion.
1389 (dolist (fi fis)
1390 (setf (cvs-fileinfo->type fi) 'DEAD)))
1391
1392 (defun-cvs-mode (cvs-mode-add . SIMPLE) (flags)
1393 "Add marked files to the cvs repository.
1394 With prefix argument, prompt for cvs flags."
1395 (interactive (list (cvs-flags-query 'cvs-add-flags "cvs add flags")))
1396 (let ((fis (cvs-mode-marked 'add))
1397 (needdesc nil) (dirs nil))
1398 ;; find directories and look for fis needing a description
1399 (dolist (fi fis)
1400 (cond
1401 ((file-directory-p (cvs-fileinfo->full-path fi)) (push fi dirs))
1402 ((eq (cvs-fileinfo->type fi) 'UNKNOWN) (setq needdesc t))))
1403 ;; prompt for description if necessary
1404 (let* ((msg (if (and needdesc
1405 (or current-prefix-arg (not cvs-add-default-message)))
1406 (read-from-minibuffer "Enter description: ")
1407 (or cvs-add-default-message "")))
1408 (flags (list* "-m" msg flags))
1409 (postproc
1410 ;; setup postprocessing for the directory entries
1411 (when dirs
1412 `((cvs-run-process (list "-n" "update")
1413 ',dirs
1414 '(cvs-parse-process t))
1415 (cvs-mark-fis-dead ',dirs)))))
1416 (cvs-mode-run "add" flags fis :postproc postproc))))
1417
1418 (defun-cvs-mode (cvs-mode-diff . DOUBLE) (flags)
1419 "Diff the selected files against the repository.
1420 This command compares the files in your working area against the
1421 revision which they are based upon."
1422 (interactive
1423 (list (cvs-add-branch-prefix
1424 (cvs-add-secondary-branch-prefix
1425 (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))))
1426 (cvs-mode-do "diff" flags 'diff
1427 :show t)) ;; :ignore-exit t
1428
1429 (defun-cvs-mode (cvs-mode-diff-head . SIMPLE) (flags)
1430 "Diff the selected files against the head of the current branch.
1431 See ``cvs-mode-diff'' for more info."
1432 (interactive (list (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))
1433 (cvs-mode-diff-1 (cons "-rHEAD" flags)))
1434
1435 (defun-cvs-mode (cvs-mode-diff-vendor . SIMPLE) (flags)
1436 "Diff the selected files against the head of the vendor branch.
1437 See ``cvs-mode-diff'' for more info."
1438 (interactive (list (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))
1439 (cvs-mode-diff-1 (cons (concat "-r" cvs-vendor-branch) flags)))
1440
1441 ;; sadly, this is not provided by cvs, so we have to roll our own
1442 (defun-cvs-mode (cvs-mode-diff-backup . SIMPLE) (flags)
1443 "Diff the files against the backup file.
1444 This command can be used on files that are marked with \"Merged\"
1445 or \"Conflict\" in the *cvs* buffer."
1446 (interactive (list (cvs-flags-query 'cvs-diff-flags "diff flags")))
1447 (unless (listp flags) (error "flags should be a list of strings"))
1448 (save-some-buffers)
1449 (let* ((filter 'diff)
1450 (marked (cvs-get-marked (cvs-ignore-marks-p "diff")))
1451 ;;(tins (cvs-filter-applicable filter marked))
1452 (fis (car (cvs-partition 'cvs-fileinfo->backup-file marked))))
1453 (unless (consp fis)
1454 (error "No files with a backup file selected!"))
1455 ;; let's extract some info into the environment for `buffer-name'
1456 (let* ((dir (cvs-fileinfo->dir (car fis)))
1457 (file (cvs-fileinfo->file (car fis))))
1458 (set-buffer (cvs-temp-buffer "diff")))
1459 (message "cvs diff backup...")
1460 (cvs-execute-single-file-list fis 'cvs-diff-backup-extractor
1461 cvs-diff-program flags))
1462 (message "cvs diff backup... Done."))
1463
1464 (defun cvs-diff-backup-extractor (fileinfo)
1465 "Return the filename and the name of the backup file as a list.
1466 Signal an error if there is no backup file."
1467 (let ((backup-file (cvs-fileinfo->backup-file fileinfo)))
1468 (unless backup-file
1469 (error "%s has no backup file" (cvs-fileinfo->full-path fileinfo)))
1470 (list backup-file (cvs-fileinfo->full-path fileinfo))))
1471
1472 ;;
1473 ;; Emerge support
1474 ;;
1475 (defun cvs-emerge-diff (b1 b2) (emerge-buffers b1 b2 b1))
1476 (defun cvs-emerge-merge (b1 b2 base out)
1477 (emerge-buffers-with-ancestor b1 b2 base (find-file-noselect out)))
1478
1479 ;;
1480 ;; Ediff support
1481 ;;
1482
1483 (defvar ediff-after-quit-destination-buffer)
1484 (defvar cvs-transient-buffers)
1485 (defun cvs-ediff-startup-hook ()
1486 (add-hook 'ediff-after-quit-hook-internal
1487 `(lambda ()
1488 (cvs-ediff-exit-hook
1489 ',ediff-after-quit-destination-buffer ',cvs-transient-buffers))
1490 nil 'local))
1491
1492 (defun cvs-ediff-exit-hook (cvs-buf tmp-bufs)
1493 ;; kill the temp buffers (and their associated windows)
1494 (dolist (tb tmp-bufs)
1495 (when (and tb (buffer-live-p tb) (not (buffer-modified-p tb)))
1496 (let ((win (get-buffer-window tb t)))
1497 (kill-buffer tb)
1498 (when (window-live-p win) (ignore-errors (delete-window win))))))
1499 ;; switch back to the *cvs* buffer
1500 (when (and cvs-buf (buffer-live-p cvs-buf)
1501 (not (get-buffer-window cvs-buf t)))
1502 (ignore-errors (switch-to-buffer cvs-buf))))
1503
1504 (defun cvs-ediff-diff (b1 b2)
1505 (let ((ediff-after-quit-destination-buffer (current-buffer))
1506 (startup-hook '(cvs-ediff-startup-hook)))
1507 (ediff-buffers b1 b2 startup-hook 'ediff-revision)))
1508
1509 (defun cvs-ediff-merge (b1 b2 base out)
1510 (let ((ediff-after-quit-destination-buffer (current-buffer))
1511 (startup-hook '(cvs-ediff-startup-hook)))
1512 (ediff-merge-buffers-with-ancestor
1513 b1 b2 base startup-hook
1514 'ediff-merge-revisions-with-ancestor
1515 out)))
1516
1517 ;;
1518 ;; Interactive merge/diff support.
1519 ;;
1520
1521 (defun cvs-retrieve-revision (fileinfo rev)
1522 "Retrieve the given REVision of the file in FILEINFO into a new buffer."
1523 (let* ((file (cvs-fileinfo->full-path fileinfo))
1524 (buffile (concat file "." rev)))
1525 (or (find-buffer-visiting buffile)
1526 (with-current-buffer (create-file-buffer buffile)
1527 (message "Retrieving revision %s..." rev)
1528 (let ((res (call-process cvs-program nil t nil
1529 "-q" "update" "-p" "-r" rev file)))
1530 (when (and res (not (and (equal 0 res))))
1531 (error "Something went wrong retrieving revision %s: %s" rev res))
1532 (set-buffer-modified-p nil)
1533 (let ((buffer-file-name (expand-file-name file)))
1534 (after-find-file))
1535 (toggle-read-only 1)
1536 (message "Retrieving revision %s... Done" rev)
1537 (current-buffer))))))
1538
1539 (eval-and-compile (autoload 'smerge-ediff "smerge-mode"))
1540
1541 ;; FIXME: The user should be able to specify ancestor/head/backup and we should
1542 ;; provide sensible defaults when merge info is unavailable (rather than rely
1543 ;; on smerge-ediff). Also provide sane defaults for need-merge files.
1544 (defun-cvs-mode cvs-mode-imerge ()
1545 "Merge interactively appropriate revisions of the selected file."
1546 (interactive)
1547 (let ((fi (cvs-mode-marked 'merge nil :one t :file t)))
1548 (let ((merge (cvs-fileinfo->merge fi))
1549 (file (cvs-fileinfo->full-path fi))
1550 (backup-file (cvs-fileinfo->backup-file fi)))
1551 (if (not (and merge backup-file))
1552 (let ((buf (find-file-noselect file)))
1553 (message "Missing merge info or backup file, using VC.")
1554 (with-current-buffer buf
1555 (smerge-ediff)))
1556 (let* ((ancestor-buf (cvs-retrieve-revision fi (car merge)))
1557 (head-buf (cvs-retrieve-revision fi (cdr merge)))
1558 (backup-buf (let ((auto-mode-alist nil))
1559 (find-file-noselect backup-file)))
1560 ;; this binding is used by cvs-ediff-startup-hook
1561 (cvs-transient-buffers (list ancestor-buf backup-buf head-buf)))
1562 (with-current-buffer backup-buf
1563 (let ((buffer-file-name (expand-file-name file)))
1564 (after-find-file)))
1565 (funcall (cdr cvs-idiff-imerge-handlers)
1566 backup-buf head-buf ancestor-buf file))))))
1567
1568 (cvs-flags-define cvs-idiff-version
1569 (list "BASE" cvs-vendor-branch cvs-vendor-branch "BASE" "BASE")
1570 "version: " cvs-qtypedesc-tag)
1571
1572 (defun-cvs-mode (cvs-mode-idiff . NOARGS) (&optional rev1 rev2)
1573 "Diff interactively current file to revisions."
1574 (interactive
1575 (let* ((rev1 (cvs-prefix-get 'cvs-branch-prefix))
1576 (rev2 (and rev1 (cvs-prefix-get 'cvs-secondary-branch-prefix))))
1577 (list (or rev1 (cvs-flags-query 'cvs-idiff-version))
1578 rev2)))
1579 (let ((fi (cvs-mode-marked 'diff "idiff" :one t :file t)))
1580 (let* ((file (cvs-fileinfo->full-path fi))
1581 (rev1-buf (cvs-retrieve-revision fi (or rev1 "BASE")))
1582 (rev2-buf (if rev2 (cvs-retrieve-revision fi rev2)))
1583 ;; this binding is used by cvs-ediff-startup-hook
1584 (cvs-transient-buffers (list rev1-buf rev2-buf)))
1585 (funcall (car cvs-idiff-imerge-handlers)
1586 rev1-buf (or rev2-buf (find-file-noselect file))))))
1587
1588 (defun-cvs-mode (cvs-mode-idiff-other . NOARGS) ()
1589 "Diff interactively current file to revisions."
1590 (interactive)
1591 (let* ((rev1 (cvs-prefix-get 'cvs-branch-prefix))
1592 (rev2 (and rev1 (cvs-prefix-get 'cvs-secondary-branch-prefix)))
1593 (fis (cvs-mode-marked 'diff "idiff" :file t)))
1594 (when (> (length fis) 2)
1595 (error "idiff-other cannot be applied to more than 2 files at a time"))
1596 (let* ((fi1 (car fis))
1597 (rev1-buf (if rev1 (cvs-retrieve-revision fi1 rev1)
1598 (find-file-noselect (cvs-fileinfo->full-path fi1))))
1599 rev2-buf)
1600 (if (cdr fis)
1601 (let ((fi2 (nth 1 fis)))
1602 (setq rev2-buf
1603 (if rev2 (cvs-retrieve-revision fi2 rev2)
1604 (find-file-noselect (cvs-fileinfo->full-path fi2)))))
1605 (error "idiff-other doesn't know what other file/buffer to use"))
1606 (let* (;; this binding is used by cvs-ediff-startup-hook
1607 (cvs-transient-buffers (list rev1-buf rev2-buf)))
1608 (funcall (car cvs-idiff-imerge-handlers)
1609 rev1-buf rev2-buf)))))
1610
1611
1612 (defun cvs-fileinfo-kill (c fi)
1613 "Mark a fileinfo xor its members (in case of a directory) as dead."
1614 (if (eq (cvs-fileinfo->type fi) 'DIRCHANGE)
1615 (dolist (fi (ewoc-collect c 'cvs-dir-member-p
1616 (cvs-fileinfo->dir fi)))
1617 (setf (cvs-fileinfo->type fi) 'DEAD))
1618 (setf (cvs-fileinfo->type fi) 'DEAD)))
1619
1620 (defun cvs-is-within-p (fis dir)
1621 "Non-nil is buffer is inside one of FIS (in DIR)."
1622 (when (stringp buffer-file-name)
1623 (setq buffer-file-name (expand-file-name buffer-file-name))
1624 (let (ret)
1625 (dolist (fi (or fis (list (cvs-create-fileinfo 'DIRCHANGE "" "." ""))))
1626 (when (cvs-string-prefix-p
1627 (expand-file-name (cvs-fileinfo->full-path fi) dir)
1628 buffer-file-name)
1629 (setq ret t)))
1630 ret)))
1631
1632 (defun* cvs-mode-run (cmd flags fis
1633 &key (buf (cvs-temp-buffer))
1634 dont-change-disc cvsargs postproc)
1635 "Generic cvs-mode-<foo> function.
1636 Executes `cvs CVSARGS CMD FLAGS FIS'.
1637 BUF is the buffer to be used for cvs' output.
1638 DONT-CHANGE-DISC non-nil indicates that the command will not change the
1639 contents of files. This is only used by the parser.
1640 POSTPROC is a list of expressions to be evaluated at the very end (after
1641 parsing if applicable). It will be prepended with `progn' is necessary."
1642 (let ((def-dir default-directory))
1643 ;; Save the relevant buffers
1644 (save-some-buffers nil (lambda () (cvs-is-within-p fis def-dir))))
1645 (unless (listp flags) (error "flags should be a list of strings"))
1646 (let* ((cvs-buf (current-buffer))
1647 (single-dir (or (not (listp cvs-execute-single-dir))
1648 (member cmd cvs-execute-single-dir)))
1649 (parse (member cmd cvs-parse-known-commands))
1650 (args (append cvsargs (list cmd) flags))
1651 (after-mode (nth 2 (cdr (assoc cmd cvs-buffer-name-alist)))))
1652 (cvs-cleanup-collection cvs-cookies ;cleanup remaining messages
1653 (eq cvs-auto-remove-handled 'delayed) nil t)
1654 (when (fboundp after-mode)
1655 (setq postproc (append postproc `((,after-mode)))))
1656 (when parse (push `(cvs-parse-process ',dont-change-disc) postproc))
1657 (when (member cmd '("status" "update")) ;FIXME: Yuck!!
1658 ;; absence of `cvs update' output has a specific meaning.
1659 (push
1660 `(dolist (fi ',(or fis
1661 (list (cvs-create-fileinfo 'DIRCHANGE "" "." ""))))
1662 (cvs-fileinfo-kill ',cvs-cookies fi))
1663 postproc))
1664 (setq postproc (if (cdr postproc) (cons 'progn postproc) (car postproc)))
1665 (cvs-update-header args fis)
1666 (with-current-buffer buf
1667 ;;(set (make-local-variable 'cvs-buffer) cvs-buf)
1668 (let ((inhibit-read-only t)) (erase-buffer))
1669 (message "Running cvs %s ..." cmd)
1670 (cvs-run-process args fis postproc single-dir))))
1671
1672
1673 (defun* cvs-mode-do (cmd flags filter
1674 &key show dont-change-disc parse cvsargs postproc)
1675 "Generic cvs-mode-<foo> function.
1676 Executes `cvs CVSARGS CMD FLAGS' on the selected files.
1677 FILTER is passed to `cvs-applicable-p' to only apply the command to
1678 files for which it makes sense.
1679 SHOW indicates that CMD should be not be run in the default temp buffer and
1680 should be shown to the user. The buffer and mode to be used is determined
1681 by `cvs-buffer-name-alist'.
1682 DONT-CHANGE-DISC non-nil indicates that the command will not change the
1683 contents of files. This is only used by the parser."
1684 (cvs-mode-run cmd flags (cvs-mode-marked filter cmd)
1685 :buf (cvs-temp-buffer (when show cmd))
1686 :dont-change-disc dont-change-disc
1687 :cvsargs cvsargs
1688 :postproc postproc))
1689
1690 (defun-cvs-mode (cvs-mode-status . SIMPLE) (flags)
1691 "Show cvs status for all marked files.
1692 With prefix argument, prompt for cvs flags."
1693 (interactive (list (cvs-flags-query 'cvs-status-flags "cvs status flags")))
1694 (cvs-mode-do "status" flags nil :dont-change-disc t :show t
1695 :postproc (when (eq cvs-auto-remove-handled 'status)
1696 '((with-current-buffer ,(current-buffer)
1697 (cvs-mode-remove-handled))))))
1698
1699 (defun-cvs-mode (cvs-mode-tree . SIMPLE) (flags)
1700 "Call cvstree using the file under the point as a keyfile."
1701 (interactive (list (cvs-flags-query 'cvs-status-flags "cvs status flags")))
1702 (cvs-mode-run "status" (cons "-v" flags) (cvs-mode-marked nil "status")
1703 :buf (cvs-temp-buffer "tree")
1704 :dont-change-disc t
1705 :postproc '((cvs-status-cvstrees))))
1706
1707 ;; cvs log
1708
1709 (defun-cvs-mode (cvs-mode-log . NOARGS) (flags)
1710 "Display the cvs log of all selected files.
1711 With prefix argument, prompt for cvs flags."
1712 (interactive (list (cvs-add-branch-prefix
1713 (cvs-flags-query 'cvs-log-flags "cvs log flags"))))
1714 (cvs-mode-do "log" flags nil :show t))
1715
1716
1717 (defun-cvs-mode (cvs-mode-update . NOARGS) (flags)
1718 "Update all marked files.
1719 With a prefix argument, prompt for cvs flags."
1720 (interactive
1721 (list (cvs-add-branch-prefix
1722 (cvs-add-secondary-branch-prefix
1723 (cvs-flags-query 'cvs-update-flags "cvs update flags")
1724 "-j") "-j")))
1725 (cvs-mode-do "update" flags 'update))
1726
1727
1728 (defun-cvs-mode (cvs-mode-examine . NOARGS) (flags)
1729 "Re-examine all marked files.
1730 With a prefix argument, prompt for cvs flags."
1731 (interactive
1732 (list (cvs-add-branch-prefix
1733 (cvs-add-secondary-branch-prefix
1734 (cvs-flags-query 'cvs-update-flags "cvs -n update flags")
1735 "-j") "-j")))
1736 (cvs-mode-do "update" flags nil :cvsargs '("-n") :dont-change-disc t))
1737
1738
1739 (defun-cvs-mode cvs-mode-ignore (&optional pattern)
1740 "Arrange so that CVS ignores the selected files.
1741 This command ignores files that are not flagged as `Unknown'."
1742 (interactive)
1743 (dolist (fi (cvs-mode-marked 'ignore))
1744 (cvs-append-to-ignore (cvs-fileinfo->dir fi) (cvs-fileinfo->file fi))
1745 (setf (cvs-fileinfo->type fi) 'DEAD))
1746 (cvs-cleanup-collection cvs-cookies nil nil nil))
1747
1748
1749 (defun cvs-append-to-ignore (dir str)
1750 "Add STR to the .cvsignore file in DIR."
1751 (save-window-excursion
1752 (set-buffer (find-file-noselect (expand-file-name ".cvsignore" dir)))
1753 (when (ignore-errors
1754 (and buffer-read-only
1755 (eq 'CVS (vc-backend buffer-file-name))
1756 (not (vc-editable-p buffer-file-name))))
1757 ;; CVSREAD=on special case
1758 (vc-toggle-read-only))
1759 (goto-char (point-max))
1760 (unless (zerop (current-column)) (insert "\n"))
1761 (insert str "\n")
1762 (if cvs-sort-ignore-file (sort-lines nil (point-min) (point-max)))
1763 (save-buffer)))
1764
1765
1766 (defun cvs-mode-find-file-other-window (e)
1767 "Select a buffer containing the file in another window."
1768 (interactive (list last-input-event))
1769 (cvs-mode-find-file e t))
1770
1771
1772 (defun cvs-mode-display-file (e)
1773 "Show a buffer containing the file in another window."
1774 (interactive (list last-input-event))
1775 (cvs-mode-find-file e 'dont-select))
1776
1777
1778 (defun cvs-find-modif (fi)
1779 (with-temp-buffer
1780 (call-process cvs-program nil (current-buffer) nil
1781 "-f" "diff" (cvs-fileinfo->file fi))
1782 (goto-char (point-min))
1783 (if (re-search-forward "^\\([0-9]+\\)" nil t)
1784 (string-to-number (match-string 1))
1785 1)))
1786
1787
1788 (defun cvs-mode-find-file (e &optional other)
1789 "Select a buffer containing the file.
1790 With a prefix, opens the buffer in an OTHER window."
1791 (interactive (list last-input-event current-prefix-arg))
1792 (when (ignore-errors (mouse-set-point e) t) ;for invocation via the mouse
1793 (unless (memq (get-text-property (point) 'face)
1794 '(cvs-header-face cvs-filename-face))
1795 (error "Not a file name")))
1796 (cvs-mode!
1797 (lambda (&optional rev)
1798 (interactive (list (cvs-prefix-get 'cvs-branch-prefix)))
1799 (let* ((cvs-buf (current-buffer))
1800 (fi (cvs-mode-marked nil nil :one t)))
1801 (if (eq (cvs-fileinfo->type fi) 'DIRCHANGE)
1802 (let ((odir default-directory))
1803 (setq default-directory
1804 (cvs-expand-dir-name (cvs-fileinfo->dir fi)))
1805 (cond ((eq other 'dont-select)
1806 (display-buffer (find-file-noselect default-directory)))
1807 (other (dired-other-window default-directory))
1808 (t (dired default-directory)))
1809 (set-buffer cvs-buf)
1810 (setq default-directory odir))
1811 (let ((buf (if rev (cvs-retrieve-revision fi rev)
1812 (find-file-noselect (cvs-fileinfo->full-path fi)))))
1813 (funcall (cond ((eq other 'dont-select) 'display-buffer)
1814 (other 'switch-to-buffer-other-window)
1815 (t 'switch-to-buffer))
1816 buf)
1817 (when (and cvs-find-file-and-jump (cvs-applicable-p fi 'diff-base))
1818 (goto-line (cvs-find-modif fi)))
1819 buf))))))
1820
1821
1822 (defun-cvs-mode (cvs-mode-undo . SIMPLE) (flags)
1823 "Undo local changes to all marked files.
1824 The file is removed and `cvs update FILE' is run."
1825 ;;"With prefix argument, prompt for cvs FLAGS."
1826 (interactive (list nil));; (cvs-flags-query 'cvs-undo-flags "undo flags")
1827 (if current-prefix-arg (call-interactively 'cvs-mode-revert-to-rev)
1828 (let* ((fis (cvs-do-removal 'undo "update" 'all))
1829 (removedp (lambda (fi) (eq (cvs-fileinfo->type fi) 'REMOVED)))
1830 (fis-split (cvs-partition removedp fis))
1831 (fis-removed (car fis-split))
1832 (fis-other (cdr fis-split)))
1833 (if (null fis-other)
1834 (when fis-removed (cvs-mode-run "add" nil fis-removed))
1835 (cvs-mode-run "update" flags fis-other
1836 :postproc
1837 (when fis-removed
1838 `((with-current-buffer ,(current-buffer)
1839 (cvs-mode-run "add" nil ',fis-removed)))))))))
1840
1841
1842 (defun-cvs-mode (cvs-mode-revert-to-rev . NOARGS) (rev)
1843 "Revert the selected files to an old revision."
1844 (interactive
1845 (list (or (cvs-prefix-get 'cvs-branch-prefix)
1846 (let ((current-prefix-arg '(4)))
1847 (cvs-flags-query 'cvs-idiff-version)))))
1848 (let* ((fis (cvs-mode-marked 'revert "revert" :file t))
1849 (tag (concat "tmp_pcl_tag_" (make-temp-name "")))
1850 (untag `((with-current-buffer ,(current-buffer)
1851 (cvs-mode-run "tag" (list "-d" ',tag) ',fis))))
1852 (update `((with-current-buffer ,(current-buffer)
1853 (cvs-mode-run "update" (list "-j" ',tag "-j" ',rev) ',fis
1854 :postproc ',untag)))))
1855 (cvs-mode-run "tag" (list tag) fis :postproc update)))
1856
1857
1858 (defun-cvs-mode cvs-mode-delete-lock ()
1859 "Delete the lock file that CVS is waiting for.
1860 Note that this can be dangerous. You should only do this
1861 if you are convinced that the process that created the lock is dead."
1862 (interactive)
1863 (let* ((default-directory (cvs-expand-dir-name cvs-lock-file))
1864 (locks (directory-files default-directory nil cvs-lock-file-regexp)))
1865 (cond
1866 ((not locks) (error "No lock files found"))
1867 ((yes-or-no-p (concat "Really delete locks in " cvs-lock-file "? "))
1868 (dolist (lock locks)
1869 (cond ((file-directory-p lock) (delete-directory lock))
1870 ((file-exists-p lock) (delete-file lock))))))))
1871
1872
1873 (defun-cvs-mode cvs-mode-remove-handled ()
1874 "Remove all lines that are handled.
1875 Empty directories are removed."
1876 (interactive)
1877 (cvs-cleanup-collection cvs-cookies
1878 t (or cvs-auto-remove-directories 'handled) t))
1879
1880
1881 (defun-cvs-mode cvs-mode-acknowledge ()
1882 "Remove all marked files from the buffer."
1883 (interactive)
1884 (dolist (fi (cvs-get-marked (cvs-ignore-marks-p "acknowledge") t))
1885 (setf (cvs-fileinfo->type fi) 'DEAD))
1886 (cvs-cleanup-collection cvs-cookies nil nil nil))
1887
1888 (defun cvs-do-removal (filter &optional cmd all)
1889 "Remove files.
1890 Returns a list of FIS that should be `cvs remove'd."
1891 (let* ((files (cvs-mode-marked filter cmd :file t :read-only t))
1892 (fis (cdr (cvs-partition (lambda (fi)
1893 (eq (cvs-fileinfo->type fi) 'UNKNOWN))
1894 (cvs-mode-marked filter cmd))))
1895 (silent (or (not cvs-confirm-removals)
1896 (cvs-every (lambda (fi)
1897 (or (not (file-exists-p
1898 (cvs-fileinfo->full-path fi)))
1899 (cvs-applicable-p fi 'safe-rm)))
1900 files)))
1901 (tmpbuf (cvs-temp-buffer)))
1902 (when (and (not silent) (equal cvs-confirm-removals 'list))
1903 (with-current-buffer tmpbuf
1904 (cvs-insert-strings (mapcar 'cvs-fileinfo->full-path fis))
1905 (cvs-pop-to-buffer-same-frame (current-buffer))
1906 (shrink-window-if-larger-than-buffer)))
1907 (if (not (or silent
1908 (unwind-protect
1909 (yes-or-no-p (format "Delete %d files? " (length files)))
1910 (cvs-bury-buffer tmpbuf cvs-buffer))))
1911 (progn (message "Aborting") nil)
1912 (dolist (fi files)
1913 (let* ((type (cvs-fileinfo->type fi))
1914 (file (cvs-fileinfo->full-path fi)))
1915 (when (or all (eq type 'UNKNOWN))
1916 (when (file-exists-p file) (delete-file file))
1917 (unless all (setf (cvs-fileinfo->type fi) 'DEAD) t))))
1918 fis)))
1919
1920 (defun-cvs-mode (cvs-mode-remove . SIMPLE) (flags)
1921 "Remove all marked files.
1922 With prefix argument, prompt for cvs flags."
1923 (interactive (list (cvs-flags-query 'cvs-remove-flags "cvs remove flags")))
1924 (let ((fis (cvs-do-removal 'remove)))
1925 (if fis (cvs-mode-run "remove" (cons "-f" flags) fis)
1926 (cvs-cleanup-collection cvs-cookies nil nil nil))))
1927
1928
1929 (defvar cvs-tag-name "")
1930 (defun-cvs-mode (cvs-mode-tag . SIMPLE) (tag &optional flags)
1931 "Run `cvs tag TAG' on all selected files.
1932 With prefix argument, prompt for cvs flags."
1933 (interactive
1934 (list (setq cvs-tag-name
1935 (cvs-query-read cvs-tag-name "Tag name: " cvs-qtypedesc-tag))
1936 (cvs-flags-query 'cvs-tag-flags "tag flags")))
1937 (cvs-mode-do "tag" (append flags (list tag))
1938 (when cvs-force-dir-tag 'tag)))
1939
1940 (defun-cvs-mode (cvs-mode-untag . SIMPLE) (tag &optional flags)
1941 "Run `cvs tag -d TAG' on all selected files.
1942 With prefix argument, prompt for cvs flags."
1943 (interactive
1944 (list (setq cvs-tag-name
1945 (cvs-query-read cvs-tag-name "Tag to delete: " cvs-qtypedesc-tag))
1946 (cvs-flags-query 'cvs-tag-flags "tag flags")))
1947 (cvs-mode-do "tag" (append '("-d") flags (list tag))
1948 (when cvs-force-dir-tag 'tag)))
1949
1950
1951 ;; Byte compile files.
1952
1953 (defun-cvs-mode cvs-mode-byte-compile-files ()
1954 "Run byte-compile-file on all selected files that end in '.el'."
1955 (interactive)
1956 (let ((marked (cvs-get-marked (cvs-ignore-marks-p "byte-compile"))))
1957 (dolist (fi marked)
1958 (let ((filename (cvs-fileinfo->full-path fi)))
1959 (when (string-match "\\.el\\'" filename)
1960 (byte-compile-file filename))))))
1961
1962 ;; ChangeLog support.
1963
1964 (defun-cvs-mode cvs-mode-add-change-log-entry-other-window ()
1965 "Add a ChangeLog entry in the ChangeLog of the current directory."
1966 (interactive)
1967 (let* ((fi (cvs-mode-marked nil nil :one t))
1968 (default-directory (cvs-expand-dir-name (cvs-fileinfo->dir fi)))
1969 (buffer-file-name (expand-file-name (cvs-fileinfo->file fi))))
1970 (kill-local-variable 'change-log-default-name)
1971 (add-change-log-entry-other-window)))
1972
1973 ;; interactive commands to set optional flags
1974
1975 (defun cvs-mode-set-flags (flag)
1976 "Ask for new setting of cvs-FLAG-flags."
1977 (interactive
1978 (list (completing-read
1979 "Which flag: "
1980 (mapcar 'list '("cvs" "diff" "update" "status" "log" "tag" ;"rtag"
1981 "commit" "remove" "undo" "checkout"))
1982 nil t)))
1983 (let* ((sym (intern (concat "cvs-" flag "-flags"))))
1984 (let ((current-prefix-arg '(16)))
1985 (cvs-flags-query sym (concat flag " flags")))))
1986
1987 \f
1988 ;;;;
1989 ;;;; Utilities for the *cvs* buffer
1990 ;;;;
1991
1992 (defun cvs-dir-member-p (fileinfo dir)
1993 "Return true if FILEINFO represents a file in directory DIR."
1994 (and (not (eq (cvs-fileinfo->type fileinfo) 'DIRCHANGE))
1995 (cvs-string-prefix-p dir (cvs-fileinfo->dir fileinfo))))
1996
1997 (defun cvs-execute-single-file (fi extractor program constant-args)
1998 "Internal function for `cvs-execute-single-file-list'."
1999 (let* ((arg-list (funcall extractor fi))
2000 (inhibit-read-only t))
2001
2002 ;; Execute the command unless extractor returned t.
2003 (when (listp arg-list)
2004 (let* ((args (append constant-args arg-list)))
2005
2006 (insert (format "=== %s %s\n\n"
2007 program (cvs-strings->string args)))
2008
2009 ;; FIXME: return the exit status?
2010 (apply 'call-process program nil t t args)
2011 (goto-char (point-max))))))
2012
2013 ;; FIXME: make this run in the background ala cvs-run-process...
2014 (defun cvs-execute-single-file-list (fis extractor program constant-args)
2015 "Run PROGRAM on all elements on FIS.
2016 CONSTANT-ARGS is a list of strings to pass as arguments to PROGRAM.
2017 The arguments given to the program will be CONSTANT-ARGS followed by
2018 the list that EXTRACTOR returns.
2019
2020 EXTRACTOR will be called once for each file on FIS. It is given
2021 one argument, the cvs-fileinfo. It can return t, which means ignore
2022 this file, or a list of arguments to send to the program."
2023 (dolist (fi fis)
2024 (cvs-execute-single-file fi extractor program constant-args)))
2025
2026 \f
2027 (defun cvs-revert-if-needed (fis)
2028 (dolist (fileinfo fis)
2029 (let* ((file (cvs-fileinfo->full-path fileinfo))
2030 (buffer (find-buffer-visiting file)))
2031 ;; For a revert to happen the user must be editing the file...
2032 (unless (or (null buffer)
2033 (eq (cvs-fileinfo->type fileinfo) 'MESSAGE)
2034 ;; FIXME: check whether revert is really needed.
2035 ;; `(verify-visited-file-modtime buffer)' doesn't cut it
2036 ;; because it only looks at the time stamp (it ignores
2037 ;; read-write changes) which is not changed by `commit'.
2038 (buffer-modified-p buffer))
2039 (with-current-buffer buffer
2040 (ignore-errors
2041 (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes)
2042 ;; `preserve-modes' avoids changing the (minor) modes. But we
2043 ;; do want to reset the mode for VC, so we do it explicitly.
2044 (vc-find-file-hook)
2045 (when (eq (cvs-fileinfo->type fileinfo) 'CONFLICT)
2046 (smerge-mode 1))))))))
2047
2048 \f
2049 (defun cvs-change-cvsroot (newroot)
2050 "Change the cvsroot."
2051 (interactive "DNew repository: ")
2052 (if (or (file-directory-p (expand-file-name "CVSROOT" newroot))
2053 (y-or-n-p (concat "Warning: no CVSROOT found inside repository."
2054 " Change cvs-cvsroot anyhow?")))
2055 (setq cvs-cvsroot newroot)))
2056
2057 ;;;;
2058 ;;;; useful global settings
2059 ;;;;
2060
2061 ;;;###autoload
2062 (add-to-list 'completion-ignored-extensions "CVS/")
2063
2064 ;;
2065 ;; Hook to allow calling PCL-CVS by visiting the /CVS subdirectory
2066 ;;
2067
2068 ;;;###autoload
2069 (defcustom cvs-dired-action 'cvs-quickdir
2070 "The action to be performed when opening a CVS directory.
2071 Sensible values are `cvs-examine', `cvs-status' and `cvs-quickdir'."
2072 :group 'pcl-cvs
2073 :type '(choice (const cvs-examine) (const cvs-status) (const cvs-quickdir)))
2074
2075 ;;;###autoload
2076 (defcustom cvs-dired-use-hook '(4)
2077 "Whether or not opening a CVS directory should run PCL-CVS.
2078 NIL means never do it.
2079 ALWAYS means to always do it unless a prefix argument is given to the
2080 command that prompted the opening of the directory.
2081 Anything else means to do it only if the prefix arg is equal to this value."
2082 :group 'pcl-cvs
2083 :type '(choice (const :tag "Never" nil)
2084 (const :tag "Always" always)
2085 (const :tag "Prefix" (4))))
2086
2087 ;;;###autoload
2088 (progn (defun cvs-dired-noselect (dir)
2089 "Run `cvs-examine' if DIR is a CVS administrative directory.
2090 The exact behavior is determined also by `cvs-dired-use-hook'."
2091 (when (stringp dir)
2092 (setq dir (directory-file-name dir))
2093 (when (and (string= "CVS" (file-name-nondirectory dir))
2094 (file-readable-p (expand-file-name "Entries" dir))
2095 cvs-dired-use-hook
2096 (if (eq cvs-dired-use-hook 'always)
2097 (not current-prefix-arg)
2098 (equal current-prefix-arg cvs-dired-use-hook)))
2099 (save-excursion
2100 (funcall cvs-dired-action (file-name-directory dir) t t))))))
2101
2102 ;;
2103 ;; hook into VC
2104 ;;
2105
2106 (add-hook 'vc-post-command-functions 'cvs-vc-command-advice)
2107
2108 (defun cvs-vc-command-advice (command file flags)
2109 (when (and (equal command "cvs")
2110 ;; don't parse output we don't understand.
2111 (member (car flags) cvs-parse-known-commands))
2112 (save-excursion
2113 (let ((buffer (current-buffer))
2114 (dir default-directory)
2115 (cvs-from-vc t))
2116 (dolist (cvs-buf (buffer-list))
2117 (set-buffer cvs-buf)
2118 ;; look for a corresponding pcl-cvs buffer
2119 (when (and (eq major-mode 'cvs-mode)
2120 (cvs-string-prefix-p default-directory dir))
2121 (let ((subdir (substring dir (length default-directory))))
2122 (set-buffer buffer)
2123 (set (make-local-variable 'cvs-buffer) cvs-buf)
2124 ;; VC never (?) does `cvs -n update' so dcd=nil
2125 ;; should probably always be the right choice.
2126 (cvs-parse-process nil subdir))))))))
2127
2128 ;;
2129 ;; Hook into write-buffer
2130 ;;
2131
2132 (defun cvs-mark-buffer-changed ()
2133 (let* ((file (expand-file-name buffer-file-name))
2134 (version (and (fboundp 'vc-backend)
2135 (eq (vc-backend file) 'CVS)
2136 (vc-workfile-version file))))
2137 (when version
2138 (save-excursion
2139 (dolist (cvs-buf (buffer-list))
2140 (set-buffer cvs-buf)
2141 ;; look for a corresponding pcl-cvs buffer
2142 (when (and (eq major-mode 'cvs-mode)
2143 (cvs-string-prefix-p default-directory file))
2144 (let* ((file (substring file (length default-directory)))
2145 (fi (cvs-create-fileinfo
2146 (if (string= "0" version)
2147 'ADDED 'MODIFIED)
2148 (or (file-name-directory file) "")
2149 (file-name-nondirectory file)
2150 "cvs-mark-buffer-changed")))
2151 (cvs-addto-collection cvs-cookies fi))))))))
2152
2153 (add-hook 'after-save-hook 'cvs-mark-buffer-changed)
2154
2155 \f
2156 (provide 'pcvs)
2157
2158 ;;; pcvs.el ends here