Mercurial > emacs
comparison lisp/ediff-vers.el @ 14234:685f31261967
Initial revision
author | Michael Kifer <kifer@cs.stonybrook.edu> |
---|---|
date | Sat, 20 Jan 1996 05:32:51 +0000 |
parents | |
children | 43a3308fcf61 |
comparison
equal
deleted
inserted
replaced
14233:396316e5fbe6 | 14234:685f31261967 |
---|---|
1 ;;; ediff-vers.el --- version control interface to Ediff | |
2 | |
3 ;;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. | |
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: | |
26 | |
27 ;; VC.el support | |
28 (defun vc-ediff-internal (rev1 rev2 &optional startup-hooks) | |
29 ;; Run Ediff on versions of the current buffer. | |
30 ;; If REV2 is "" then compare current buffer with REV1. | |
31 ;; If the current buffer is named `F', the version is named `F.~REV~'. | |
32 ;; If `F.~REV~' already exists, it is used instead of being re-created. | |
33 (let (file1 file2 rev1buf rev2buf) | |
34 (save-excursion | |
35 (vc-version-other-window rev1) | |
36 (setq rev1buf (current-buffer) | |
37 file1 (buffer-file-name))) | |
38 (save-excursion | |
39 (or (string= rev2 "") ; use current buffer | |
40 (vc-version-other-window rev2)) | |
41 (setq rev2buf (current-buffer) | |
42 file2 (buffer-file-name))) | |
43 (setq startup-hooks | |
44 (cons (` (lambda () | |
45 (delete-file (, file1)) | |
46 (or (, (string= rev2 "")) (delete-file (, file2))) | |
47 )) | |
48 startup-hooks)) | |
49 (ediff-buffers | |
50 rev1buf rev2buf | |
51 startup-hooks | |
52 'ediff-revision))) | |
53 | |
54 ;; RCS.el support | |
55 (defun rcs-ediff-view-revision (&optional rev) | |
56 ;; View previous RCS revision of current file. | |
57 ;; With prefix argument, prompts for a revision name. | |
58 (interactive (list (if current-prefix-arg | |
59 (read-string "Revision: ")))) | |
60 (let* ((filename (buffer-file-name (current-buffer))) | |
61 (switches (append '("-p") | |
62 (if rev (list (concat "-r" rev)) nil))) | |
63 (buff (concat (file-name-nondirectory filename) ".~" rev "~"))) | |
64 (message "Working ...") | |
65 (setq filename (expand-file-name filename)) | |
66 (with-output-to-temp-buffer buff | |
67 (let ((output-buffer (ediff-rcs-get-output-buffer filename buff))) | |
68 (delete-windows-on output-buffer) | |
69 (save-excursion | |
70 (set-buffer output-buffer) | |
71 (apply 'call-process "co" nil t nil | |
72 ;; -q: quiet (no diagnostics) | |
73 (append switches rcs-default-co-switches | |
74 (list "-q" filename))))) | |
75 (message "") | |
76 buff))) | |
77 | |
78 (defun ediff-rcs-get-output-buffer (file name) | |
79 ;; Get a buffer for RCS output for FILE, make it writable and clean it up. | |
80 ;; Optional NAME is name to use instead of `*RCS-output*'. | |
81 ;; This is a modified version from rcs.el v1.1. I use it here to make | |
82 ;; Ediff immune to changes in rcs.el | |
83 (let* ((default-major-mode 'fundamental-mode) ; no frills! | |
84 (buf (get-buffer-create name))) | |
85 (save-excursion | |
86 (set-buffer buf) | |
87 (setq buffer-read-only nil | |
88 default-directory (file-name-directory (expand-file-name file))) | |
89 (erase-buffer)) | |
90 buf)) | |
91 | |
92 (defun rcs-ediff-internal (rev1 rev2 &optional startup-hooks) | |
93 ;; Run Ediff on versions of the current buffer. | |
94 ;; If REV2 is "" then use current buffer. | |
95 (let ((rev2buf (if (string= rev2 "") | |
96 (current-buffer) | |
97 (rcs-ediff-view-revision rev2))) | |
98 (rev1buf (rcs-ediff-view-revision rev1))) | |
99 | |
100 ;; rcs.el doesn't create temp version files, so we don't have to delete | |
101 ;; anything in startup hooks to ediff-buffers | |
102 (ediff-buffers rev1buf rev2buf startup-hooks 'ediff-revision) | |
103 )) | |
104 | |
105 | |
106 ;; GENERIC-SC.el support | |
107 | |
108 (defun generic-sc-get-latest-rev () | |
109 (cond ((eq sc-mode 'CCASE) | |
110 (eval "main/LATEST")) | |
111 (t (eval "")))) | |
112 | |
113 (defun generic-sc-ediff-internal (rev1 rev2 &optional startup-hooks) | |
114 ;; Run Ediff on versions of the current buffer. | |
115 ;; If REV2 is "" then compare current buffer with REV1. | |
116 ;; If the current buffer is named `F', the version is named `F.~REV~'. | |
117 ;; If `F.~REV~' already exists, it is used instead of being re-created. | |
118 (let (rev1buf rev2buf) | |
119 (save-excursion | |
120 (if (or (not rev1) (string= rev1 "")) | |
121 (setq rev1 (generic-sc-get-latest-rev))) | |
122 (sc-visit-previous-revision rev1) | |
123 (setq rev1buf (current-buffer))) | |
124 (save-excursion | |
125 (or (string= rev2 "") ; use current buffer | |
126 (sc-visit-previous-revision rev2)) | |
127 (setq rev2buf (current-buffer))) | |
128 (ediff-buffers rev1buf rev2buf startup-hooks 'ediff-revision))) | |
129 | |
130 | |
131 ;;; Merge with Version Control | |
132 | |
133 (defun vc-ediff-merge-internal (rev1 rev2 ancestor-rev &optional startup-hooks) | |
134 ;; If ANCESTOR-REV non-nil, merge with ancestor | |
135 (let (buf1 buf2 ancestor-buf) | |
136 (save-excursion | |
137 (vc-version-other-window rev1) | |
138 (setq buf1 (current-buffer))) | |
139 (save-excursion | |
140 (or (string= rev2 "") | |
141 (vc-version-other-window rev2)) | |
142 (setq buf2 (current-buffer))) | |
143 (if ancestor-rev | |
144 (save-excursion | |
145 (or (string= ancestor-rev "") | |
146 (vc-version-other-window ancestor-rev)) | |
147 (setq ancestor-buf (current-buffer)))) | |
148 (setq startup-hooks | |
149 (cons | |
150 (` (lambda () | |
151 (delete-file (, (buffer-file-name buf1))) | |
152 (or (, (string= rev2 "")) | |
153 (delete-file (, (buffer-file-name buf2)))) | |
154 (or (, (string= ancestor-rev "")) | |
155 (, (not ancestor-rev)) | |
156 (delete-file (, (buffer-file-name ancestor-buf)))) | |
157 )) | |
158 startup-hooks)) | |
159 (if ancestor-rev | |
160 (ediff-merge-buffers-with-ancestor | |
161 buf1 buf2 ancestor-buf | |
162 startup-hooks 'ediff-merge-revisions-with-ancestor) | |
163 (ediff-merge-buffers buf1 buf2 startup-hooks 'ediff-merge-revisions)) | |
164 )) | |
165 | |
166 (defun rcs-ediff-merge-internal (rev1 rev2 ancestor-rev | |
167 &optional startup-hooks) | |
168 ;; If ANCESTOR-REV non-nil, merge with ancestor | |
169 (let (buf1 buf2 ancestor-buf) | |
170 (setq buf1 (rcs-ediff-view-revision rev1) | |
171 buf2 (if (string= rev2 "") | |
172 (current-buffer) | |
173 (rcs-ediff-view-revision rev2)) | |
174 ancestor-buf (if ancestor-rev | |
175 (if (string= ancestor-rev "") | |
176 (current-buffer) | |
177 (rcs-ediff-view-revision ancestor-rev)))) | |
178 ;; rcs.el doesn't create temp version files, so we don't have to delete | |
179 ;; anything in startup hooks to ediff-buffers | |
180 (if ancestor-rev | |
181 (ediff-merge-buffers-with-ancestor | |
182 buf1 buf2 ancestor-buf | |
183 startup-hooks 'ediff-merge-revisions-with-ancestor) | |
184 (ediff-merge-buffers buf1 buf2 startup-hooks 'ediff-merge-revisions)))) | |
185 | |
186 (defun generic-sc-ediff-merge-internal (rev1 rev2 ancestor-rev | |
187 &optional startup-hooks) | |
188 ;; If ANCESTOR-REV non-nil, merge with ancestor | |
189 (let (buf1 buf2 ancestor-buf) | |
190 (save-excursion | |
191 (if (string= rev1 "") | |
192 (setq rev1 (generic-sc-get-latest-rev))) | |
193 (sc-visit-previous-revision rev1) | |
194 (setq buf1 (current-buffer))) | |
195 (save-excursion | |
196 (or (string= rev2 "") | |
197 (sc-visit-previous-revision rev2)) | |
198 (setq buf2 (current-buffer))) | |
199 (if ancestor-rev | |
200 (save-excursion | |
201 (or (string= ancestor-rev "") | |
202 (sc-visit-previous-revision ancestor-rev)) | |
203 (setq ancestor-buf (current-buffer)))) | |
204 (if ancestor-rev | |
205 (ediff-merge-buffers-with-ancestor | |
206 buf1 buf2 ancestor-buf | |
207 startup-hooks 'ediff-merge-revisions-with-ancestor) | |
208 (ediff-merge-buffers buf1 buf2 startup-hooks 'ediff-merge-revisions)))) | |
209 | |
210 | |
211 ;; PCL-CVS.el support | |
212 | |
213 (defun pcl-cvs-ediff-internal (rev1 rev2 &optional startup-hooks) | |
214 ;; Run Ediff on a pair of revisions of the current buffer. | |
215 ;; If REV1 is "", use the latest revision. | |
216 ;; If REV2 is "", use the current buffer as the second file to compare. | |
217 (let ((orig-buf (current-buffer)) | |
218 orig-file-name buf1 buf2 file1 file2) | |
219 | |
220 (or (setq orig-file-name (buffer-file-name (current-buffer))) | |
221 (error "Current buffer is not visiting any file")) | |
222 (if (string= rev1 "") (setq rev1 nil)) ; latest revision | |
223 (setq buf1 (ediff-pcl-cvs-view-revision orig-file-name rev1) | |
224 buf2 (if (string= rev2 "") | |
225 orig-buf | |
226 (ediff-pcl-cvs-view-revision orig-file-name rev2)) | |
227 file1 (buffer-file-name buf1) | |
228 file2 (buffer-file-name buf2)) | |
229 (setq startup-hooks | |
230 (cons (` (lambda () | |
231 (delete-file (, file1)) | |
232 (or (, (string= rev2 "")) (delete-file (, file2))) | |
233 )) | |
234 startup-hooks)) | |
235 (ediff-buffers buf1 buf2 startup-hooks 'ediff-revision))) | |
236 | |
237 ;; This function is the standard Ediff's interface to pcl-cvs. | |
238 ;; Works like with other interfaces: runs ediff on versions of the file in the | |
239 ;; current buffer. | |
240 (defun pcl-cvs-ediff-merge-internal (rev1 rev2 ancestor-rev | |
241 &optional startup-hooks) | |
242 ;; Ediff-merge appropriate revisions of the selected file. | |
243 ;; If REV1 is "" then use the latest revision. | |
244 ;; If REV2 is "" then merge current buffer's file with REV1. | |
245 ;; If ANCESTOR-REV is "" then use current buffer's file as ancestor. | |
246 ;; If ANCESTOR-REV is nil, then merge without the ancestor. | |
247 (let ((orig-buf (current-buffer)) | |
248 orig-file-name buf1 buf2 ancestor-buf) | |
249 | |
250 (or (setq orig-file-name (buffer-file-name (current-buffer))) | |
251 (error "Current buffer is not visiting any file")) | |
252 (if (string= rev1 "") (setq rev1 nil)) ; latest revision | |
253 | |
254 (setq buf1 (ediff-pcl-cvs-view-revision orig-file-name rev1)) | |
255 (setq buf2 (if (string= rev2 "") | |
256 orig-buf | |
257 (ediff-pcl-cvs-view-revision orig-file-name rev2))) | |
258 (if (stringp ancestor-rev) | |
259 (setq ancestor-buf | |
260 (if (string= ancestor-rev "") | |
261 orig-buf | |
262 (ediff-pcl-cvs-view-revision orig-file-name ancestor-rev)))) | |
263 | |
264 (setq startup-hooks | |
265 (cons | |
266 (` (lambda () | |
267 (delete-file (, (buffer-file-name buf1))) | |
268 (or (, (string= rev2 "")) | |
269 (delete-file (, (buffer-file-name buf2)))) | |
270 (or (, (string= ancestor-rev "")) | |
271 (, (not ancestor-rev)) | |
272 (delete-file (, (buffer-file-name ancestor-buf)))) | |
273 )) | |
274 startup-hooks)) | |
275 | |
276 (if ancestor-buf | |
277 (ediff-merge-buffers-with-ancestor | |
278 buf1 buf2 ancestor-buf startup-hooks | |
279 'ediff-merge-revisions-with-ancestor) | |
280 (ediff-merge-buffers | |
281 buf1 buf2 startup-hooks 'ediff-merge-revisions)) | |
282 )) | |
283 | |
284 (defun ediff-pcl-cvs-view-revision (file rev) | |
285 ;; if rev = "", get the latest revision | |
286 (let ((temp-name (make-temp-name | |
287 (concat ediff-temp-file-prefix | |
288 "ediff_" rev)))) | |
289 (cvs-kill-buffer-visiting temp-name) | |
290 (if rev | |
291 (message "Retrieving revision %s..." rev) | |
292 (message "Retrieving latest revision...")) | |
293 (let ((res (call-process cvs-shell nil nil nil "-c" | |
294 (concat cvs-program " update -p " | |
295 (if rev | |
296 (concat "-r " rev " ") | |
297 "") | |
298 file | |
299 " > " temp-name)))) | |
300 (if (and res (not (and (integerp res) (zerop res)))) | |
301 (error "Failed to retrieve revision: %s" res)) | |
302 | |
303 (if rev | |
304 (message "Retrieving revision %s... Done." rev) | |
305 (message "Retrieving latest revision... Done.")) | |
306 (find-file-noselect temp-name)))) | |
307 | |
308 | |
309 (defun cvs-run-ediff-on-file-descriptor (tin) | |
310 ;; This is a replacement for cvs-emerge-mode | |
311 ;; Run after cvs-update. | |
312 ;; Ediff-merge appropriate revisions of the selected file. | |
313 (let* ((fileinfo (tin-cookie cvs-cookie-handle tin)) | |
314 (type (cvs-fileinfo->type fileinfo)) | |
315 (tmp-file | |
316 (cvs-retrieve-revision-to-tmpfile fileinfo)) | |
317 ancestor-file) | |
318 | |
319 (or (memq type '(MERGED CONFLICT MODIFIED)) | |
320 (error | |
321 "Can only merge `Modified', `Merged' or `Conflict' files")) | |
322 | |
323 (cond ((memq type '(MERGED CONFLICT)) | |
324 (setq ancestor-file | |
325 (cvs-retrieve-revision-to-tmpfile | |
326 fileinfo | |
327 ;; revision | |
328 (cvs-fileinfo->base-revision fileinfo))) | |
329 (ediff-merge-buffers-with-ancestor | |
330 (find-file-noselect tmp-file) | |
331 (find-file-noselect (cvs-fileinfo->backup-file fileinfo)) | |
332 (find-file-noselect ancestor-file) | |
333 nil ; startup-hooks | |
334 'ediff-merge-revisions-with-ancestor)) | |
335 ((eq type 'MODIFIED) | |
336 (ediff-merge-buffers | |
337 (find-file-noselect tmp-file) | |
338 (find-file-noselect (cvs-fileinfo->full-path fileinfo)) | |
339 nil ; startup-hooks | |
340 'ediff-merge-revisions))) | |
341 (if (stringp tmp-file) (delete-file tmp-file)) | |
342 (if (stringp ancestor-file) (delete-file ancestor-file)))) | |
343 | |
344 ;;; Local Variables: | |
345 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun) | |
346 ;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1) | |
347 ;;; End: | |
348 | |
349 (provide 'ediff-vers) | |
350 | |
351 ;;; ediff-vers.el ends here |