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