Fix typo.
[emacs.git] / lisp / pcvs.el
blobb6be1fc5135bb998af7d9c8f3339e831047fdeb6
1 ;;; pcvs.el --- a front-end to CVS
3 ;; Copyright (C) 1991,92,93,94,95,95,97,98,99,2000,02,2003
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
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 *********
63 ;; - rework the displaying of error messages.
64 ;; - allow to flush messages only
65 ;; - allow to protect files like ChangeLog from flushing
66 ;; - automatically cvs-mode-insert files from find-file-hook
67 ;; (and don't flush them as long as they are visited)
68 ;; - query the user for cvs-get-marked (for some cmds or if nothing's selected)
69 ;; - don't return the first (resp last) FI if the cursor is before
70 ;; (resp after) it.
71 ;; - allow cvs-confirm-removals to force always confirmation.
72 ;; - cvs-checkout should ask for a revision (with completion).
73 ;; - removal confirmation should allow specifying another file name.
75 ;; - hide fileinfos without getting rid of them (will require ewok work).
76 ;; - add toolbar entries
77 ;; - marking
78 ;; marking directories should jump to just after the dir.
79 ;; allow (un)marking directories at a time with the mouse.
80 ;; allow cvs-cmd-do to either clear the marks or not.
81 ;; add a "marks active" notion, like transient-mark-mode does.
82 ;; - liveness indicator
83 ;; - indicate in docstring if the cmd understands the `b' prefix(es).
84 ;; - call smerge-mode when opening CONFLICT files.
85 ;; - have vc-checkin delegate to cvs-mode-commit when applicable
86 ;; - higher-level CVS operations
87 ;; cvs-mode-rename
88 ;; cvs-mode-branch
89 ;; - module-level commands
90 ;; add support for parsing 'modules' file ("cvs co -c")
91 ;; cvs-mode-rcs2log
92 ;; cvs-rdiff
93 ;; cvs-release
94 ;; cvs-import
95 ;; C-u M-x cvs-checkout should ask for a cvsroot
96 ;; cvs-mode-handle-new-vendor-version
97 ;; - checks out module, or alternately does update join
98 ;; - does "cvs -n tag LAST_VENDOR" to find old files into *cvs*
99 ;; cvs-export
100 ;; (with completion on tag names and hooks to help generate full releases)
101 ;; - display stickiness information. And current CVS/Tag as well.
102 ;; - write 'cvs-mode-admin' to do arbitrary 'cvs admin' commands
103 ;; Most interesting would be version removal and log message replacement.
104 ;; The last one would be neat when called from log-view-mode.
105 ;; - cvs-mode-incorporate
106 ;; It would merge in the status from one *cvs* buffer into another.
107 ;; This would be used to populate such a buffer that had been created with
108 ;; a `cvs {update,status,checkout} -l'.
109 ;; - cvs-mode-(i)diff-other-{file,buffer,cvs-buffer}
110 ;; - offer the choice to kill the process when the user kills the cvs buffer.
111 ;; right now, it's killed without further ado.
112 ;; - make `cvs-mode-ignore' allow manually entering a pattern.
113 ;; to which dir should it apply ?
114 ;; - cvs-mode-ignore should try to remove duplicate entries.
115 ;; - maybe poll/check CVS/Entries files to react to external `cvs' commands ?
116 ;; - some kind of `cvs annotate' support ?
117 ;; but vc-annotate can be used instead.
118 ;; - proper `g' that passes safe args and uses either cvs-status or cvs-examine
119 ;; maybe also use cvs-update depending on I-don't-know-what.
120 ;; - add message-levels so that we can hide some levels of messages
122 ;;; Code:
124 (eval-when-compile (require 'cl))
125 (require 'ewoc) ;Ewoc was once cookie
126 (require 'pcvs-defs)
127 (require 'pcvs-util)
128 (require 'pcvs-parse)
129 (require 'pcvs-info)
132 ;;;;
133 ;;;; global vars
134 ;;;;
136 (defvar cvs-cookies) ;;nil
137 ;;"Handle for the cookie structure that is displayed in the *cvs* buffer.")
138 ;;(make-variable-buffer-local 'cvs-cookies)
140 ;;;;
141 ;;;; Dynamically scoped variables
142 ;;;;
144 (defvar cvs-from-vc nil "Bound to t inside VC advice.")
146 ;;;;
147 ;;;; flags variables
148 ;;;;
150 (defun cvs-defaults (&rest defs)
151 (let ((defs (cvs-first defs cvs-shared-start)))
152 (append defs
153 (make-list (- cvs-shared-start (length defs)) (car defs))
154 cvs-shared-flags)))
156 ;; For cvs flags, we need to add "-f" to override the cvsrc settings
157 ;; we also want to evict the annoying -q and -Q options that hide useful
158 ;; information from pcl-cvs.
159 (cvs-flags-define cvs-cvs-flags '(("-f")))
161 (cvs-flags-define cvs-checkout-flags (cvs-defaults '("-P")))
162 (cvs-flags-define cvs-status-flags (cvs-defaults '("-v") nil))
163 (cvs-flags-define cvs-log-flags (cvs-defaults nil))
164 (cvs-flags-define cvs-diff-flags (cvs-defaults '("-u" "-N") '("-c" "-N") '("-u" "-b")))
165 (cvs-flags-define cvs-tag-flags (cvs-defaults nil))
166 (cvs-flags-define cvs-add-flags (cvs-defaults nil))
167 (cvs-flags-define cvs-commit-flags (cvs-defaults nil))
168 (cvs-flags-define cvs-remove-flags (cvs-defaults nil))
169 ;;(cvs-flags-define cvs-undo-flags (cvs-defaults nil))
170 (cvs-flags-define cvs-update-flags (cvs-defaults '("-d" "-P")))
172 (defun cvs-reread-cvsrc ()
173 "Reset the default arguments to those in the `cvs-cvsrc-file'."
174 (interactive)
175 (condition-case nil
176 (with-temp-buffer
177 (insert-file-contents cvs-cvsrc-file)
178 ;; fetch the values
179 (dolist (cmd '("cvs" "checkout" "status" "log" "diff" "tag"
180 "add" "commit" "remove" "update"))
181 (goto-char (point-min))
182 (when (re-search-forward
183 (concat "^" cmd "\\(\\s-+\\(.*\\)\\)?$") nil t)
184 (let* ((sym (intern (concat "cvs-" cmd "-flags")))
185 (val (cvs-string->strings (or (match-string 2) ""))))
186 (cvs-flags-set sym 0 val))))
187 ;; ensure that cvs doesn't have -q or -Q
188 (cvs-flags-set 'cvs-cvs-flags 0
189 (cons "-f"
190 (cdr (cvs-partition
191 (lambda (x) (member x '("-q" "-Q" "-f")))
192 (cvs-flags-query 'cvs-cvs-flags
193 nil 'noquery))))))
194 (file-error nil)))
196 ;; initialize to cvsrc's default values
197 (cvs-reread-cvsrc)
200 ;;;;
201 ;;;; Mouse bindings and mode motion
202 ;;;;
204 (defvar cvs-minor-current-files)
206 (defun cvs-menu (e)
207 "Popup the CVS menu."
208 (interactive "e")
209 (let ((cvs-minor-current-files
210 (list (ewoc-data (ewoc-locate
211 cvs-cookies (posn-point (event-end e)))))))
212 (popup-menu cvs-menu e)))
214 (defvar cvs-mode-line-process nil
215 "Mode-line control for displaying info on cvs process status.")
218 ;;;;
219 ;;;; Query-Type-Descriptor for Tags
220 ;;;;
222 (autoload 'cvs-status-get-tags "cvs-status")
223 (defun cvs-tags-list ()
224 "Return a list of acceptable tags, ready for completions."
225 (assert (cvs-buffer-p))
226 (let ((marked (cvs-get-marked)))
227 (list* '("BASE") '("HEAD")
228 (when marked
229 (with-temp-buffer
230 (call-process cvs-program
231 nil ;no input
232 t ;output to current-buffer
233 nil ;don't update display while running
234 "status"
235 "-v"
236 (cvs-fileinfo->full-path (car marked)))
237 (goto-char (point-min))
238 (let ((tags (cvs-status-get-tags)))
239 (when (listp tags) tags)))))))
241 (defvar cvs-tag-history nil)
242 (defconst cvs-qtypedesc-tag
243 (cvs-qtypedesc-create 'identity 'identity 'cvs-tags-list 'cvs-tag-history))
245 ;;;;
247 (defun cvs-mode! (&optional -cvs-mode!-fun)
248 "Switch to the *cvs* buffer.
249 If -CVS-MODE!-FUN is provided, it is executed *cvs* being the current buffer
250 and with its window selected. Else, the *cvs* buffer is simply selected.
251 -CVS-MODE!-FUN is called interactively if applicable and else with no argument."
252 (let* ((-cvs-mode!-buf (current-buffer))
253 (cvsbuf (cond ((cvs-buffer-p) (current-buffer))
254 ((and cvs-buffer (cvs-buffer-p cvs-buffer)) cvs-buffer)
255 (t (error "can't find the *cvs* buffer"))))
256 (-cvs-mode!-wrapper cvs-minor-wrap-function)
257 (-cvs-mode!-cont (lambda ()
258 (save-current-buffer
259 (if (commandp -cvs-mode!-fun)
260 (call-interactively -cvs-mode!-fun)
261 (funcall -cvs-mode!-fun))))))
262 (if (not -cvs-mode!-fun) (set-buffer cvsbuf)
263 (let ((cvs-mode!-buf (current-buffer))
264 (cvs-mode!-owin (selected-window))
265 (cvs-mode!-nwin (get-buffer-window cvsbuf 'visible)))
266 (unwind-protect
267 (progn
268 (set-buffer cvsbuf)
269 (when cvs-mode!-nwin (select-window cvs-mode!-nwin))
270 (if -cvs-mode!-wrapper
271 (funcall -cvs-mode!-wrapper -cvs-mode!-buf -cvs-mode!-cont)
272 (funcall -cvs-mode!-cont)))
273 (set-buffer cvs-mode!-buf)
274 (when (and cvs-mode!-nwin (eq cvs-mode!-nwin (selected-window)))
275 ;; the selected window has not been changed by FUN
276 (select-window cvs-mode!-owin)))))))
278 ;;;;
279 ;;;; Prefixes
280 ;;;;
282 (defvar cvs-branches (list cvs-vendor-branch "HEAD" "HEAD"))
283 (cvs-prefix-define cvs-branch-prefix
284 "Current selected branch."
285 "version"
286 (cons cvs-vendor-branch cvs-branches)
287 cvs-qtypedesc-tag)
289 (defun cvs-set-branch-prefix (arg)
290 "Set the branch prefix to take action at the next command.
291 See `cvs-prefix-set' for a further the description of the behavior.
292 \\[universal-argument] 1 selects the vendor branch
293 and \\[universal-argument] 2 selects the HEAD."
294 (interactive "P")
295 (cvs-mode!)
296 (cvs-prefix-set 'cvs-branch-prefix arg))
298 (defun cvs-add-branch-prefix (flags &optional arg)
299 "Add branch selection argument if the branch prefix was set.
300 The argument is added (or not) to the list of FLAGS and is constructed
301 by appending the branch to ARG which defaults to \"-r\"."
302 (let ((branch (cvs-prefix-get 'cvs-branch-prefix)))
303 ;; deactivate the secondary prefix, even if not used.
304 (cvs-prefix-get 'cvs-secondary-branch-prefix)
305 (if branch (cons (concat (or arg "-r") branch) flags) flags)))
307 (cvs-prefix-define cvs-secondary-branch-prefix
308 "Current secondary selected branch."
309 "version"
310 (cons cvs-vendor-branch cvs-branches)
311 cvs-qtypedesc-tag)
313 (defun cvs-set-secondary-branch-prefix (arg)
314 "Set the branch prefix to take action at the next command.
315 See `cvs-prefix-set' for a further the description of the behavior.
316 \\[universal-argument] 1 selects the vendor branch
317 and \\[universal-argument] 2 selects the HEAD."
318 (interactive "P")
319 (cvs-mode!)
320 (cvs-prefix-set 'cvs-secondary-branch-prefix arg))
322 (defun cvs-add-secondary-branch-prefix (flags &optional arg)
323 "Add branch selection argument if the secondary branch prefix was set.
324 The argument is added (or not) to the list of FLAGS and is constructed
325 by appending the branch to ARG which defaults to \"-r\".
326 Since the `cvs-secondary-branch-prefix' is only active if the primary
327 prefix is active, it is important to read the secondary prefix before
328 the primay since reading the primary can deactivate it."
329 (let ((branch (and (cvs-prefix-get 'cvs-branch-prefix 'read-only)
330 (cvs-prefix-get 'cvs-secondary-branch-prefix))))
331 (if branch (cons (concat (or arg "-r") branch) flags) flags)))
333 ;;;;
335 (define-minor-mode cvs-minor-mode
336 "This mode is used for buffers related to a main *cvs* buffer.
337 All the `cvs-mode' buffer operations are simply rebound under
338 the \\[cvs-mode-map] prefix."
339 nil " CVS"
340 :group 'pcl-cvs)
341 (put 'cvs-minor-mode 'permanent-local t)
344 (defvar cvs-temp-buffers nil)
345 (defun cvs-temp-buffer (&optional cmd normal nosetup)
346 "Create a temporary buffer to run CMD in.
347 If CMD is a string, use it to lookup `cvs-buffer-name-alist' to find
348 the buffer name to be used and its `major-mode'.
350 The selected window will not be changed. The new buffer will not maintain undo
351 information and will be read-only unless NORMAL is non-nil. It will be emptied
352 \(unless NOSETUP is non-nil\) and its `default-directory' will be inherited
353 from the current buffer."
354 (let* ((cvs-buf (current-buffer))
355 (info (cdr (assoc cmd cvs-buffer-name-alist)))
356 (name (eval (nth 0 info)))
357 (mode (nth 1 info))
358 (dir default-directory)
359 (buf (cond
360 (name (cvs-get-buffer-create name))
361 ((and (bufferp cvs-temp-buffer) (buffer-name cvs-temp-buffer))
362 cvs-temp-buffer)
364 (set (make-local-variable 'cvs-temp-buffer)
365 (cvs-get-buffer-create
366 (eval cvs-temp-buffer-name) 'noreuse))))))
368 ;; handle the potential pre-existing process
369 (let ((proc (get-buffer-process buf)))
370 (when (and (not normal) (processp proc)
371 (memq (process-status proc) '(run stop)))
372 (error "Can not run two cvs processes simultaneously")))
374 (if (not name) (kill-local-variable 'other-window-scroll-buffer)
375 ;; Strangely, if no window is created, `display-buffer' ends up
376 ;; doing a `switch-to-buffer' which does a `set-buffer', hence
377 ;; the need for `save-excursion'.
378 (unless nosetup (save-excursion (display-buffer buf)))
379 ;; FIXME: this doesn't do the right thing if the user later on
380 ;; does a `find-file-other-window' and `scroll-other-window'
381 (set (make-local-variable 'other-window-scroll-buffer) buf))
383 (add-to-list 'cvs-temp-buffers buf)
385 (with-current-buffer buf
386 (setq buffer-read-only nil)
387 (setq default-directory dir)
388 (unless nosetup (erase-buffer))
389 (set (make-local-variable 'cvs-buffer) cvs-buf)
390 ;;(cvs-minor-mode 1)
391 (let ((lbd list-buffers-directory))
392 (if (fboundp mode) (funcall mode) (fundamental-mode))
393 (when lbd (set (make-local-variable 'list-buffers-directory) lbd)))
394 (cvs-minor-mode 1)
395 ;;(set (make-local-variable 'cvs-buffer) cvs-buf)
396 (unless normal
397 (setq buffer-read-only t)
398 (buffer-disable-undo))
399 buf)))
401 (defun cvs-mode-kill-buffers ()
402 "Kill all the \"temporary\" buffers created by the *cvs* buffer."
403 (interactive)
404 (dolist (buf cvs-temp-buffers) (ignore-errors (kill-buffer buf))))
406 (defun cvs-make-cvs-buffer (dir &optional new)
407 "Create the *cvs* buffer for directory DIR.
408 If non-nil, NEW means to create a new buffer no matter what."
409 ;; the real cvs-buffer creation
410 (setq dir (cvs-expand-dir-name dir))
411 (let* ((buffer-name (eval cvs-buffer-name))
412 (buffer
413 (or (and (not new)
414 (eq cvs-reuse-cvs-buffer 'current)
415 (cvs-buffer-p) ;reuse the current buffer if possible
416 (current-buffer))
417 ;; look for another cvs buffer visiting the same directory
418 (save-excursion
419 (unless new
420 (dolist (buffer (cons (current-buffer) (buffer-list)))
421 (set-buffer buffer)
422 (and (cvs-buffer-p)
423 (case cvs-reuse-cvs-buffer
424 (always t)
425 (subdir
426 (or (cvs-string-prefix-p default-directory dir)
427 (cvs-string-prefix-p dir default-directory)))
428 (samedir (string= default-directory dir)))
429 (return buffer)))))
430 ;; we really have to create a new buffer:
431 ;; we temporarily bind cwd to "" to prevent
432 ;; create-file-buffer from using directory info
433 ;; unless it is explicitly in the cvs-buffer-name.
434 (cvs-get-buffer-create buffer-name new))))
435 (with-current-buffer buffer
437 (and (string= dir default-directory) (cvs-buffer-p)
438 ;; just a refresh
439 (ignore-errors
440 (cvs-cleanup-collection cvs-cookies nil nil t)
441 (current-buffer)))
442 ;; setup from scratch
443 (progn
444 (setq default-directory dir)
445 (setq buffer-read-only nil)
446 (erase-buffer)
447 (insert "\
448 Repository : " (directory-file-name (cvs-get-cvsroot)) "
449 Module : " (cvs-get-module) "
450 Working dir: " (abbreviate-file-name dir) "
453 (setq buffer-read-only t)
454 (cvs-mode)
455 (set (make-local-variable 'list-buffers-directory) buffer-name)
456 ;;(set (make-local-variable 'cvs-temp-buffer) (cvs-temp-buffer))
457 (let ((cookies (ewoc-create 'cvs-fileinfo-pp "\n" "")))
458 (set (make-local-variable 'cvs-cookies) cookies)
459 (add-hook 'kill-buffer-hook
460 (lambda ()
461 (ignore-errors (kill-buffer cvs-temp-buffer)))
462 nil t)
463 ;;(set-buffer buf)
464 buffer))))))
466 (defun* cvs-cmd-do (cmd dir flags fis new
467 &key cvsargs noexist dont-change-disc noshow)
468 (let* ((dir (file-name-as-directory
469 (abbreviate-file-name (expand-file-name dir))))
470 (cvsbuf (cvs-make-cvs-buffer dir new)))
471 ;; Check that dir is under CVS control.
472 (unless (file-directory-p dir)
473 (error "%s is not a directory" dir))
474 (unless (or noexist (file-directory-p (expand-file-name "CVS" dir))
475 (file-expand-wildcards (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 ;; If process-connection-type is nil and the repository
540 ;; is accessed via SSH, a bad interaction between libc,
541 ;; CVS and SSH can lead to garbled output.
542 ;; It might be a glibc-specific problem (but it also happens
543 ;; under Mac OS X, it seems).
544 ;; Until the problem is cleared, we'll use a pty rather than
545 ;; a pipe.
546 ;; (process-connection-type nil) ; Use a pipe, not a pty.
547 (process
548 ;; the process will be run in the selected dir
549 (let ((default-directory (cvs-expand-dir-name dir)))
550 (apply 'start-process "cvs" procbuf cvs-program args))))
551 (set-process-sentinel process 'cvs-sentinel)
552 (set-process-filter process 'cvs-update-filter)
553 (set-marker (process-mark process) (point-max))
554 (ignore-errors (process-send-eof process)) ;close its stdin to avoid hangs
556 ;; now finish setting up the cvs-buffer
557 (set-buffer cvsbuf)
558 (setq cvs-mode-line-process (symbol-name (process-status process)))
559 (force-mode-line-update)))))
561 ;; The following line is said to improve display updates on some
562 ;; emacsen. It shouldn't be needed, but it does no harm.
563 (sit-for 0))
565 (defun cvs-update-header (args fis) ; inline
566 (let* ((lastarg nil)
567 (args (mapcar (lambda (arg)
568 (cond
569 ;; filter out the largish commit message
570 ((and (eq lastarg nil) (string= arg "commit"))
571 (setq lastarg 'commit) arg)
572 ((and (eq lastarg 'commit) (string= arg "-m"))
573 (setq lastarg '-m) arg)
574 ((eq lastarg '-m)
575 (setq lastarg 'done) "<log message>")
576 ;; filter out the largish `admin -mrev:msg' message
577 ((and (eq lastarg nil) (string= arg "admin"))
578 (setq lastarg 'admin) arg)
579 ((and (eq lastarg 'admin)
580 (string-match "\\`-m[^:]*:" arg))
581 (setq lastarg 'done)
582 (concat (match-string 0 arg) "<log message>"))
583 ;; Keep the rest as is.
584 (t arg)))
585 args))
586 ;; turn them into a string
587 (arg (cvs-strings->string
588 (append (cvs-flags-query 'cvs-cvs-flags nil 'noquery)
589 (if cvs-cvsroot (list "-d" cvs-cvsroot))
590 args
591 (mapcar 'cvs-fileinfo->full-path fis))))
592 (str (if args (concat "-- Running " cvs-program " " arg " ...\n")
593 "\n")))
594 (if nil (insert str) ;inline
595 ;;(with-current-buffer cvs-buffer
596 (let* ((prev-msg (car (ewoc-get-hf cvs-cookies)))
597 (tin (ewoc-nth cvs-cookies 0)))
598 ;; look for the first *real* fileinfo (to determine emptyness)
599 (while
600 (and tin
601 (memq (cvs-fileinfo->type (ewoc-data tin))
602 '(MESSAGE DIRCHANGE)))
603 (setq tin (ewoc-next cvs-cookies tin)))
604 ;; cleanup the prev-msg
605 (when (string-match "Running \\(.*\\) ...\n" prev-msg)
606 (setq prev-msg
607 (concat
608 "-- last cmd: "
609 (match-string 1 prev-msg)
610 " --")))
611 ;; set the new header and footer
612 (ewoc-set-hf cvs-cookies
613 str (concat "\n--------------------- "
614 (if tin "End" "Empty")
615 " ---------------------\n"
616 prev-msg))))))
619 (defun cvs-sentinel (proc msg)
620 "Sentinel for the cvs update process.
621 This is responsible for parsing the output from the cvs update when
622 it is finished."
623 (when (memq (process-status proc) '(signal exit))
624 (if (null (buffer-name (process-buffer proc)))
625 ;;(set-process-buffer proc nil)
626 (error "cvs' process buffer was killed")
627 (let* ((obuf (current-buffer))
628 (procbuffer (process-buffer proc)))
629 (set-buffer (with-current-buffer procbuffer cvs-buffer))
630 (setq cvs-mode-line-process (symbol-name (process-status proc)))
631 (force-mode-line-update)
632 (set-buffer procbuffer)
633 (let ((cvs-postproc cvs-postprocess))
634 ;; Since the buffer and mode line will show that the
635 ;; process is dead, we can delete it now. Otherwise it
636 ;; will stay around until M-x list-processes.
637 (delete-process proc)
638 (setq cvs-postprocess nil)
639 ;; do the postprocessing like parsing and such
640 (save-excursion (eval cvs-postproc))
641 ;; check whether something is left
642 (unless cvs-postprocess
643 ;; IIRC, we enable undo again once the process is finished
644 ;; for cases where the output was inserted in *vc-diff* or
645 ;; in a file-like buffer. -stef
646 (buffer-enable-undo)
647 (with-current-buffer cvs-buffer
648 (cvs-update-header nil nil) ;FIXME: might need to be inline
649 (message "CVS process has completed in %s" (buffer-name)))))
650 ;; This might not even be necessary
651 (set-buffer obuf)))))
653 (defun cvs-parse-process (dcd &optional subdir old-fis)
654 "Parse the output of a cvs process.
655 DCD is the `dont-change-disc' flag to use when parsing that output.
656 SUBDIR is the subdirectory (if any) where this command was run.
657 OLD-FIS is the list of fileinfos on which the cvs command was applied and
658 which should be considered up-to-date if they are missing from the output."
659 (let* ((fileinfos (cvs-parse-buffer 'cvs-parse-table dcd subdir))
660 last)
661 (with-current-buffer cvs-buffer
662 ;; Expand OLD-FIS to actual files.
663 (let ((fis nil))
664 (dolist (fi old-fis)
665 (setq fis (if (eq (cvs-fileinfo->type fi) 'DIRCHANGE)
666 (nconc (ewoc-collect cvs-cookies 'cvs-dir-member-p
667 (cvs-fileinfo->dir fi))
668 fis)
669 (cons fi fis))))
670 (setq old-fis fis))
671 ;; Drop OLD-FIS which were already up-to-date.
672 (let ((fis nil))
673 (dolist (fi old-fis)
674 (unless (eq (cvs-fileinfo->type fi) 'UP-TO-DATE) (push fi fis)))
675 (setq old-fis fis))
676 ;; Add the new fileinfos to the ewoc.
677 (dolist (fi fileinfos)
678 (setq last (cvs-addto-collection cvs-cookies fi last))
679 ;; This FI was in the output, so remove it from OLD-FIS.
680 (setq old-fis (delq (ewoc-data last) old-fis)))
681 ;; Process the "silent output" (i.e. absence means up-to-date).
682 (dolist (fi old-fis)
683 (setf (cvs-fileinfo->type fi) 'UP-TO-DATE)
684 (setq last (cvs-addto-collection cvs-cookies fi last)))
685 (setq fileinfos (nconc old-fis fileinfos))
686 ;; Clean up the ewoc as requested by the user.
687 (cvs-cleanup-collection cvs-cookies
688 (eq cvs-auto-remove-handled t)
689 cvs-auto-remove-directories
690 nil)
691 ;; Revert buffers if necessary.
692 (when (and cvs-auto-revert (not dcd) (not cvs-from-vc))
693 (cvs-revert-if-needed fileinfos)))))
695 (defmacro defun-cvs-mode (fun args docstring interact &rest body)
696 "Define a function to be used in a *cvs* buffer.
697 This will look for a *cvs* buffer and execute BODY in it.
698 Since the interactive arguments might need to be queried after
699 switching to the *cvs* buffer, the generic code is rather ugly,
700 but luckily we can often use simpler alternatives.
702 FUN can be either a symbol (i.e. STYLE is nil) or a cons (FUN . STYLE).
703 ARGS and DOCSTRING are the normal argument list.
704 INTERACT is the interactive specification or nil for non-commands.
706 STYLE can be either SIMPLE, NOARGS or DOUBLE. It's an error for it
707 to have any other value, unless other details of the function make it
708 clear what alternative to use.
709 - SIMPLE will get all the interactive arguments from the original buffer.
710 - NOARGS will get all the arguments from the *cvs* buffer and will
711 always behave as if called interactively.
712 - DOUBLE is the generic case."
713 (declare (debug (&define sexp lambda-list stringp ("interactive" interactive) def-body)))
714 (let ((style (cvs-cdr fun))
715 (fun (cvs-car fun)))
716 (cond
717 ;; a trivial interaction, no need to move it
718 ((or (eq style 'SIMPLE)
719 (null (nth 1 interact))
720 (stringp (nth 1 interact)))
721 `(defun ,fun ,args ,docstring ,interact
722 (cvs-mode! (lambda () ,@body))))
724 ;; fun is only called interactively: move all the args to the inner fun
725 ((eq style 'NOARGS)
726 `(defun ,fun () ,docstring (interactive)
727 (cvs-mode! (lambda ,args ,interact ,@body))))
729 ;; bad case
730 ((eq style 'DOUBLE)
731 (string-match ".*" docstring)
732 (let ((line1 (match-string 0 docstring))
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 (when find-file-visit-truename (setq directory (file-truename directory)))
968 (cvs-cmd-do "update" directory flags nil
969 (> (prefix-numeric-value current-prefix-arg) 8)
970 :cvsargs '("-n")
971 :noshow noshow
972 :dont-change-disc t))
975 ;;;###autoload
976 (defun cvs-update (directory flags)
977 "Run a `cvs update' in the current working DIRECTORY.
978 Feed the output to a *cvs* buffer and run `cvs-mode' on it.
979 With a \\[universal-argument] prefix argument, prompt for a directory to use.
980 A prefix arg >8 (ex: \\[universal-argument] \\[universal-argument]),
981 prevents reuse of an existing *cvs* buffer.
982 The prefix is also passed to `cvs-flags-query' to select the FLAGS
983 passed to cvs."
984 (interactive (list (cvs-query-directory "CVS Update (directory): ")
985 (cvs-flags-query 'cvs-update-flags "cvs update flags")))
986 (when (eq flags t)
987 (setf flags (cvs-flags-query 'cvs-update-flags nil 'noquery)))
988 (cvs-cmd-do "update" directory flags nil
989 (> (prefix-numeric-value current-prefix-arg) 8)))
992 ;;;###autoload
993 (defun cvs-status (directory flags &optional noshow)
994 "Run a `cvs status' in the current working DIRECTORY.
995 Feed the output to a *cvs* buffer and run `cvs-mode' on it.
996 With a prefix argument, prompt for a directory and cvs FLAGS to use.
997 A prefix arg >8 (ex: \\[universal-argument] \\[universal-argument]),
998 prevents reuse of an existing *cvs* buffer.
999 Optional argument NOSHOW if non-nil means not to display the buffer."
1000 (interactive (list (cvs-query-directory "CVS Status (directory): ")
1001 (cvs-flags-query 'cvs-status-flags "cvs status flags")))
1002 (when (eq flags t)
1003 (setf flags (cvs-flags-query 'cvs-status-flags nil 'noquery)))
1004 (cvs-cmd-do "status" directory flags nil
1005 (> (prefix-numeric-value current-prefix-arg) 8)
1006 :noshow noshow :dont-change-disc t))
1008 (defun cvs-update-filter (proc string)
1009 "Filter function for pcl-cvs.
1010 This function gets the output that CVS sends to stdout. It inserts
1011 the STRING into (process-buffer PROC) but it also checks if CVS is waiting
1012 for a lock file. If so, it inserts a message cookie in the *cvs* buffer."
1013 (save-match-data
1014 (with-current-buffer (process-buffer proc)
1015 (let ((inhibit-read-only t))
1016 (save-excursion
1017 ;; Insert the text, moving the process-marker.
1018 (goto-char (process-mark proc))
1019 (insert string)
1020 (set-marker (process-mark proc) (point))
1021 ;; FIXME: Delete any old lock message
1022 ;;(if (tin-nth cookies 1)
1023 ;; (tin-delete cookies
1024 ;; (tin-nth cookies 1)))
1025 ;; Check if CVS is waiting for a lock.
1026 (beginning-of-line 0) ;Move to beginning of last complete line.
1027 (when (looking-at "^[ a-z]+: \\(.*waiting for .*lock in \\(.*\\)\\)$")
1028 (let ((msg (match-string 1))
1029 (lock (match-string 2)))
1030 (with-current-buffer cvs-buffer
1031 (set (make-local-variable 'cvs-lock-file) lock)
1032 ;; display the lock situation in the *cvs* buffer:
1033 (ewoc-enter-last
1034 cvs-cookies
1035 (cvs-create-fileinfo
1036 'MESSAGE "" " "
1037 (concat msg
1038 (when (file-exists-p lock)
1039 (substitute-command-keys
1040 "\n\t(type \\[cvs-mode-delete-lock] to delete it)")))
1041 :subtype 'TEMP))
1042 (pop-to-buffer (current-buffer))
1043 (goto-char (point-max))
1044 (beep)))))))))
1047 ;;;;
1048 ;;;; The cvs-mode and its associated commands.
1049 ;;;;
1051 (cvs-prefix-define cvs-force-command "" "" '("/F") cvs-qtypedesc-string1)
1052 (defun-cvs-mode cvs-mode-force-command (arg)
1053 "Force the next cvs command to operate on all the selected files.
1054 By default, cvs commands only operate on files on which the command
1055 \"makes sense\". This overrides the safety feature on the next cvs command.
1056 It actually behaves as a toggle. If prefixed by \\[universal-argument] \\[universal-argument],
1057 the override will persist until the next toggle."
1058 (interactive "P")
1059 (cvs-prefix-set 'cvs-force-command arg))
1061 (put 'cvs-mode 'mode-class 'special)
1062 (define-derived-mode cvs-mode fundamental-mode "CVS"
1063 "Mode used for PCL-CVS, a frontend to CVS.
1064 Full documentation is in the Texinfo file."
1065 (setq mode-line-process
1066 '("" cvs-force-command cvs-ignore-marks-modif
1067 ":" (cvs-branch-prefix
1068 ("" cvs-branch-prefix (cvs-secondary-branch-prefix
1069 ("->" cvs-secondary-branch-prefix))))
1070 " " cvs-mode-line-process))
1071 (buffer-disable-undo)
1072 ;;(set (make-local-variable 'goal-column) cvs-cursor-column)
1073 (set (make-local-variable 'revert-buffer-function) 'cvs-mode-revert-buffer)
1074 (setq truncate-lines t)
1075 (cvs-prefix-make-local 'cvs-branch-prefix)
1076 (cvs-prefix-make-local 'cvs-secondary-branch-prefix)
1077 (cvs-prefix-make-local 'cvs-force-command)
1078 (cvs-prefix-make-local 'cvs-ignore-marks-modif)
1079 (make-local-variable 'cvs-mode-line-process)
1080 (make-local-variable 'cvs-temp-buffers))
1083 (defun cvs-buffer-p (&optional buffer)
1084 "Return whether the (by default current) BUFFER is a `cvs-mode' buffer."
1085 (save-excursion
1086 (if buffer (set-buffer buffer))
1087 (and (eq major-mode 'cvs-mode))))
1089 (defun cvs-buffer-check ()
1090 "Check that the current buffer follows cvs-buffer's conventions."
1091 (let ((buf (current-buffer))
1092 (check 'none))
1093 (or (and (setq check 'collection)
1094 (eq (ewoc-buffer cvs-cookies) buf)
1095 (setq check 'cvs-temp-buffer)
1096 (or (null cvs-temp-buffer)
1097 (null (buffer-name cvs-temp-buffer))
1098 (and (eq (with-current-buffer cvs-temp-buffer cvs-buffer) buf)
1099 (equal (with-current-buffer cvs-temp-buffer
1100 default-directory)
1101 default-directory)))
1103 (error "Inconsistent %s in buffer %s" check (buffer-name buf)))))
1106 (defun cvs-mode-quit ()
1107 "Quit PCL-CVS, killing the *cvs* buffer."
1108 (interactive)
1109 (and (y-or-n-p "Quit pcl-cvs? ") (kill-buffer (current-buffer))))
1111 ;; Give help....
1113 (defun cvs-help ()
1114 "Display help for various PCL-CVS commands."
1115 (interactive)
1116 (if (eq last-command 'cvs-help)
1117 (describe-function 'cvs-mode) ; would need minor-mode for log-edit-mode
1118 (message
1119 (substitute-command-keys
1120 "`\\[cvs-help]':help `\\[cvs-mode-add]':add `\\[cvs-mode-commit]':commit \
1121 `\\[cvs-mode-diff-map]':diff* `\\[cvs-mode-log]':log \
1122 `\\[cvs-mode-remove]':remove `\\[cvs-mode-status]':status \
1123 `\\[cvs-mode-undo]':undo"))))
1125 ;; Move around in the buffer
1127 (defun cvs-move-to-goal-column ()
1128 (let* ((eol (line-end-position))
1129 (fpos (next-single-property-change (point) 'cvs-goal-column nil eol)))
1130 (when (< fpos eol)
1131 (goto-char fpos))))
1133 (defun-cvs-mode cvs-mode-previous-line (arg)
1134 "Go to the previous line.
1135 If a prefix argument is given, move by that many lines."
1136 (interactive "p")
1137 (ewoc-goto-prev cvs-cookies arg)
1138 (cvs-move-to-goal-column))
1140 (defun-cvs-mode cvs-mode-next-line (arg)
1141 "Go to the next line.
1142 If a prefix argument is given, move by that many lines."
1143 (interactive "p")
1144 (ewoc-goto-next cvs-cookies arg)
1145 (cvs-move-to-goal-column))
1147 ;;;;
1148 ;;;; Mark handling
1149 ;;;;
1151 (defun-cvs-mode cvs-mode-mark (&optional arg)
1152 "Mark the fileinfo on the current line.
1153 If the fileinfo is a directory, all the contents of that directory are
1154 marked instead. A directory can never be marked."
1155 (interactive)
1156 (let* ((tin (ewoc-locate cvs-cookies))
1157 (fi (ewoc-data tin)))
1158 (if (eq (cvs-fileinfo->type fi) 'DIRCHANGE)
1159 ;; it's a directory: let's mark all files inside
1160 (ewoc-map
1161 (lambda (f dir)
1162 (when (cvs-dir-member-p f dir)
1163 (setf (cvs-fileinfo->marked f)
1164 (not (if (eq arg 'toggle) (cvs-fileinfo->marked f) arg)))
1165 t)) ;Tell cookie to redisplay this cookie.
1166 cvs-cookies
1167 (cvs-fileinfo->dir fi))
1168 ;; not a directory: just do the obvious
1169 (setf (cvs-fileinfo->marked fi)
1170 (not (if (eq arg 'toggle) (cvs-fileinfo->marked fi) arg)))
1171 (ewoc-invalidate cvs-cookies tin)
1172 (cvs-mode-next-line 1))))
1174 (defun cvs-mouse-toggle-mark (e)
1175 "Toggle the mark of the entry under the mouse."
1176 (interactive "e")
1177 (save-excursion
1178 (mouse-set-point e)
1179 (cvs-mode-mark 'toggle)))
1181 (defun-cvs-mode cvs-mode-unmark ()
1182 "Unmark the fileinfo on the current line."
1183 (interactive)
1184 (cvs-mode-mark t))
1186 (defun-cvs-mode cvs-mode-mark-all-files ()
1187 "Mark all files."
1188 (interactive)
1189 (ewoc-map (lambda (cookie)
1190 (unless (eq (cvs-fileinfo->type cookie) 'DIRCHANGE)
1191 (setf (cvs-fileinfo->marked cookie) t)))
1192 cvs-cookies))
1194 (defun-cvs-mode (cvs-mode-mark-on-state . SIMPLE) (state)
1195 "Mark all files in state STATE."
1196 (interactive
1197 (list
1198 (let ((default
1199 (condition-case nil
1200 (downcase
1201 (symbol-name
1202 (cvs-fileinfo->type
1203 (cvs-mode-marked nil nil :read-only t :one t :noquery t))))
1204 (error nil))))
1205 (intern
1206 (upcase
1207 (completing-read
1208 (concat
1209 "Mark files in state" (if default (concat " [" default "]")) ": ")
1210 (mapcar (lambda (x)
1211 (list (downcase (symbol-name (car x)))))
1212 cvs-states)
1213 nil t nil nil default))))))
1214 (ewoc-map (lambda (fi)
1215 (when (eq (cvs-fileinfo->type fi) state)
1216 (setf (cvs-fileinfo->marked fi) t)))
1217 cvs-cookies))
1219 (defun-cvs-mode cvs-mode-mark-matching-files (regex)
1220 "Mark all files matching REGEX."
1221 (interactive "sMark files matching: ")
1222 (ewoc-map (lambda (cookie)
1223 (when (and (not (eq (cvs-fileinfo->type cookie) 'DIRCHANGE))
1224 (string-match regex (cvs-fileinfo->file cookie)))
1225 (setf (cvs-fileinfo->marked cookie) t)))
1226 cvs-cookies))
1228 (defun-cvs-mode cvs-mode-unmark-all-files ()
1229 "Unmark all files.
1230 Directories are also unmarked, but that doesn't matter, since
1231 they should always be unmarked."
1232 (interactive)
1233 (ewoc-map (lambda (cookie)
1234 (setf (cvs-fileinfo->marked cookie) nil)
1236 cvs-cookies))
1238 (defun-cvs-mode cvs-mode-unmark-up ()
1239 "Unmark the file on the previous line."
1240 (interactive)
1241 (let ((tin (ewoc-goto-prev cvs-cookies 1)))
1242 (when tin
1243 (setf (cvs-fileinfo->marked (ewoc-data tin)) nil)
1244 (ewoc-invalidate cvs-cookies tin))))
1246 (defconst cvs-ignore-marks-alternatives
1247 '(("toggle-marks" . "/TM")
1248 ("force-marks" . "/FM")
1249 ("ignore-marks" . "/IM")))
1251 (cvs-prefix-define cvs-ignore-marks-modif
1252 "Prefix to decide whether to ignore marks or not."
1253 "active"
1254 (mapcar 'cdr cvs-ignore-marks-alternatives)
1255 (cvs-qtypedesc-create
1256 (lambda (str) (cdr (assoc str cvs-ignore-marks-alternatives)))
1257 (lambda (obj) (car (rassoc obj cvs-ignore-marks-alternatives)))
1258 (lambda () cvs-ignore-marks-alternatives)
1259 nil t))
1261 (defun-cvs-mode cvs-mode-toggle-marks (arg)
1262 "Toggle whether the next CVS command uses marks.
1263 See `cvs-prefix-set' for further description of the behavior.
1264 \\[universal-argument] 1 selects `force-marks',
1265 \\[universal-argument] 2 selects `ignore-marks',
1266 \\[universal-argument] 3 selects `toggle-marks'."
1267 (interactive "P")
1268 (cvs-prefix-set 'cvs-ignore-marks-modif arg))
1270 (defun cvs-ignore-marks-p (cmd &optional read-only)
1271 (let ((default (if (member cmd cvs-invert-ignore-marks)
1272 (not cvs-default-ignore-marks)
1273 cvs-default-ignore-marks))
1274 (modif (cvs-prefix-get 'cvs-ignore-marks-modif read-only)))
1275 (cond
1276 ((equal modif "/IM") t)
1277 ((equal modif "/TM") (not default))
1278 ((equal modif "/FM") nil)
1279 (t default))))
1281 (defun cvs-mode-mark-get-modif (cmd)
1282 (if (cvs-ignore-marks-p cmd 'read-only) "/IM" "/FM"))
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 (defvar cvs-edit-log-revision)
1428 (defun cvs-mode-edit-log (rev &optional text)
1429 "Edit the log message at point.
1430 This is best called from a `log-view-mode' buffer."
1431 (interactive
1432 (list
1433 (or (cvs-mode! (lambda () (cvs-prefix-get 'cvs-branch-prefix)))
1434 (read-string "Revision to edit: "))
1435 (cvs-edit-log-text-at-point)))
1436 ;; It seems that the save-excursion that happens if I use the better
1437 ;; form of `(cvs-mode! (lambda ...))' screws up a couple things which
1438 ;; end up being rather annoying (like log-edit-mode's message being
1439 ;; displayed in the wrong minibuffer).
1440 (cvs-mode!)
1441 (let ((buf (cvs-temp-buffer "message" 'normal 'nosetup))
1442 (lbd list-buffers-directory)
1443 (setupfun (or (nth 2 (cdr (assoc "message" cvs-buffer-name-alist)))
1444 'log-edit)))
1445 (funcall setupfun 'cvs-do-edit-log nil 'cvs-edit-log-filelist buf)
1446 (when text (erase-buffer) (insert text))
1447 (set (make-local-variable 'cvs-edit-log-revision) rev)
1448 (set (make-local-variable 'cvs-minor-wrap-function) 'cvs-edit-log-minor-wrap)
1449 (set (make-local-variable 'list-buffers-directory) lbd)
1450 ;; (run-hooks 'cvs-mode-commit-hook)
1453 (defun cvs-edit-log-minor-wrap (buf f)
1454 (let ((cvs-ignore-marks-modif (cvs-mode-mark-get-modif "commit")))
1455 (funcall f)))
1457 (defun cvs-edit-log-filelist ()
1458 (cvs-mode-files nil nil :read-only t :file t :noquery t))
1460 (defun cvs-do-edit-log (rev)
1461 "Do the actual commit, using the current buffer as the log message."
1462 (interactive (list cvs-edit-log-revision))
1463 (let ((msg (buffer-substring-no-properties (point-min) (point-max))))
1464 (cvs-mode!)
1465 (cvs-mode-do "admin" (list (concat "-m" rev ":" msg)) nil)))
1468 ;;;;
1469 ;;;; CVS Mode commands
1470 ;;;;
1472 (defun-cvs-mode (cvs-mode-insert . NOARGS) (file)
1473 "Insert an entry for a specific file into the current listing.
1474 This is typically used if the file is up-to-date (or has been added
1475 outside of PCL-CVS) and one wants to do some operation on it."
1476 (interactive
1477 (list (read-file-name
1478 "File to insert: "
1479 ;; Can't use ignore-errors here because interactive
1480 ;; specs aren't byte-compiled.
1481 (condition-case nil
1482 (file-name-as-directory
1483 (expand-file-name
1484 (cvs-fileinfo->dir
1485 (cvs-mode-marked nil nil :read-only t :one t :noquery t))))
1486 (error nil)))))
1487 (cvs-insert-file file))
1489 (defun cvs-insert-file (file)
1490 "Insert FILE (and its contents if it's a dir) and return its FI."
1491 (let ((file (file-relative-name (directory-file-name file))) last)
1492 (dolist (fi (cvs-fileinfo-from-entries file))
1493 (setq last (cvs-addto-collection cvs-cookies fi last)))
1494 ;; There should have been at least one entry.
1495 (goto-char (ewoc-location last))
1496 (ewoc-data last)))
1498 (defun cvs-mark-fis-dead (fis)
1499 ;; Helper function, introduced because of the need for macro-expansion.
1500 (dolist (fi fis)
1501 (setf (cvs-fileinfo->type fi) 'DEAD)))
1503 (defun-cvs-mode (cvs-mode-add . SIMPLE) (flags)
1504 "Add marked files to the cvs repository.
1505 With prefix argument, prompt for cvs flags."
1506 (interactive (list (cvs-flags-query 'cvs-add-flags "cvs add flags")))
1507 (let ((fis (cvs-mode-marked 'add))
1508 (needdesc nil) (dirs nil))
1509 ;; find directories and look for fis needing a description
1510 (dolist (fi fis)
1511 (cond
1512 ((file-directory-p (cvs-fileinfo->full-path fi)) (push fi dirs))
1513 ((eq (cvs-fileinfo->type fi) 'UNKNOWN) (setq needdesc t))))
1514 ;; prompt for description if necessary
1515 (let* ((msg (if (and needdesc
1516 (or current-prefix-arg (not cvs-add-default-message)))
1517 (read-from-minibuffer "Enter description: ")
1518 (or cvs-add-default-message "")))
1519 (flags (list* "-m" msg flags))
1520 (postproc
1521 ;; setup postprocessing for the directory entries
1522 (when dirs
1523 `((cvs-run-process (list "-n" "update")
1524 ',dirs
1525 '(cvs-parse-process t))
1526 (cvs-mark-fis-dead ',dirs)))))
1527 (cvs-mode-run "add" flags fis :postproc postproc))))
1529 (defun-cvs-mode (cvs-mode-diff . DOUBLE) (flags)
1530 "Diff the selected files against the repository.
1531 This command compares the files in your working area against the
1532 revision which they are based upon."
1533 (interactive
1534 (list (cvs-add-branch-prefix
1535 (cvs-add-secondary-branch-prefix
1536 (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))))
1537 (cvs-mode-do "diff" flags 'diff
1538 :show t)) ;; :ignore-exit t
1540 (defun-cvs-mode (cvs-mode-diff-head . SIMPLE) (flags)
1541 "Diff the selected files against the head of the current branch.
1542 See ``cvs-mode-diff'' for more info."
1543 (interactive (list (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))
1544 (cvs-mode-diff-1 (cons "-rHEAD" flags)))
1546 (defun-cvs-mode (cvs-mode-diff-vendor . SIMPLE) (flags)
1547 "Diff the selected files against the head of the vendor branch.
1548 See ``cvs-mode-diff'' for more info."
1549 (interactive (list (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))
1550 (cvs-mode-diff-1 (cons (concat "-r" cvs-vendor-branch) flags)))
1552 ;; sadly, this is not provided by cvs, so we have to roll our own
1553 (defun-cvs-mode (cvs-mode-diff-backup . SIMPLE) (flags)
1554 "Diff the files against the backup file.
1555 This command can be used on files that are marked with \"Merged\"
1556 or \"Conflict\" in the *cvs* buffer."
1557 (interactive (list (cvs-flags-query 'cvs-diff-flags "diff flags")))
1558 (unless (listp flags) (error "flags should be a list of strings"))
1559 (save-some-buffers)
1560 (let* ((marked (cvs-get-marked (cvs-ignore-marks-p "diff")))
1561 (fis (car (cvs-partition 'cvs-fileinfo->backup-file marked))))
1562 (unless (consp fis)
1563 (error "No files with a backup file selected!"))
1564 ;; let's extract some info into the environment for `buffer-name'
1565 (let* ((dir (cvs-fileinfo->dir (car fis)))
1566 (file (cvs-fileinfo->file (car fis))))
1567 (set-buffer (cvs-temp-buffer "diff")))
1568 (message "cvs diff backup...")
1569 (cvs-execute-single-file-list fis 'cvs-diff-backup-extractor
1570 cvs-diff-program flags))
1571 (message "cvs diff backup... Done."))
1573 (defun cvs-diff-backup-extractor (fileinfo)
1574 "Return the filename and the name of the backup file as a list.
1575 Signal an error if there is no backup file."
1576 (let ((backup-file (cvs-fileinfo->backup-file fileinfo)))
1577 (unless backup-file
1578 (error "%s has no backup file" (cvs-fileinfo->full-path fileinfo)))
1579 (list backup-file (cvs-fileinfo->full-path fileinfo))))
1582 ;; Emerge support
1584 (defun cvs-emerge-diff (b1 b2) (emerge-buffers b1 b2 b1))
1585 (defun cvs-emerge-merge (b1 b2 base out)
1586 (emerge-buffers-with-ancestor b1 b2 base (find-file-noselect out)))
1589 ;; Ediff support
1592 (defvar ediff-after-quit-destination-buffer)
1593 (defvar ediff-after-quit-hook-internal)
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 (apply 'call-process cvs-program nil '(t . nil) nil
1642 "-q" "update" "-p"
1643 ;; If `rev' is HEAD, don't pass it at all:
1644 ;; the default behavior is to get the head
1645 ;; of the current branch whereas "-r HEAD"
1646 ;; stupidly gives you the head of the trunk.
1647 (append (unless (equal rev "HEAD") (list "-r" rev))
1648 (list file)))))
1649 (when (and res (not (and (equal 0 res))))
1650 (error "Something went wrong retrieving revision %s: %s" rev res))
1651 (set-buffer-modified-p nil)
1652 (let ((buffer-file-name (expand-file-name file)))
1653 (after-find-file))
1654 (toggle-read-only 1)
1655 (message "Retrieving revision %s... Done" rev)
1656 (current-buffer))))))
1658 (eval-and-compile (autoload 'smerge-ediff "smerge-mode"))
1660 ;; FIXME: The user should be able to specify ancestor/head/backup and we should
1661 ;; provide sensible defaults when merge info is unavailable (rather than rely
1662 ;; on smerge-ediff). Also provide sane defaults for need-merge files.
1663 (defun-cvs-mode cvs-mode-imerge ()
1664 "Merge interactively appropriate revisions of the selected file."
1665 (interactive)
1666 (let ((fi (cvs-mode-marked 'merge nil :one t :file t)))
1667 (let ((merge (cvs-fileinfo->merge fi))
1668 (file (cvs-fileinfo->full-path fi))
1669 (backup-file (cvs-fileinfo->backup-file fi)))
1670 (if (not (and merge backup-file))
1671 (let ((buf (find-file-noselect file)))
1672 (message "Missing merge info or backup file, using VC.")
1673 (with-current-buffer buf
1674 (smerge-ediff)))
1675 (let* ((ancestor-buf (cvs-retrieve-revision fi (car merge)))
1676 (head-buf (cvs-retrieve-revision fi (cdr merge)))
1677 (backup-buf (let ((auto-mode-alist nil))
1678 (find-file-noselect backup-file)))
1679 ;; this binding is used by cvs-ediff-startup-hook
1680 (cvs-transient-buffers (list ancestor-buf backup-buf head-buf)))
1681 (with-current-buffer backup-buf
1682 (let ((buffer-file-name (expand-file-name file)))
1683 (after-find-file)))
1684 (funcall (cdr cvs-idiff-imerge-handlers)
1685 backup-buf head-buf ancestor-buf file))))))
1687 (cvs-flags-define cvs-idiff-version
1688 (list "BASE" cvs-vendor-branch cvs-vendor-branch "BASE" "BASE")
1689 "version: " cvs-qtypedesc-tag)
1691 (defun-cvs-mode (cvs-mode-idiff . NOARGS) (&optional rev1 rev2)
1692 "Diff interactively current file to revisions."
1693 (interactive
1694 (let* ((rev1 (cvs-prefix-get 'cvs-branch-prefix))
1695 (rev2 (and rev1 (cvs-prefix-get 'cvs-secondary-branch-prefix))))
1696 (list (or rev1 (cvs-flags-query 'cvs-idiff-version))
1697 rev2)))
1698 (let ((fi (cvs-mode-marked 'diff "idiff" :one t :file t)))
1699 (let* ((file (cvs-fileinfo->full-path fi))
1700 (rev1-buf (cvs-retrieve-revision fi (or rev1 "BASE")))
1701 (rev2-buf (if rev2 (cvs-retrieve-revision fi rev2)))
1702 ;; this binding is used by cvs-ediff-startup-hook
1703 (cvs-transient-buffers (list rev1-buf rev2-buf)))
1704 (funcall (car cvs-idiff-imerge-handlers)
1705 rev1-buf (or rev2-buf (find-file-noselect file))))))
1707 (defun-cvs-mode (cvs-mode-idiff-other . NOARGS) ()
1708 "Diff interactively current file to revisions."
1709 (interactive)
1710 (let* ((rev1 (cvs-prefix-get 'cvs-branch-prefix))
1711 (rev2 (and rev1 (cvs-prefix-get 'cvs-secondary-branch-prefix)))
1712 (fis (cvs-mode-marked 'diff "idiff" :file t)))
1713 (when (> (length fis) 2)
1714 (error "idiff-other cannot be applied to more than 2 files at a time"))
1715 (let* ((fi1 (car fis))
1716 (rev1-buf (if rev1 (cvs-retrieve-revision fi1 rev1)
1717 (find-file-noselect (cvs-fileinfo->full-path fi1))))
1718 rev2-buf)
1719 (if (cdr fis)
1720 (let ((fi2 (nth 1 fis)))
1721 (setq rev2-buf
1722 (if rev2 (cvs-retrieve-revision fi2 rev2)
1723 (find-file-noselect (cvs-fileinfo->full-path fi2)))))
1724 (error "idiff-other doesn't know what other file/buffer to use"))
1725 (let* (;; this binding is used by cvs-ediff-startup-hook
1726 (cvs-transient-buffers (list rev1-buf rev2-buf)))
1727 (funcall (car cvs-idiff-imerge-handlers)
1728 rev1-buf rev2-buf)))))
1731 (defun cvs-is-within-p (fis dir)
1732 "Non-nil is buffer is inside one of FIS (in DIR)."
1733 (when (stringp buffer-file-name)
1734 (setq buffer-file-name (expand-file-name buffer-file-name))
1735 (let (ret)
1736 (dolist (fi (or fis (list (cvs-create-fileinfo 'DIRCHANGE "" "." ""))))
1737 (when (cvs-string-prefix-p
1738 (expand-file-name (cvs-fileinfo->full-path fi) dir)
1739 buffer-file-name)
1740 (setq ret t)))
1741 ret)))
1743 (defun* cvs-mode-run (cmd flags fis
1744 &key (buf (cvs-temp-buffer))
1745 dont-change-disc cvsargs postproc)
1746 "Generic cvs-mode-<foo> function.
1747 Executes `cvs CVSARGS CMD FLAGS FIS'.
1748 BUF is the buffer to be used for cvs' output.
1749 DONT-CHANGE-DISC non-nil indicates that the command will not change the
1750 contents of files. This is only used by the parser.
1751 POSTPROC is a list of expressions to be evaluated at the very end (after
1752 parsing if applicable). It will be prepended with `progn' is necessary."
1753 (let ((def-dir default-directory))
1754 ;; Save the relevant buffers
1755 (save-some-buffers nil (lambda () (cvs-is-within-p fis def-dir))))
1756 (unless (listp flags) (error "flags should be a list of strings"))
1757 ;; Some w32 versions of CVS don't like an explicit . too much.
1758 (when (and (car fis) (null (cdr fis))
1759 (eq (cvs-fileinfo->type (car fis)) 'DIRCHANGE)
1760 ;; (equal (cvs-fileinfo->file (car fis)) ".")
1761 (equal (cvs-fileinfo->dir (car fis)) ""))
1762 (setq fis nil))
1763 (let* ((single-dir (or (not (listp cvs-execute-single-dir))
1764 (member cmd cvs-execute-single-dir)))
1765 (parse (member cmd cvs-parse-known-commands))
1766 (args (append cvsargs (list cmd) flags))
1767 (after-mode (nth 2 (cdr (assoc cmd cvs-buffer-name-alist)))))
1768 (cvs-cleanup-collection cvs-cookies ;cleanup remaining messages
1769 (eq cvs-auto-remove-handled 'delayed) nil t)
1770 (when (fboundp after-mode)
1771 (setq postproc (append postproc `((,after-mode)))))
1772 (when parse
1773 (let ((old-fis
1774 (when (member cmd '("status" "update")) ;FIXME: Yuck!!
1775 ;; absence of `cvs update' output has a specific meaning.
1776 (or fis (list (cvs-create-fileinfo 'DIRCHANGE "" "." ""))))))
1777 (push `(cvs-parse-process ',dont-change-disc nil ',old-fis) postproc)))
1778 (setq postproc (if (cdr postproc) (cons 'progn postproc) (car postproc)))
1779 (cvs-update-header args fis)
1780 (with-current-buffer buf
1781 (let ((inhibit-read-only t)) (erase-buffer))
1782 (message "Running cvs %s ..." cmd)
1783 (cvs-run-process args fis postproc single-dir))))
1786 (defun* cvs-mode-do (cmd flags filter
1787 &key show dont-change-disc cvsargs postproc)
1788 "Generic cvs-mode-<foo> function.
1789 Executes `cvs CVSARGS CMD FLAGS' on the selected files.
1790 FILTER is passed to `cvs-applicable-p' to only apply the command to
1791 files for which it makes sense.
1792 SHOW indicates that CMD should be not be run in the default temp buffer and
1793 should be shown to the user. The buffer and mode to be used is determined
1794 by `cvs-buffer-name-alist'.
1795 DONT-CHANGE-DISC non-nil indicates that the command will not change the
1796 contents of files. This is only used by the parser."
1797 (cvs-mode-run cmd flags (cvs-mode-marked filter cmd)
1798 :buf (cvs-temp-buffer (when show cmd))
1799 :dont-change-disc dont-change-disc
1800 :cvsargs cvsargs
1801 :postproc postproc))
1803 (defun-cvs-mode (cvs-mode-status . SIMPLE) (flags)
1804 "Show cvs status for all marked files.
1805 With prefix argument, prompt for cvs flags."
1806 (interactive (list (cvs-flags-query 'cvs-status-flags "cvs status flags")))
1807 (cvs-mode-do "status" flags nil :dont-change-disc t :show t
1808 :postproc (when (eq cvs-auto-remove-handled 'status)
1809 '((with-current-buffer ,(current-buffer)
1810 (cvs-mode-remove-handled))))))
1812 (defun-cvs-mode (cvs-mode-tree . SIMPLE) (flags)
1813 "Call cvstree using the file under the point as a keyfile."
1814 (interactive (list (cvs-flags-query 'cvs-status-flags "cvs status flags")))
1815 (cvs-mode-run "status" (cons "-v" flags) (cvs-mode-marked nil "status")
1816 :buf (cvs-temp-buffer "tree")
1817 :dont-change-disc t
1818 :postproc '((cvs-status-cvstrees))))
1820 ;; cvs log
1822 (defun-cvs-mode (cvs-mode-log . NOARGS) (flags)
1823 "Display the cvs log of all selected files.
1824 With prefix argument, prompt for cvs flags."
1825 (interactive (list (cvs-add-branch-prefix
1826 (cvs-flags-query 'cvs-log-flags "cvs log flags"))))
1827 (cvs-mode-do "log" flags nil :show t))
1830 (defun-cvs-mode (cvs-mode-update . NOARGS) (flags)
1831 "Update all marked files.
1832 With a prefix argument, prompt for cvs flags."
1833 (interactive
1834 (list (cvs-add-branch-prefix
1835 (cvs-add-secondary-branch-prefix
1836 (cvs-flags-query 'cvs-update-flags "cvs update flags")
1837 "-j") "-j")))
1838 (cvs-mode-do "update" flags 'update))
1841 (defun-cvs-mode (cvs-mode-examine . NOARGS) (flags)
1842 "Re-examine all marked files.
1843 With a prefix argument, prompt for cvs flags."
1844 (interactive
1845 (list (cvs-add-branch-prefix
1846 (cvs-add-secondary-branch-prefix
1847 (cvs-flags-query 'cvs-update-flags "cvs -n update flags")
1848 "-j") "-j")))
1849 (cvs-mode-do "update" flags nil :cvsargs '("-n") :dont-change-disc t))
1852 (defun-cvs-mode cvs-mode-ignore (&optional pattern)
1853 "Arrange so that CVS ignores the selected files.
1854 This command ignores files that are not flagged as `Unknown'."
1855 (interactive)
1856 (dolist (fi (cvs-mode-marked 'ignore))
1857 (cvs-append-to-ignore (cvs-fileinfo->dir fi) (cvs-fileinfo->file fi))
1858 (setf (cvs-fileinfo->type fi) 'DEAD))
1859 (cvs-cleanup-collection cvs-cookies nil nil nil))
1862 (defun cvs-append-to-ignore (dir str)
1863 "Add STR to the .cvsignore file in DIR."
1864 (save-window-excursion
1865 (set-buffer (find-file-noselect (expand-file-name ".cvsignore" dir)))
1866 (when (ignore-errors
1867 (and buffer-read-only
1868 (eq 'CVS (vc-backend buffer-file-name))
1869 (not (vc-editable-p buffer-file-name))))
1870 ;; CVSREAD=on special case
1871 (vc-toggle-read-only))
1872 (goto-char (point-max))
1873 (unless (zerop (current-column)) (insert "\n"))
1874 (insert str "\n")
1875 (if cvs-sort-ignore-file (sort-lines nil (point-min) (point-max)))
1876 (save-buffer)))
1879 (defun cvs-mode-find-file-other-window (e)
1880 "Select a buffer containing the file in another window."
1881 (interactive (list last-input-event))
1882 (cvs-mode-find-file e t))
1885 (defun cvs-mode-display-file (e)
1886 "Show a buffer containing the file in another window."
1887 (interactive (list last-input-event))
1888 (cvs-mode-find-file e 'dont-select))
1891 (defun cvs-find-modif (fi)
1892 (with-temp-buffer
1893 (call-process cvs-program nil (current-buffer) nil
1894 "-f" "diff" (cvs-fileinfo->file fi))
1895 (goto-char (point-min))
1896 (if (re-search-forward "^\\([0-9]+\\)" nil t)
1897 (string-to-number (match-string 1))
1898 1)))
1901 (defun cvs-mode-find-file (e &optional other)
1902 "Select a buffer containing the file.
1903 With a prefix, opens the buffer in an OTHER window."
1904 (interactive (list last-input-event current-prefix-arg))
1905 ;; If the event moves point, check that it moves it to a valid location.
1906 (when (and (/= (point) (progn (ignore-errors (mouse-set-point e)) (point)))
1907 (not (memq (get-text-property (1- (line-end-position))
1908 'font-lock-face)
1909 '(cvs-header-face cvs-filename-face))))
1910 (error "Not a file name"))
1911 (cvs-mode!
1912 (lambda (&optional rev)
1913 (interactive (list (cvs-prefix-get 'cvs-branch-prefix)))
1914 (let* ((cvs-buf (current-buffer))
1915 (fi (cvs-mode-marked nil nil :one t)))
1916 (if (eq (cvs-fileinfo->type fi) 'DIRCHANGE)
1917 (let ((odir default-directory))
1918 (setq default-directory
1919 (cvs-expand-dir-name (cvs-fileinfo->dir fi)))
1920 (cond ((eq other 'dont-select)
1921 (display-buffer (find-file-noselect default-directory)))
1922 (other (dired-other-window default-directory))
1923 (t (dired default-directory)))
1924 (set-buffer cvs-buf)
1925 (setq default-directory odir))
1926 (let ((buf (if rev (cvs-retrieve-revision fi rev)
1927 (find-file-noselect (cvs-fileinfo->full-path fi)))))
1928 (funcall (cond ((eq other 'dont-select) 'display-buffer)
1929 (other 'switch-to-buffer-other-window)
1930 (t 'switch-to-buffer))
1931 buf)
1932 (when (and cvs-find-file-and-jump (cvs-applicable-p fi 'diff-base))
1933 (goto-line (cvs-find-modif fi)))
1934 buf))))))
1937 (defun-cvs-mode (cvs-mode-undo . SIMPLE) (flags)
1938 "Undo local changes to all marked files.
1939 The file is removed and `cvs update FILE' is run."
1940 ;;"With prefix argument, prompt for cvs FLAGS."
1941 (interactive (list nil));; (cvs-flags-query 'cvs-undo-flags "undo flags")
1942 (if current-prefix-arg (call-interactively 'cvs-mode-revert-to-rev)
1943 (let* ((fis (cvs-do-removal 'undo "update" 'all))
1944 (removedp (lambda (fi)
1945 (or (eq (cvs-fileinfo->type fi) 'REMOVED)
1946 (and (eq (cvs-fileinfo->type fi) 'CONFLICT)
1947 (eq (cvs-fileinfo->subtype fi) 'REMOVED)))))
1948 (fis-split (cvs-partition removedp fis))
1949 (fis-removed (car fis-split))
1950 (fis-other (cdr fis-split)))
1951 (if (null fis-other)
1952 (when fis-removed (cvs-mode-run "add" nil fis-removed))
1953 (cvs-mode-run "update" flags fis-other
1954 :postproc
1955 (when fis-removed
1956 `((with-current-buffer ,(current-buffer)
1957 (cvs-mode-run "add" nil ',fis-removed)))))))))
1960 (defun-cvs-mode (cvs-mode-revert-to-rev . NOARGS) (rev)
1961 "Revert the selected files to an old revision."
1962 (interactive
1963 (list (or (cvs-prefix-get 'cvs-branch-prefix)
1964 (let ((current-prefix-arg '(4)))
1965 (cvs-flags-query 'cvs-idiff-version)))))
1966 (let* ((fis (cvs-mode-marked 'revert "revert" :file t))
1967 (tag (concat "tmp_pcl_tag_" (make-temp-name "")))
1968 (untag `((with-current-buffer ,(current-buffer)
1969 (cvs-mode-run "tag" (list "-d" ',tag) ',fis))))
1970 (update `((with-current-buffer ,(current-buffer)
1971 (cvs-mode-run "update" (list "-j" ',tag "-j" ',rev) ',fis
1972 :postproc ',untag)))))
1973 (cvs-mode-run "tag" (list tag) fis :postproc update)))
1976 (defun-cvs-mode cvs-mode-delete-lock ()
1977 "Delete the lock file that CVS is waiting for.
1978 Note that this can be dangerous. You should only do this
1979 if you are convinced that the process that created the lock is dead."
1980 (interactive)
1981 (let* ((default-directory (cvs-expand-dir-name cvs-lock-file))
1982 (locks (directory-files default-directory nil cvs-lock-file-regexp)))
1983 (cond
1984 ((not locks) (error "No lock files found"))
1985 ((yes-or-no-p (concat "Really delete locks in " cvs-lock-file "? "))
1986 (dolist (lock locks)
1987 (cond ((file-directory-p lock) (delete-directory lock))
1988 ((file-exists-p lock) (delete-file lock))))))))
1991 (defun-cvs-mode cvs-mode-remove-handled ()
1992 "Remove all lines that are handled.
1993 Empty directories are removed."
1994 (interactive)
1995 (cvs-cleanup-collection cvs-cookies
1996 t (or cvs-auto-remove-directories 'handled) t))
1999 (defun-cvs-mode cvs-mode-acknowledge ()
2000 "Remove all marked files from the buffer."
2001 (interactive)
2002 (dolist (fi (cvs-get-marked (cvs-ignore-marks-p "acknowledge") t))
2003 (setf (cvs-fileinfo->type fi) 'DEAD))
2004 (cvs-cleanup-collection cvs-cookies nil nil nil))
2006 (defun cvs-do-removal (filter &optional cmd all)
2007 "Remove files.
2008 Returns a list of FIS that should be `cvs remove'd."
2009 (let* ((files (cvs-mode-marked filter cmd :file t :read-only t))
2010 (fis (cdr (cvs-partition (lambda (fi)
2011 (eq (cvs-fileinfo->type fi) 'UNKNOWN))
2012 (cvs-mode-marked filter cmd))))
2013 (silent (or (not cvs-confirm-removals)
2014 (cvs-every (lambda (fi)
2015 (or (not (file-exists-p
2016 (cvs-fileinfo->full-path fi)))
2017 (cvs-applicable-p fi 'safe-rm)))
2018 files)))
2019 (tmpbuf (cvs-temp-buffer)))
2020 (when (and (not silent) (equal cvs-confirm-removals 'list))
2021 (with-current-buffer tmpbuf
2022 (let ((inhibit-read-only t))
2023 (cvs-insert-strings (mapcar 'cvs-fileinfo->full-path fis))
2024 (cvs-pop-to-buffer-same-frame (current-buffer))
2025 (shrink-window-if-larger-than-buffer))))
2026 (if (not (or silent
2027 (unwind-protect
2028 (yes-or-no-p (format "Delete %d files? " (length files)))
2029 (cvs-bury-buffer tmpbuf cvs-buffer))))
2030 (progn (message "Aborting") nil)
2031 (dolist (fi files)
2032 (let* ((type (cvs-fileinfo->type fi))
2033 (file (cvs-fileinfo->full-path fi)))
2034 (when (or all (eq type 'UNKNOWN))
2035 (when (file-exists-p file) (delete-file file))
2036 (unless all (setf (cvs-fileinfo->type fi) 'DEAD) t))))
2037 fis)))
2039 (defun-cvs-mode (cvs-mode-remove . SIMPLE) (flags)
2040 "Remove all marked files.
2041 With prefix argument, prompt for cvs flags."
2042 (interactive (list (cvs-flags-query 'cvs-remove-flags "cvs remove flags")))
2043 (let ((fis (cvs-do-removal 'remove)))
2044 (if fis (cvs-mode-run "remove" (cons "-f" flags) fis)
2045 (cvs-cleanup-collection cvs-cookies nil nil nil))))
2048 (defvar cvs-tag-name "")
2049 (defun-cvs-mode (cvs-mode-tag . SIMPLE) (tag &optional flags)
2050 "Run `cvs tag TAG' on all selected files.
2051 With prefix argument, prompt for cvs flags.
2052 By default this can only be used on directories.
2053 Use \\[cvs-mode-force-command] or change `cvs-force-dir-tag' if you need
2054 to use it on individual files."
2055 (interactive
2056 (list (setq cvs-tag-name
2057 (cvs-query-read cvs-tag-name "Tag name: " cvs-qtypedesc-tag))
2058 (cvs-flags-query 'cvs-tag-flags "tag flags")))
2059 (cvs-mode-do "tag" (append flags (list tag))
2060 (when cvs-force-dir-tag 'tag)))
2062 (defun-cvs-mode (cvs-mode-untag . SIMPLE) (tag &optional flags)
2063 "Run `cvs tag -d TAG' on all selected files.
2064 With prefix argument, prompt for cvs flags."
2065 (interactive
2066 (list (setq cvs-tag-name
2067 (cvs-query-read cvs-tag-name "Tag to delete: " cvs-qtypedesc-tag))
2068 (cvs-flags-query 'cvs-tag-flags "tag flags")))
2069 (cvs-mode-do "tag" (append '("-d") flags (list tag))
2070 (when cvs-force-dir-tag 'tag)))
2073 ;; Byte compile files.
2075 (defun-cvs-mode cvs-mode-byte-compile-files ()
2076 "Run byte-compile-file on all selected files that end in '.el'."
2077 (interactive)
2078 (let ((marked (cvs-get-marked (cvs-ignore-marks-p "byte-compile"))))
2079 (dolist (fi marked)
2080 (let ((filename (cvs-fileinfo->full-path fi)))
2081 (when (string-match "\\.el\\'" filename)
2082 (byte-compile-file filename))))))
2084 ;; ChangeLog support.
2086 (defun-cvs-mode cvs-mode-add-change-log-entry-other-window ()
2087 "Add a ChangeLog entry in the ChangeLog of the current directory."
2088 (interactive)
2089 (dolist (fi (cvs-mode-marked nil nil))
2090 (let ((default-directory (cvs-expand-dir-name (cvs-fileinfo->dir fi)))
2091 (buffer-file-name (expand-file-name (cvs-fileinfo->file fi))))
2092 (kill-local-variable 'change-log-default-name)
2093 (save-excursion (add-change-log-entry-other-window)))))
2095 ;; interactive commands to set optional flags
2097 (defun cvs-mode-set-flags (flag)
2098 "Ask for new setting of cvs-FLAG-flags."
2099 (interactive
2100 (list (completing-read
2101 "Which flag: "
2102 '("cvs" "diff" "update" "status" "log" "tag" ;"rtag"
2103 "commit" "remove" "undo" "checkout")
2104 nil t)))
2105 (let* ((sym (intern (concat "cvs-" flag "-flags"))))
2106 (let ((current-prefix-arg '(16)))
2107 (cvs-flags-query sym (concat flag " flags")))))
2110 ;;;;
2111 ;;;; Utilities for the *cvs* buffer
2112 ;;;;
2114 (defun cvs-dir-member-p (fileinfo dir)
2115 "Return true if FILEINFO represents a file in directory DIR."
2116 (and (not (eq (cvs-fileinfo->type fileinfo) 'DIRCHANGE))
2117 (cvs-string-prefix-p dir (cvs-fileinfo->dir fileinfo))))
2119 (defun cvs-execute-single-file (fi extractor program constant-args)
2120 "Internal function for `cvs-execute-single-file-list'."
2121 (let* ((arg-list (funcall extractor fi))
2122 (inhibit-read-only t))
2124 ;; Execute the command unless extractor returned t.
2125 (when (listp arg-list)
2126 (let* ((args (append constant-args arg-list)))
2128 (insert (format "=== %s %s\n\n"
2129 program (cvs-strings->string args)))
2131 ;; FIXME: return the exit status?
2132 (apply 'call-process program nil t t args)
2133 (goto-char (point-max))))))
2135 ;; FIXME: make this run in the background ala cvs-run-process...
2136 (defun cvs-execute-single-file-list (fis extractor program constant-args)
2137 "Run PROGRAM on all elements on FIS.
2138 CONSTANT-ARGS is a list of strings to pass as arguments to PROGRAM.
2139 The arguments given to the program will be CONSTANT-ARGS followed by
2140 the list that EXTRACTOR returns.
2142 EXTRACTOR will be called once for each file on FIS. It is given
2143 one argument, the cvs-fileinfo. It can return t, which means ignore
2144 this file, or a list of arguments to send to the program."
2145 (dolist (fi fis)
2146 (cvs-execute-single-file fi extractor program constant-args)))
2149 (defun cvs-revert-if-needed (fis)
2150 (dolist (fileinfo fis)
2151 (let* ((file (cvs-fileinfo->full-path fileinfo))
2152 (buffer (find-buffer-visiting file)))
2153 ;; For a revert to happen the user must be editing the file...
2154 (unless (or (null buffer)
2155 (eq (cvs-fileinfo->type fileinfo) 'MESSAGE)
2156 ;; FIXME: check whether revert is really needed.
2157 ;; `(verify-visited-file-modtime buffer)' doesn't cut it
2158 ;; because it only looks at the time stamp (it ignores
2159 ;; read-write changes) which is not changed by `commit'.
2160 (buffer-modified-p buffer))
2161 (with-current-buffer buffer
2162 (ignore-errors
2163 (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes)
2164 ;; `preserve-modes' avoids changing the (minor) modes. But we
2165 ;; do want to reset the mode for VC, so we do it explicitly.
2166 (vc-find-file-hook)
2167 (when (eq (cvs-fileinfo->type fileinfo) 'CONFLICT)
2168 (smerge-mode 1))))))))
2171 (defun cvs-change-cvsroot (newroot)
2172 "Change the cvsroot."
2173 (interactive "DNew repository: ")
2174 (if (or (file-directory-p (expand-file-name "CVSROOT" newroot))
2175 (y-or-n-p (concat "Warning: no CVSROOT found inside repository."
2176 " Change cvs-cvsroot anyhow?")))
2177 (setq cvs-cvsroot newroot)))
2179 ;;;;
2180 ;;;; useful global settings
2181 ;;;;
2183 ;;;###autoload
2184 (add-to-list 'completion-ignored-extensions "CVS/")
2187 ;; Hook to allow calling PCL-CVS by visiting the /CVS subdirectory
2190 ;;;###autoload
2191 (defcustom cvs-dired-action 'cvs-quickdir
2192 "The action to be performed when opening a CVS directory.
2193 Sensible values are `cvs-examine', `cvs-status' and `cvs-quickdir'."
2194 :group 'pcl-cvs
2195 :type '(choice (const cvs-examine) (const cvs-status) (const cvs-quickdir)))
2197 ;;;###autoload
2198 (defcustom cvs-dired-use-hook '(4)
2199 "Whether or not opening a CVS directory should run PCL-CVS.
2200 nil means never do it.
2201 ALWAYS means to always do it unless a prefix argument is given to the
2202 command that prompted the opening of the directory.
2203 Anything else means to do it only if the prefix arg is equal to this value."
2204 :group 'pcl-cvs
2205 :type '(choice (const :tag "Never" nil)
2206 (const :tag "Always" always)
2207 (const :tag "Prefix" (4))))
2209 ;;;###autoload
2210 (progn (defun cvs-dired-noselect (dir)
2211 "Run `cvs-examine' if DIR is a CVS administrative directory.
2212 The exact behavior is determined also by `cvs-dired-use-hook'."
2213 (when (stringp dir)
2214 (setq dir (directory-file-name dir))
2215 (when (and (string= "CVS" (file-name-nondirectory dir))
2216 (file-readable-p (expand-file-name "Entries" dir))
2217 cvs-dired-use-hook
2218 (if (eq cvs-dired-use-hook 'always)
2219 (not current-prefix-arg)
2220 (equal current-prefix-arg cvs-dired-use-hook)))
2221 (save-excursion
2222 (funcall cvs-dired-action (file-name-directory dir) t t))))))
2225 ;; hook into VC
2228 (add-hook 'vc-post-command-functions 'cvs-vc-command-advice)
2230 (defun cvs-vc-command-advice (command file flags)
2231 (when (and (equal command "cvs")
2232 (progn
2233 (while (and (stringp (car flags))
2234 (string-match "\\`-" (car flags)))
2235 (pop flags))
2236 ;; don't parse output we don't understand.
2237 (member (car flags) cvs-parse-known-commands))
2238 ;; Don't parse "update -p" output.
2239 (not (and (member (car flags) '("update" "checkout"))
2240 (let ((found-p nil))
2241 (dolist (flag flags found-p)
2242 (if (equal flag "-p") (setq found-p t)))))))
2243 (save-current-buffer
2244 (let ((buffer (current-buffer))
2245 (dir default-directory)
2246 (cvs-from-vc t))
2247 (dolist (cvs-buf (buffer-list))
2248 (set-buffer cvs-buf)
2249 ;; look for a corresponding pcl-cvs buffer
2250 (when (and (eq major-mode 'cvs-mode)
2251 (cvs-string-prefix-p default-directory dir))
2252 (let ((subdir (substring dir (length default-directory))))
2253 (set-buffer buffer)
2254 (set (make-local-variable 'cvs-buffer) cvs-buf)
2255 ;; `cvs -q add file' produces no useful output :-(
2256 (when (and (equal (car flags) "add")
2257 (goto-char (point-min))
2258 (looking-at ".*to add this file permanently\n\\'"))
2259 (insert "cvs add: scheduling file `"
2260 (file-name-nondirectory file)
2261 "' for addition\n"))
2262 ;; VC never (?) does `cvs -n update' so dcd=nil
2263 ;; should probably always be the right choice.
2264 (cvs-parse-process nil subdir))))))))
2267 ;; Hook into write-buffer
2270 (defun cvs-mark-buffer-changed ()
2271 (let* ((file (expand-file-name buffer-file-name))
2272 (version (and (fboundp 'vc-backend)
2273 (eq (vc-backend file) 'CVS)
2274 (vc-workfile-version file))))
2275 (when version
2276 (save-excursion
2277 (dolist (cvs-buf (buffer-list))
2278 (set-buffer cvs-buf)
2279 ;; look for a corresponding pcl-cvs buffer
2280 (when (and (eq major-mode 'cvs-mode)
2281 (cvs-string-prefix-p default-directory file))
2282 (let* ((file (substring file (length default-directory)))
2283 (fi (cvs-create-fileinfo
2284 (if (string= "0" version)
2285 'ADDED 'MODIFIED)
2286 (or (file-name-directory file) "")
2287 (file-name-nondirectory file)
2288 "cvs-mark-buffer-changed")))
2289 (cvs-addto-collection cvs-cookies fi))))))))
2291 (add-hook 'after-save-hook 'cvs-mark-buffer-changed)
2294 (provide 'pcvs)
2296 ;;; pcvs.el ends here