1 ;;; ediff-vers.el --- version control interface to Ediff
3 ;; Copyright (C) 1995, 1996, 1997, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
8 ;; This file is part of GNU Emacs.
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 3, or (at your option)
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.
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
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
30 (defvar rcs-default-co-switches
)
34 (defvar cvs-cookie-handle
)
35 (defvar ediff-temp-file-prefix
)
40 ;; for compatibility with current stable version of xemacs
42 ;;(require 'pcvs nil 'noerror)
43 ;;(require 'rcs nil 'noerror)
52 (defcustom ediff-keep-tmp-versions nil
53 "*If t, do not delete temporary previous versions for the files on which
54 comparison or merge operations are being performed."
59 (defalias 'ediff-vc-revision-other-window
60 (if (fboundp 'vc-revision-other-window
)
61 'vc-revision-other-window
62 'vc-version-other-window
))
64 (defalias 'ediff-vc-working-revision
65 (if (fboundp 'vc-working-revision
)
67 'vc-workfile-version
))
72 (require 'vc-hooks
)) ;; for vc-call macro
75 (defun ediff-vc-latest-version (file)
76 "Return the version level of the latest version of FILE in repository."
77 (if (fboundp 'vc-latest-version
)
78 (vc-latest-version file
)
79 (or (vc-file-getprop file
'vc-latest-version
)
80 (cond ((vc-backend file
)
82 (vc-file-getprop file
'vc-latest-version
))
83 (t (error "File %s is not under version control" file
))))
87 (defun ediff-vc-internal (rev1 rev2
&optional startup-hooks
)
88 ;; Run Ediff on versions of the current buffer.
89 ;; If REV1 is "", use the latest version of the current buffer's file.
90 ;; If REV2 is "" then compare current buffer with REV1.
91 ;; If the current buffer is named `F', the version is named `F.~REV~'.
92 ;; If `F.~REV~' already exists, it is used instead of being re-created.
93 (let (file1 file2 rev1buf rev2buf
)
95 (setq rev1
(ediff-vc-latest-version (buffer-file-name))))
96 (save-window-excursion
98 (ediff-vc-revision-other-window rev1
)
99 (setq rev1buf
(current-buffer)
100 file1
(buffer-file-name)))
102 (or (string= rev2
"") ; use current buffer
103 (ediff-vc-revision-other-window rev2
))
104 (setq rev2buf
(current-buffer)
105 file2
(buffer-file-name)))
108 (ediff-delete-version-file ,file1
)
109 (or ,(string= rev2
"") (ediff-delete-version-file ,file2
)))
117 (defun rcs-ediff-view-revision (&optional rev
)
118 ;; View previous RCS revision of current file.
119 ;; With prefix argument, prompts for a revision name.
120 (interactive (list (if current-prefix-arg
121 (read-string "Revision: "))))
122 (let* ((filename (buffer-file-name (current-buffer)))
123 (switches (append '("-p")
124 (if rev
(list (concat "-r" rev
)) nil
)))
125 (buff (concat (file-name-nondirectory filename
) ".~" rev
"~")))
126 (message "Working ...")
127 (setq filename
(expand-file-name filename
))
128 (with-output-to-temp-buffer buff
129 (ediff-with-current-buffer standard-output
131 (let ((output-buffer (ediff-rcs-get-output-buffer filename buff
)))
132 (delete-windows-on output-buffer
)
134 (set-buffer output-buffer
)
135 (apply 'call-process
"co" nil t nil
136 ;; -q: quiet (no diagnostics)
137 (append switches rcs-default-co-switches
138 (list "-q" filename
)))))
142 (defun ediff-rcs-get-output-buffer (file name
)
143 ;; Get a buffer for RCS output for FILE, make it writable and clean it up.
144 ;; Optional NAME is name to use instead of `*RCS-output*'.
145 ;; This is a modified version from rcs.el v1.1. I use it here to make
146 ;; Ediff immune to changes in rcs.el
147 (let* ((default-major-mode 'fundamental-mode
) ; no frills!
148 (buf (get-buffer-create name
)))
151 (setq buffer-read-only nil
152 default-directory
(file-name-directory (expand-file-name file
)))
156 (defun ediff-rcs-internal (rev1 rev2
&optional startup-hooks
)
157 ;; Run Ediff on versions of the current buffer.
158 ;; If REV2 is "" then use current buffer.
159 (let (rev2buf rev1buf
)
160 (save-window-excursion
161 (setq rev2buf
(if (string= rev2
"")
163 (rcs-ediff-view-revision rev2
))
164 rev1buf
(rcs-ediff-view-revision rev1
)))
166 ;; rcs.el doesn't create temp version files, so we don't have to delete
167 ;; anything in startup hooks to ediff-buffers
168 (ediff-buffers rev1buf rev2buf startup-hooks
'ediff-revision
)
171 ;;; Merge with Version Control
173 (defun ediff-vc-merge-internal (rev1 rev2 ancestor-rev
174 &optional startup-hooks merge-buffer-file
)
175 ;; If ANCESTOR-REV non-nil, merge with ancestor
176 (let (buf1 buf2 ancestor-buf
)
177 (save-window-excursion
179 (ediff-vc-revision-other-window rev1
)
180 (setq buf1
(current-buffer)))
182 (or (string= rev2
"")
183 (ediff-vc-revision-other-window rev2
))
184 (setq buf2
(current-buffer)))
187 (if (string= ancestor-rev
"")
188 (setq ancestor-rev
(ediff-vc-working-revision buffer-file-name
)))
189 (ediff-vc-revision-other-window ancestor-rev
)
190 (setq ancestor-buf
(current-buffer))))
194 (ediff-delete-version-file ,(buffer-file-name buf1
))
195 (or ,(string= rev2
"")
196 (ediff-delete-version-file ,(buffer-file-name buf2
)))
197 (or ,(string= ancestor-rev
"")
199 (ediff-delete-version-file ,(buffer-file-name ancestor-buf
)))
203 (ediff-merge-buffers-with-ancestor
204 buf1 buf2 ancestor-buf
205 startup-hooks
'ediff-merge-revisions-with-ancestor merge-buffer-file
)
207 buf1 buf2 startup-hooks
'ediff-merge-revisions merge-buffer-file
))
210 (defun ediff-rcs-merge-internal (rev1 rev2 ancestor-rev
212 startup-hooks merge-buffer-file
)
213 ;; If ANCESTOR-REV non-nil, merge with ancestor
214 (let (buf1 buf2 ancestor-buf
)
215 (save-window-excursion
216 (setq buf1
(rcs-ediff-view-revision rev1
)
217 buf2
(if (string= rev2
"")
219 (rcs-ediff-view-revision rev2
))
220 ancestor-buf
(if ancestor-rev
221 (if (string= ancestor-rev
"")
223 (rcs-ediff-view-revision ancestor-rev
)))))
224 ;; rcs.el doesn't create temp version files, so we don't have to delete
225 ;; anything in startup hooks to ediff-buffers
227 (ediff-merge-buffers-with-ancestor
228 buf1 buf2 ancestor-buf
229 startup-hooks
'ediff-merge-revisions-with-ancestor merge-buffer-file
)
231 buf1 buf2 startup-hooks
'ediff-merge-revisions merge-buffer-file
))))
234 ;; delete version file on exit unless ediff-keep-tmp-versions is true
235 (defun ediff-delete-version-file (file)
236 (or ediff-keep-tmp-versions
(delete-file file
)))
239 (provide 'ediff-vers
)
243 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
244 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
245 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
248 ;; arch-tag: bbb34f0c-2a90-426a-a77a-c75f479ebbbf
249 ;;; ediff-vers.el ends here