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