(url-retrieve-synchronously): Adjust the workaround so as not
[emacs.git] / lisp / pcvs.el
blob0f0ff76ed0cf09cfa8db48286960e6fa4859ddd6
1 ;;; pcvs.el --- a front-end to CVS
3 ;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 ;; 2000, 2002, 2003, 2004, 2005 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@gnu.org
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., 51 Franklin Street, Fifth Floor,
33 ;; Boston, MA 02110-1301, 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-name (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-live-p 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 (if cmd
373 ;; When CMD is specified, the buffer is normally shown to the
374 ;; user, so interrupting the process is not harmful.
375 ;; Use `delete-process' rather than `kill-process' otherwise
376 ;; the pending output of the process will still get inserted
377 ;; after we erase the buffer.
378 (delete-process proc)
379 (error "Can not run two cvs processes simultaneously"))))
381 (if (not name) (kill-local-variable 'other-window-scroll-buffer)
382 ;; Strangely, if no window is created, `display-buffer' ends up
383 ;; doing a `switch-to-buffer' which does a `set-buffer', hence
384 ;; the need for `save-excursion'.
385 (unless nosetup (save-excursion (display-buffer buf)))
386 ;; FIXME: this doesn't do the right thing if the user later on
387 ;; does a `find-file-other-window' and `scroll-other-window'
388 (set (make-local-variable 'other-window-scroll-buffer) buf))
390 (add-to-list 'cvs-temp-buffers buf)
392 (with-current-buffer buf
393 (setq buffer-read-only nil)
394 (setq default-directory dir)
395 (unless nosetup (erase-buffer))
396 (set (make-local-variable 'cvs-buffer) cvs-buf)
397 ;;(cvs-minor-mode 1)
398 (let ((lbd list-buffers-directory))
399 (if (fboundp mode) (funcall mode) (fundamental-mode))
400 (when lbd (set (make-local-variable 'list-buffers-directory) lbd)))
401 (cvs-minor-mode 1)
402 ;;(set (make-local-variable 'cvs-buffer) cvs-buf)
403 (unless normal
404 (setq buffer-read-only t)
405 (buffer-disable-undo))
406 buf)))
408 (defun cvs-mode-kill-buffers ()
409 "Kill all the \"temporary\" buffers created by the *cvs* buffer."
410 (interactive)
411 (dolist (buf cvs-temp-buffers) (ignore-errors (kill-buffer buf))))
413 (defun cvs-make-cvs-buffer (dir &optional new)
414 "Create the *cvs* buffer for directory DIR.
415 If non-nil, NEW means to create a new buffer no matter what."
416 ;; the real cvs-buffer creation
417 (setq dir (cvs-expand-dir-name dir))
418 (let* ((buffer-name (eval cvs-buffer-name))
419 (buffer
420 (or (and (not new)
421 (eq cvs-reuse-cvs-buffer 'current)
422 (cvs-buffer-p) ;reuse the current buffer if possible
423 (current-buffer))
424 ;; look for another cvs buffer visiting the same directory
425 (save-excursion
426 (unless new
427 (dolist (buffer (cons (current-buffer) (buffer-list)))
428 (set-buffer buffer)
429 (and (cvs-buffer-p)
430 (case cvs-reuse-cvs-buffer
431 (always t)
432 (subdir
433 (or (cvs-string-prefix-p default-directory dir)
434 (cvs-string-prefix-p dir default-directory)))
435 (samedir (string= default-directory dir)))
436 (return buffer)))))
437 ;; we really have to create a new buffer:
438 ;; we temporarily bind cwd to "" to prevent
439 ;; create-file-buffer from using directory info
440 ;; unless it is explicitly in the cvs-buffer-name.
441 (cvs-get-buffer-create buffer-name new))))
442 (with-current-buffer buffer
444 (and (string= dir default-directory) (cvs-buffer-p)
445 ;; just a refresh
446 (ignore-errors
447 (cvs-cleanup-collection cvs-cookies nil nil t)
448 (current-buffer)))
449 ;; setup from scratch
450 (progn
451 (setq default-directory dir)
452 (setq buffer-read-only nil)
453 (erase-buffer)
454 (insert "Repository : " (directory-file-name (cvs-get-cvsroot))
455 "\nModule : " (cvs-get-module)
456 "\nWorking dir: " (abbreviate-file-name dir)
457 (if (not (file-readable-p "CVS/Tag")) "\n"
458 (let ((tag (cvs-file-to-string "CVS/Tag")))
459 (cond
460 ((string-match "\\`T" tag)
461 (concat "\nTag : " (substring tag 1)))
462 ((string-match "\\`D" tag)
463 (concat "\nDate : " (substring tag 1)))
464 ("\n"))))
465 "\n")
466 (setq buffer-read-only t)
467 (cvs-mode)
468 (set (make-local-variable 'list-buffers-directory) buffer-name)
469 ;;(set (make-local-variable 'cvs-temp-buffer) (cvs-temp-buffer))
470 (let ((cookies (ewoc-create 'cvs-fileinfo-pp "\n" "")))
471 (set (make-local-variable 'cvs-cookies) cookies)
472 (add-hook 'kill-buffer-hook
473 (lambda ()
474 (ignore-errors (kill-buffer cvs-temp-buffer)))
475 nil t)
476 ;;(set-buffer buf)
477 buffer))))))
479 (defun* cvs-cmd-do (cmd dir flags fis new
480 &key cvsargs noexist dont-change-disc noshow)
481 (let* ((dir (file-name-as-directory
482 (abbreviate-file-name (expand-file-name dir))))
483 (cvsbuf (cvs-make-cvs-buffer dir new)))
484 ;; Check that dir is under CVS control.
485 (unless (file-directory-p dir)
486 (error "%s is not a directory" dir))
487 (unless (or noexist (file-directory-p (expand-file-name "CVS" dir))
488 (file-expand-wildcards (expand-file-name "*/CVS" dir)))
489 (error "%s does not contain CVS controlled files" dir))
491 (set-buffer cvsbuf)
492 (cvs-mode-run cmd flags fis
493 :cvsargs cvsargs :dont-change-disc dont-change-disc)
495 (if noshow cvsbuf
496 (let ((pop-up-windows nil)) (pop-to-buffer cvsbuf)))))
497 ;; (funcall (if (and (boundp 'pop-up-frames) pop-up-frames)
498 ;; 'pop-to-buffer 'switch-to-buffer)
499 ;; cvsbuf))))
501 (defun cvs-run-process (args fis postprocess &optional single-dir)
502 (assert (cvs-buffer-p cvs-buffer))
503 (save-current-buffer
504 (let ((procbuf (current-buffer))
505 (cvsbuf cvs-buffer)
506 (single-dir (or single-dir (eq cvs-execute-single-dir t))))
508 (set-buffer procbuf)
509 (goto-char (point-max))
510 (unless (bolp) (let ((inhibit-read-only t)) (insert "\n")))
511 ;; find the set of files we'll process in this round
512 (let* ((dir+files+rest
513 (if (or (null fis) (not single-dir))
514 ;; not single-dir mode: just process the whole thing
515 (list "" (mapcar 'cvs-fileinfo->full-name fis) nil)
516 ;; single-dir mode: extract the same-dir-elements
517 (let ((dir (cvs-fileinfo->dir (car fis))))
518 ;; output the concerned dir so the parser can translate paths
519 (let ((inhibit-read-only t))
520 (insert "pcl-cvs: descending directory " dir "\n"))
521 ;; loop to find the same-dir-elems
522 (do* ((files () (cons (cvs-fileinfo->file fi) files))
523 (fis fis (cdr fis))
524 (fi (car fis) (car fis)))
525 ((not (and fis (string= dir (cvs-fileinfo->dir fi))))
526 (list dir files fis))))))
527 (dir (nth 0 dir+files+rest))
528 (files (nth 1 dir+files+rest))
529 (rest (nth 2 dir+files+rest)))
531 (add-hook 'kill-buffer-hook
532 (lambda ()
533 (let ((proc (get-buffer-process (current-buffer))))
534 (when (processp proc)
535 (set-process-filter proc nil)
536 ;; Abort postprocessing but leave the sentinel so it
537 ;; will update the list of running procs.
538 (process-put proc 'cvs-postprocess nil)
539 (interrupt-process proc))))
540 nil t)
542 ;; create the new process and setup the procbuffer correspondingly
543 (let* ((msg (cvs-header-msg args fis))
544 (args (append (cvs-flags-query 'cvs-cvs-flags nil 'noquery)
545 (if cvs-cvsroot (list "-d" cvs-cvsroot))
546 args
547 files))
548 ;; If process-connection-type is nil and the repository
549 ;; is accessed via SSH, a bad interaction between libc,
550 ;; CVS and SSH can lead to garbled output.
551 ;; It might be a glibc-specific problem (but it can also happens
552 ;; under Mac OS X, it seems).
553 ;; It seems that using a pty can help circumvent the problem,
554 ;; but at the cost of screwing up when the process thinks it
555 ;; can ask for user input (such as password or host-key
556 ;; confirmation). A better workaround is to set CVS_RSH to
557 ;; an appropriate script, or to use a later version of CVS.
558 (process-connection-type nil) ; Use a pipe, not a pty.
559 (process
560 ;; the process will be run in the selected dir
561 (let ((default-directory (cvs-expand-dir-name dir)))
562 (apply 'start-process "cvs" procbuf cvs-program args))))
563 ;; setup the process.
564 (process-put process 'cvs-buffer cvs-buffer)
565 (with-current-buffer cvs-buffer (cvs-update-header msg 'add))
566 (process-put process 'cvs-header msg)
567 (process-put
568 process 'cvs-postprocess
569 (if (null rest)
570 ;; this is the last invocation
571 postprocess
572 ;; else, we have to register ourselves to be rerun on the rest
573 `(cvs-run-process ',args ',rest ',postprocess ',single-dir)))
574 (set-process-sentinel process 'cvs-sentinel)
575 (set-process-filter process 'cvs-update-filter)
576 (set-marker (process-mark process) (point-max))
577 (ignore-errors (process-send-eof process)) ;close its stdin to avoid hangs
579 ;; now finish setting up the cvs-buffer
580 (set-buffer cvsbuf)
581 (setq cvs-mode-line-process (symbol-name (process-status process)))
582 (force-mode-line-update)))))
584 ;; The following line is said to improve display updates on some
585 ;; emacsen. It shouldn't be needed, but it does no harm.
586 (sit-for 0))
588 (defun cvs-header-msg (args fis)
589 (let* ((lastarg nil)
590 (args (mapcar (lambda (arg)
591 (cond
592 ;; filter out the largish commit message
593 ((and (eq lastarg nil) (string= arg "commit"))
594 (setq lastarg 'commit) arg)
595 ((and (eq lastarg 'commit) (string= arg "-m"))
596 (setq lastarg '-m) arg)
597 ((eq lastarg '-m)
598 (setq lastarg 'done) "<log message>")
599 ;; filter out the largish `admin -mrev:msg' message
600 ((and (eq lastarg nil) (string= arg "admin"))
601 (setq lastarg 'admin) arg)
602 ((and (eq lastarg 'admin)
603 (string-match "\\`-m[^:]*:" arg))
604 (setq lastarg 'done)
605 (concat (match-string 0 arg) "<log message>"))
606 ;; Keep the rest as is.
607 (t arg)))
608 args)))
609 (concat cvs-program " "
610 (cvs-strings->string
611 (append (cvs-flags-query 'cvs-cvs-flags nil 'noquery)
612 (if cvs-cvsroot (list "-d" cvs-cvsroot))
613 args
614 (mapcar 'cvs-fileinfo->full-name fis))))))
616 (defun cvs-update-header (cmd add)
617 (let* ((hf (ewoc-get-hf cvs-cookies))
618 (str (car hf))
619 (done "")
620 (tin (ewoc-nth cvs-cookies 0)))
621 (if (eq (length str) 1) (setq str ""))
622 ;; look for the first *real* fileinfo (to determine emptyness)
623 (while
624 (and tin
625 (memq (cvs-fileinfo->type (ewoc-data tin))
626 '(MESSAGE DIRCHANGE)))
627 (setq tin (ewoc-next cvs-cookies tin)))
628 (if add
629 (setq str (concat "-- Running " cmd " ...\n" str))
630 (if (not (string-match
631 (concat "^-- Running " (regexp-quote cmd) " \\.\\.\\.\n") str))
632 (error "Internal PCL-CVS error while removing message")
633 (setq str (replace-match "" t t str))
634 (if (zerop (length str)) (setq str "\n"))
635 (setq done (concat "-- last cmd: " cmd " --"))))
636 ;; set the new header and footer
637 (ewoc-set-hf cvs-cookies
638 str (concat "\n--------------------- "
639 (if tin "End" "Empty")
640 " ---------------------\n"
641 done))))
644 (defun cvs-sentinel (proc msg)
645 "Sentinel for the cvs update process.
646 This is responsible for parsing the output from the cvs update when
647 it is finished."
648 (when (memq (process-status proc) '(signal exit))
649 (let ((cvs-postproc (process-get proc 'cvs-postprocess))
650 (cvs-buf (process-get proc 'cvs-buffer))
651 (procbuf (process-buffer proc)))
652 (unless (buffer-live-p cvs-buf) (setq cvs-buf nil))
653 (unless (buffer-live-p procbuf) (setq procbuf nil))
654 ;; Since the buffer and mode line will show that the
655 ;; process is dead, we can delete it now. Otherwise it
656 ;; will stay around until M-x list-processes.
657 (process-put proc 'postprocess nil)
658 (delete-process proc)
659 ;; Don't do anything if the main buffer doesn't exist any more.
660 (when cvs-buf
661 (with-current-buffer cvs-buf
662 (cvs-update-header (process-get proc 'cvs-header) nil)
663 (setq cvs-mode-line-process (symbol-name (process-status proc)))
664 (force-mode-line-update)
665 (when cvs-postproc
666 (if (null procbuf)
667 ;;(set-process-buffer proc nil)
668 (error "cvs' process buffer was killed")
669 (with-current-buffer procbuf
670 ;; Do the postprocessing like parsing and such.
671 (save-excursion (eval cvs-postproc)))))))
672 ;; Check whether something is left.
673 (when (and procbuf (not (get-buffer-process procbuf)))
674 (with-current-buffer procbuf
675 ;; IIRC, we enable undo again once the process is finished
676 ;; for cases where the output was inserted in *vc-diff* or
677 ;; in a file-like buffer. --Stef
678 (buffer-enable-undo)
679 (with-current-buffer (or cvs-buf (current-buffer))
680 (message "CVS process has completed in %s"
681 (buffer-name))))))))
683 (defun cvs-parse-process (dcd &optional subdir old-fis)
684 "Parse the output of a cvs process.
685 DCD is the `dont-change-disc' flag to use when parsing that output.
686 SUBDIR is the subdirectory (if any) where this command was run.
687 OLD-FIS is the list of fileinfos on which the cvs command was applied and
688 which should be considered up-to-date if they are missing from the output."
689 (when (eq system-type 'darwin)
690 ;; Fixup the ^D^H^H inserted at beginning of buffer sometimes on MacOSX
691 ;; because of the call to `process-send-eof'.
692 (save-excursion
693 (goto-char (point-min))
694 (while (re-search-forward "^\\^D\b+" nil t)
695 (let ((inhibit-read-only t))
696 (delete-region (match-beginning 0) (match-end 0))))))
697 (let* ((fileinfos (cvs-parse-buffer 'cvs-parse-table dcd subdir))
698 last)
699 (with-current-buffer cvs-buffer
700 ;; Expand OLD-FIS to actual files.
701 (let ((fis nil))
702 (dolist (fi old-fis)
703 (setq fis (if (eq (cvs-fileinfo->type fi) 'DIRCHANGE)
704 (nconc (ewoc-collect cvs-cookies 'cvs-dir-member-p
705 (cvs-fileinfo->dir fi))
706 fis)
707 (cons fi fis))))
708 (setq old-fis fis))
709 ;; Drop OLD-FIS which were already up-to-date.
710 (let ((fis nil))
711 (dolist (fi old-fis)
712 (unless (eq (cvs-fileinfo->type fi) 'UP-TO-DATE) (push fi fis)))
713 (setq old-fis fis))
714 ;; Add the new fileinfos to the ewoc.
715 (dolist (fi fileinfos)
716 (setq last (cvs-addto-collection cvs-cookies fi last))
717 ;; This FI was in the output, so remove it from OLD-FIS.
718 (setq old-fis (delq (ewoc-data last) old-fis)))
719 ;; Process the "silent output" (i.e. absence means up-to-date).
720 (dolist (fi old-fis)
721 (setf (cvs-fileinfo->type fi) 'UP-TO-DATE)
722 (setq last (cvs-addto-collection cvs-cookies fi last)))
723 (setq fileinfos (nconc old-fis fileinfos))
724 ;; Clean up the ewoc as requested by the user.
725 (cvs-cleanup-collection cvs-cookies
726 (eq cvs-auto-remove-handled t)
727 cvs-auto-remove-directories
728 nil)
729 ;; Revert buffers if necessary.
730 (when (and cvs-auto-revert (not dcd) (not cvs-from-vc))
731 (cvs-revert-if-needed fileinfos)))))
733 (defmacro defun-cvs-mode (fun args docstring interact &rest body)
734 "Define a function to be used in a *cvs* buffer.
735 This will look for a *cvs* buffer and execute BODY in it.
736 Since the interactive arguments might need to be queried after
737 switching to the *cvs* buffer, the generic code is rather ugly,
738 but luckily we can often use simpler alternatives.
740 FUN can be either a symbol (i.e. STYLE is nil) or a cons (FUN . STYLE).
741 ARGS and DOCSTRING are the normal argument list.
742 INTERACT is the interactive specification or nil for non-commands.
744 STYLE can be either SIMPLE, NOARGS or DOUBLE. It's an error for it
745 to have any other value, unless other details of the function make it
746 clear what alternative to use.
747 - SIMPLE will get all the interactive arguments from the original buffer.
748 - NOARGS will get all the arguments from the *cvs* buffer and will
749 always behave as if called interactively.
750 - DOUBLE is the generic case."
751 (declare (debug (&define sexp lambda-list stringp ("interactive" interactive) def-body)))
752 (let ((style (cvs-cdr fun))
753 (fun (cvs-car fun)))
754 (cond
755 ;; a trivial interaction, no need to move it
756 ((or (eq style 'SIMPLE)
757 (null (nth 1 interact))
758 (stringp (nth 1 interact)))
759 `(defun ,fun ,args ,docstring ,interact
760 (cvs-mode! (lambda () ,@body))))
762 ;; fun is only called interactively: move all the args to the inner fun
763 ((eq style 'NOARGS)
764 `(defun ,fun () ,docstring (interactive)
765 (cvs-mode! (lambda ,args ,interact ,@body))))
767 ;; bad case
768 ((eq style 'DOUBLE)
769 (string-match ".*" docstring)
770 (let ((line1 (match-string 0 docstring))
771 (fun-1 (intern (concat (symbol-name fun) "-1"))))
772 `(progn
773 (defun ,fun-1 ,args
774 ,(concat docstring "\nThis function only works within a *cvs* buffer.
775 For interactive use, use `" (symbol-name fun) "' instead.")
776 ,interact
777 ,@body)
778 (put ',fun-1 'definition-name ',fun)
779 (defun ,fun ()
780 ,(concat line1 "\nWrapper function that switches to a *cvs* buffer
781 before calling the real function `" (symbol-name fun-1) "'.\n")
782 (interactive)
783 (cvs-mode! ',fun-1)))))
785 (t (error "Unknown style %s in `defun-cvs-mode'" style)))))
787 (defun-cvs-mode cvs-mode-kill-process ()
788 "Kill the temporary buffer and associated process."
789 (interactive)
790 (when (and (bufferp cvs-temp-buffer) (buffer-live-p cvs-temp-buffer))
791 (let ((proc (get-buffer-process cvs-temp-buffer)))
792 (when proc (delete-process proc)))))
795 ;; Maintaining the collection in the face of updates
798 (defun cvs-addto-collection (c fi &optional tin)
799 "Add FI to C and return FI's corresponding tin.
800 FI is inserted in its proper place or maybe even merged with a preexisting
801 fileinfo if applicable.
802 TIN specifies an optional starting point."
803 (unless tin (setq tin (ewoc-nth c 0)))
804 (while (and tin (cvs-fileinfo< fi (ewoc-data tin)))
805 (setq tin (ewoc-prev c tin)))
806 (if (null tin) (ewoc-enter-first c fi) ;empty collection
807 (assert (not (cvs-fileinfo< fi (ewoc-data tin))))
808 (let ((next-tin (ewoc-next c tin)))
809 (while (not (or (null next-tin)
810 (cvs-fileinfo< fi (ewoc-data next-tin))))
811 (setq tin next-tin next-tin (ewoc-next c next-tin)))
812 (if (or (cvs-fileinfo< (ewoc-data tin) fi)
813 (eq (cvs-fileinfo->type fi) 'MESSAGE))
814 ;; tin < fi < next-tin
815 (ewoc-enter-after c tin fi)
816 ;; fi == tin
817 (cvs-fileinfo-update (ewoc-data tin) fi)
818 (ewoc-invalidate c tin)
819 ;; Move cursor back to where it belongs.
820 (when (bolp) (cvs-move-to-goal-column))
821 tin))))
823 (defcustom cvs-cleanup-functions nil
824 "Functions to tweak the cleanup process.
825 The functions are called with a single argument (a FILEINFO) and should
826 return a non-nil value if that fileinfo should be removed."
827 :group 'pcl-cvs
828 :type '(hook :options (cvs-cleanup-removed)))
830 (defun cvs-cleanup-removed (fi)
831 "Non-nil if FI has been cvs-removed but still exists.
832 This is intended for use on `cvs-cleanup-functions' when you have cvs-removed
833 automatically generated files (which should hence not be under CVS control)
834 but can't commit the removal because the repository's owner doesn't understand
835 the problem."
836 (and (or (eq (cvs-fileinfo->type fi) 'REMOVED)
837 (and (eq (cvs-fileinfo->type fi) 'CONFLICT)
838 (eq (cvs-fileinfo->subtype fi) 'REMOVED)))
839 (file-exists-p (cvs-fileinfo->full-name fi))))
841 ;; called at the following times:
842 ;; - postparse ((eq cvs-auto-remove-handled t) cvs-auto-remove-directories nil)
843 ;; - pre-run ((eq cvs-auto-remove-handled 'delayed) nil t)
844 ;; - remove-handled (t (or cvs-auto-remove-directories 'handled) t)
845 ;; - cvs-cmd-do (nil nil t)
846 ;; - post-ignore (nil nil nil)
847 ;; - acknowledge (nil nil nil)
848 ;; - remove (nil nil nil)
849 (defun cvs-cleanup-collection (c rm-handled rm-dirs rm-msgs)
850 "Remove undesired entries.
851 C is the collection
852 RM-HANDLED if non-nil means remove handled entries.
853 RM-DIRS behaves like `cvs-auto-remove-directories'.
854 RM-MSGS if non-nil means remove messages."
855 (let (last-fi first-dir (rerun t))
856 (while rerun
857 (setq rerun nil)
858 (setq first-dir t)
859 (setq last-fi (cvs-create-fileinfo 'DEAD "../" "" "")) ;place-holder
860 (ewoc-filter
861 c (lambda (fi)
862 (let* ((type (cvs-fileinfo->type fi))
863 (subtype (cvs-fileinfo->subtype fi))
864 (keep
865 (case type
866 ;; remove temp messages and keep the others
867 (MESSAGE (not (or rm-msgs (eq subtype 'TEMP))))
868 ;; remove entries
869 (DEAD nil)
870 ;; handled also?
871 (UP-TO-DATE (not rm-handled))
872 ;; keep the rest
873 (t (not (run-hook-with-args-until-success
874 'cvs-cleanup-functions fi))))))
876 ;; mark dirs for removal
877 (when (and keep rm-dirs
878 (eq (cvs-fileinfo->type last-fi) 'DIRCHANGE)
879 (not (when first-dir (setq first-dir nil) t))
880 (or (eq rm-dirs 'all)
881 (not (cvs-string-prefix-p
882 (cvs-fileinfo->dir last-fi)
883 (cvs-fileinfo->dir fi)))
884 (and (eq type 'DIRCHANGE) (eq rm-dirs 'empty))
885 (eq subtype 'FOOTER)))
886 (setf (cvs-fileinfo->type last-fi) 'DEAD)
887 (setq rerun t))
888 (when keep (setq last-fi fi)))))
889 ;; remove empty last dir
890 (when (and rm-dirs
891 (not first-dir)
892 (eq (cvs-fileinfo->type last-fi) 'DIRCHANGE))
893 (setf (cvs-fileinfo->type last-fi) 'DEAD)
894 (setq rerun t)))))
896 (defun cvs-get-cvsroot ()
897 "Gets the CVSROOT for DIR."
898 (let ((cvs-cvsroot-file (expand-file-name "Root" "CVS")))
899 (or (cvs-file-to-string cvs-cvsroot-file t)
900 cvs-cvsroot
901 (getenv "CVSROOT")
902 "?????")))
904 (defun cvs-get-module ()
905 "Return the current CVS module.
906 This usually doesn't really work but is a handy initval in a prompt."
907 (let* ((repfile (expand-file-name "Repository" "CVS"))
908 (rep (cvs-file-to-string repfile t)))
909 (cond
910 ((null rep) "")
911 ((not (file-name-absolute-p rep)) rep)
913 (let* ((root (cvs-get-cvsroot))
914 (str (concat (file-name-as-directory (or root "/")) " || " rep)))
915 (if (and root (string-match "\\(.*\\) || \\1\\(.*\\)\\'" str))
916 (match-string 2 str)
917 (file-name-nondirectory rep)))))))
921 ;;;;
922 ;;;; running a "cvs checkout".
923 ;;;;
925 ;;;###autoload
926 (defun cvs-checkout (modules dir flags &optional root)
927 "Run a 'cvs checkout MODULES' in DIR.
928 Feed the output to a *cvs* buffer, display it in the current window,
929 and run `cvs-mode' on it.
931 With a prefix argument, prompt for cvs FLAGS to use."
932 (interactive
933 (let ((root (cvs-get-cvsroot)))
934 (if (or (null root) current-prefix-arg)
935 (setq root (read-string "CVS Root: ")))
936 (list (cvs-string->strings (read-string "Module(s): " (cvs-get-module)))
937 (read-directory-name "CVS Checkout Directory: "
938 nil default-directory nil)
939 (cvs-add-branch-prefix
940 (cvs-flags-query 'cvs-checkout-flags "cvs checkout flags"))
941 root)))
942 (when (eq flags t)
943 (setf flags (cvs-flags-query 'cvs-checkout-flags nil 'noquery)))
944 (let ((cvs-cvsroot root))
945 (cvs-cmd-do "checkout" (or dir default-directory)
946 (append flags modules) nil 'new
947 :noexist t)))
949 (defun-cvs-mode (cvs-mode-checkout . NOARGS) (dir)
950 "Run cvs checkout against the current branch.
951 The files are stored to DIR."
952 (interactive
953 (let* ((branch (cvs-prefix-get 'cvs-branch-prefix))
954 (prompt (format "CVS Checkout Directory for `%s%s': "
955 (cvs-get-module)
956 (if branch (format " (branch: %s)" branch)
957 ""))))
958 (list (read-directory-name prompt nil default-directory nil))))
959 (let ((modules (cvs-string->strings (cvs-get-module)))
960 (flags (cvs-add-branch-prefix
961 (cvs-flags-query 'cvs-checkout-flags "cvs checkout flags")))
962 (cvs-cvsroot (cvs-get-cvsroot)))
963 (cvs-checkout modules dir flags)))
965 ;;;;
966 ;;;; The code for running a "cvs update" and friends in various ways.
967 ;;;;
969 (defun-cvs-mode (cvs-mode-revert-buffer . SIMPLE)
970 (&optional ignore-auto noconfirm)
971 "Rerun `cvs-examine' on the current directory with the default flags."
972 (interactive)
973 (cvs-examine default-directory t))
975 (defun cvs-query-directory (msg)
976 ;; last-command-char = ?\r hints that the command was run via M-x
977 (if (and (cvs-buffer-p)
978 (not current-prefix-arg)
979 (not (eq last-command-char ?\r)))
980 default-directory
981 (read-directory-name msg nil default-directory nil)))
983 ;;;###autoload
984 (defun cvs-quickdir (dir &optional flags noshow)
985 "Open a *cvs* buffer on DIR without running cvs.
986 With a prefix argument, prompt for a directory to use.
987 A prefix arg >8 (ex: \\[universal-argument] \\[universal-argument]),
988 prevents reuse of an existing *cvs* buffer.
989 Optional argument NOSHOW if non-nil means not to display the buffer.
990 FLAGS is ignored."
991 (interactive (list (cvs-query-directory "CVS quickdir (directory): ")))
992 ;; FIXME: code duplication with cvs-cmd-do and cvs-parse-process
993 (let* ((dir (file-name-as-directory
994 (abbreviate-file-name (expand-file-name dir))))
995 (new (> (prefix-numeric-value current-prefix-arg) 8))
996 (cvsbuf (cvs-make-cvs-buffer dir new))
997 last)
998 ;; Check that dir is under CVS control.
999 (unless (file-directory-p dir)
1000 (error "%s is not a directory" dir))
1001 (unless (file-directory-p (expand-file-name "CVS" dir))
1002 (error "%s does not contain CVS controlled files" dir))
1003 (set-buffer cvsbuf)
1004 (dolist (fi (cvs-fileinfo-from-entries ""))
1005 (setq last (cvs-addto-collection cvs-cookies fi last)))
1006 (cvs-cleanup-collection cvs-cookies
1007 (eq cvs-auto-remove-handled t)
1008 cvs-auto-remove-directories
1009 nil)
1010 (if noshow cvsbuf
1011 (let ((pop-up-windows nil)) (pop-to-buffer cvsbuf)))))
1013 ;;;###autoload
1014 (defun cvs-examine (directory flags &optional noshow)
1015 "Run a `cvs -n update' in the specified DIRECTORY.
1016 That is, check what needs to be done, but don't change the disc.
1017 Feed the output to a *cvs* buffer and run `cvs-mode' on it.
1018 With a prefix argument, prompt for a directory and cvs FLAGS to use.
1019 A prefix arg >8 (ex: \\[universal-argument] \\[universal-argument]),
1020 prevents reuse of an existing *cvs* buffer.
1021 Optional argument NOSHOW if non-nil means not to display the buffer."
1022 (interactive (list (cvs-query-directory "CVS Examine (directory): ")
1023 (cvs-flags-query 'cvs-update-flags "cvs -n update flags")))
1024 (when (eq flags t)
1025 (setf flags (cvs-flags-query 'cvs-update-flags nil 'noquery)))
1026 (when find-file-visit-truename (setq directory (file-truename directory)))
1027 (cvs-cmd-do "update" directory flags nil
1028 (> (prefix-numeric-value current-prefix-arg) 8)
1029 :cvsargs '("-n")
1030 :noshow noshow
1031 :dont-change-disc t))
1034 ;;;###autoload
1035 (defun cvs-update (directory flags)
1036 "Run a `cvs update' in the current working DIRECTORY.
1037 Feed the output to a *cvs* buffer and run `cvs-mode' on it.
1038 With a \\[universal-argument] prefix argument, prompt for a directory to use.
1039 A prefix arg >8 (ex: \\[universal-argument] \\[universal-argument]),
1040 prevents reuse of an existing *cvs* buffer.
1041 The prefix is also passed to `cvs-flags-query' to select the FLAGS
1042 passed to cvs."
1043 (interactive (list (cvs-query-directory "CVS Update (directory): ")
1044 (cvs-flags-query 'cvs-update-flags "cvs update flags")))
1045 (when (eq flags t)
1046 (setf flags (cvs-flags-query 'cvs-update-flags nil 'noquery)))
1047 (cvs-cmd-do "update" directory flags nil
1048 (> (prefix-numeric-value current-prefix-arg) 8)))
1051 ;;;###autoload
1052 (defun cvs-status (directory flags &optional noshow)
1053 "Run a `cvs status' in the current working DIRECTORY.
1054 Feed the output to a *cvs* buffer and run `cvs-mode' on it.
1055 With a prefix argument, prompt for a directory and cvs FLAGS to use.
1056 A prefix arg >8 (ex: \\[universal-argument] \\[universal-argument]),
1057 prevents reuse of an existing *cvs* buffer.
1058 Optional argument NOSHOW if non-nil means not to display the buffer."
1059 (interactive (list (cvs-query-directory "CVS Status (directory): ")
1060 (cvs-flags-query 'cvs-status-flags "cvs status flags")))
1061 (when (eq flags t)
1062 (setf flags (cvs-flags-query 'cvs-status-flags nil 'noquery)))
1063 (cvs-cmd-do "status" directory flags nil
1064 (> (prefix-numeric-value current-prefix-arg) 8)
1065 :noshow noshow :dont-change-disc t))
1067 (defun cvs-update-filter (proc string)
1068 "Filter function for pcl-cvs.
1069 This function gets the output that CVS sends to stdout. It inserts
1070 the STRING into (process-buffer PROC) but it also checks if CVS is waiting
1071 for a lock file. If so, it inserts a message cookie in the *cvs* buffer."
1072 (save-match-data
1073 (with-current-buffer (process-buffer proc)
1074 (let ((inhibit-read-only t))
1075 (save-excursion
1076 ;; Insert the text, moving the process-marker.
1077 (goto-char (process-mark proc))
1078 (insert string)
1079 (set-marker (process-mark proc) (point))
1080 ;; FIXME: Delete any old lock message
1081 ;;(if (tin-nth cookies 1)
1082 ;; (tin-delete cookies
1083 ;; (tin-nth cookies 1)))
1084 ;; Check if CVS is waiting for a lock.
1085 (beginning-of-line 0) ;Move to beginning of last complete line.
1086 (when (looking-at "^[ a-z]+: \\(.*waiting for .*lock in \\(.*\\)\\)$")
1087 (let ((msg (match-string 1))
1088 (lock (match-string 2)))
1089 (with-current-buffer cvs-buffer
1090 (set (make-local-variable 'cvs-lock-file) lock)
1091 ;; display the lock situation in the *cvs* buffer:
1092 (ewoc-enter-last
1093 cvs-cookies
1094 (cvs-create-fileinfo
1095 'MESSAGE "" " "
1096 (concat msg
1097 (when (file-exists-p lock)
1098 (substitute-command-keys
1099 "\n\t(type \\[cvs-mode-delete-lock] to delete it)")))
1100 :subtype 'TEMP))
1101 (pop-to-buffer (current-buffer))
1102 (goto-char (point-max))
1103 (beep)))))))))
1106 ;;;;
1107 ;;;; The cvs-mode and its associated commands.
1108 ;;;;
1110 (cvs-prefix-define cvs-force-command "" "" '("/F") cvs-qtypedesc-string1)
1111 (defun-cvs-mode cvs-mode-force-command (arg)
1112 "Force the next cvs command to operate on all the selected files.
1113 By default, cvs commands only operate on files on which the command
1114 \"makes sense\". This overrides the safety feature on the next cvs command.
1115 It actually behaves as a toggle. If prefixed by \\[universal-argument] \\[universal-argument],
1116 the override will persist until the next toggle."
1117 (interactive "P")
1118 (cvs-prefix-set 'cvs-force-command arg))
1120 (put 'cvs-mode 'mode-class 'special)
1121 (define-derived-mode cvs-mode nil "CVS"
1122 "Mode used for PCL-CVS, a frontend to CVS.
1123 Full documentation is in the Texinfo file."
1124 (setq mode-line-process
1125 '("" cvs-force-command cvs-ignore-marks-modif
1126 ":" (cvs-branch-prefix
1127 ("" cvs-branch-prefix (cvs-secondary-branch-prefix
1128 ("->" cvs-secondary-branch-prefix))))
1129 " " cvs-mode-line-process))
1130 (if buffer-file-name
1131 (error "Use M-x cvs-quickdir to get a *cvs* buffer"))
1132 (buffer-disable-undo)
1133 ;;(set (make-local-variable 'goal-column) cvs-cursor-column)
1134 (set (make-local-variable 'revert-buffer-function) 'cvs-mode-revert-buffer)
1135 (setq truncate-lines t)
1136 (cvs-prefix-make-local 'cvs-branch-prefix)
1137 (cvs-prefix-make-local 'cvs-secondary-branch-prefix)
1138 (cvs-prefix-make-local 'cvs-force-command)
1139 (cvs-prefix-make-local 'cvs-ignore-marks-modif)
1140 (make-local-variable 'cvs-mode-line-process)
1141 (make-local-variable 'cvs-temp-buffers))
1144 (defun cvs-buffer-p (&optional buffer)
1145 "Return whether the (by default current) BUFFER is a `cvs-mode' buffer."
1146 (save-excursion
1147 (if buffer (set-buffer buffer))
1148 (and (eq major-mode 'cvs-mode))))
1150 (defun cvs-buffer-check ()
1151 "Check that the current buffer follows cvs-buffer's conventions."
1152 (let ((buf (current-buffer))
1153 (check 'none))
1154 (or (and (setq check 'collection)
1155 (eq (ewoc-buffer cvs-cookies) buf)
1156 (setq check 'cvs-temp-buffer)
1157 (or (null cvs-temp-buffer)
1158 (null (buffer-live-p cvs-temp-buffer))
1159 (and (eq (with-current-buffer cvs-temp-buffer cvs-buffer) buf)
1160 (equal (with-current-buffer cvs-temp-buffer
1161 default-directory)
1162 default-directory)))
1164 (error "Inconsistent %s in buffer %s" check (buffer-name buf)))))
1167 (defun cvs-mode-quit ()
1168 "Quit PCL-CVS, killing the *cvs* buffer."
1169 (interactive)
1170 (and (y-or-n-p "Quit pcl-cvs? ") (kill-buffer (current-buffer))))
1172 ;; Give help....
1174 (defun cvs-help ()
1175 "Display help for various PCL-CVS commands."
1176 (interactive)
1177 (if (eq last-command 'cvs-help)
1178 (describe-function 'cvs-mode) ; would need minor-mode for log-edit-mode
1179 (message "%s"
1180 (substitute-command-keys
1181 "`\\[cvs-help]':help `\\[cvs-mode-add]':add `\\[cvs-mode-commit]':commit \
1182 `\\[cvs-mode-diff-map]':diff* `\\[cvs-mode-log]':log \
1183 `\\[cvs-mode-remove]':remove `\\[cvs-mode-status]':status \
1184 `\\[cvs-mode-undo]':undo"))))
1186 ;; Move around in the buffer
1188 (defun cvs-move-to-goal-column ()
1189 (let* ((eol (line-end-position))
1190 (fpos (next-single-property-change (point) 'cvs-goal-column nil eol)))
1191 (when (< fpos eol)
1192 (goto-char fpos))))
1194 (defun-cvs-mode cvs-mode-previous-line (arg)
1195 "Go to the previous line.
1196 If a prefix argument is given, move by that many lines."
1197 (interactive "p")
1198 (ewoc-goto-prev cvs-cookies arg)
1199 (cvs-move-to-goal-column))
1201 (defun-cvs-mode cvs-mode-next-line (arg)
1202 "Go to the next line.
1203 If a prefix argument is given, move by that many lines."
1204 (interactive "p")
1205 (ewoc-goto-next cvs-cookies arg)
1206 (cvs-move-to-goal-column))
1208 ;;;;
1209 ;;;; Mark handling
1210 ;;;;
1212 (defun-cvs-mode cvs-mode-mark (&optional arg)
1213 "Mark the fileinfo on the current line.
1214 If the fileinfo is a directory, all the contents of that directory are
1215 marked instead. A directory can never be marked."
1216 (interactive)
1217 (let* ((tin (ewoc-locate cvs-cookies))
1218 (fi (ewoc-data tin)))
1219 (if (eq (cvs-fileinfo->type fi) 'DIRCHANGE)
1220 ;; it's a directory: let's mark all files inside
1221 (ewoc-map
1222 (lambda (f dir)
1223 (when (cvs-dir-member-p f dir)
1224 (setf (cvs-fileinfo->marked f)
1225 (not (if (eq arg 'toggle) (cvs-fileinfo->marked f) arg)))
1226 t)) ;Tell cookie to redisplay this cookie.
1227 cvs-cookies
1228 (cvs-fileinfo->dir fi))
1229 ;; not a directory: just do the obvious
1230 (setf (cvs-fileinfo->marked fi)
1231 (not (if (eq arg 'toggle) (cvs-fileinfo->marked fi) arg)))
1232 (ewoc-invalidate cvs-cookies tin)
1233 (cvs-mode-next-line 1))))
1235 (defalias 'cvs-mouse-toggle-mark 'cvs-mode-toggle-mark)
1236 (defun cvs-mode-toggle-mark (e)
1237 "Toggle the mark of the entry at point."
1238 (interactive (list last-input-event))
1239 (save-excursion
1240 (posn-set-point (event-end e))
1241 (cvs-mode-mark 'toggle)))
1243 (defun-cvs-mode cvs-mode-unmark ()
1244 "Unmark the fileinfo on the current line."
1245 (interactive)
1246 (cvs-mode-mark t))
1248 (defun-cvs-mode cvs-mode-mark-all-files ()
1249 "Mark all files."
1250 (interactive)
1251 (ewoc-map (lambda (cookie)
1252 (unless (eq (cvs-fileinfo->type cookie) 'DIRCHANGE)
1253 (setf (cvs-fileinfo->marked cookie) t)))
1254 cvs-cookies))
1256 (defun-cvs-mode (cvs-mode-mark-on-state . SIMPLE) (state)
1257 "Mark all files in state STATE."
1258 (interactive
1259 (list
1260 (let ((default
1261 (condition-case nil
1262 (downcase
1263 (symbol-name
1264 (cvs-fileinfo->type
1265 (cvs-mode-marked nil nil :read-only t :one t :noquery t))))
1266 (error nil))))
1267 (intern
1268 (upcase
1269 (completing-read
1270 (concat
1271 "Mark files in state" (if default (concat " [" default "]")) ": ")
1272 (mapcar (lambda (x)
1273 (list (downcase (symbol-name (car x)))))
1274 cvs-states)
1275 nil t nil nil default))))))
1276 (ewoc-map (lambda (fi)
1277 (when (eq (cvs-fileinfo->type fi) state)
1278 (setf (cvs-fileinfo->marked fi) t)))
1279 cvs-cookies))
1281 (defun-cvs-mode cvs-mode-mark-matching-files (regex)
1282 "Mark all files matching REGEX."
1283 (interactive "sMark files matching: ")
1284 (ewoc-map (lambda (cookie)
1285 (when (and (not (eq (cvs-fileinfo->type cookie) 'DIRCHANGE))
1286 (string-match regex (cvs-fileinfo->file cookie)))
1287 (setf (cvs-fileinfo->marked cookie) t)))
1288 cvs-cookies))
1290 (defun-cvs-mode cvs-mode-unmark-all-files ()
1291 "Unmark all files.
1292 Directories are also unmarked, but that doesn't matter, since
1293 they should always be unmarked."
1294 (interactive)
1295 (ewoc-map (lambda (cookie)
1296 (setf (cvs-fileinfo->marked cookie) nil)
1298 cvs-cookies))
1300 (defun-cvs-mode cvs-mode-unmark-up ()
1301 "Unmark the file on the previous line."
1302 (interactive)
1303 (let ((tin (ewoc-goto-prev cvs-cookies 1)))
1304 (when tin
1305 (setf (cvs-fileinfo->marked (ewoc-data tin)) nil)
1306 (ewoc-invalidate cvs-cookies tin)))
1307 (cvs-move-to-goal-column))
1309 (defconst cvs-ignore-marks-alternatives
1310 '(("toggle-marks" . "/TM")
1311 ("force-marks" . "/FM")
1312 ("ignore-marks" . "/IM")))
1314 (cvs-prefix-define cvs-ignore-marks-modif
1315 "Prefix to decide whether to ignore marks or not."
1316 "active"
1317 (mapcar 'cdr cvs-ignore-marks-alternatives)
1318 (cvs-qtypedesc-create
1319 (lambda (str) (cdr (assoc str cvs-ignore-marks-alternatives)))
1320 (lambda (obj) (car (rassoc obj cvs-ignore-marks-alternatives)))
1321 (lambda () cvs-ignore-marks-alternatives)
1322 nil t))
1324 (defun-cvs-mode cvs-mode-toggle-marks (arg)
1325 "Toggle whether the next CVS command uses marks.
1326 See `cvs-prefix-set' for further description of the behavior.
1327 \\[universal-argument] 1 selects `force-marks',
1328 \\[universal-argument] 2 selects `ignore-marks',
1329 \\[universal-argument] 3 selects `toggle-marks'."
1330 (interactive "P")
1331 (cvs-prefix-set 'cvs-ignore-marks-modif arg))
1333 (defun cvs-ignore-marks-p (cmd &optional read-only)
1334 (let ((default (if (member cmd cvs-invert-ignore-marks)
1335 (not cvs-default-ignore-marks)
1336 cvs-default-ignore-marks))
1337 (modif (cvs-prefix-get 'cvs-ignore-marks-modif read-only)))
1338 (cond
1339 ((equal modif "/IM") t)
1340 ((equal modif "/TM") (not default))
1341 ((equal modif "/FM") nil)
1342 (t default))))
1344 (defun cvs-mode-mark-get-modif (cmd)
1345 (if (cvs-ignore-marks-p cmd 'read-only) "/IM" "/FM"))
1347 (defun cvs-get-marked (&optional ignore-marks ignore-contents)
1348 "Return a list of all selected fileinfos.
1349 If there are any marked tins, and IGNORE-MARKS is nil, return them.
1350 Otherwise, if the cursor selects a directory, and IGNORE-CONTENTS is
1351 nil, return all files in it, else return just the directory.
1352 Otherwise return (a list containing) the file the cursor points to, or
1353 an empty list if it doesn't point to a file at all."
1354 (let ((fis nil))
1355 (dolist (fi (if (and (boundp 'cvs-minor-current-files)
1356 (consp cvs-minor-current-files))
1357 (mapcar
1358 (lambda (f)
1359 (if (cvs-fileinfo-p f) f
1360 (let ((f (file-relative-name f)))
1361 (if (file-directory-p f)
1362 (cvs-create-fileinfo
1363 'DIRCHANGE (file-name-as-directory f) "." "")
1364 (let ((dir (file-name-directory f))
1365 (file (file-name-nondirectory f)))
1366 (cvs-create-fileinfo
1367 'UNKNOWN (or dir "") file ""))))))
1368 cvs-minor-current-files)
1369 (or (and (not ignore-marks)
1370 (ewoc-collect cvs-cookies 'cvs-fileinfo->marked))
1371 (list (ewoc-data (ewoc-locate cvs-cookies))))))
1373 (if (or ignore-contents (not (eq (cvs-fileinfo->type fi) 'DIRCHANGE)))
1374 (push fi fis)
1375 ;; If a directory is selected, return members, if any.
1376 (setq fis
1377 (append (ewoc-collect
1378 cvs-cookies 'cvs-dir-member-p (cvs-fileinfo->dir fi))
1379 fis))))
1380 (nreverse fis)))
1382 (defun* cvs-mode-marked (filter &optional cmd
1383 &key read-only one file noquery)
1384 "Get the list of marked FIS.
1385 CMD is used to determine whether to use the marks or not.
1386 Only files for which FILTER is applicable are returned.
1387 If READ-ONLY is non-nil, the current toggling is left intact.
1388 If ONE is non-nil, marks are ignored and a single FI is returned.
1389 If FILE is non-nil, directory entries won't be selected."
1390 (unless cmd (setq cmd (symbol-name filter)))
1391 (let* ((fis (cvs-get-marked (or one (cvs-ignore-marks-p cmd read-only))
1392 (and (not file)
1393 (cvs-applicable-p 'DIRCHANGE filter))))
1394 (force (cvs-prefix-get 'cvs-force-command))
1395 (fis (car (cvs-partition
1396 (lambda (fi) (cvs-applicable-p fi (and (not force) filter)))
1397 fis))))
1398 (when (and (or (null fis) (and one (cdr fis))) (not noquery))
1399 (message (if (null fis)
1400 "`%s' is not applicable to any of the selected files."
1401 "`%s' is only applicable to a single file.") cmd)
1402 (sit-for 1)
1403 (setq fis (list (cvs-insert-file
1404 (read-file-name (format "File to %s: " cmd))))))
1405 (if one (car fis) fis)))
1407 (defun cvs-enabledp (filter)
1408 "Determine whether FILTER applies to at least one of the selected files."
1409 (ignore-errors (cvs-mode-marked filter nil :read-only t :noquery t)))
1411 (defun cvs-mode-files (&rest -cvs-mode-files-args)
1412 (cvs-mode!
1413 (lambda ()
1414 (mapcar 'cvs-fileinfo->full-name
1415 (apply 'cvs-mode-marked -cvs-mode-files-args)))))
1418 ;; Interface between Log-Edit and PCL-CVS
1421 (defun cvs-mode-commit-setup ()
1422 "Run `cvs-mode-commit' with setup."
1423 (interactive)
1424 (cvs-mode-commit 'force))
1426 (defcustom cvs-mode-commit-hook nil
1427 "Hook run after setting up the commit buffer."
1428 :type 'hook
1429 :options '(cvs-mode-diff)
1430 :group 'pcl-cvs)
1432 (defun cvs-mode-commit (setup)
1433 "Check in all marked files, or the current file.
1434 The user will be asked for a log message in a buffer.
1435 The buffer's mode and name is determined by the \"message\" setting
1436 of `cvs-buffer-name-alist'.
1437 The POSTPROC specified there (typically `log-edit') is then called,
1438 passing it the SETUP argument."
1439 (interactive "P")
1440 ;; It seems that the save-excursion that happens if I use the better
1441 ;; form of `(cvs-mode! (lambda ...))' screws up a couple things which
1442 ;; end up being rather annoying (like log-edit-mode's message being
1443 ;; displayed in the wrong minibuffer).
1444 (cvs-mode!)
1445 (let ((buf (cvs-temp-buffer "message" 'normal 'nosetup))
1446 (setupfun (or (nth 2 (cdr (assoc "message" cvs-buffer-name-alist)))
1447 'log-edit)))
1448 (funcall setupfun 'cvs-do-commit setup 'cvs-commit-filelist buf)
1449 (set (make-local-variable 'cvs-minor-wrap-function) 'cvs-commit-minor-wrap)
1450 (run-hooks 'cvs-mode-commit-hook)))
1452 (defun cvs-commit-minor-wrap (buf f)
1453 (let ((cvs-ignore-marks-modif (cvs-mode-mark-get-modif "commit")))
1454 (funcall f)))
1456 (defun cvs-commit-filelist ()
1457 (cvs-mode-files 'commit nil :read-only t :file t :noquery t))
1459 (defun cvs-do-commit (flags)
1460 "Do the actual commit, using the current buffer as the log message."
1461 (interactive (list (cvs-flags-query 'cvs-commit-flags "cvs commit flags")))
1462 (let ((msg (buffer-substring-no-properties (point-min) (point-max))))
1463 (cvs-mode!)
1464 ;;(pop-to-buffer cvs-buffer)
1465 (cvs-mode-do "commit" (list* "-m" msg flags) 'commit)))
1468 ;;;; Editing existing commit log messages.
1470 (defun cvs-edit-log-text-at-point ()
1471 (save-excursion
1472 (end-of-line)
1473 (when (re-search-backward "^revision " nil t)
1474 (forward-line 1)
1475 (if (looking-at "date:") (forward-line 1))
1476 (if (looking-at "branches:") (forward-line 1))
1477 (buffer-substring
1478 (point)
1479 (if (re-search-forward
1480 "^\\(-\\{28\\}\\|=\\{77\\}\\|revision [.0-9]+\\)$"
1481 nil t)
1482 (match-beginning 0)
1483 (point))))))
1485 (defvar cvs-edit-log-revision)
1486 (defvar cvs-edit-log-files) (put 'cvs-edit-log-files 'permanent-local t)
1487 (defun cvs-mode-edit-log (file rev &optional text)
1488 "Edit the log message at point.
1489 This is best called from a `log-view-mode' buffer."
1490 (interactive
1491 (list
1492 (or (cvs-mode! (lambda ()
1493 (car (cvs-mode-files nil nil
1494 :read-only t :file t :noquery t))))
1495 (read-string "File name: "))
1496 (or (cvs-mode! (lambda () (cvs-prefix-get 'cvs-branch-prefix)))
1497 (read-string "Revision to edit: "))
1498 (cvs-edit-log-text-at-point)))
1499 ;; It seems that the save-excursion that happens if I use the better
1500 ;; form of `(cvs-mode! (lambda ...))' screws up a couple things which
1501 ;; end up being rather annoying (like log-edit-mode's message being
1502 ;; displayed in the wrong minibuffer).
1503 (cvs-mode!)
1504 (let ((buf (cvs-temp-buffer "message" 'normal 'nosetup))
1505 (setupfun (or (nth 2 (cdr (assoc "message" cvs-buffer-name-alist)))
1506 'log-edit)))
1507 (with-current-buffer buf
1508 ;; Set the filename before, so log-edit can correctly setup its
1509 ;; log-edit-initial-files variable.
1510 (set (make-local-variable 'cvs-edit-log-files) (list file)))
1511 (funcall setupfun 'cvs-do-edit-log nil 'cvs-edit-log-filelist buf)
1512 (when text (erase-buffer) (insert text))
1513 (set (make-local-variable 'cvs-edit-log-revision) rev)
1514 (set (make-local-variable 'cvs-minor-wrap-function)
1515 'cvs-edit-log-minor-wrap)
1516 ;; (run-hooks 'cvs-mode-commit-hook)
1519 (defun cvs-edit-log-minor-wrap (buf f)
1520 (let ((cvs-branch-prefix (with-current-buffer buf cvs-edit-log-revision))
1521 (cvs-minor-current-files
1522 (with-current-buffer buf cvs-edit-log-files))
1523 ;; FIXME: I need to force because the fileinfos are UNKNOWN
1524 (cvs-force-command "/F"))
1525 (funcall f)))
1527 (defun cvs-edit-log-filelist ()
1528 (if cvs-minor-wrap-function
1529 (cvs-mode-files nil nil :read-only t :file t :noquery t)
1530 cvs-edit-log-files))
1532 (defun cvs-do-edit-log (rev)
1533 "Do the actual commit, using the current buffer as the log message."
1534 (interactive (list cvs-edit-log-revision))
1535 (let ((msg (buffer-substring-no-properties (point-min) (point-max))))
1536 (cvs-mode!
1537 (lambda ()
1538 (cvs-mode-do "admin" (list (concat "-m" rev ":" msg)) nil)))))
1541 ;;;;
1542 ;;;; CVS Mode commands
1543 ;;;;
1545 (defun-cvs-mode (cvs-mode-insert . NOARGS) (file)
1546 "Insert an entry for a specific file into the current listing.
1547 This is typically used if the file is up-to-date (or has been added
1548 outside of PCL-CVS) and one wants to do some operation on it."
1549 (interactive
1550 (list (read-file-name
1551 "File to insert: "
1552 ;; Can't use ignore-errors here because interactive
1553 ;; specs aren't byte-compiled.
1554 (condition-case nil
1555 (file-name-as-directory
1556 (expand-file-name
1557 (cvs-fileinfo->dir
1558 (cvs-mode-marked nil nil :read-only t :one t :noquery t))))
1559 (error nil)))))
1560 (cvs-insert-file file))
1562 (defun cvs-insert-file (file)
1563 "Insert FILE (and its contents if it's a dir) and return its FI."
1564 (let ((file (file-relative-name (directory-file-name file))) last)
1565 (dolist (fi (cvs-fileinfo-from-entries file))
1566 (setq last (cvs-addto-collection cvs-cookies fi last)))
1567 ;; There should have been at least one entry.
1568 (goto-char (ewoc-location last))
1569 (ewoc-data last)))
1571 (defun cvs-mark-fis-dead (fis)
1572 ;; Helper function, introduced because of the need for macro-expansion.
1573 (dolist (fi fis)
1574 (setf (cvs-fileinfo->type fi) 'DEAD)))
1576 (defun-cvs-mode (cvs-mode-add . SIMPLE) (flags)
1577 "Add marked files to the cvs repository.
1578 With prefix argument, prompt for cvs flags."
1579 (interactive (list (cvs-flags-query 'cvs-add-flags "cvs add flags")))
1580 (let ((fis (cvs-mode-marked 'add))
1581 (needdesc nil) (dirs nil))
1582 ;; find directories and look for fis needing a description
1583 (dolist (fi fis)
1584 (cond
1585 ((file-directory-p (cvs-fileinfo->full-name fi)) (push fi dirs))
1586 ((eq (cvs-fileinfo->type fi) 'UNKNOWN) (setq needdesc t))))
1587 ;; prompt for description if necessary
1588 (let* ((msg (if (and needdesc
1589 (or current-prefix-arg (not cvs-add-default-message)))
1590 (read-from-minibuffer "Enter description: ")
1591 (or cvs-add-default-message "")))
1592 (flags (list* "-m" msg flags))
1593 (postproc
1594 ;; setup postprocessing for the directory entries
1595 (when dirs
1596 `((cvs-run-process (list "-n" "update")
1597 ',dirs
1598 '(cvs-parse-process t))
1599 (cvs-mark-fis-dead ',dirs)))))
1600 (cvs-mode-run "add" flags fis :postproc postproc))))
1602 (defun-cvs-mode (cvs-mode-diff . DOUBLE) (flags)
1603 "Diff the selected files against the repository.
1604 This command compares the files in your working area against the
1605 revision which they are based upon."
1606 (interactive
1607 (list (cvs-add-branch-prefix
1608 (cvs-add-secondary-branch-prefix
1609 (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))))
1610 (cvs-mode-do "diff" flags 'diff
1611 :show t)) ;; :ignore-exit t
1613 (defun-cvs-mode (cvs-mode-diff-head . SIMPLE) (flags)
1614 "Diff the selected files against the head of the current branch.
1615 See ``cvs-mode-diff'' for more info."
1616 (interactive (list (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))
1617 (cvs-mode-diff-1 (cons "-rHEAD" flags)))
1619 (defun-cvs-mode (cvs-mode-diff-repository . SIMPLE) (flags)
1620 "Diff the files for changes in the repository since last co/update/commit.
1621 See ``cvs-mode-diff'' for more info."
1622 (interactive (list (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))
1623 (cvs-mode-diff-1 (cons "-rBASE" (cons "-rHEAD" flags))))
1625 (defun-cvs-mode (cvs-mode-diff-yesterday . SIMPLE) (flags)
1626 "Diff the selected files against yesterday's head of the current branch.
1627 See ``cvs-mode-diff'' for more info."
1628 (interactive (list (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))
1629 (cvs-mode-diff-1 (cons "-Dyesterday" flags)))
1631 (defun-cvs-mode (cvs-mode-diff-vendor . SIMPLE) (flags)
1632 "Diff the selected files against the head of the vendor branch.
1633 See ``cvs-mode-diff'' for more info."
1634 (interactive (list (cvs-flags-query 'cvs-diff-flags "cvs diff flags")))
1635 (cvs-mode-diff-1 (cons (concat "-r" cvs-vendor-branch) flags)))
1637 ;; sadly, this is not provided by cvs, so we have to roll our own
1638 (defun-cvs-mode (cvs-mode-diff-backup . SIMPLE) (flags)
1639 "Diff the files against the backup file.
1640 This command can be used on files that are marked with \"Merged\"
1641 or \"Conflict\" in the *cvs* buffer."
1642 (interactive (list (cvs-flags-query 'cvs-diff-flags "diff flags")))
1643 (unless (listp flags) (error "flags should be a list of strings"))
1644 (save-some-buffers)
1645 (let* ((marked (cvs-get-marked (cvs-ignore-marks-p "diff")))
1646 (fis (car (cvs-partition 'cvs-fileinfo->backup-file marked))))
1647 (unless (consp fis)
1648 (error "No files with a backup file selected!"))
1649 ;; let's extract some info into the environment for `buffer-name'
1650 (let* ((dir (cvs-fileinfo->dir (car fis)))
1651 (file (cvs-fileinfo->file (car fis))))
1652 (set-buffer (cvs-temp-buffer "diff")))
1653 (message "cvs diff backup...")
1654 (cvs-execute-single-file-list fis 'cvs-diff-backup-extractor
1655 cvs-diff-program flags))
1656 (message "cvs diff backup... Done."))
1658 (defun cvs-diff-backup-extractor (fileinfo)
1659 "Return the filename and the name of the backup file as a list.
1660 Signal an error if there is no backup file."
1661 (let ((backup-file (cvs-fileinfo->backup-file fileinfo)))
1662 (unless backup-file
1663 (error "%s has no backup file" (cvs-fileinfo->full-name fileinfo)))
1664 (list backup-file (cvs-fileinfo->full-name fileinfo))))
1667 ;; Emerge support
1669 (defun cvs-emerge-diff (b1 b2) (emerge-buffers b1 b2 b1))
1670 (defun cvs-emerge-merge (b1 b2 base out)
1671 (emerge-buffers-with-ancestor b1 b2 base (find-file-noselect out)))
1674 ;; Ediff support
1677 (defvar ediff-after-quit-destination-buffer)
1678 (defvar ediff-after-quit-hook-internal)
1679 (defvar cvs-transient-buffers)
1680 (defun cvs-ediff-startup-hook ()
1681 (add-hook 'ediff-after-quit-hook-internal
1682 `(lambda ()
1683 (cvs-ediff-exit-hook
1684 ',ediff-after-quit-destination-buffer ',cvs-transient-buffers))
1685 nil 'local))
1687 (defun cvs-ediff-exit-hook (cvs-buf tmp-bufs)
1688 ;; kill the temp buffers (and their associated windows)
1689 (dolist (tb tmp-bufs)
1690 (when (and tb (buffer-live-p tb) (not (buffer-modified-p tb)))
1691 (let ((win (get-buffer-window tb t)))
1692 (kill-buffer tb)
1693 (when (window-live-p win) (ignore-errors (delete-window win))))))
1694 ;; switch back to the *cvs* buffer
1695 (when (and cvs-buf (buffer-live-p cvs-buf)
1696 (not (get-buffer-window cvs-buf t)))
1697 (ignore-errors (switch-to-buffer cvs-buf))))
1699 (defun cvs-ediff-diff (b1 b2)
1700 (let ((ediff-after-quit-destination-buffer (current-buffer))
1701 (startup-hook '(cvs-ediff-startup-hook)))
1702 (ediff-buffers b1 b2 startup-hook 'ediff-revision)))
1704 (defun cvs-ediff-merge (b1 b2 base out)
1705 (let ((ediff-after-quit-destination-buffer (current-buffer))
1706 (startup-hook '(cvs-ediff-startup-hook)))
1707 (ediff-merge-buffers-with-ancestor
1708 b1 b2 base startup-hook
1709 'ediff-merge-revisions-with-ancestor
1710 out)))
1713 ;; Interactive merge/diff support.
1716 (defun cvs-retrieve-revision (fileinfo rev)
1717 "Retrieve the given REVision of the file in FILEINFO into a new buffer."
1718 (let* ((file (cvs-fileinfo->full-name fileinfo))
1719 (buffile (concat file "." rev)))
1720 (or (find-buffer-visiting buffile)
1721 (with-current-buffer (create-file-buffer buffile)
1722 (message "Retrieving revision %s..." rev)
1723 ;; Discard stderr output to work around the CVS+SSH+libc
1724 ;; problem when stdout and stderr are the same.
1725 (let ((res (apply 'call-process cvs-program nil '(t nil) nil
1726 "-q" "update" "-p"
1727 ;; If `rev' is HEAD, don't pass it at all:
1728 ;; the default behavior is to get the head
1729 ;; of the current branch whereas "-r HEAD"
1730 ;; stupidly gives you the head of the trunk.
1731 (append (unless (equal rev "HEAD") (list "-r" rev))
1732 (list file)))))
1733 (when (and res (not (and (equal 0 res))))
1734 (error "Something went wrong retrieving revision %s: %s" rev res))
1735 (set-buffer-modified-p nil)
1736 (let ((buffer-file-name (expand-file-name file)))
1737 (after-find-file))
1738 (toggle-read-only 1)
1739 (message "Retrieving revision %s... Done" rev)
1740 (current-buffer))))))
1742 ;; FIXME: The user should be able to specify ancestor/head/backup and we should
1743 ;; provide sensible defaults when merge info is unavailable (rather than rely
1744 ;; on smerge-ediff). Also provide sane defaults for need-merge files.
1745 (defun-cvs-mode cvs-mode-imerge ()
1746 "Merge interactively appropriate revisions of the selected file."
1747 (interactive)
1748 (let ((fi (cvs-mode-marked 'merge nil :one t :file t)))
1749 (let ((merge (cvs-fileinfo->merge fi))
1750 (file (cvs-fileinfo->full-name fi))
1751 (backup-file (cvs-fileinfo->backup-file fi)))
1752 (if (not (and merge backup-file))
1753 (let ((buf (find-file-noselect file)))
1754 (message "Missing merge info or backup file, using VC.")
1755 (with-current-buffer buf
1756 (smerge-ediff)))
1757 (let* ((ancestor-buf (cvs-retrieve-revision fi (car merge)))
1758 (head-buf (cvs-retrieve-revision fi (cdr merge)))
1759 (backup-buf (let ((auto-mode-alist nil))
1760 (find-file-noselect backup-file)))
1761 ;; this binding is used by cvs-ediff-startup-hook
1762 (cvs-transient-buffers (list ancestor-buf backup-buf head-buf)))
1763 (with-current-buffer backup-buf
1764 (let ((buffer-file-name (expand-file-name file)))
1765 (after-find-file)))
1766 (funcall (cdr cvs-idiff-imerge-handlers)
1767 backup-buf head-buf ancestor-buf file))))))
1769 (cvs-flags-define cvs-idiff-version
1770 (list "BASE" cvs-vendor-branch cvs-vendor-branch "BASE" "BASE")
1771 "version: " cvs-qtypedesc-tag)
1773 (defun-cvs-mode (cvs-mode-idiff . NOARGS) (&optional rev1 rev2)
1774 "Diff interactively current file to revisions."
1775 (interactive
1776 (let* ((rev1 (cvs-prefix-get 'cvs-branch-prefix))
1777 (rev2 (and rev1 (cvs-prefix-get 'cvs-secondary-branch-prefix))))
1778 (list (or rev1 (cvs-flags-query 'cvs-idiff-version))
1779 rev2)))
1780 (let ((fi (cvs-mode-marked 'diff "idiff" :one t :file t)))
1781 (let* ((file (cvs-fileinfo->full-name fi))
1782 (rev1-buf (cvs-retrieve-revision fi (or rev1 "BASE")))
1783 (rev2-buf (if rev2 (cvs-retrieve-revision fi rev2)))
1784 ;; this binding is used by cvs-ediff-startup-hook
1785 (cvs-transient-buffers (list rev1-buf rev2-buf)))
1786 (funcall (car cvs-idiff-imerge-handlers)
1787 rev1-buf (or rev2-buf (find-file-noselect file))))))
1789 (defun-cvs-mode (cvs-mode-idiff-other . NOARGS) ()
1790 "Diff interactively current file to revisions."
1791 (interactive)
1792 (let* ((rev1 (cvs-prefix-get 'cvs-branch-prefix))
1793 (rev2 (and rev1 (cvs-prefix-get 'cvs-secondary-branch-prefix)))
1794 (fis (cvs-mode-marked 'diff "idiff" :file t)))
1795 (when (> (length fis) 2)
1796 (error "idiff-other cannot be applied to more than 2 files at a time"))
1797 (let* ((fi1 (car fis))
1798 (rev1-buf (if rev1 (cvs-retrieve-revision fi1 rev1)
1799 (find-file-noselect (cvs-fileinfo->full-name fi1))))
1800 rev2-buf)
1801 (if (cdr fis)
1802 (let ((fi2 (nth 1 fis)))
1803 (setq rev2-buf
1804 (if rev2 (cvs-retrieve-revision fi2 rev2)
1805 (find-file-noselect (cvs-fileinfo->full-name fi2)))))
1806 (error "idiff-other doesn't know what other file/buffer to use"))
1807 (let* (;; this binding is used by cvs-ediff-startup-hook
1808 (cvs-transient-buffers (list rev1-buf rev2-buf)))
1809 (funcall (car cvs-idiff-imerge-handlers)
1810 rev1-buf rev2-buf)))))
1813 (defun cvs-is-within-p (fis dir)
1814 "Non-nil if buffer is inside one of FIS (in DIR)."
1815 (when (stringp buffer-file-name)
1816 (setq buffer-file-name (expand-file-name buffer-file-name))
1817 (let (ret)
1818 (dolist (fi (or fis (list (cvs-create-fileinfo 'DIRCHANGE "" "." ""))))
1819 (when (cvs-string-prefix-p
1820 (expand-file-name (cvs-fileinfo->full-name fi) dir)
1821 buffer-file-name)
1822 (setq ret t)))
1823 ret)))
1825 (defun* cvs-mode-run (cmd flags fis
1826 &key (buf (cvs-temp-buffer))
1827 dont-change-disc cvsargs postproc)
1828 "Generic cvs-mode-<foo> function.
1829 Executes `cvs CVSARGS CMD FLAGS FIS'.
1830 BUF is the buffer to be used for cvs' output.
1831 DONT-CHANGE-DISC non-nil indicates that the command will not change the
1832 contents of files. This is only used by the parser.
1833 POSTPROC is a list of expressions to be evaluated at the very end (after
1834 parsing if applicable). It will be prepended with `progn' if necessary."
1835 (let ((def-dir default-directory))
1836 ;; Save the relevant buffers
1837 (save-some-buffers nil (lambda () (cvs-is-within-p fis def-dir))))
1838 (unless (listp flags) (error "flags should be a list of strings"))
1839 ;; Some w32 versions of CVS don't like an explicit . too much.
1840 (when (and (car fis) (null (cdr fis))
1841 (eq (cvs-fileinfo->type (car fis)) 'DIRCHANGE)
1842 ;; (equal (cvs-fileinfo->file (car fis)) ".")
1843 (equal (cvs-fileinfo->dir (car fis)) ""))
1844 (setq fis nil))
1845 (let* ((single-dir (or (not (listp cvs-execute-single-dir))
1846 (member cmd cvs-execute-single-dir)))
1847 (parse (member cmd cvs-parse-known-commands))
1848 (args (append cvsargs (list cmd) flags))
1849 (after-mode (nth 2 (cdr (assoc cmd cvs-buffer-name-alist)))))
1850 (cvs-cleanup-collection cvs-cookies ;cleanup remaining messages
1851 (eq cvs-auto-remove-handled 'delayed) nil t)
1852 (when (fboundp after-mode)
1853 (setq postproc (append postproc `((,after-mode)))))
1854 (when parse
1855 (let ((old-fis
1856 (when (member cmd '("status" "update")) ;FIXME: Yuck!!
1857 ;; absence of `cvs update' output has a specific meaning.
1858 (or fis (list (cvs-create-fileinfo 'DIRCHANGE "" "." ""))))))
1859 (push `(cvs-parse-process ',dont-change-disc nil ',old-fis) postproc)))
1860 (setq postproc (if (cdr postproc) (cons 'progn postproc) (car postproc)))
1861 (with-current-buffer buf
1862 (let ((inhibit-read-only t)) (erase-buffer))
1863 (message "Running cvs %s ..." cmd)
1864 (cvs-run-process args fis postproc single-dir))))
1867 (defun* cvs-mode-do (cmd flags filter
1868 &key show dont-change-disc cvsargs postproc)
1869 "Generic cvs-mode-<foo> function.
1870 Executes `cvs CVSARGS CMD FLAGS' on the selected files.
1871 FILTER is passed to `cvs-applicable-p' to only apply the command to
1872 files for which it makes sense.
1873 SHOW indicates that CMD should be not be run in the default temp buffer and
1874 should be shown to the user. The buffer and mode to be used is determined
1875 by `cvs-buffer-name-alist'.
1876 DONT-CHANGE-DISC non-nil indicates that the command will not change the
1877 contents of files. This is only used by the parser."
1878 (cvs-mode-run cmd flags (cvs-mode-marked filter cmd)
1879 :buf (cvs-temp-buffer (when show cmd))
1880 :dont-change-disc dont-change-disc
1881 :cvsargs cvsargs
1882 :postproc postproc))
1884 (defun-cvs-mode (cvs-mode-status . SIMPLE) (flags)
1885 "Show cvs status for all marked files.
1886 With prefix argument, prompt for cvs flags."
1887 (interactive (list (cvs-flags-query 'cvs-status-flags "cvs status flags")))
1888 (cvs-mode-do "status" flags nil :dont-change-disc t :show t
1889 :postproc (when (eq cvs-auto-remove-handled 'status)
1890 '((with-current-buffer ,(current-buffer)
1891 (cvs-mode-remove-handled))))))
1893 (defun-cvs-mode (cvs-mode-tree . SIMPLE) (flags)
1894 "Call cvstree using the file under the point as a keyfile."
1895 (interactive (list (cvs-flags-query 'cvs-status-flags "cvs status flags")))
1896 (cvs-mode-run "status" (cons "-v" flags) (cvs-mode-marked nil "status")
1897 :buf (cvs-temp-buffer "tree")
1898 :dont-change-disc t
1899 :postproc '((cvs-status-cvstrees))))
1901 ;; cvs log
1903 (defun-cvs-mode (cvs-mode-log . NOARGS) (flags)
1904 "Display the cvs log of all selected files.
1905 With prefix argument, prompt for cvs flags."
1906 (interactive (list (cvs-add-branch-prefix
1907 (cvs-flags-query 'cvs-log-flags "cvs log flags"))))
1908 (cvs-mode-do "log" flags nil :show t))
1911 (defun-cvs-mode (cvs-mode-update . NOARGS) (flags)
1912 "Update all marked files.
1913 With a prefix argument, prompt for cvs flags."
1914 (interactive
1915 (list (cvs-add-branch-prefix
1916 (cvs-add-secondary-branch-prefix
1917 (cvs-flags-query 'cvs-update-flags "cvs update flags")
1918 "-j") "-j")))
1919 (cvs-mode-do "update" flags 'update))
1922 (defun-cvs-mode (cvs-mode-examine . NOARGS) (flags)
1923 "Re-examine all marked files.
1924 With a prefix argument, prompt for cvs flags."
1925 (interactive
1926 (list (cvs-add-branch-prefix
1927 (cvs-add-secondary-branch-prefix
1928 (cvs-flags-query 'cvs-update-flags "cvs -n update flags")
1929 "-j") "-j")))
1930 (cvs-mode-do "update" flags nil :cvsargs '("-n") :dont-change-disc t))
1933 (defun-cvs-mode cvs-mode-ignore (&optional pattern)
1934 "Arrange so that CVS ignores the selected files.
1935 This command ignores files that are not flagged as `Unknown'."
1936 (interactive)
1937 (dolist (fi (cvs-mode-marked 'ignore))
1938 (cvs-append-to-ignore (cvs-fileinfo->dir fi) (cvs-fileinfo->file fi)
1939 (eq (cvs-fileinfo->subtype fi) 'NEW-DIR))
1940 (setf (cvs-fileinfo->type fi) 'DEAD))
1941 (cvs-cleanup-collection cvs-cookies nil nil nil))
1944 (defun cvs-append-to-ignore (dir str &optional old-dir)
1945 "Add STR to the .cvsignore file in DIR.
1946 If OLD-DIR is non-nil, then this is a directory that we don't want
1947 to hear about anymore."
1948 (with-current-buffer
1949 (find-file-noselect (expand-file-name ".cvsignore" dir))
1950 (when (ignore-errors
1951 (and buffer-read-only
1952 (eq 'CVS (vc-backend buffer-file-name))
1953 (not (vc-editable-p buffer-file-name))))
1954 ;; CVSREAD=on special case
1955 (vc-checkout buffer-file-name t))
1956 (goto-char (point-max))
1957 (unless (bolp) (insert "\n"))
1958 (insert str (if old-dir "/\n" "\n"))
1959 (if cvs-sort-ignore-file (sort-lines nil (point-min) (point-max)))
1960 (save-buffer)))
1963 (defun cvs-mode-find-file-other-window (e)
1964 "Select a buffer containing the file in another window."
1965 (interactive (list last-input-event))
1966 (cvs-mode-find-file e t))
1969 (defun cvs-mode-display-file (e)
1970 "Show a buffer containing the file in another window."
1971 (interactive (list last-input-event))
1972 (cvs-mode-find-file e 'dont-select))
1975 (defun cvs-mode-view-file (e)
1976 "View the file."
1977 (interactive (list last-input-event))
1978 (cvs-mode-find-file e nil t))
1981 (defun cvs-mode-view-file-other-window (e)
1982 "View the file."
1983 (interactive (list last-input-event))
1984 (cvs-mode-find-file e t t))
1987 (defun cvs-find-modif (fi)
1988 (with-temp-buffer
1989 (call-process cvs-program nil (current-buffer) nil
1990 "-f" "diff" (cvs-fileinfo->file fi))
1991 (goto-char (point-min))
1992 (if (re-search-forward "^\\([0-9]+\\)" nil t)
1993 (string-to-number (match-string 1))
1994 1)))
1997 (defun cvs-mode-find-file (e &optional other view)
1998 "Select a buffer containing the file.
1999 With a prefix, opens the buffer in an OTHER window."
2000 (interactive (list last-input-event current-prefix-arg))
2001 ;; If the event moves point, check that it moves it to a valid location.
2002 (when (and (/= (point) (progn (posn-set-point (event-end e)) (point)))
2003 (not (memq (get-text-property (1- (line-end-position))
2004 'font-lock-face)
2005 '(cvs-header cvs-filename))))
2006 (error "Not a file name"))
2007 (cvs-mode!
2008 (lambda (&optional rev)
2009 (interactive (list (cvs-prefix-get 'cvs-branch-prefix)))
2010 (let* ((cvs-buf (current-buffer))
2011 (fi (cvs-mode-marked nil nil :one t)))
2012 (if (eq (cvs-fileinfo->type fi) 'DIRCHANGE)
2013 (let ((odir default-directory))
2014 (setq default-directory
2015 (cvs-expand-dir-name (cvs-fileinfo->dir fi)))
2016 (cond ((eq other 'dont-select)
2017 (display-buffer (find-file-noselect default-directory)))
2018 (other (dired-other-window default-directory))
2019 (t (dired default-directory)))
2020 (set-buffer cvs-buf)
2021 (setq default-directory odir))
2022 (let ((buf (if rev (cvs-retrieve-revision fi rev)
2023 (find-file-noselect (cvs-fileinfo->full-name fi)))))
2024 (funcall (cond ((eq other 'dont-select) 'display-buffer)
2025 (other
2026 (if view 'view-buffer-other-window
2027 'switch-to-buffer-other-window))
2028 (t (if view 'view-buffer 'switch-to-buffer)))
2029 buf)
2030 (when (and cvs-find-file-and-jump (cvs-applicable-p fi 'diff-base))
2031 (goto-line (cvs-find-modif fi)))
2032 buf))))))
2035 (defun-cvs-mode (cvs-mode-undo . SIMPLE) (flags)
2036 "Undo local changes to all marked files.
2037 The file is removed and `cvs update FILE' is run."
2038 ;;"With prefix argument, prompt for cvs FLAGS."
2039 (interactive (list nil));; (cvs-flags-query 'cvs-undo-flags "undo flags")
2040 (if current-prefix-arg (call-interactively 'cvs-mode-revert-to-rev)
2041 (let* ((fis (cvs-do-removal 'undo "update" 'all))
2042 (removedp (lambda (fi)
2043 (or (eq (cvs-fileinfo->type fi) 'REMOVED)
2044 (and (eq (cvs-fileinfo->type fi) 'CONFLICT)
2045 (eq (cvs-fileinfo->subtype fi) 'REMOVED)))))
2046 (fis-split (cvs-partition removedp fis))
2047 (fis-removed (car fis-split))
2048 (fis-other (cdr fis-split)))
2049 (if (null fis-other)
2050 (when fis-removed (cvs-mode-run "add" nil fis-removed))
2051 (cvs-mode-run "update" flags fis-other
2052 :postproc
2053 (when fis-removed
2054 `((with-current-buffer ,(current-buffer)
2055 (cvs-mode-run "add" nil ',fis-removed)))))))))
2058 (defun-cvs-mode (cvs-mode-revert-to-rev . NOARGS) (rev)
2059 "Revert the selected files to an old revision."
2060 (interactive
2061 (list (or (cvs-prefix-get 'cvs-branch-prefix)
2062 (let ((current-prefix-arg '(4)))
2063 (cvs-flags-query 'cvs-idiff-version)))))
2064 (let* ((fis (cvs-mode-marked 'revert "revert" :file t))
2065 (tag (concat "tmp_pcl_tag_" (make-temp-name "")))
2066 (untag `((with-current-buffer ,(current-buffer)
2067 (cvs-mode-run "tag" (list "-d" ',tag) ',fis))))
2068 (update `((with-current-buffer ,(current-buffer)
2069 (cvs-mode-run "update" (list "-j" ',tag "-j" ',rev) ',fis
2070 :postproc ',untag)))))
2071 (cvs-mode-run "tag" (list tag) fis :postproc update)))
2074 (defun-cvs-mode cvs-mode-delete-lock ()
2075 "Delete the lock file that CVS is waiting for.
2076 Note that this can be dangerous. You should only do this
2077 if you are convinced that the process that created the lock is dead."
2078 (interactive)
2079 (let* ((default-directory (cvs-expand-dir-name cvs-lock-file))
2080 (locks (directory-files default-directory nil cvs-lock-file-regexp)))
2081 (cond
2082 ((not locks) (error "No lock files found"))
2083 ((yes-or-no-p (concat "Really delete locks in " cvs-lock-file "? "))
2084 (dolist (lock locks)
2085 (cond ((file-directory-p lock) (delete-directory lock))
2086 ((file-exists-p lock) (delete-file lock))))))))
2089 (defun-cvs-mode cvs-mode-remove-handled ()
2090 "Remove all lines that are handled.
2091 Empty directories are removed."
2092 (interactive)
2093 (cvs-cleanup-collection cvs-cookies
2094 t (or cvs-auto-remove-directories 'handled) t))
2097 (defun-cvs-mode cvs-mode-acknowledge ()
2098 "Remove all marked files from the buffer."
2099 (interactive)
2100 (dolist (fi (cvs-get-marked (cvs-ignore-marks-p "acknowledge") t))
2101 (setf (cvs-fileinfo->type fi) 'DEAD))
2102 (cvs-cleanup-collection cvs-cookies nil nil nil))
2104 (defun cvs-do-removal (filter &optional cmd all)
2105 "Remove files.
2106 Returns a list of FIS that should be `cvs remove'd."
2107 (let* ((files (cvs-mode-marked filter cmd :file t :read-only t))
2108 (fis (cdr (cvs-partition (lambda (fi)
2109 (eq (cvs-fileinfo->type fi) 'UNKNOWN))
2110 (cvs-mode-marked filter cmd))))
2111 (silent (or (not cvs-confirm-removals)
2112 (cvs-every (lambda (fi)
2113 (or (not (file-exists-p
2114 (cvs-fileinfo->full-name fi)))
2115 (cvs-applicable-p fi 'safe-rm)))
2116 files)))
2117 (tmpbuf (cvs-temp-buffer)))
2118 (when (and (not silent) (equal cvs-confirm-removals 'list))
2119 (with-current-buffer tmpbuf
2120 (let ((inhibit-read-only t))
2121 (cvs-insert-strings (mapcar 'cvs-fileinfo->full-name fis))
2122 (cvs-pop-to-buffer-same-frame (current-buffer))
2123 (shrink-window-if-larger-than-buffer))))
2124 (if (not (or silent
2125 (unwind-protect
2126 (yes-or-no-p
2127 (let ((nfiles (length files))
2128 (verb (if (eq filter 'undo) "Undo" "Delete")))
2129 (if (= 1 nfiles)
2130 (format "%s file: \"%s\" ? "
2131 verb
2132 (cvs-fileinfo->file (car files)))
2133 (format "%s %d files? "
2134 verb
2135 nfiles))))
2136 (cvs-bury-buffer tmpbuf cvs-buffer))))
2137 (progn (message "Aborting") nil)
2138 (dolist (fi files)
2139 (let* ((type (cvs-fileinfo->type fi))
2140 (file (cvs-fileinfo->full-name fi)))
2141 (when (or all (eq type 'UNKNOWN))
2142 (when (file-exists-p file) (delete-file file))
2143 (unless all (setf (cvs-fileinfo->type fi) 'DEAD) t))))
2144 fis)))
2146 (defun-cvs-mode (cvs-mode-remove . SIMPLE) (flags)
2147 "Remove all marked files.
2148 With prefix argument, prompt for cvs flags."
2149 (interactive (list (cvs-flags-query 'cvs-remove-flags "cvs remove flags")))
2150 (let ((fis (cvs-do-removal 'remove)))
2151 (if fis (cvs-mode-run "remove" (cons "-f" flags) fis)
2152 (cvs-cleanup-collection cvs-cookies nil nil nil))))
2155 (defvar cvs-tag-name "")
2156 (defun-cvs-mode (cvs-mode-tag . SIMPLE) (tag &optional flags)
2157 "Run `cvs tag TAG' on all selected files.
2158 With prefix argument, prompt for cvs flags.
2159 By default this can only be used on directories.
2160 Use \\[cvs-mode-force-command] or change `cvs-force-dir-tag' if you need
2161 to use it on individual files."
2162 (interactive
2163 (list (setq cvs-tag-name
2164 (cvs-query-read cvs-tag-name "Tag name: " cvs-qtypedesc-tag))
2165 (cvs-flags-query 'cvs-tag-flags "tag flags")))
2166 (cvs-mode-do "tag" (append flags (list tag))
2167 (when cvs-force-dir-tag 'tag)))
2169 (defun-cvs-mode (cvs-mode-untag . SIMPLE) (tag &optional flags)
2170 "Run `cvs tag -d TAG' on all selected files.
2171 With prefix argument, prompt for cvs flags."
2172 (interactive
2173 (list (setq cvs-tag-name
2174 (cvs-query-read cvs-tag-name "Tag to delete: " cvs-qtypedesc-tag))
2175 (cvs-flags-query 'cvs-tag-flags "tag flags")))
2176 (cvs-mode-do "tag" (append '("-d") flags (list tag))
2177 (when cvs-force-dir-tag 'tag)))
2180 ;; Byte compile files.
2182 (defun-cvs-mode cvs-mode-byte-compile-files ()
2183 "Run byte-compile-file on all selected files that end in '.el'."
2184 (interactive)
2185 (let ((marked (cvs-get-marked (cvs-ignore-marks-p "byte-compile"))))
2186 (dolist (fi marked)
2187 (let ((filename (cvs-fileinfo->full-name fi)))
2188 (when (string-match "\\.el\\'" filename)
2189 (byte-compile-file filename))))))
2191 ;; ChangeLog support.
2193 (defun-cvs-mode cvs-mode-add-change-log-entry-other-window ()
2194 "Add a ChangeLog entry in the ChangeLog of the current directory."
2195 (interactive)
2196 (dolist (fi (cvs-mode-marked nil nil))
2197 (let* ((default-directory (cvs-expand-dir-name (cvs-fileinfo->dir fi)))
2198 (buffer-file-name (expand-file-name (cvs-fileinfo->file fi))))
2199 (kill-local-variable 'change-log-default-name)
2200 (save-excursion (add-change-log-entry-other-window)))))
2202 ;; interactive commands to set optional flags
2204 (defun cvs-mode-set-flags (flag)
2205 "Ask for new setting of cvs-FLAG-flags."
2206 (interactive
2207 (list (completing-read
2208 "Which flag: "
2209 '("cvs" "diff" "update" "status" "log" "tag" ;"rtag"
2210 "commit" "remove" "undo" "checkout")
2211 nil t)))
2212 (let* ((sym (intern (concat "cvs-" flag "-flags"))))
2213 (let ((current-prefix-arg '(16)))
2214 (cvs-flags-query sym (concat flag " flags")))))
2217 ;;;;
2218 ;;;; Utilities for the *cvs* buffer
2219 ;;;;
2221 (defun cvs-dir-member-p (fileinfo dir)
2222 "Return true if FILEINFO represents a file in directory DIR."
2223 (and (not (eq (cvs-fileinfo->type fileinfo) 'DIRCHANGE))
2224 (cvs-string-prefix-p dir (cvs-fileinfo->dir fileinfo))))
2226 (defun cvs-execute-single-file (fi extractor program constant-args)
2227 "Internal function for `cvs-execute-single-file-list'."
2228 (let* ((arg-list (funcall extractor fi))
2229 (inhibit-read-only t))
2231 ;; Execute the command unless extractor returned t.
2232 (when (listp arg-list)
2233 (let* ((args (append constant-args arg-list)))
2235 (insert (format "=== %s %s\n\n"
2236 program (cvs-strings->string args)))
2238 ;; FIXME: return the exit status?
2239 (apply 'call-process program nil t t args)
2240 (goto-char (point-max))))))
2242 ;; FIXME: make this run in the background ala cvs-run-process...
2243 (defun cvs-execute-single-file-list (fis extractor program constant-args)
2244 "Run PROGRAM on all elements on FIS.
2245 CONSTANT-ARGS is a list of strings to pass as arguments to PROGRAM.
2246 The arguments given to the program will be CONSTANT-ARGS followed by
2247 the list that EXTRACTOR returns.
2249 EXTRACTOR will be called once for each file on FIS. It is given
2250 one argument, the cvs-fileinfo. It can return t, which means ignore
2251 this file, or a list of arguments to send to the program."
2252 (dolist (fi fis)
2253 (cvs-execute-single-file fi extractor program constant-args)))
2256 (defun cvs-revert-if-needed (fis)
2257 (dolist (fileinfo fis)
2258 (let* ((file (cvs-fileinfo->full-name fileinfo))
2259 (buffer (find-buffer-visiting file)))
2260 ;; For a revert to happen the user must be editing the file...
2261 (unless (or (null buffer)
2262 (eq (cvs-fileinfo->type fileinfo) 'MESSAGE)
2263 ;; FIXME: check whether revert is really needed.
2264 ;; `(verify-visited-file-modtime buffer)' doesn't cut it
2265 ;; because it only looks at the time stamp (it ignores
2266 ;; read-write changes) which is not changed by `commit'.
2267 (buffer-modified-p buffer))
2268 (with-current-buffer buffer
2269 (ignore-errors
2270 (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes)
2271 ;; `preserve-modes' avoids changing the (minor) modes. But we
2272 ;; do want to reset the mode for VC, so we do it explicitly.
2273 (vc-find-file-hook)
2274 (when (eq (cvs-fileinfo->type fileinfo) 'CONFLICT)
2275 (smerge-mode 1))))))))
2278 (defun cvs-change-cvsroot (newroot)
2279 "Change the cvsroot."
2280 (interactive "DNew repository: ")
2281 (if (or (file-directory-p (expand-file-name "CVSROOT" newroot))
2282 (y-or-n-p (concat "Warning: no CVSROOT found inside repository."
2283 " Change cvs-cvsroot anyhow?")))
2284 (setq cvs-cvsroot newroot)))
2286 ;;;;
2287 ;;;; useful global settings
2288 ;;;;
2290 ;;;###autoload
2291 (add-to-list 'completion-ignored-extensions "CVS/")
2294 ;; Hook to allow calling PCL-CVS by visiting the /CVS subdirectory
2297 ;;;###autoload
2298 (defcustom cvs-dired-action 'cvs-quickdir
2299 "The action to be performed when opening a CVS directory.
2300 Sensible values are `cvs-examine', `cvs-status' and `cvs-quickdir'."
2301 :group 'pcl-cvs
2302 :type '(choice (const cvs-examine) (const cvs-status) (const cvs-quickdir)))
2304 ;;;###autoload
2305 (defcustom cvs-dired-use-hook '(4)
2306 "Whether or not opening a CVS directory should run PCL-CVS.
2307 nil means never do it.
2308 ALWAYS means to always do it unless a prefix argument is given to the
2309 command that prompted the opening of the directory.
2310 Anything else means to do it only if the prefix arg is equal to this value."
2311 :group 'pcl-cvs
2312 :type '(choice (const :tag "Never" nil)
2313 (const :tag "Always" always)
2314 (const :tag "Prefix" (4))))
2316 ;;;###autoload
2317 (progn (defun cvs-dired-noselect (dir)
2318 "Run `cvs-examine' if DIR is a CVS administrative directory.
2319 The exact behavior is determined also by `cvs-dired-use-hook'."
2320 (when (stringp dir)
2321 (setq dir (directory-file-name dir))
2322 (when (and (string= "CVS" (file-name-nondirectory dir))
2323 (file-readable-p (expand-file-name "Entries" dir))
2324 cvs-dired-use-hook
2325 (if (eq cvs-dired-use-hook 'always)
2326 (not current-prefix-arg)
2327 (equal current-prefix-arg cvs-dired-use-hook)))
2328 (save-excursion
2329 (funcall cvs-dired-action (file-name-directory dir) t t))))))
2332 ;; hook into VC
2335 (add-hook 'vc-post-command-functions 'cvs-vc-command-advice)
2337 (defun cvs-vc-command-advice (command file flags)
2338 (when (and (equal command "cvs")
2339 (progn
2340 (while (and (stringp (car flags))
2341 (string-match "\\`-" (car flags)))
2342 (pop flags))
2343 ;; don't parse output we don't understand.
2344 (member (car flags) cvs-parse-known-commands))
2345 ;; Don't parse "update -p" output.
2346 (not (and (member (car flags) '("update" "checkout"))
2347 (let ((found-p nil))
2348 (dolist (flag flags found-p)
2349 (if (equal flag "-p") (setq found-p t)))))))
2350 (save-current-buffer
2351 (let ((buffer (current-buffer))
2352 (dir default-directory)
2353 (cvs-from-vc t))
2354 (dolist (cvs-buf (buffer-list))
2355 (set-buffer cvs-buf)
2356 ;; look for a corresponding pcl-cvs buffer
2357 (when (and (eq major-mode 'cvs-mode)
2358 (cvs-string-prefix-p default-directory dir))
2359 (let ((subdir (substring dir (length default-directory))))
2360 (set-buffer buffer)
2361 (set (make-local-variable 'cvs-buffer) cvs-buf)
2362 ;; `cvs -q add file' produces no useful output :-(
2363 (when (and (equal (car flags) "add")
2364 (goto-char (point-min))
2365 (looking-at ".*to add this file permanently\n\\'"))
2366 (insert "cvs add: scheduling file `"
2367 (file-name-nondirectory file)
2368 "' for addition\n"))
2369 ;; VC never (?) does `cvs -n update' so dcd=nil
2370 ;; should probably always be the right choice.
2371 (cvs-parse-process nil subdir))))))))
2374 ;; Hook into write-buffer
2377 (defun cvs-mark-buffer-changed ()
2378 (let* ((file (expand-file-name buffer-file-name))
2379 (version (and (fboundp 'vc-backend)
2380 (eq (vc-backend file) 'CVS)
2381 (vc-workfile-version file))))
2382 (when version
2383 (save-excursion
2384 (dolist (cvs-buf (buffer-list))
2385 (set-buffer cvs-buf)
2386 ;; look for a corresponding pcl-cvs buffer
2387 (when (and (eq major-mode 'cvs-mode)
2388 (cvs-string-prefix-p default-directory file))
2389 (let* ((file (substring file (length default-directory)))
2390 (fi (cvs-create-fileinfo
2391 (if (string= "0" version)
2392 'ADDED 'MODIFIED)
2393 (or (file-name-directory file) "")
2394 (file-name-nondirectory file)
2395 "cvs-mark-buffer-changed")))
2396 (cvs-addto-collection cvs-cookies fi))))))))
2398 (add-hook 'after-save-hook 'cvs-mark-buffer-changed)
2401 (provide 'pcvs)
2403 ;; arch-tag: 8e3a7494-0453-4389-9ab3-a557ce9fab61
2404 ;;; pcvs.el ends here