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