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