1 ;;; ediff-vers.el --- version control interface to Ediff
3 ;;; Copyright (C) 1995, 1996 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
7 ;; This file is part of GNU Emacs.
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)
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.
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.
28 (defvar rcs-default-co-switches
)
32 (defvar cvs-cookie-handle
)
36 (load "pcl-cvs" 'noerror
)
38 (load "generic-sc" 'noerror
)
39 (load "vc" 'noerror
)))
43 (defun ediff-vc-internal (rev1 rev2
&optional startup-hooks
)
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
)
50 (vc-version-other-window rev1
)
51 (setq rev1buf
(current-buffer)
52 file1
(buffer-file-name)))
54 (or (string= rev2
"") ; use current buffer
55 (vc-version-other-window rev2
))
56 (setq rev2buf
(current-buffer)
57 file2
(buffer-file-name)))
60 (delete-file (, file1
))
61 (or (, (string= rev2
"")) (delete-file (, file2
)))
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
)
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
)))))
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
)))
102 (setq buffer-read-only nil
103 default-directory
(file-name-directory (expand-file-name file
)))
107 (defun ediff-rcs-internal (rev1 rev2
&optional startup-hooks
)
108 ;; Run Ediff on versions of the current buffer.
109 ;; If REV2 is "" then use current buffer.
110 (let ((rev2buf (if (string= rev2
"")
112 (rcs-ediff-view-revision rev2
)))
113 (rev1buf (rcs-ediff-view-revision rev1
)))
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
)
121 ;; GENERIC-SC.el support
123 (defun generic-sc-get-latest-rev ()
124 (cond ((eq sc-mode
'CCASE
)
125 (eval "main/LATEST"))
128 (defun ediff-generic-sc-internal (rev1 rev2
&optional startup-hooks
)
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
)
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)))
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
)))
146 ;;; Merge with Version Control
148 (defun ediff-vc-merge-internal (rev1 rev2 ancestor-rev
&optional startup-hooks
)
149 ;; If ANCESTOR-REV non-nil, merge with ancestor
150 (let (buf1 buf2 ancestor-buf
)
152 (vc-version-other-window rev1
)
153 (setq buf1
(current-buffer)))
155 (or (string= rev2
"")
156 (vc-version-other-window rev2
))
157 (setq buf2
(current-buffer)))
160 (or (string= ancestor-rev
"")
161 (vc-version-other-window ancestor-rev
))
162 (setq ancestor-buf
(current-buffer))))
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
))))
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
))
181 (defun ediff-rcs-merge-internal (rev1 rev2 ancestor-rev
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
"")
188 (rcs-ediff-view-revision rev2
))
189 ancestor-buf
(if ancestor-rev
190 (if (string= ancestor-rev
"")
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
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
))))
201 (defun ediff-generic-sc-merge-internal (rev1 rev2 ancestor-rev
202 &optional startup-hooks
)
203 ;; If ANCESTOR-REV non-nil, merge with ancestor
204 (let (buf1 buf2 ancestor-buf
)
206 (if (string= rev1
"")
207 (setq rev1
(generic-sc-get-latest-rev)))
208 (sc-visit-previous-revision rev1
)
209 (setq buf1
(current-buffer)))
211 (or (string= rev2
"")
212 (sc-visit-previous-revision rev2
))
213 (setq buf2
(current-buffer)))
216 (or (string= ancestor-rev
"")
217 (sc-visit-previous-revision ancestor-rev
))
218 (setq ancestor-buf
(current-buffer))))
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
))))
226 ;; PCL-CVS.el support
228 (defun ediff-pcl-cvs-internal (rev1 rev2
&optional startup-hooks
)
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
)
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
"")
241 (ediff-pcl-cvs-view-revision orig-file-name rev2
))
242 file1
(buffer-file-name buf1
)
243 file2
(buffer-file-name buf2
))
246 (delete-file (, file1
))
247 (or (, (string= rev2
"")) (delete-file (, file2
)))
250 (ediff-buffers buf1 buf2 startup-hooks
'ediff-revision
)))
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
255 (defun ediff-pcl-cvs-merge-internal (rev1 rev2 ancestor-rev
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
)
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
269 (setq buf1
(ediff-pcl-cvs-view-revision orig-file-name rev1
))
270 (setq buf2
(if (string= rev2
"")
272 (ediff-pcl-cvs-view-revision orig-file-name rev2
)))
273 (if (stringp ancestor-rev
)
275 (if (string= ancestor-rev
"")
277 (ediff-pcl-cvs-view-revision orig-file-name ancestor-rev
))))
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
))))
292 (ediff-merge-buffers-with-ancestor
293 buf1 buf2 ancestor-buf startup-hooks
294 'ediff-merge-revisions-with-ancestor
)
296 buf1 buf2 startup-hooks
'ediff-merge-revisions
))
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
304 (cvs-kill-buffer-visiting temp-name
)
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 "
311 (concat "-r " rev
" ")
315 (if (and res
(not (and (integerp res
) (zerop res
))))
316 (error "Failed to retrieve revision: %s" res
))
319 (message "Retrieving revision %s... Done." rev
)
320 (message "Retrieving latest revision... Done."))
321 (find-file-noselect temp-name
))))
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
))
331 (cvs-retrieve-revision-to-tmpfile fileinfo
))
334 (or (memq type
'(MERGED CONFLICT MODIFIED
))
336 "Can only merge `Modified', `Merged' or `Conflict' files"))
338 (cond ((memq type
'(MERGED CONFLICT
))
340 (cvs-retrieve-revision-to-tmpfile
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
)
349 'ediff-merge-revisions-with-ancestor
))
352 (find-file-noselect tmp-file
)
353 (find-file-noselect (cvs-fileinfo->full-path fileinfo
))
355 'ediff-merge-revisions
)))
356 (if (stringp tmp-file
) (delete-file tmp-file
))
357 (if (stringp ancestor-file
) (delete-file ancestor-file
))))
360 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
361 ;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1)
362 ;;; eval: (put 'ediff-eval-in-buffer 'edebug-form-spec '(form body))
365 (provide 'ediff-vers
)
367 ;;; ediff-vers.el ends here