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