1 ;;; ediff-vers.el --- version control interface to Ediff
3 ;; Copyright (C) 1995, 1996, 1997, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 (defvar rcs-default-co-switches
)
34 ;; for compatibility with current stable version of xemacs
36 ;;(require 'pcvs nil 'noerror)
37 ;;(require 'rcs nil 'noerror)
46 (defcustom ediff-keep-tmp-versions nil
47 "If t, do not delete temporary previous versions for the files on which
48 comparison or merge operations are being performed."
53 (defalias 'ediff-vc-revision-other-window
54 (if (fboundp 'vc-revision-other-window
)
55 'vc-revision-other-window
56 'vc-version-other-window
))
58 (defalias 'ediff-vc-working-revision
59 (if (fboundp 'vc-working-revision
)
61 'vc-workfile-version
))
66 (require 'vc-hooks
)) ;; for vc-call macro
69 (defun ediff-vc-latest-version (file)
70 "Return the version level of the latest version of FILE in repository."
71 (if (fboundp 'vc-latest-version
)
72 (vc-latest-version file
)
73 (or (vc-file-getprop file
'vc-latest-revision
)
74 (cond ((vc-backend file
)
76 (vc-file-getprop file
'vc-latest-revision
))
77 (t (error "File %s is not under version control" file
))))
81 (defun ediff-vc-internal (rev1 rev2
&optional startup-hooks
)
82 ;; Run Ediff on versions of the current buffer.
83 ;; If REV1 is "", use the latest version of the current buffer's file.
84 ;; If REV2 is "" then compare current buffer with REV1.
85 ;; If the current buffer is named `F', the version is named `F.~REV~'.
86 ;; If `F.~REV~' already exists, it is used instead of being re-created.
87 (let (file1 file2 rev1buf rev2buf
)
89 (setq rev1
(ediff-vc-latest-version (buffer-file-name))))
90 (save-window-excursion
92 (ediff-vc-revision-other-window rev1
)
93 (setq rev1buf
(current-buffer)
94 file1
(buffer-file-name)))
96 (or (string= rev2
"") ; use current buffer
97 (ediff-vc-revision-other-window rev2
))
98 (setq rev2buf
(current-buffer)
99 file2
(buffer-file-name)))
102 (ediff-delete-version-file ,file1
)
103 (or ,(string= rev2
"") (ediff-delete-version-file ,file2
)))
111 (defun rcs-ediff-view-revision (&optional rev
)
112 ;; View previous RCS revision of current file.
113 ;; With prefix argument, prompts for a revision name.
114 (interactive (list (if current-prefix-arg
115 (read-string "Revision: "))))
116 (let* ((filename (buffer-file-name (current-buffer)))
117 (switches (append '("-p")
118 (if rev
(list (concat "-r" rev
)) nil
)))
119 (buff (concat (file-name-nondirectory filename
) ".~" rev
"~")))
120 (message "Working ...")
121 (setq filename
(expand-file-name filename
))
122 (with-output-to-temp-buffer buff
123 (ediff-with-current-buffer standard-output
125 (let ((output-buffer (ediff-rcs-get-output-buffer filename buff
)))
126 (delete-windows-on output-buffer
)
127 (with-current-buffer output-buffer
128 (apply 'call-process
"co" nil t nil
129 ;; -q: quiet (no diagnostics)
130 (append switches rcs-default-co-switches
131 (list "-q" filename
)))))
135 (defun ediff-rcs-get-output-buffer (file name
)
136 ;; Get a buffer for RCS output for FILE, make it writable and clean it up.
137 ;; Optional NAME is name to use instead of `*RCS-output*'.
138 ;; This is a modified version from rcs.el v1.1. I use it here to make
139 ;; Ediff immune to changes in rcs.el
140 (let ((buf (get-buffer-create name
)))
141 (with-current-buffer buf
142 (setq buffer-read-only nil
143 default-directory
(file-name-directory (expand-file-name file
)))
147 (defun ediff-rcs-internal (rev1 rev2
&optional startup-hooks
)
148 ;; Run Ediff on versions of the current buffer.
149 ;; If REV2 is "" then use current buffer.
150 (let (rev2buf rev1buf
)
151 (save-window-excursion
152 (setq rev2buf
(if (string= rev2
"")
154 (rcs-ediff-view-revision rev2
))
155 rev1buf
(rcs-ediff-view-revision rev1
)))
157 ;; rcs.el doesn't create temp version files, so we don't have to delete
158 ;; anything in startup hooks to ediff-buffers
159 (ediff-buffers rev1buf rev2buf startup-hooks
'ediff-revision
)
162 ;;; Merge with Version Control
164 (defun ediff-vc-merge-internal (rev1 rev2 ancestor-rev
165 &optional startup-hooks merge-buffer-file
)
166 ;; If ANCESTOR-REV non-nil, merge with ancestor
167 (let (buf1 buf2 ancestor-buf
)
168 (save-window-excursion
170 (ediff-vc-revision-other-window rev1
)
171 (setq buf1
(current-buffer)))
173 (or (string= rev2
"")
174 (ediff-vc-revision-other-window rev2
))
175 (setq buf2
(current-buffer)))
178 (if (string= ancestor-rev
"")
179 (setq ancestor-rev
(ediff-vc-working-revision buffer-file-name
)))
180 (ediff-vc-revision-other-window ancestor-rev
)
181 (setq ancestor-buf
(current-buffer))))
185 (ediff-delete-version-file ,(buffer-file-name buf1
))
186 (or ,(string= rev2
"")
187 (ediff-delete-version-file ,(buffer-file-name buf2
)))
188 (or ,(string= ancestor-rev
"")
190 (ediff-delete-version-file ,(buffer-file-name ancestor-buf
)))
194 (ediff-merge-buffers-with-ancestor
195 buf1 buf2 ancestor-buf
196 startup-hooks
'ediff-merge-revisions-with-ancestor merge-buffer-file
)
198 buf1 buf2 startup-hooks
'ediff-merge-revisions merge-buffer-file
))
201 (defun ediff-rcs-merge-internal (rev1 rev2 ancestor-rev
203 startup-hooks merge-buffer-file
)
204 ;; If ANCESTOR-REV non-nil, merge with ancestor
205 (let (buf1 buf2 ancestor-buf
)
206 (save-window-excursion
207 (setq buf1
(rcs-ediff-view-revision rev1
)
208 buf2
(if (string= rev2
"")
210 (rcs-ediff-view-revision rev2
))
211 ancestor-buf
(if ancestor-rev
212 (if (string= ancestor-rev
"")
214 (rcs-ediff-view-revision ancestor-rev
)))))
215 ;; rcs.el doesn't create temp version files, so we don't have to delete
216 ;; anything in startup hooks to ediff-buffers
218 (ediff-merge-buffers-with-ancestor
219 buf1 buf2 ancestor-buf
220 startup-hooks
'ediff-merge-revisions-with-ancestor merge-buffer-file
)
222 buf1 buf2 startup-hooks
'ediff-merge-revisions merge-buffer-file
))))
225 ;; delete version file on exit unless ediff-keep-tmp-versions is true
226 (defun ediff-delete-version-file (file)
227 (or ediff-keep-tmp-versions
(delete-file file
)))
230 (provide 'ediff-vers
)
234 ;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
235 ;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
236 ;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
239 ;; arch-tag: bbb34f0c-2a90-426a-a77a-c75f479ebbbf
240 ;;; ediff-vers.el ends here