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