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 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 of the License, or
13 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
28 (defvar rcs-default-co-switches
)
33 ;; for compatibility with current stable version of xemacs
35 ;;(require 'pcvs nil 'noerror)
36 ;;(require 'rcs nil 'noerror)
45 (defcustom ediff-keep-tmp-versions nil
46 "If t, do not delete temporary previous versions for the files on which
47 comparison or merge operations are being performed."
52 (defalias 'ediff-vc-revision-other-window
53 (if (fboundp 'vc-revision-other-window
)
54 'vc-revision-other-window
55 'vc-version-other-window
))
57 (defalias 'ediff-vc-working-revision
58 (if (fboundp 'vc-working-revision
)
60 'vc-workfile-version
))
65 (require 'vc-hooks
)) ;; for vc-call macro
68 (defun ediff-vc-latest-version (file)
69 "Return the version level of the latest version of FILE in repository."
70 (if (fboundp 'vc-latest-version
)
71 (vc-latest-version file
)
72 (or (vc-file-getprop file
'vc-latest-revision
)
73 (cond ((vc-backend file
)
75 (vc-file-getprop file
'vc-latest-revision
))
76 (t (error "File %s is not under version control" file
))))
80 (defun ediff-vc-internal (rev1 rev2
&optional startup-hooks
)
81 ;; Run Ediff on versions of the current buffer.
82 ;; If REV1 is "", use the latest version of the current buffer's file.
83 ;; If REV2 is "" then compare current buffer with REV1.
84 ;; If the current buffer is named `F', the version is named `F.~REV~'.
85 ;; If `F.~REV~' already exists, it is used instead of being re-created.
86 (let (file1 file2 rev1buf rev2buf
)
88 (setq rev1
(ediff-vc-latest-version (buffer-file-name))))
89 (save-window-excursion
91 (ediff-vc-revision-other-window rev1
)
92 (setq rev1buf
(current-buffer)
93 file1
(buffer-file-name)))
95 (or (string= rev2
"") ; use current buffer
96 (ediff-vc-revision-other-window rev2
))
97 (setq rev2buf
(current-buffer)
98 file2
(buffer-file-name)))
101 (ediff-delete-version-file ,file1
)
102 (or ,(string= rev2
"") (ediff-delete-version-file ,file2
)))
110 (defun rcs-ediff-view-revision (&optional rev
)
111 ;; View previous RCS revision of current file.
112 ;; With prefix argument, prompts for a revision name.
113 (interactive (list (if current-prefix-arg
114 (read-string "Revision: "))))
115 (let* ((filename (buffer-file-name (current-buffer)))
116 (switches (append '("-p")
117 (if rev
(list (concat "-r" rev
)) nil
)))
118 (buff (concat (file-name-nondirectory filename
) ".~" rev
"~")))
119 (message "Working ...")
120 (setq filename
(expand-file-name filename
))
121 (with-output-to-temp-buffer buff
122 (ediff-with-current-buffer standard-output
124 (let ((output-buffer (ediff-rcs-get-output-buffer filename buff
)))
125 (delete-windows-on output-buffer
)
126 (with-current-buffer output-buffer
127 (apply 'call-process
"co" nil t nil
128 ;; -q: quiet (no diagnostics)
129 (append switches rcs-default-co-switches
130 (list "-q" filename
)))))
134 (defun ediff-rcs-get-output-buffer (file name
)
135 ;; Get a buffer for RCS output for FILE, make it writable and clean it up.
136 ;; Optional NAME is name to use instead of `*RCS-output*'.
137 ;; This is a modified version from rcs.el v1.1. I use it here to make
138 ;; Ediff immune to changes in rcs.el
139 (let ((buf (get-buffer-create name
)))
140 (with-current-buffer buf
141 (setq buffer-read-only nil
142 default-directory
(file-name-directory (expand-file-name file
)))
146 (defun ediff-rcs-internal (rev1 rev2
&optional startup-hooks
)
147 ;; Run Ediff on versions of the current buffer.
148 ;; If REV2 is "" then use current buffer.
149 (let (rev2buf rev1buf
)
150 (save-window-excursion
151 (setq rev2buf
(if (string= rev2
"")
153 (rcs-ediff-view-revision rev2
))
154 rev1buf
(rcs-ediff-view-revision rev1
)))
156 ;; rcs.el doesn't create temp version files, so we don't have to delete
157 ;; anything in startup hooks to ediff-buffers
158 (ediff-buffers rev1buf rev2buf startup-hooks
'ediff-revision
)
161 ;;; Merge with Version Control
163 (defun ediff-vc-merge-internal (rev1 rev2 ancestor-rev
164 &optional startup-hooks merge-buffer-file
)
165 ;; If ANCESTOR-REV non-nil, merge with ancestor
166 (let (buf1 buf2 ancestor-buf
)
167 (save-window-excursion
169 (ediff-vc-revision-other-window rev1
)
170 (setq buf1
(current-buffer)))
172 (or (string= rev2
"")
173 (ediff-vc-revision-other-window rev2
))
174 (setq buf2
(current-buffer)))
177 (if (string= ancestor-rev
"")
178 (setq ancestor-rev
(ediff-vc-working-revision buffer-file-name
)))
179 (ediff-vc-revision-other-window ancestor-rev
)
180 (setq ancestor-buf
(current-buffer))))
184 (ediff-delete-version-file ,(buffer-file-name buf1
))
185 (or ,(string= rev2
"")
186 (ediff-delete-version-file ,(buffer-file-name buf2
)))
187 (or ,(string= ancestor-rev
"")
189 (ediff-delete-version-file ,(buffer-file-name ancestor-buf
)))
193 (ediff-merge-buffers-with-ancestor
194 buf1 buf2 ancestor-buf
195 startup-hooks
'ediff-merge-revisions-with-ancestor merge-buffer-file
)
197 buf1 buf2 startup-hooks
'ediff-merge-revisions merge-buffer-file
))
200 (defun ediff-rcs-merge-internal (rev1 rev2 ancestor-rev
202 startup-hooks merge-buffer-file
)
203 ;; If ANCESTOR-REV non-nil, merge with ancestor
204 (let (buf1 buf2 ancestor-buf
)
205 (save-window-excursion
206 (setq buf1
(rcs-ediff-view-revision rev1
)
207 buf2
(if (string= rev2
"")
209 (rcs-ediff-view-revision rev2
))
210 ancestor-buf
(if ancestor-rev
211 (if (string= ancestor-rev
"")
213 (rcs-ediff-view-revision ancestor-rev
)))))
214 ;; rcs.el doesn't create temp version files, so we don't have to delete
215 ;; anything in startup hooks to ediff-buffers
217 (ediff-merge-buffers-with-ancestor
218 buf1 buf2 ancestor-buf
219 startup-hooks
'ediff-merge-revisions-with-ancestor merge-buffer-file
)
221 buf1 buf2 startup-hooks
'ediff-merge-revisions merge-buffer-file
))))
224 ;; delete version file on exit unless ediff-keep-tmp-versions is true
225 (defun ediff-delete-version-file (file)
226 (or ediff-keep-tmp-versions
(delete-file file
)))
229 (provide 'ediff-vers
)
233 ;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
234 ;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
235 ;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
238 ;; arch-tag: bbb34f0c-2a90-426a-a77a-c75f479ebbbf
239 ;;; ediff-vers.el ends here