Mercurial > emacs
annotate lisp/ediff-vers.el @ 31391:0275fa841f55
*** empty log message ***
author | Dave Love <fx@gnu.org> |
---|---|
date | Mon, 04 Sep 2000 21:23:51 +0000 |
parents | 3ec5a485d0ab |
children | 6306740f6938 |
rev | line source |
---|---|
14234 | 1 ;;; ediff-vers.el --- version control interface to Ediff |
2 | |
18054 | 3 ;;; Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. |
14234 | 4 |
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
23 | |
24 | |
25 ;;; Code: | |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
26 |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
27 ;; Compiler pacifier |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
28 (defvar rcs-default-co-switches) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
29 (defvar sc-mode) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
30 (defvar cvs-shell) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
31 (defvar cvs-program) |
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
32 (defvar cvs-cookie-handle) |
18054 | 33 (defvar ediff-temp-file-prefix) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
34 |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
35 (and noninteractive |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
36 (eval-when-compile |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
37 (load "pcl-cvs" 'noerror) |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
38 (load "rcs" 'noerror) |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
39 (load "generic-sc" 'noerror) |
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
40 (load "vc" 'noerror))) |
15480
43a3308fcf61
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
14234
diff
changeset
|
41 ;; end pacifier |
14234 | 42 |
43 ;; VC.el support | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
44 (defun ediff-vc-internal (rev1 rev2 &optional startup-hooks) |
14234 | 45 ;; Run Ediff on versions of the current buffer. |
46 ;; If REV2 is "" then compare current buffer with REV1. | |
47 ;; If the current buffer is named `F', the version is named `F.~REV~'. | |
48 ;; If `F.~REV~' already exists, it is used instead of being re-created. | |
49 (let (file1 file2 rev1buf rev2buf) | |
50 (save-excursion | |
51 (vc-version-other-window rev1) | |
52 (setq rev1buf (current-buffer) | |
53 file1 (buffer-file-name))) | |
54 (save-excursion | |
55 (or (string= rev2 "") ; use current buffer | |
56 (vc-version-other-window rev2)) | |
57 (setq rev2buf (current-buffer) | |
58 file2 (buffer-file-name))) | |
59 (setq startup-hooks | |
26585
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
60 (cons `(lambda () |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
61 (delete-file ,file1) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
62 (or ,(string= rev2 "") (delete-file ,file2))) |
14234 | 63 startup-hooks)) |
64 (ediff-buffers | |
65 rev1buf rev2buf | |
66 startup-hooks | |
67 'ediff-revision))) | |
68 | |
69 ;; RCS.el support | |
70 (defun rcs-ediff-view-revision (&optional rev) | |
71 ;; View previous RCS revision of current file. | |
72 ;; With prefix argument, prompts for a revision name. | |
73 (interactive (list (if current-prefix-arg | |
74 (read-string "Revision: ")))) | |
75 (let* ((filename (buffer-file-name (current-buffer))) | |
76 (switches (append '("-p") | |
77 (if rev (list (concat "-r" rev)) nil))) | |
78 (buff (concat (file-name-nondirectory filename) ".~" rev "~"))) | |
79 (message "Working ...") | |
80 (setq filename (expand-file-name filename)) | |
81 (with-output-to-temp-buffer buff | |
82 (let ((output-buffer (ediff-rcs-get-output-buffer filename buff))) | |
83 (delete-windows-on output-buffer) | |
84 (save-excursion | |
85 (set-buffer output-buffer) | |
86 (apply 'call-process "co" nil t nil | |
87 ;; -q: quiet (no diagnostics) | |
88 (append switches rcs-default-co-switches | |
89 (list "-q" filename))))) | |
90 (message "") | |
91 buff))) | |
92 | |
93 (defun ediff-rcs-get-output-buffer (file name) | |
94 ;; Get a buffer for RCS output for FILE, make it writable and clean it up. | |
95 ;; Optional NAME is name to use instead of `*RCS-output*'. | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26039
diff
changeset
|
96 ;; This is a modified version from rcs.el v1.1. I use it here to make |
14234 | 97 ;; Ediff immune to changes in rcs.el |
98 (let* ((default-major-mode 'fundamental-mode) ; no frills! | |
99 (buf (get-buffer-create name))) | |
100 (save-excursion | |
101 (set-buffer buf) | |
102 (setq buffer-read-only nil | |
103 default-directory (file-name-directory (expand-file-name file))) | |
104 (erase-buffer)) | |
105 buf)) | |
106 | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
107 (defun ediff-rcs-internal (rev1 rev2 &optional startup-hooks) |
14234 | 108 ;; Run Ediff on versions of the current buffer. |
109 ;; If REV2 is "" then use current buffer. | |
110 (let ((rev2buf (if (string= rev2 "") | |
111 (current-buffer) | |
112 (rcs-ediff-view-revision rev2))) | |
113 (rev1buf (rcs-ediff-view-revision rev1))) | |
114 | |
115 ;; rcs.el doesn't create temp version files, so we don't have to delete | |
116 ;; anything in startup hooks to ediff-buffers | |
117 (ediff-buffers rev1buf rev2buf startup-hooks 'ediff-revision) | |
118 )) | |
119 | |
120 | |
121 ;; GENERIC-SC.el support | |
122 | |
123 (defun generic-sc-get-latest-rev () | |
124 (cond ((eq sc-mode 'CCASE) | |
125 (eval "main/LATEST")) | |
126 (t (eval "")))) | |
127 | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
128 (defun ediff-generic-sc-internal (rev1 rev2 &optional startup-hooks) |
14234 | 129 ;; Run Ediff on versions of the current buffer. |
130 ;; If REV2 is "" then compare current buffer with REV1. | |
131 ;; If the current buffer is named `F', the version is named `F.~REV~'. | |
132 ;; If `F.~REV~' already exists, it is used instead of being re-created. | |
133 (let (rev1buf rev2buf) | |
134 (save-excursion | |
135 (if (or (not rev1) (string= rev1 "")) | |
136 (setq rev1 (generic-sc-get-latest-rev))) | |
137 (sc-visit-previous-revision rev1) | |
138 (setq rev1buf (current-buffer))) | |
139 (save-excursion | |
140 (or (string= rev2 "") ; use current buffer | |
141 (sc-visit-previous-revision rev2)) | |
142 (setq rev2buf (current-buffer))) | |
143 (ediff-buffers rev1buf rev2buf startup-hooks 'ediff-revision))) | |
144 | |
145 | |
146 ;;; Merge with Version Control | |
147 | |
20206 | 148 (defun ediff-vc-merge-internal (rev1 rev2 ancestor-rev |
149 &optional startup-hooks merge-buffer-file) | |
14234 | 150 ;; If ANCESTOR-REV non-nil, merge with ancestor |
151 (let (buf1 buf2 ancestor-buf) | |
152 (save-excursion | |
153 (vc-version-other-window rev1) | |
154 (setq buf1 (current-buffer))) | |
155 (save-excursion | |
156 (or (string= rev2 "") | |
157 (vc-version-other-window rev2)) | |
158 (setq buf2 (current-buffer))) | |
159 (if ancestor-rev | |
160 (save-excursion | |
26263
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26039
diff
changeset
|
161 (if (string= ancestor-rev "") |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26039
diff
changeset
|
162 (setq ancestor-rev (vc-workfile-version buffer-file-name))) |
4f315ca65976
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26039
diff
changeset
|
163 (vc-version-other-window ancestor-rev) |
14234 | 164 (setq ancestor-buf (current-buffer)))) |
165 (setq startup-hooks | |
166 (cons | |
26585
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
167 `(lambda () |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
168 (delete-file ,(buffer-file-name buf1)) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
169 (or ,(string= rev2 "") |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
170 (delete-file ,(buffer-file-name buf2))) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
171 (or ,(string= ancestor-rev "") |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
172 ,(not ancestor-rev) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
173 (delete-file ,(buffer-file-name ancestor-buf))) |
3ec5a485d0ab
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
26263
diff
changeset
|
174 ) |
14234 | 175 startup-hooks)) |
176 (if ancestor-rev | |
177 (ediff-merge-buffers-with-ancestor | |
178 buf1 buf2 ancestor-buf | |
20206 | 179 startup-hooks 'ediff-merge-revisions-with-ancestor merge-buffer-file) |
180 (ediff-merge-buffers | |
181 buf1 buf2 startup-hooks 'ediff-merge-revisions merge-buffer-file)) | |
14234 | 182 )) |
183 | |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
184 (defun ediff-rcs-merge-internal (rev1 rev2 ancestor-rev |
20206 | 185 &optional |
186 startup-hooks merge-buffer-file) | |
14234 | 187 ;; If ANCESTOR-REV non-nil, merge with ancestor |
188 (let (buf1 buf2 ancestor-buf) | |
189 (setq buf1 (rcs-ediff-view-revision rev1) | |
190 buf2 (if (string= rev2 "") | |
191 (current-buffer) | |
192 (rcs-ediff-view-revision rev2)) | |
193 ancestor-buf (if ancestor-rev | |
194 (if (string= ancestor-rev "") | |
195 (current-buffer) | |
196 (rcs-ediff-view-revision ancestor-rev)))) | |
197 ;; rcs.el doesn't create temp version files, so we don't have to delete | |
198 ;; anything in startup hooks to ediff-buffers | |
199 (if ancestor-rev | |
200 (ediff-merge-buffers-with-ancestor | |
201 buf1 buf2 ancestor-buf | |
20206 | 202 startup-hooks 'ediff-merge-revisions-with-ancestor merge-buffer-file) |
203 (ediff-merge-buffers | |
204 buf1 buf2 startup-hooks 'ediff-merge-revisions merge-buffer-file)))) | |
14234 | 205 |
16248
b2fae8abc5b0
*** empty log message ***
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
15480
diff
changeset
|
206 (defun ediff-generic-sc-merge-internal (rev1 rev2 ancestor-rev |
20206 | 207 &optional |
208 startup-hooks merge-buffer-file) | |
14234 | 209 ;; If ANCESTOR-REV non-nil, merge with ancestor |
210 (let (buf1 buf2 ancestor-buf) | |
211 (save-excursion | |
212 (if (string= rev1 "") | |
213 (setq rev1 (generic-sc-get-latest-rev))) | |
214 (sc-visit-previous-revision rev1) | |
215 (setq buf1 (current-buffer))) | |
216 (save-excursion | |
217 (or (string= rev2 "") | |
218 (sc-visit-previous-revision rev2)) | |
219 (setq buf2 (current-buffer))) | |
220 (if ancestor-rev | |
221 (save-excursion | |
222 (or (string= ancestor-rev "") | |
223 (sc-visit-previous-revision ancestor-rev)) | |
224 (setq ancestor-buf (current-buffer)))) | |
225 (if ancestor-rev | |
226 (ediff-merge-buffers-with-ancestor | |
227 buf1 buf2 ancestor-buf | |
20206 | 228 startup-hooks 'ediff-merge-revisions-with-ancestor merge-buffer-file) |
229 (ediff-merge-buffers | |
230 buf1 buf2 startup-hooks 'ediff-merge-revisions merge-buffer-file)))) | |
14234 | 231 |
232 | |
233 ;; PCL-CVS.el support | |
234 | |
235 | |
236 (defun cvs-run-ediff-on-file-descriptor (tin) | |
237 ;; This is a replacement for cvs-emerge-mode | |
20206 | 238 ;; Runs after cvs-update. |
14234 | 239 ;; Ediff-merge appropriate revisions of the selected file. |
240 (let* ((fileinfo (tin-cookie cvs-cookie-handle tin)) | |
241 (type (cvs-fileinfo->type fileinfo)) | |
242 (tmp-file | |
243 (cvs-retrieve-revision-to-tmpfile fileinfo)) | |
20343 | 244 (default-directory |
21940 | 245 (file-name-as-directory (cvs-fileinfo->dir fileinfo))) |
14234 | 246 ancestor-file) |
247 | |
248 (or (memq type '(MERGED CONFLICT MODIFIED)) | |
249 (error | |
250 "Can only merge `Modified', `Merged' or `Conflict' files")) | |
251 | |
252 (cond ((memq type '(MERGED CONFLICT)) | |
253 (setq ancestor-file | |
254 (cvs-retrieve-revision-to-tmpfile | |
255 fileinfo | |
256 ;; revision | |
257 (cvs-fileinfo->base-revision fileinfo))) | |
258 (ediff-merge-buffers-with-ancestor | |
259 (find-file-noselect tmp-file) | |
260 (find-file-noselect (cvs-fileinfo->backup-file fileinfo)) | |
261 (find-file-noselect ancestor-file) | |
262 nil ; startup-hooks | |
263 'ediff-merge-revisions-with-ancestor)) | |
264 ((eq type 'MODIFIED) | |
20343 | 265 (ediff-buffers |
14234 | 266 (find-file-noselect tmp-file) |
267 (find-file-noselect (cvs-fileinfo->full-path fileinfo)) | |
268 nil ; startup-hooks | |
20343 | 269 'ediff-revisions))) |
14234 | 270 (if (stringp tmp-file) (delete-file tmp-file)) |
271 (if (stringp ancestor-file) (delete-file ancestor-file)))) | |
272 | |
273 ;;; Local Variables: | |
274 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun) | |
19047 | 275 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1) |
276 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body)) | |
14234 | 277 ;;; End: |
278 | |
279 (provide 'ediff-vers) | |
280 | |
281 ;;; ediff-vers.el ends here |