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