1 ;;; ediff-vers.el --- version control interface to Ediff
3 ;;; Copyright (C) 1995, 1996, 1997 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.
29 (defvar rcs-default-co-switches
)
33 (defvar cvs-cookie-handle
)
34 (defvar ediff-temp-file-prefix
)
38 (load "pcl-cvs" 'noerror
)
40 ;; On 8+3 MS-DOS filesystems, generic-x.el is loaded
41 ;; instead of (the missing) generic-sc.el. Since the
42 ;; version of Emacs which supports MS-DOS doesn't have
43 ;; generic-sc, we simply avoid loading it.
44 (or (and (fboundp 'msdos-long-file-names
)
45 (not (msdos-long-file-names)))
46 (load "generic-sc" 'noerror
))
47 (load "vc" 'noerror
)))
51 (defun ediff-vc-internal (rev1 rev2
&optional startup-hooks
)
52 ;; Run Ediff on versions of the current buffer.
53 ;; If REV2 is "" then compare current buffer with REV1.
54 ;; If the current buffer is named `F', the version is named `F.~REV~'.
55 ;; If `F.~REV~' already exists, it is used instead of being re-created.
56 (let (file1 file2 rev1buf rev2buf
)
57 (save-window-excursion
59 (vc-version-other-window rev1
)
60 (setq rev1buf
(current-buffer)
61 file1
(buffer-file-name)))
63 (or (string= rev2
"") ; use current buffer
64 (vc-version-other-window rev2
))
65 (setq rev2buf
(current-buffer)
66 file2
(buffer-file-name)))
70 (or ,(string= rev2
"") (delete-file ,file2
)))
78 (defun rcs-ediff-view-revision (&optional rev
)
79 ;; View previous RCS revision of current file.
80 ;; With prefix argument, prompts for a revision name.
81 (interactive (list (if current-prefix-arg
82 (read-string "Revision: "))))
83 (let* ((filename (buffer-file-name (current-buffer)))
84 (switches (append '("-p")
85 (if rev
(list (concat "-r" rev
)) nil
)))
86 (buff (concat (file-name-nondirectory filename
) ".~" rev
"~")))
87 (message "Working ...")
88 (setq filename
(expand-file-name filename
))
89 (with-output-to-temp-buffer buff
90 (ediff-with-current-buffer standard-output
92 (let ((output-buffer (ediff-rcs-get-output-buffer filename buff
)))
93 (delete-windows-on output-buffer
)
95 (set-buffer output-buffer
)
96 (apply 'call-process
"co" nil t nil
97 ;; -q: quiet (no diagnostics)
98 (append switches rcs-default-co-switches
99 (list "-q" filename
)))))
103 (defun ediff-rcs-get-output-buffer (file name
)
104 ;; Get a buffer for RCS output for FILE, make it writable and clean it up.
105 ;; Optional NAME is name to use instead of `*RCS-output*'.
106 ;; This is a modified version from rcs.el v1.1. I use it here to make
107 ;; Ediff immune to changes in rcs.el
108 (let* ((default-major-mode 'fundamental-mode
) ; no frills!
109 (buf (get-buffer-create name
)))
112 (setq buffer-read-only nil
113 default-directory
(file-name-directory (expand-file-name file
)))
117 (defun ediff-rcs-internal (rev1 rev2
&optional startup-hooks
)
118 ;; Run Ediff on versions of the current buffer.
119 ;; If REV2 is "" then use current buffer.
120 (let (rev2buf rev1buf
)
121 (save-window-excursion
122 (setq rev2buf
(if (string= rev2
"")
124 (rcs-ediff-view-revision rev2
))
125 rev1buf
(rcs-ediff-view-revision rev1
)))
127 ;; rcs.el doesn't create temp version files, so we don't have to delete
128 ;; anything in startup hooks to ediff-buffers
129 (ediff-buffers rev1buf rev2buf startup-hooks
'ediff-revision
)
133 ;; GENERIC-SC.el support
135 (defun generic-sc-get-latest-rev ()
136 (cond ((eq sc-mode
'CCASE
)
137 (eval "main/LATEST"))
140 (defun ediff-generic-sc-internal (rev1 rev2
&optional startup-hooks
)
141 ;; Run Ediff on versions of the current buffer.
142 ;; If REV2 is "" then compare current buffer with REV1.
143 ;; If the current buffer is named `F', the version is named `F.~REV~'.
144 ;; If `F.~REV~' already exists, it is used instead of being re-created.
145 (let (rev1buf rev2buf
)
147 (if (or (not rev1
) (string= rev1
""))
148 (setq rev1
(generic-sc-get-latest-rev)))
149 (sc-visit-previous-revision rev1
)
150 (setq rev1buf
(current-buffer)))
152 (or (string= rev2
"") ; use current buffer
153 (sc-visit-previous-revision rev2
))
154 (setq rev2buf
(current-buffer)))
155 (ediff-buffers rev1buf rev2buf startup-hooks
'ediff-revision
)))
158 ;;; Merge with Version Control
160 (defun ediff-vc-merge-internal (rev1 rev2 ancestor-rev
161 &optional startup-hooks merge-buffer-file
)
162 ;; If ANCESTOR-REV non-nil, merge with ancestor
163 (let (buf1 buf2 ancestor-buf
)
164 (save-window-excursion
166 (vc-version-other-window rev1
)
167 (setq buf1
(current-buffer)))
169 (or (string= rev2
"")
170 (vc-version-other-window rev2
))
171 (setq buf2
(current-buffer)))
174 (if (string= ancestor-rev
"")
175 (setq ancestor-rev
(vc-workfile-version buffer-file-name
)))
176 (vc-version-other-window ancestor-rev
)
177 (setq ancestor-buf
(current-buffer))))
181 (delete-file ,(buffer-file-name buf1
))
182 (or ,(string= rev2
"")
183 (delete-file ,(buffer-file-name buf2
)))
184 (or ,(string= ancestor-rev
"")
186 (delete-file ,(buffer-file-name ancestor-buf
)))
190 (ediff-merge-buffers-with-ancestor
191 buf1 buf2 ancestor-buf
192 startup-hooks
'ediff-merge-revisions-with-ancestor merge-buffer-file
)
194 buf1 buf2 startup-hooks
'ediff-merge-revisions merge-buffer-file
))
197 (defun ediff-rcs-merge-internal (rev1 rev2 ancestor-rev
199 startup-hooks merge-buffer-file
)
200 ;; If ANCESTOR-REV non-nil, merge with ancestor
201 (let (buf1 buf2 ancestor-buf
)
202 (save-window-excursion
203 (setq buf1
(rcs-ediff-view-revision rev1
)
204 buf2
(if (string= rev2
"")
206 (rcs-ediff-view-revision rev2
))
207 ancestor-buf
(if ancestor-rev
208 (if (string= ancestor-rev
"")
210 (rcs-ediff-view-revision ancestor-rev
)))))
211 ;; rcs.el doesn't create temp version files, so we don't have to delete
212 ;; anything in startup hooks to ediff-buffers
214 (ediff-merge-buffers-with-ancestor
215 buf1 buf2 ancestor-buf
216 startup-hooks
'ediff-merge-revisions-with-ancestor merge-buffer-file
)
218 buf1 buf2 startup-hooks
'ediff-merge-revisions merge-buffer-file
))))
220 (defun ediff-generic-sc-merge-internal (rev1 rev2 ancestor-rev
222 startup-hooks merge-buffer-file
)
223 ;; If ANCESTOR-REV non-nil, merge with ancestor
224 (let (buf1 buf2 ancestor-buf
)
226 (if (string= rev1
"")
227 (setq rev1
(generic-sc-get-latest-rev)))
228 (sc-visit-previous-revision rev1
)
229 (setq buf1
(current-buffer)))
231 (or (string= rev2
"")
232 (sc-visit-previous-revision rev2
))
233 (setq buf2
(current-buffer)))
236 (or (string= ancestor-rev
"")
237 (sc-visit-previous-revision ancestor-rev
))
238 (setq ancestor-buf
(current-buffer))))
240 (ediff-merge-buffers-with-ancestor
241 buf1 buf2 ancestor-buf
242 startup-hooks
'ediff-merge-revisions-with-ancestor merge-buffer-file
)
244 buf1 buf2 startup-hooks
'ediff-merge-revisions merge-buffer-file
))))
247 ;; PCL-CVS.el support
250 (defun cvs-run-ediff-on-file-descriptor (tin)
251 ;; This is a replacement for cvs-emerge-mode
252 ;; Runs after cvs-update.
253 ;; Ediff-merge appropriate revisions of the selected file.
254 (let* ((fileinfo (tin-cookie cvs-cookie-handle tin
))
255 (type (cvs-fileinfo->type fileinfo
))
257 (cvs-retrieve-revision-to-tmpfile fileinfo
))
259 (file-name-as-directory (cvs-fileinfo->dir fileinfo
)))
262 (or (memq type
'(MERGED CONFLICT MODIFIED
))
264 "Can only merge `Modified', `Merged' or `Conflict' files"))
266 (cond ((memq type
'(MERGED CONFLICT
))
268 (cvs-retrieve-revision-to-tmpfile
271 (cvs-fileinfo->base-revision fileinfo
)))
272 (ediff-merge-buffers-with-ancestor
273 (find-file-noselect tmp-file
)
274 (find-file-noselect (cvs-fileinfo->backup-file fileinfo
))
275 (find-file-noselect ancestor-file
)
277 'ediff-merge-revisions-with-ancestor
))
280 (find-file-noselect tmp-file
)
281 (find-file-noselect (cvs-fileinfo->full-path fileinfo
))
284 (if (stringp tmp-file
) (delete-file tmp-file
))
285 (if (stringp ancestor-file
) (delete-file ancestor-file
))))
288 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
289 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
290 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
293 (provide 'ediff-vers
)
295 ;;; ediff-vers.el ends here