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
)
39 (let ((load-path (cons (expand-file-name ".") load-path
)))
40 (load "pcl-cvs" 'noerror
)
42 ;; (load "vc" 'noerror) ; this sometimes causes compiler error
43 (or (featurep 'ediff-init
)
44 (load "ediff-init.el" nil t
'nosuffix
))
48 (defcustom ediff-keep-tmp-versions nil
49 "*If t, do not delete temporary previous versions for the files on which
50 comparison or merge operations are being performed."
55 (defalias 'ediff-vc-revision-other-window
56 (if (fboundp 'vc-revision-other-window
)
57 'vc-revision-other-window
58 'vc-version-other-window
))
60 (defalias 'ediff-vc-working-revision
61 (if (fboundp 'vc-working-revision
)
63 'vc-workfile-version
))
68 (require 'vc-hooks
)) ;; for vc-call macro
71 (defun ediff-vc-latest-version (file)
72 "Return the version level of the latest version of FILE in repository."
73 (if (fboundp 'vc-latest-version
)
74 (vc-latest-version file
)
75 (or (vc-file-getprop file
'vc-latest-version
)
76 (cond ((vc-backend file
)
78 (vc-file-getprop file
'vc-latest-version
))
79 (t (error "File %s is not under version control" file
))))
83 (defun ediff-vc-internal (rev1 rev2
&optional startup-hooks
)
84 ;; Run Ediff on versions of the current buffer.
85 ;; If REV1 is "", use the latest version of the current buffer's file.
86 ;; If REV2 is "" then compare current buffer with REV1.
87 ;; If the current buffer is named `F', the version is named `F.~REV~'.
88 ;; If `F.~REV~' already exists, it is used instead of being re-created.
89 (let (file1 file2 rev1buf rev2buf
)
91 (setq rev1
(ediff-vc-latest-version (buffer-file-name))))
92 (save-window-excursion
94 (ediff-vc-revision-other-window rev1
)
95 (setq rev1buf
(current-buffer)
96 file1
(buffer-file-name)))
98 (or (string= rev2
"") ; use current buffer
99 (ediff-vc-revision-other-window rev2
))
100 (setq rev2buf
(current-buffer)
101 file2
(buffer-file-name)))
104 (ediff-delete-version-file ,file1
)
105 (or ,(string= rev2
"") (ediff-delete-version-file ,file2
)))
113 (defun rcs-ediff-view-revision (&optional rev
)
114 ;; View previous RCS revision of current file.
115 ;; With prefix argument, prompts for a revision name.
116 (interactive (list (if current-prefix-arg
117 (read-string "Revision: "))))
118 (let* ((filename (buffer-file-name (current-buffer)))
119 (switches (append '("-p")
120 (if rev
(list (concat "-r" rev
)) nil
)))
121 (buff (concat (file-name-nondirectory filename
) ".~" rev
"~")))
122 (message "Working ...")
123 (setq filename
(expand-file-name filename
))
124 (with-output-to-temp-buffer buff
125 (ediff-with-current-buffer standard-output
127 (let ((output-buffer (ediff-rcs-get-output-buffer filename buff
)))
128 (delete-windows-on output-buffer
)
130 (set-buffer output-buffer
)
131 (apply 'call-process
"co" nil t nil
132 ;; -q: quiet (no diagnostics)
133 (append switches rcs-default-co-switches
134 (list "-q" filename
)))))
138 (defun ediff-rcs-get-output-buffer (file name
)
139 ;; Get a buffer for RCS output for FILE, make it writable and clean it up.
140 ;; Optional NAME is name to use instead of `*RCS-output*'.
141 ;; This is a modified version from rcs.el v1.1. I use it here to make
142 ;; Ediff immune to changes in rcs.el
143 (let* ((default-major-mode 'fundamental-mode
) ; no frills!
144 (buf (get-buffer-create name
)))
147 (setq buffer-read-only nil
148 default-directory
(file-name-directory (expand-file-name file
)))
152 (defun ediff-rcs-internal (rev1 rev2
&optional startup-hooks
)
153 ;; Run Ediff on versions of the current buffer.
154 ;; If REV2 is "" then use current buffer.
155 (let (rev2buf rev1buf
)
156 (save-window-excursion
157 (setq rev2buf
(if (string= rev2
"")
159 (rcs-ediff-view-revision rev2
))
160 rev1buf
(rcs-ediff-view-revision rev1
)))
162 ;; rcs.el doesn't create temp version files, so we don't have to delete
163 ;; anything in startup hooks to ediff-buffers
164 (ediff-buffers rev1buf rev2buf startup-hooks
'ediff-revision
)
167 ;;; Merge with Version Control
169 (defun ediff-vc-merge-internal (rev1 rev2 ancestor-rev
170 &optional startup-hooks merge-buffer-file
)
171 ;; If ANCESTOR-REV non-nil, merge with ancestor
172 (let (buf1 buf2 ancestor-buf
)
173 (save-window-excursion
175 (ediff-vc-revision-other-window rev1
)
176 (setq buf1
(current-buffer)))
178 (or (string= rev2
"")
179 (ediff-vc-revision-other-window rev2
))
180 (setq buf2
(current-buffer)))
183 (if (string= ancestor-rev
"")
184 (setq ancestor-rev
(ediff-vc-working-revision buffer-file-name
)))
185 (ediff-vc-revision-other-window ancestor-rev
)
186 (setq ancestor-buf
(current-buffer))))
190 (ediff-delete-version-file ,(buffer-file-name buf1
))
191 (or ,(string= rev2
"")
192 (ediff-delete-version-file ,(buffer-file-name buf2
)))
193 (or ,(string= ancestor-rev
"")
195 (ediff-delete-version-file ,(buffer-file-name ancestor-buf
)))
199 (ediff-merge-buffers-with-ancestor
200 buf1 buf2 ancestor-buf
201 startup-hooks
'ediff-merge-revisions-with-ancestor merge-buffer-file
)
203 buf1 buf2 startup-hooks
'ediff-merge-revisions merge-buffer-file
))
206 (defun ediff-rcs-merge-internal (rev1 rev2 ancestor-rev
208 startup-hooks merge-buffer-file
)
209 ;; If ANCESTOR-REV non-nil, merge with ancestor
210 (let (buf1 buf2 ancestor-buf
)
211 (save-window-excursion
212 (setq buf1
(rcs-ediff-view-revision rev1
)
213 buf2
(if (string= rev2
"")
215 (rcs-ediff-view-revision rev2
))
216 ancestor-buf
(if ancestor-rev
217 (if (string= ancestor-rev
"")
219 (rcs-ediff-view-revision ancestor-rev
)))))
220 ;; rcs.el doesn't create temp version files, so we don't have to delete
221 ;; anything in startup hooks to ediff-buffers
223 (ediff-merge-buffers-with-ancestor
224 buf1 buf2 ancestor-buf
225 startup-hooks
'ediff-merge-revisions-with-ancestor merge-buffer-file
)
227 buf1 buf2 startup-hooks
'ediff-merge-revisions merge-buffer-file
))))
230 ;; delete version file on exit unless ediff-keep-tmp-versions is true
231 (defun ediff-delete-version-file (file)
232 (or ediff-keep-tmp-versions
(delete-file file
)))
235 (provide 'ediff-vers
)
239 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
240 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
241 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
244 ;;; arch-tag: bbb34f0c-2a90-426a-a77a-c75f479ebbbf
245 ;;; ediff-vers.el ends here