Commit | Line | Data |
---|---|---|
8122a6da MK |
1 | ;;; ediff-vers.el --- version control interface to Ediff |
2 | ||
e91081eb | 3 | ;; Copyright (C) 1995, 1996, 1997, 2001, 2002, 2003, 2004, |
5df4f04c | 4 | ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
8122a6da | 5 | |
50a07e18 | 6 | ;; Author: Michael Kifer <kifer@cs.stonybrook.edu> |
bd78fa1d | 7 | ;; Package: ediff |
8122a6da MK |
8 | |
9 | ;; This file is part of GNU Emacs. | |
10 | ||
eb3fa2cf | 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
8122a6da | 12 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
13 | ;; the Free Software Foundation, either version 3 of the License, or |
14 | ;; (at your option) any later version. | |
8122a6da MK |
15 | |
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. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
8122a6da | 23 | |
3afbc435 | 24 | ;;; Commentary: |
8122a6da MK |
25 | |
26 | ;;; Code: | |
bbe6126c MK |
27 | |
28 | ;; Compiler pacifier | |
29 | (defvar rcs-default-co-switches) | |
bbe6126c | 30 | |
92c51e07 MK |
31 | (and noninteractive |
32 | (eval-when-compile | |
a5254f37 MK |
33 | (condition-case nil |
34 | ;; for compatibility with current stable version of xemacs | |
35 | (progn | |
36 | ;;(require 'pcvs nil 'noerror) | |
37 | ;;(require 'rcs nil 'noerror) | |
38 | (require 'pcvs) | |
39 | (require 'rcs)) | |
40 | (error nil)) | |
2d84cc27 MK |
41 | (require 'vc) |
42 | (require 'ediff-init) | |
43 | )) | |
bbe6126c | 44 | ;; end pacifier |
71296446 | 45 | |
ec6aebe8 | 46 | (defcustom ediff-keep-tmp-versions nil |
9201cc28 | 47 | "If t, do not delete temporary previous versions for the files on which |
ec6aebe8 MK |
48 | comparison or merge operations are being performed." |
49 | :type 'boolean | |
50 | :group 'ediff-vers | |
51 | ) | |
52 | ||
33468a59 MK |
53 | (defalias 'ediff-vc-revision-other-window |
54 | (if (fboundp 'vc-revision-other-window) | |
55 | 'vc-revision-other-window | |
56 | 'vc-version-other-window)) | |
57 | ||
58 | (defalias 'ediff-vc-working-revision | |
59 | (if (fboundp 'vc-working-revision) | |
60 | 'vc-working-revision | |
8ef97aec | 61 | 'vc-workfile-version)) |
33468a59 | 62 | |
8122a6da | 63 | ;; VC.el support |
0831d50c | 64 | |
33468a59 MK |
65 | (eval-when-compile |
66 | (require 'vc-hooks)) ;; for vc-call macro | |
67 | ||
68 | ||
0831d50c MK |
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) | |
e290f028 | 73 | (or (vc-file-getprop file 'vc-latest-revision) |
0831d50c MK |
74 | (cond ((vc-backend file) |
75 | (vc-call state file) | |
e290f028 | 76 | (vc-file-getprop file 'vc-latest-revision)) |
0831d50c MK |
77 | (t (error "File %s is not under version control" file)))) |
78 | )) | |
79 | ||
80 | ||
92c51e07 | 81 | (defun ediff-vc-internal (rev1 rev2 &optional startup-hooks) |
0831d50c MK |
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. | |
8122a6da | 87 | (let (file1 file2 rev1buf rev2buf) |
71296446 | 88 | (if (string= rev1 "") |
0831d50c | 89 | (setq rev1 (ediff-vc-latest-version (buffer-file-name)))) |
657f9cb8 MK |
90 | (save-window-excursion |
91 | (save-excursion | |
33468a59 | 92 | (ediff-vc-revision-other-window rev1) |
657f9cb8 MK |
93 | (setq rev1buf (current-buffer) |
94 | file1 (buffer-file-name))) | |
95 | (save-excursion | |
96 | (or (string= rev2 "") ; use current buffer | |
33468a59 | 97 | (ediff-vc-revision-other-window rev2)) |
657f9cb8 MK |
98 | (setq rev2buf (current-buffer) |
99 | file2 (buffer-file-name))) | |
100 | (setq startup-hooks | |
101 | (cons `(lambda () | |
ec6aebe8 MK |
102 | (ediff-delete-version-file ,file1) |
103 | (or ,(string= rev2 "") (ediff-delete-version-file ,file2))) | |
657f9cb8 | 104 | startup-hooks))) |
8122a6da MK |
105 | (ediff-buffers |
106 | rev1buf rev2buf | |
107 | startup-hooks | |
108 | 'ediff-revision))) | |
71296446 | 109 | |
8122a6da MK |
110 | ;; RCS.el support |
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. | |
71296446 | 114 | (interactive (list (if current-prefix-arg |
8122a6da MK |
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 | |
7de0717c DL |
123 | (ediff-with-current-buffer standard-output |
124 | (fundamental-mode)) | |
8122a6da MK |
125 | (let ((output-buffer (ediff-rcs-get-output-buffer filename buff))) |
126 | (delete-windows-on output-buffer) | |
7fdbcd83 | 127 | (with-current-buffer output-buffer |
8122a6da MK |
128 | (apply 'call-process "co" nil t nil |
129 | ;; -q: quiet (no diagnostics) | |
130 | (append switches rcs-default-co-switches | |
71296446 | 131 | (list "-q" filename))))) |
8122a6da | 132 | (message "") |
71296446 JB |
133 | buff))) |
134 | ||
8122a6da MK |
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*'. | |
3af0304a | 138 | ;; This is a modified version from rcs.el v1.1. I use it here to make |
8122a6da | 139 | ;; Ediff immune to changes in rcs.el |
a34d8565 | 140 | (let ((buf (get-buffer-create name))) |
72f16325 | 141 | (with-current-buffer buf |
8122a6da MK |
142 | (setq buffer-read-only nil |
143 | default-directory (file-name-directory (expand-file-name file))) | |
144 | (erase-buffer)) | |
145 | buf)) | |
146 | ||
92c51e07 | 147 | (defun ediff-rcs-internal (rev1 rev2 &optional startup-hooks) |
8122a6da MK |
148 | ;; Run Ediff on versions of the current buffer. |
149 | ;; If REV2 is "" then use current buffer. | |
657f9cb8 MK |
150 | (let (rev2buf rev1buf) |
151 | (save-window-excursion | |
152 | (setq rev2buf (if (string= rev2 "") | |
153 | (current-buffer) | |
154 | (rcs-ediff-view-revision rev2)) | |
155 | rev1buf (rcs-ediff-view-revision rev1))) | |
71296446 | 156 | |
8122a6da MK |
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) | |
160 | )) | |
161 | ||
8122a6da MK |
162 | ;;; Merge with Version Control |
163 | ||
71296446 | 164 | (defun ediff-vc-merge-internal (rev1 rev2 ancestor-rev |
328b4b70 | 165 | &optional startup-hooks merge-buffer-file) |
8122a6da MK |
166 | ;; If ANCESTOR-REV non-nil, merge with ancestor |
167 | (let (buf1 buf2 ancestor-buf) | |
657f9cb8 MK |
168 | (save-window-excursion |
169 | (save-excursion | |
33468a59 | 170 | (ediff-vc-revision-other-window rev1) |
657f9cb8 MK |
171 | (setq buf1 (current-buffer))) |
172 | (save-excursion | |
173 | (or (string= rev2 "") | |
33468a59 | 174 | (ediff-vc-revision-other-window rev2)) |
657f9cb8 MK |
175 | (setq buf2 (current-buffer))) |
176 | (if ancestor-rev | |
177 | (save-excursion | |
178 | (if (string= ancestor-rev "") | |
33468a59 MK |
179 | (setq ancestor-rev (ediff-vc-working-revision buffer-file-name))) |
180 | (ediff-vc-revision-other-window ancestor-rev) | |
657f9cb8 | 181 | (setq ancestor-buf (current-buffer)))) |
71296446 JB |
182 | (setq startup-hooks |
183 | (cons | |
184 | `(lambda () | |
ec6aebe8 | 185 | (ediff-delete-version-file ,(buffer-file-name buf1)) |
657f9cb8 | 186 | (or ,(string= rev2 "") |
ec6aebe8 | 187 | (ediff-delete-version-file ,(buffer-file-name buf2))) |
657f9cb8 MK |
188 | (or ,(string= ancestor-rev "") |
189 | ,(not ancestor-rev) | |
ec6aebe8 | 190 | (ediff-delete-version-file ,(buffer-file-name ancestor-buf))) |
657f9cb8 MK |
191 | ) |
192 | startup-hooks))) | |
8122a6da MK |
193 | (if ancestor-rev |
194 | (ediff-merge-buffers-with-ancestor | |
195 | buf1 buf2 ancestor-buf | |
328b4b70 MK |
196 | startup-hooks 'ediff-merge-revisions-with-ancestor merge-buffer-file) |
197 | (ediff-merge-buffers | |
198 | buf1 buf2 startup-hooks 'ediff-merge-revisions merge-buffer-file)) | |
8122a6da MK |
199 | )) |
200 | ||
92c51e07 | 201 | (defun ediff-rcs-merge-internal (rev1 rev2 ancestor-rev |
328b4b70 MK |
202 | &optional |
203 | startup-hooks merge-buffer-file) | |
8122a6da MK |
204 | ;; If ANCESTOR-REV non-nil, merge with ancestor |
205 | (let (buf1 buf2 ancestor-buf) | |
657f9cb8 MK |
206 | (save-window-excursion |
207 | (setq buf1 (rcs-ediff-view-revision rev1) | |
208 | buf2 (if (string= rev2 "") | |
209 | (current-buffer) | |
210 | (rcs-ediff-view-revision rev2)) | |
211 | ancestor-buf (if ancestor-rev | |
212 | (if (string= ancestor-rev "") | |
213 | (current-buffer) | |
214 | (rcs-ediff-view-revision ancestor-rev))))) | |
8122a6da MK |
215 | ;; rcs.el doesn't create temp version files, so we don't have to delete |
216 | ;; anything in startup hooks to ediff-buffers | |
217 | (if ancestor-rev | |
218 | (ediff-merge-buffers-with-ancestor | |
219 | buf1 buf2 ancestor-buf | |
328b4b70 MK |
220 | startup-hooks 'ediff-merge-revisions-with-ancestor merge-buffer-file) |
221 | (ediff-merge-buffers | |
222 | buf1 buf2 startup-hooks 'ediff-merge-revisions merge-buffer-file)))) | |
8122a6da | 223 | |
ec6aebe8 MK |
224 | |
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))) | |
8122a6da | 228 | |
8ea74b0e MK |
229 | |
230 | (provide 'ediff-vers) | |
231 | ||
b6178721 | 232 | |
fa043571 SM |
233 | ;; Local Variables: |
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)) | |
237 | ;; End: | |
8122a6da | 238 | |
cbee283d | 239 | ;; arch-tag: bbb34f0c-2a90-426a-a77a-c75f479ebbbf |
8122a6da | 240 | ;;; ediff-vers.el ends here |