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