Mercurial > emacs
annotate lisp/ediff-vers.el @ 16591:afb15f49a0c9
Use new file name dos-w32.el
author | Geoff Voelker <voelker@cs.washington.edu> |
---|---|
date | Tue, 19 Nov 1996 07:02:50 +0000 |
parents | b2fae8abc5b0 |
children | 0b9d9cbf3cd4 |
rev | line source |
---|---|
14234 | 1 ;;; ediff-vers.el --- version control interface to Ediff |
2 | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
3 ;;; Copyright (C) 1995, 1996 Free Software Foundation, Inc. |
14234 | 4 |
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
23 | |
24 | |
25 ;;; Code: | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
26 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
27 ;; Compiler pacifier |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
28 (defvar rcs-default-co-switches) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
29 (defvar sc-mode) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
30 (defvar cvs-shell) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
31 (defvar cvs-program) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
32 (defvar cvs-cookie-handle) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
33 |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
34 (and noninteractive |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
35 (eval-when-compile |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
36 (load "pcl-cvs" 'noerror) |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
37 (load "rcs" 'noerror) |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
38 (load "generic-sc" 'noerror) |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
39 (load "vc" 'noerror))) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
40 ;; end pacifier |
14234 | 41 |
42 ;; VC.el support | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
43 (defun ediff-vc-internal (rev1 rev2 &optional startup-hooks) |
14234 | 44 ;; Run Ediff on versions of the current buffer. |
45 ;; If REV2 is "" then compare current buffer with REV1. | |
46 ;; If the current buffer is named `F', the version is named `F.~REV~'. | |
47 ;; If `F.~REV~' already exists, it is used instead of being re-created. | |
48 (let (file1 file2 rev1buf rev2buf) | |
49 (save-excursion | |
50 (vc-version-other-window rev1) | |
51 (setq rev1buf (current-buffer) | |
52 file1 (buffer-file-name))) | |
53 (save-excursion | |
54 (or (string= rev2 "") ; use current buffer | |
55 (vc-version-other-window rev2)) | |
56 (setq rev2buf (current-buffer) | |
57 file2 (buffer-file-name))) | |
58 (setq startup-hooks | |
59 (cons (` (lambda () | |
60 (delete-file (, file1)) | |
61 (or (, (string= rev2 "")) (delete-file (, file2))) | |
62 )) | |
63 startup-hooks)) | |
64 (ediff-buffers | |
65 rev1buf rev2buf | |
66 startup-hooks | |
67 'ediff-revision))) | |
68 | |
69 ;; RCS.el support | |
70 (defun rcs-ediff-view-revision (&optional rev) | |
71 ;; View previous RCS revision of current file. | |
72 ;; With prefix argument, prompts for a revision name. | |
73 (interactive (list (if current-prefix-arg | |
74 (read-string "Revision: ")))) | |
75 (let* ((filename (buffer-file-name (current-buffer))) | |
76 (switches (append '("-p") | |
77 (if rev (list (concat "-r" rev)) nil))) | |
78 (buff (concat (file-name-nondirectory filename) ".~" rev "~"))) | |
79 (message "Working ...") | |
80 (setq filename (expand-file-name filename)) | |
81 (with-output-to-temp-buffer buff | |
82 (let ((output-buffer (ediff-rcs-get-output-buffer filename buff))) | |
83 (delete-windows-on output-buffer) | |
84 (save-excursion | |
85 (set-buffer output-buffer) | |
86 (apply 'call-process "co" nil t nil | |
87 ;; -q: quiet (no diagnostics) | |
88 (append switches rcs-default-co-switches | |
89 (list "-q" filename))))) | |
90 (message "") | |
91 buff))) | |
92 | |
93 (defun ediff-rcs-get-output-buffer (file name) | |
94 ;; Get a buffer for RCS output for FILE, make it writable and clean it up. | |
95 ;; Optional NAME is name to use instead of `*RCS-output*'. | |
96 ;; This is a modified version from rcs.el v1.1. I use it here to make | |
97 ;; Ediff immune to changes in rcs.el | |
98 (let* ((default-major-mode 'fundamental-mode) ; no frills! | |
99 (buf (get-buffer-create name))) | |
100 (save-excursion | |
101 (set-buffer buf) | |
102 (setq buffer-read-only nil | |
103 default-directory (file-name-directory (expand-file-name file))) | |
104 (erase-buffer)) | |
105 buf)) | |
106 | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
107 (defun ediff-rcs-internal (rev1 rev2 &optional startup-hooks) |
14234 | 108 ;; Run Ediff on versions of the current buffer. |
109 ;; If REV2 is "" then use current buffer. | |
110 (let ((rev2buf (if (string= rev2 "") | |
111 (current-buffer) | |
112 (rcs-ediff-view-revision rev2))) | |
113 (rev1buf (rcs-ediff-view-revision rev1))) | |
114 | |
115 ;; rcs.el doesn't create temp version files, so we don't have to delete | |
116 ;; anything in startup hooks to ediff-buffers | |
117 (ediff-buffers rev1buf rev2buf startup-hooks 'ediff-revision) | |
118 )) | |
119 | |
120 | |
121 ;; GENERIC-SC.el support | |
122 | |
123 (defun generic-sc-get-latest-rev () | |
124 (cond ((eq sc-mode 'CCASE) | |
125 (eval "main/LATEST")) | |
126 (t (eval "")))) | |
127 | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
128 (defun ediff-generic-sc-internal (rev1 rev2 &optional startup-hooks) |
14234 | 129 ;; Run Ediff on versions of the current buffer. |
130 ;; If REV2 is "" then compare current buffer with REV1. | |
131 ;; If the current buffer is named `F', the version is named `F.~REV~'. | |
132 ;; If `F.~REV~' already exists, it is used instead of being re-created. | |
133 (let (rev1buf rev2buf) | |
134 (save-excursion | |
135 (if (or (not rev1) (string= rev1 "")) | |
136 (setq rev1 (generic-sc-get-latest-rev))) | |
137 (sc-visit-previous-revision rev1) | |
138 (setq rev1buf (current-buffer))) | |
139 (save-excursion | |
140 (or (string= rev2 "") ; use current buffer | |
141 (sc-visit-previous-revision rev2)) | |
142 (setq rev2buf (current-buffer))) | |
143 (ediff-buffers rev1buf rev2buf startup-hooks 'ediff-revision))) | |
144 | |
145 | |
146 ;;; Merge with Version Control | |
147 | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
148 (defun ediff-vc-merge-internal (rev1 rev2 ancestor-rev &optional startup-hooks) |
14234 | 149 ;; If ANCESTOR-REV non-nil, merge with ancestor |
150 (let (buf1 buf2 ancestor-buf) | |
151 (save-excursion | |
152 (vc-version-other-window rev1) | |
153 (setq buf1 (current-buffer))) | |
154 (save-excursion | |
155 (or (string= rev2 "") | |
156 (vc-version-other-window rev2)) | |
157 (setq buf2 (current-buffer))) | |
158 (if ancestor-rev | |
159 (save-excursion | |
160 (or (string= ancestor-rev "") | |
161 (vc-version-other-window ancestor-rev)) | |
162 (setq ancestor-buf (current-buffer)))) | |
163 (setq startup-hooks | |
164 (cons | |
165 (` (lambda () | |
166 (delete-file (, (buffer-file-name buf1))) | |
167 (or (, (string= rev2 "")) | |
168 (delete-file (, (buffer-file-name buf2)))) | |
169 (or (, (string= ancestor-rev "")) | |
170 (, (not ancestor-rev)) | |
171 (delete-file (, (buffer-file-name ancestor-buf)))) | |
172 )) | |
173 startup-hooks)) | |
174 (if ancestor-rev | |
175 (ediff-merge-buffers-with-ancestor | |
176 buf1 buf2 ancestor-buf | |
177 startup-hooks 'ediff-merge-revisions-with-ancestor) | |
178 (ediff-merge-buffers buf1 buf2 startup-hooks 'ediff-merge-revisions)) | |
179 )) | |
180 | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
181 (defun ediff-rcs-merge-internal (rev1 rev2 ancestor-rev |
14234 | 182 &optional startup-hooks) |
183 ;; If ANCESTOR-REV non-nil, merge with ancestor | |
184 (let (buf1 buf2 ancestor-buf) | |
185 (setq buf1 (rcs-ediff-view-revision rev1) | |
186 buf2 (if (string= rev2 "") | |
187 (current-buffer) | |
188 (rcs-ediff-view-revision rev2)) | |
189 ancestor-buf (if ancestor-rev | |
190 (if (string= ancestor-rev "") | |
191 (current-buffer) | |
192 (rcs-ediff-view-revision ancestor-rev)))) | |
193 ;; rcs.el doesn't create temp version files, so we don't have to delete | |
194 ;; anything in startup hooks to ediff-buffers | |
195 (if ancestor-rev | |
196 (ediff-merge-buffers-with-ancestor | |
197 buf1 buf2 ancestor-buf | |
198 startup-hooks 'ediff-merge-revisions-with-ancestor) | |
199 (ediff-merge-buffers buf1 buf2 startup-hooks 'ediff-merge-revisions)))) | |
200 | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
201 (defun ediff-generic-sc-merge-internal (rev1 rev2 ancestor-rev |
14234 | 202 &optional startup-hooks) |
203 ;; If ANCESTOR-REV non-nil, merge with ancestor | |
204 (let (buf1 buf2 ancestor-buf) | |
205 (save-excursion | |
206 (if (string= rev1 "") | |
207 (setq rev1 (generic-sc-get-latest-rev))) | |
208 (sc-visit-previous-revision rev1) | |
209 (setq buf1 (current-buffer))) | |
210 (save-excursion | |
211 (or (string= rev2 "") | |
212 (sc-visit-previous-revision rev2)) | |
213 (setq buf2 (current-buffer))) | |
214 (if ancestor-rev | |
215 (save-excursion | |
216 (or (string= ancestor-rev "") | |
217 (sc-visit-previous-revision ancestor-rev)) | |
218 (setq ancestor-buf (current-buffer)))) | |
219 (if ancestor-rev | |
220 (ediff-merge-buffers-with-ancestor | |
221 buf1 buf2 ancestor-buf | |
222 startup-hooks 'ediff-merge-revisions-with-ancestor) | |
223 (ediff-merge-buffers buf1 buf2 startup-hooks 'ediff-merge-revisions)))) | |
224 | |
225 | |
226 ;; PCL-CVS.el support | |
227 | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
228 (defun ediff-pcl-cvs-internal (rev1 rev2 &optional startup-hooks) |
14234 | 229 ;; Run Ediff on a pair of revisions of the current buffer. |
230 ;; If REV1 is "", use the latest revision. | |
231 ;; If REV2 is "", use the current buffer as the second file to compare. | |
232 (let ((orig-buf (current-buffer)) | |
233 orig-file-name buf1 buf2 file1 file2) | |
234 | |
235 (or (setq orig-file-name (buffer-file-name (current-buffer))) | |
236 (error "Current buffer is not visiting any file")) | |
237 (if (string= rev1 "") (setq rev1 nil)) ; latest revision | |
238 (setq buf1 (ediff-pcl-cvs-view-revision orig-file-name rev1) | |
239 buf2 (if (string= rev2 "") | |
240 orig-buf | |
241 (ediff-pcl-cvs-view-revision orig-file-name rev2)) | |
242 file1 (buffer-file-name buf1) | |
243 file2 (buffer-file-name buf2)) | |
244 (setq startup-hooks | |
245 (cons (` (lambda () | |
246 (delete-file (, file1)) | |
247 (or (, (string= rev2 "")) (delete-file (, file2))) | |
248 )) | |
249 startup-hooks)) | |
250 (ediff-buffers buf1 buf2 startup-hooks 'ediff-revision))) | |
251 | |
252 ;; This function is the standard Ediff's interface to pcl-cvs. | |
253 ;; Works like with other interfaces: runs ediff on versions of the file in the | |
254 ;; current buffer. | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
255 (defun ediff-pcl-cvs-merge-internal (rev1 rev2 ancestor-rev |
14234 | 256 &optional startup-hooks) |
257 ;; Ediff-merge appropriate revisions of the selected file. | |
258 ;; If REV1 is "" then use the latest revision. | |
259 ;; If REV2 is "" then merge current buffer's file with REV1. | |
260 ;; If ANCESTOR-REV is "" then use current buffer's file as ancestor. | |
261 ;; If ANCESTOR-REV is nil, then merge without the ancestor. | |
262 (let ((orig-buf (current-buffer)) | |
263 orig-file-name buf1 buf2 ancestor-buf) | |
264 | |
265 (or (setq orig-file-name (buffer-file-name (current-buffer))) | |
266 (error "Current buffer is not visiting any file")) | |
267 (if (string= rev1 "") (setq rev1 nil)) ; latest revision | |
268 | |
269 (setq buf1 (ediff-pcl-cvs-view-revision orig-file-name rev1)) | |
270 (setq buf2 (if (string= rev2 "") | |
271 orig-buf | |
272 (ediff-pcl-cvs-view-revision orig-file-name rev2))) | |
273 (if (stringp ancestor-rev) | |
274 (setq ancestor-buf | |
275 (if (string= ancestor-rev "") | |
276 orig-buf | |
277 (ediff-pcl-cvs-view-revision orig-file-name ancestor-rev)))) | |
278 | |
279 (setq startup-hooks | |
280 (cons | |
281 (` (lambda () | |
282 (delete-file (, (buffer-file-name buf1))) | |
283 (or (, (string= rev2 "")) | |
284 (delete-file (, (buffer-file-name buf2)))) | |
285 (or (, (string= ancestor-rev "")) | |
286 (, (not ancestor-rev)) | |
287 (delete-file (, (buffer-file-name ancestor-buf)))) | |
288 )) | |
289 startup-hooks)) | |
290 | |
291 (if ancestor-buf | |
292 (ediff-merge-buffers-with-ancestor | |
293 buf1 buf2 ancestor-buf startup-hooks | |
294 'ediff-merge-revisions-with-ancestor) | |
295 (ediff-merge-buffers | |
296 buf1 buf2 startup-hooks 'ediff-merge-revisions)) | |
297 )) | |
298 | |
299 (defun ediff-pcl-cvs-view-revision (file rev) | |
300 ;; if rev = "", get the latest revision | |
301 (let ((temp-name (make-temp-name | |
302 (concat ediff-temp-file-prefix | |
303 "ediff_" rev)))) | |
304 (cvs-kill-buffer-visiting temp-name) | |
305 (if rev | |
306 (message "Retrieving revision %s..." rev) | |
307 (message "Retrieving latest revision...")) | |
308 (let ((res (call-process cvs-shell nil nil nil "-c" | |
309 (concat cvs-program " update -p " | |
310 (if rev | |
311 (concat "-r " rev " ") | |
312 "") | |
313 file | |
314 " > " temp-name)))) | |
315 (if (and res (not (and (integerp res) (zerop res)))) | |
316 (error "Failed to retrieve revision: %s" res)) | |
317 | |
318 (if rev | |
319 (message "Retrieving revision %s... Done." rev) | |
320 (message "Retrieving latest revision... Done.")) | |
321 (find-file-noselect temp-name)))) | |
322 | |
323 | |
324 (defun cvs-run-ediff-on-file-descriptor (tin) | |
325 ;; This is a replacement for cvs-emerge-mode | |
326 ;; Run after cvs-update. | |
327 ;; Ediff-merge appropriate revisions of the selected file. | |
328 (let* ((fileinfo (tin-cookie cvs-cookie-handle tin)) | |
329 (type (cvs-fileinfo->type fileinfo)) | |
330 (tmp-file | |
331 (cvs-retrieve-revision-to-tmpfile fileinfo)) | |
332 ancestor-file) | |
333 | |
334 (or (memq type '(MERGED CONFLICT MODIFIED)) | |
335 (error | |
336 "Can only merge `Modified', `Merged' or `Conflict' files")) | |
337 | |
338 (cond ((memq type '(MERGED CONFLICT)) | |
339 (setq ancestor-file | |
340 (cvs-retrieve-revision-to-tmpfile | |
341 fileinfo | |
342 ;; revision | |
343 (cvs-fileinfo->base-revision fileinfo))) | |
344 (ediff-merge-buffers-with-ancestor | |
345 (find-file-noselect tmp-file) | |
346 (find-file-noselect (cvs-fileinfo->backup-file fileinfo)) | |
347 (find-file-noselect ancestor-file) | |
348 nil ; startup-hooks | |
349 'ediff-merge-revisions-with-ancestor)) | |
350 ((eq type 'MODIFIED) | |
351 (ediff-merge-buffers | |
352 (find-file-noselect tmp-file) | |
353 (find-file-noselect (cvs-fileinfo->full-path fileinfo)) | |
354 nil ; startup-hooks | |
355 'ediff-merge-revisions))) | |
356 (if (stringp tmp-file) (delete-file tmp-file)) | |
357 (if (stringp ancestor-file) (delete-file ancestor-file)))) | |
358 | |
359 ;;; Local Variables: | |
360 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun) | |
361 ;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1) | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
362 ;;; eval: (put 'ediff-eval-in-buffer 'edebug-form-spec '(form body)) |
14234 | 363 ;;; End: |
364 | |
365 (provide 'ediff-vers) | |
366 | |
367 ;;; ediff-vers.el ends here |