Commit | Line | Data |
---|---|---|
8122a6da MK |
1 | ;;; ediff-vers.el --- version control interface to Ediff |
2 | ||
0d30b337 | 3 | ;; Copyright (C) 1995, 1996, 1997, 2002, 2003, 2004, |
aaef169d | 4 | ;; 2005, 2006 Free Software Foundation, Inc. |
8122a6da | 5 | |
50a07e18 | 6 | ;; Author: Michael Kifer <kifer@cs.stonybrook.edu> |
8122a6da MK |
7 | |
8 | ;; This file is part of GNU Emacs. | |
9 | ||
10 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 | ;; it under the terms of the GNU General Public License as published by | |
12 | ;; the Free Software Foundation; either version 2, or (at your option) | |
13 | ;; any later version. | |
14 | ||
15 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
21 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
086add15 LK |
22 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 | ;; Boston, MA 02110-1301, USA. | |
8122a6da | 24 | |
3afbc435 | 25 | ;;; Commentary: |
8122a6da MK |
26 | |
27 | ;;; Code: | |
bbe6126c MK |
28 | |
29 | ;; Compiler pacifier | |
30 | (defvar rcs-default-co-switches) | |
31 | (defvar sc-mode) | |
32 | (defvar cvs-shell) | |
33 | (defvar cvs-program) | |
34 | (defvar cvs-cookie-handle) | |
ddc90f39 | 35 | (defvar ediff-temp-file-prefix) |
bbe6126c | 36 | |
92c51e07 MK |
37 | (and noninteractive |
38 | (eval-when-compile | |
50a07e18 MK |
39 | (let ((load-path (cons (expand-file-name ".") load-path))) |
40 | (load "pcl-cvs" 'noerror) | |
41 | (load "rcs" 'noerror) | |
42 | ;; On 8+3 MS-DOS filesystems, generic-x.el is loaded | |
43 | ;; instead of (the missing) generic-sc.el. Since the | |
44 | ;; version of Emacs which supports MS-DOS doesn't have | |
45 | ;; generic-sc, we simply avoid loading it. | |
46 | (or (and (fboundp 'msdos-long-file-names) | |
47 | (not (msdos-long-file-names))) | |
48 | (load "generic-sc" 'noerror)) | |
49 | ;; (load "vc" 'noerror) ; this sometimes causes compiler error | |
50 | (or (featurep 'ediff-init) | |
51 | (load "ediff-init.el" nil nil 'nosuffix)) | |
52 | ))) | |
bbe6126c | 53 | ;; end pacifier |
71296446 | 54 | |
8122a6da | 55 | ;; VC.el support |
0831d50c MK |
56 | |
57 | (defun ediff-vc-latest-version (file) | |
58 | "Return the version level of the latest version of FILE in repository." | |
59 | (if (fboundp 'vc-latest-version) | |
60 | (vc-latest-version file) | |
61 | (or (vc-file-getprop file 'vc-latest-version) | |
62 | (cond ((vc-backend file) | |
63 | (vc-call state file) | |
64 | (vc-file-getprop file 'vc-latest-version)) | |
65 | (t (error "File %s is not under version control" file)))) | |
66 | )) | |
67 | ||
68 | ||
92c51e07 | 69 | (defun ediff-vc-internal (rev1 rev2 &optional startup-hooks) |
0831d50c MK |
70 | ;; Run Ediff on versions of the current buffer. |
71 | ;; If REV1 is "", use the latest version of the current buffer's file. | |
72 | ;; If REV2 is "" then compare current buffer with REV1. | |
73 | ;; If the current buffer is named `F', the version is named `F.~REV~'. | |
74 | ;; If `F.~REV~' already exists, it is used instead of being re-created. | |
8122a6da | 75 | (let (file1 file2 rev1buf rev2buf) |
71296446 | 76 | (if (string= rev1 "") |
0831d50c | 77 | (setq rev1 (ediff-vc-latest-version (buffer-file-name)))) |
657f9cb8 MK |
78 | (save-window-excursion |
79 | (save-excursion | |
80 | (vc-version-other-window rev1) | |
81 | (setq rev1buf (current-buffer) | |
82 | file1 (buffer-file-name))) | |
83 | (save-excursion | |
84 | (or (string= rev2 "") ; use current buffer | |
85 | (vc-version-other-window rev2)) | |
86 | (setq rev2buf (current-buffer) | |
87 | file2 (buffer-file-name))) | |
88 | (setq startup-hooks | |
89 | (cons `(lambda () | |
90 | (delete-file ,file1) | |
91 | (or ,(string= rev2 "") (delete-file ,file2))) | |
92 | startup-hooks))) | |
8122a6da MK |
93 | (ediff-buffers |
94 | rev1buf rev2buf | |
95 | startup-hooks | |
96 | 'ediff-revision))) | |
71296446 | 97 | |
8122a6da MK |
98 | ;; RCS.el support |
99 | (defun rcs-ediff-view-revision (&optional rev) | |
100 | ;; View previous RCS revision of current file. | |
101 | ;; With prefix argument, prompts for a revision name. | |
71296446 | 102 | (interactive (list (if current-prefix-arg |
8122a6da MK |
103 | (read-string "Revision: ")))) |
104 | (let* ((filename (buffer-file-name (current-buffer))) | |
105 | (switches (append '("-p") | |
106 | (if rev (list (concat "-r" rev)) nil))) | |
107 | (buff (concat (file-name-nondirectory filename) ".~" rev "~"))) | |
108 | (message "Working ...") | |
109 | (setq filename (expand-file-name filename)) | |
110 | (with-output-to-temp-buffer buff | |
7de0717c DL |
111 | (ediff-with-current-buffer standard-output |
112 | (fundamental-mode)) | |
8122a6da MK |
113 | (let ((output-buffer (ediff-rcs-get-output-buffer filename buff))) |
114 | (delete-windows-on output-buffer) | |
115 | (save-excursion | |
116 | (set-buffer output-buffer) | |
117 | (apply 'call-process "co" nil t nil | |
118 | ;; -q: quiet (no diagnostics) | |
119 | (append switches rcs-default-co-switches | |
71296446 | 120 | (list "-q" filename))))) |
8122a6da | 121 | (message "") |
71296446 JB |
122 | buff))) |
123 | ||
8122a6da MK |
124 | (defun ediff-rcs-get-output-buffer (file name) |
125 | ;; Get a buffer for RCS output for FILE, make it writable and clean it up. | |
126 | ;; Optional NAME is name to use instead of `*RCS-output*'. | |
3af0304a | 127 | ;; This is a modified version from rcs.el v1.1. I use it here to make |
8122a6da MK |
128 | ;; Ediff immune to changes in rcs.el |
129 | (let* ((default-major-mode 'fundamental-mode) ; no frills! | |
130 | (buf (get-buffer-create name))) | |
131 | (save-excursion | |
132 | (set-buffer buf) | |
133 | (setq buffer-read-only nil | |
134 | default-directory (file-name-directory (expand-file-name file))) | |
135 | (erase-buffer)) | |
136 | buf)) | |
137 | ||
92c51e07 | 138 | (defun ediff-rcs-internal (rev1 rev2 &optional startup-hooks) |
8122a6da MK |
139 | ;; Run Ediff on versions of the current buffer. |
140 | ;; If REV2 is "" then use current buffer. | |
657f9cb8 MK |
141 | (let (rev2buf rev1buf) |
142 | (save-window-excursion | |
143 | (setq rev2buf (if (string= rev2 "") | |
144 | (current-buffer) | |
145 | (rcs-ediff-view-revision rev2)) | |
146 | rev1buf (rcs-ediff-view-revision rev1))) | |
71296446 | 147 | |
8122a6da MK |
148 | ;; rcs.el doesn't create temp version files, so we don't have to delete |
149 | ;; anything in startup hooks to ediff-buffers | |
150 | (ediff-buffers rev1buf rev2buf startup-hooks 'ediff-revision) | |
151 | )) | |
152 | ||
153 | ||
154 | ;; GENERIC-SC.el support | |
155 | ||
156 | (defun generic-sc-get-latest-rev () | |
157 | (cond ((eq sc-mode 'CCASE) | |
158 | (eval "main/LATEST")) | |
159 | (t (eval "")))) | |
160 | ||
92c51e07 | 161 | (defun ediff-generic-sc-internal (rev1 rev2 &optional startup-hooks) |
8122a6da MK |
162 | ;; Run Ediff on versions of the current buffer. |
163 | ;; If REV2 is "" then compare current buffer with REV1. | |
164 | ;; If the current buffer is named `F', the version is named `F.~REV~'. | |
165 | ;; If `F.~REV~' already exists, it is used instead of being re-created. | |
166 | (let (rev1buf rev2buf) | |
167 | (save-excursion | |
168 | (if (or (not rev1) (string= rev1 "")) | |
169 | (setq rev1 (generic-sc-get-latest-rev))) | |
170 | (sc-visit-previous-revision rev1) | |
171 | (setq rev1buf (current-buffer))) | |
172 | (save-excursion | |
173 | (or (string= rev2 "") ; use current buffer | |
174 | (sc-visit-previous-revision rev2)) | |
175 | (setq rev2buf (current-buffer))) | |
176 | (ediff-buffers rev1buf rev2buf startup-hooks 'ediff-revision))) | |
177 | ||
178 | ||
179 | ;;; Merge with Version Control | |
180 | ||
71296446 | 181 | (defun ediff-vc-merge-internal (rev1 rev2 ancestor-rev |
328b4b70 | 182 | &optional startup-hooks merge-buffer-file) |
8122a6da MK |
183 | ;; If ANCESTOR-REV non-nil, merge with ancestor |
184 | (let (buf1 buf2 ancestor-buf) | |
657f9cb8 MK |
185 | (save-window-excursion |
186 | (save-excursion | |
187 | (vc-version-other-window rev1) | |
188 | (setq buf1 (current-buffer))) | |
189 | (save-excursion | |
190 | (or (string= rev2 "") | |
191 | (vc-version-other-window rev2)) | |
192 | (setq buf2 (current-buffer))) | |
193 | (if ancestor-rev | |
194 | (save-excursion | |
195 | (if (string= ancestor-rev "") | |
196 | (setq ancestor-rev (vc-workfile-version buffer-file-name))) | |
197 | (vc-version-other-window ancestor-rev) | |
198 | (setq ancestor-buf (current-buffer)))) | |
71296446 JB |
199 | (setq startup-hooks |
200 | (cons | |
201 | `(lambda () | |
657f9cb8 MK |
202 | (delete-file ,(buffer-file-name buf1)) |
203 | (or ,(string= rev2 "") | |
204 | (delete-file ,(buffer-file-name buf2))) | |
205 | (or ,(string= ancestor-rev "") | |
206 | ,(not ancestor-rev) | |
207 | (delete-file ,(buffer-file-name ancestor-buf))) | |
208 | ) | |
209 | startup-hooks))) | |
8122a6da MK |
210 | (if ancestor-rev |
211 | (ediff-merge-buffers-with-ancestor | |
212 | buf1 buf2 ancestor-buf | |
328b4b70 MK |
213 | startup-hooks 'ediff-merge-revisions-with-ancestor merge-buffer-file) |
214 | (ediff-merge-buffers | |
215 | buf1 buf2 startup-hooks 'ediff-merge-revisions merge-buffer-file)) | |
8122a6da MK |
216 | )) |
217 | ||
92c51e07 | 218 | (defun ediff-rcs-merge-internal (rev1 rev2 ancestor-rev |
328b4b70 MK |
219 | &optional |
220 | startup-hooks merge-buffer-file) | |
8122a6da MK |
221 | ;; If ANCESTOR-REV non-nil, merge with ancestor |
222 | (let (buf1 buf2 ancestor-buf) | |
657f9cb8 MK |
223 | (save-window-excursion |
224 | (setq buf1 (rcs-ediff-view-revision rev1) | |
225 | buf2 (if (string= rev2 "") | |
226 | (current-buffer) | |
227 | (rcs-ediff-view-revision rev2)) | |
228 | ancestor-buf (if ancestor-rev | |
229 | (if (string= ancestor-rev "") | |
230 | (current-buffer) | |
231 | (rcs-ediff-view-revision ancestor-rev))))) | |
8122a6da MK |
232 | ;; rcs.el doesn't create temp version files, so we don't have to delete |
233 | ;; anything in startup hooks to ediff-buffers | |
234 | (if ancestor-rev | |
235 | (ediff-merge-buffers-with-ancestor | |
236 | buf1 buf2 ancestor-buf | |
328b4b70 MK |
237 | startup-hooks 'ediff-merge-revisions-with-ancestor merge-buffer-file) |
238 | (ediff-merge-buffers | |
239 | buf1 buf2 startup-hooks 'ediff-merge-revisions merge-buffer-file)))) | |
8122a6da | 240 | |
92c51e07 | 241 | (defun ediff-generic-sc-merge-internal (rev1 rev2 ancestor-rev |
328b4b70 MK |
242 | &optional |
243 | startup-hooks merge-buffer-file) | |
8122a6da MK |
244 | ;; If ANCESTOR-REV non-nil, merge with ancestor |
245 | (let (buf1 buf2 ancestor-buf) | |
246 | (save-excursion | |
247 | (if (string= rev1 "") | |
248 | (setq rev1 (generic-sc-get-latest-rev))) | |
249 | (sc-visit-previous-revision rev1) | |
250 | (setq buf1 (current-buffer))) | |
251 | (save-excursion | |
252 | (or (string= rev2 "") | |
253 | (sc-visit-previous-revision rev2)) | |
254 | (setq buf2 (current-buffer))) | |
255 | (if ancestor-rev | |
256 | (save-excursion | |
257 | (or (string= ancestor-rev "") | |
258 | (sc-visit-previous-revision ancestor-rev)) | |
259 | (setq ancestor-buf (current-buffer)))) | |
260 | (if ancestor-rev | |
261 | (ediff-merge-buffers-with-ancestor | |
262 | buf1 buf2 ancestor-buf | |
328b4b70 MK |
263 | startup-hooks 'ediff-merge-revisions-with-ancestor merge-buffer-file) |
264 | (ediff-merge-buffers | |
265 | buf1 buf2 startup-hooks 'ediff-merge-revisions merge-buffer-file)))) | |
8122a6da MK |
266 | |
267 | ||
268 | ;; PCL-CVS.el support | |
269 | ||
50a07e18 | 270 | ;; MK: Check. This function doesn't seem to be used any more by pcvs or pcl-cvs |
8122a6da MK |
271 | (defun cvs-run-ediff-on-file-descriptor (tin) |
272 | ;; This is a replacement for cvs-emerge-mode | |
328b4b70 | 273 | ;; Runs after cvs-update. |
8122a6da MK |
274 | ;; Ediff-merge appropriate revisions of the selected file. |
275 | (let* ((fileinfo (tin-cookie cvs-cookie-handle tin)) | |
276 | (type (cvs-fileinfo->type fileinfo)) | |
277 | (tmp-file | |
278 | (cvs-retrieve-revision-to-tmpfile fileinfo)) | |
c004db97 | 279 | (default-directory |
2eb4bdca | 280 | (file-name-as-directory (cvs-fileinfo->dir fileinfo))) |
8122a6da | 281 | ancestor-file) |
71296446 | 282 | |
8122a6da MK |
283 | (or (memq type '(MERGED CONFLICT MODIFIED)) |
284 | (error | |
285 | "Can only merge `Modified', `Merged' or `Conflict' files")) | |
71296446 | 286 | |
8122a6da MK |
287 | (cond ((memq type '(MERGED CONFLICT)) |
288 | (setq ancestor-file | |
289 | (cvs-retrieve-revision-to-tmpfile | |
290 | fileinfo | |
291 | ;; revision | |
292 | (cvs-fileinfo->base-revision fileinfo))) | |
293 | (ediff-merge-buffers-with-ancestor | |
294 | (find-file-noselect tmp-file) | |
295 | (find-file-noselect (cvs-fileinfo->backup-file fileinfo)) | |
296 | (find-file-noselect ancestor-file) | |
297 | nil ; startup-hooks | |
298 | 'ediff-merge-revisions-with-ancestor)) | |
299 | ((eq type 'MODIFIED) | |
c004db97 | 300 | (ediff-buffers |
8122a6da | 301 | (find-file-noselect tmp-file) |
15c77b9e MK |
302 | (if (featurep 'xemacs) |
303 | ;; XEmacs doesn't seem to have cvs-fileinfo->full-name | |
304 | (find-file-noselect (cvs-fileinfo->full-path fileinfo)) | |
305 | (find-file-noselect (cvs-fileinfo->full-name fileinfo))) | |
8122a6da | 306 | nil ; startup-hooks |
c004db97 | 307 | 'ediff-revisions))) |
8122a6da MK |
308 | (if (stringp tmp-file) (delete-file tmp-file)) |
309 | (if (stringp ancestor-file) (delete-file ancestor-file)))) | |
310 | ||
8ea74b0e MK |
311 | |
312 | (provide 'ediff-vers) | |
313 | ||
b6178721 | 314 | |
8122a6da MK |
315 | ;;; Local Variables: |
316 | ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun) | |
e756eb9f MK |
317 | ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1) |
318 | ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body)) | |
8122a6da MK |
319 | ;;; End: |
320 | ||
ab5796a9 | 321 | ;;; arch-tag: bbb34f0c-2a90-426a-a77a-c75f479ebbbf |
8122a6da | 322 | ;;; ediff-vers.el ends here |