Fix up comment convention on the arch-tag lines.
[bpt/emacs.git] / lisp / ediff-vers.el
CommitLineData
8122a6da
MK
1;;; ediff-vers.el --- version control interface to Ediff
2
e91081eb 3;; Copyright (C) 1995, 1996, 1997, 2001, 2002, 2003, 2004,
409cc4a3 4;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
8122a6da 5
50a07e18 6;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
8122a6da
MK
7
8;; This file is part of GNU Emacs.
9
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
b4aa6026 12;; the Free Software Foundation; either version 3, or (at your option)
8122a6da
MK
13;; any later version.
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
21;; along with GNU Emacs; see the file COPYING. If not, write to the
086add15
LK
22;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23;; Boston, MA 02110-1301, USA.
8122a6da 24
3afbc435 25;;; Commentary:
8122a6da
MK
26
27;;; Code:
bbe6126c
MK
28
29;; Compiler pacifier
30(defvar rcs-default-co-switches)
31(defvar sc-mode)
32(defvar cvs-shell)
33(defvar cvs-program)
34(defvar cvs-cookie-handle)
ddc90f39 35(defvar ediff-temp-file-prefix)
bbe6126c 36
92c51e07
MK
37(and noninteractive
38 (eval-when-compile
a5254f37
MK
39 (condition-case nil
40 ;; for compatibility with current stable version of xemacs
41 (progn
42 ;;(require 'pcvs nil 'noerror)
43 ;;(require 'rcs nil 'noerror)
44 (require 'pcvs)
45 (require 'rcs))
46 (error nil))
2d84cc27
MK
47 (require 'vc)
48 (require 'ediff-init)
49 ))
bbe6126c 50;; end pacifier
71296446 51
ec6aebe8
MK
52(defcustom ediff-keep-tmp-versions nil
53 "*If t, do not delete temporary previous versions for the files on which
54comparison or merge operations are being performed."
55 :type 'boolean
56 :group 'ediff-vers
57 )
58
33468a59
MK
59(defalias 'ediff-vc-revision-other-window
60 (if (fboundp 'vc-revision-other-window)
61 'vc-revision-other-window
62 'vc-version-other-window))
63
64(defalias 'ediff-vc-working-revision
65 (if (fboundp 'vc-working-revision)
66 'vc-working-revision
8ef97aec 67 'vc-workfile-version))
33468a59 68
8122a6da 69;; VC.el support
0831d50c 70
33468a59
MK
71(eval-when-compile
72 (require 'vc-hooks)) ;; for vc-call macro
73
74
0831d50c
MK
75(defun ediff-vc-latest-version (file)
76 "Return the version level of the latest version of FILE in repository."
77 (if (fboundp 'vc-latest-version)
78 (vc-latest-version file)
79 (or (vc-file-getprop file 'vc-latest-version)
80 (cond ((vc-backend file)
81 (vc-call state file)
82 (vc-file-getprop file 'vc-latest-version))
83 (t (error "File %s is not under version control" file))))
84 ))
85
86
92c51e07 87(defun ediff-vc-internal (rev1 rev2 &optional startup-hooks)
0831d50c
MK
88 ;; Run Ediff on versions of the current buffer.
89 ;; If REV1 is "", use the latest version of the current buffer's file.
90 ;; If REV2 is "" then compare current buffer with REV1.
91 ;; If the current buffer is named `F', the version is named `F.~REV~'.
92 ;; If `F.~REV~' already exists, it is used instead of being re-created.
8122a6da 93 (let (file1 file2 rev1buf rev2buf)
71296446 94 (if (string= rev1 "")
0831d50c 95 (setq rev1 (ediff-vc-latest-version (buffer-file-name))))
657f9cb8
MK
96 (save-window-excursion
97 (save-excursion
33468a59 98 (ediff-vc-revision-other-window rev1)
657f9cb8
MK
99 (setq rev1buf (current-buffer)
100 file1 (buffer-file-name)))
101 (save-excursion
102 (or (string= rev2 "") ; use current buffer
33468a59 103 (ediff-vc-revision-other-window rev2))
657f9cb8
MK
104 (setq rev2buf (current-buffer)
105 file2 (buffer-file-name)))
106 (setq startup-hooks
107 (cons `(lambda ()
ec6aebe8
MK
108 (ediff-delete-version-file ,file1)
109 (or ,(string= rev2 "") (ediff-delete-version-file ,file2)))
657f9cb8 110 startup-hooks)))
8122a6da
MK
111 (ediff-buffers
112 rev1buf rev2buf
113 startup-hooks
114 'ediff-revision)))
71296446 115
8122a6da
MK
116;; RCS.el support
117(defun rcs-ediff-view-revision (&optional rev)
118;; View previous RCS revision of current file.
119;; With prefix argument, prompts for a revision name.
71296446 120 (interactive (list (if current-prefix-arg
8122a6da
MK
121 (read-string "Revision: "))))
122 (let* ((filename (buffer-file-name (current-buffer)))
123 (switches (append '("-p")
124 (if rev (list (concat "-r" rev)) nil)))
125 (buff (concat (file-name-nondirectory filename) ".~" rev "~")))
126 (message "Working ...")
127 (setq filename (expand-file-name filename))
128 (with-output-to-temp-buffer buff
7de0717c
DL
129 (ediff-with-current-buffer standard-output
130 (fundamental-mode))
8122a6da
MK
131 (let ((output-buffer (ediff-rcs-get-output-buffer filename buff)))
132 (delete-windows-on output-buffer)
133 (save-excursion
134 (set-buffer output-buffer)
135 (apply 'call-process "co" nil t nil
136 ;; -q: quiet (no diagnostics)
137 (append switches rcs-default-co-switches
71296446 138 (list "-q" filename)))))
8122a6da 139 (message "")
71296446
JB
140 buff)))
141
8122a6da
MK
142(defun ediff-rcs-get-output-buffer (file name)
143 ;; Get a buffer for RCS output for FILE, make it writable and clean it up.
144 ;; Optional NAME is name to use instead of `*RCS-output*'.
3af0304a 145 ;; This is a modified version from rcs.el v1.1. I use it here to make
8122a6da
MK
146 ;; Ediff immune to changes in rcs.el
147 (let* ((default-major-mode 'fundamental-mode) ; no frills!
148 (buf (get-buffer-create name)))
149 (save-excursion
150 (set-buffer buf)
151 (setq buffer-read-only nil
152 default-directory (file-name-directory (expand-file-name file)))
153 (erase-buffer))
154 buf))
155
92c51e07 156(defun ediff-rcs-internal (rev1 rev2 &optional startup-hooks)
8122a6da
MK
157;; Run Ediff on versions of the current buffer.
158;; If REV2 is "" then use current buffer.
657f9cb8
MK
159 (let (rev2buf rev1buf)
160 (save-window-excursion
161 (setq rev2buf (if (string= rev2 "")
162 (current-buffer)
163 (rcs-ediff-view-revision rev2))
164 rev1buf (rcs-ediff-view-revision rev1)))
71296446 165
8122a6da
MK
166 ;; rcs.el doesn't create temp version files, so we don't have to delete
167 ;; anything in startup hooks to ediff-buffers
168 (ediff-buffers rev1buf rev2buf startup-hooks 'ediff-revision)
169 ))
170
8122a6da
MK
171;;; Merge with Version Control
172
71296446 173(defun ediff-vc-merge-internal (rev1 rev2 ancestor-rev
328b4b70 174 &optional startup-hooks merge-buffer-file)
8122a6da
MK
175;; If ANCESTOR-REV non-nil, merge with ancestor
176 (let (buf1 buf2 ancestor-buf)
657f9cb8
MK
177 (save-window-excursion
178 (save-excursion
33468a59 179 (ediff-vc-revision-other-window rev1)
657f9cb8
MK
180 (setq buf1 (current-buffer)))
181 (save-excursion
182 (or (string= rev2 "")
33468a59 183 (ediff-vc-revision-other-window rev2))
657f9cb8
MK
184 (setq buf2 (current-buffer)))
185 (if ancestor-rev
186 (save-excursion
187 (if (string= ancestor-rev "")
33468a59
MK
188 (setq ancestor-rev (ediff-vc-working-revision buffer-file-name)))
189 (ediff-vc-revision-other-window ancestor-rev)
657f9cb8 190 (setq ancestor-buf (current-buffer))))
71296446
JB
191 (setq startup-hooks
192 (cons
193 `(lambda ()
ec6aebe8 194 (ediff-delete-version-file ,(buffer-file-name buf1))
657f9cb8 195 (or ,(string= rev2 "")
ec6aebe8 196 (ediff-delete-version-file ,(buffer-file-name buf2)))
657f9cb8
MK
197 (or ,(string= ancestor-rev "")
198 ,(not ancestor-rev)
ec6aebe8 199 (ediff-delete-version-file ,(buffer-file-name ancestor-buf)))
657f9cb8
MK
200 )
201 startup-hooks)))
8122a6da
MK
202 (if ancestor-rev
203 (ediff-merge-buffers-with-ancestor
204 buf1 buf2 ancestor-buf
328b4b70
MK
205 startup-hooks 'ediff-merge-revisions-with-ancestor merge-buffer-file)
206 (ediff-merge-buffers
207 buf1 buf2 startup-hooks 'ediff-merge-revisions merge-buffer-file))
8122a6da
MK
208 ))
209
92c51e07 210(defun ediff-rcs-merge-internal (rev1 rev2 ancestor-rev
328b4b70
MK
211 &optional
212 startup-hooks merge-buffer-file)
8122a6da
MK
213 ;; If ANCESTOR-REV non-nil, merge with ancestor
214 (let (buf1 buf2 ancestor-buf)
657f9cb8
MK
215 (save-window-excursion
216 (setq buf1 (rcs-ediff-view-revision rev1)
217 buf2 (if (string= rev2 "")
218 (current-buffer)
219 (rcs-ediff-view-revision rev2))
220 ancestor-buf (if ancestor-rev
221 (if (string= ancestor-rev "")
222 (current-buffer)
223 (rcs-ediff-view-revision ancestor-rev)))))
8122a6da
MK
224 ;; rcs.el doesn't create temp version files, so we don't have to delete
225 ;; anything in startup hooks to ediff-buffers
226 (if ancestor-rev
227 (ediff-merge-buffers-with-ancestor
228 buf1 buf2 ancestor-buf
328b4b70
MK
229 startup-hooks 'ediff-merge-revisions-with-ancestor merge-buffer-file)
230 (ediff-merge-buffers
231 buf1 buf2 startup-hooks 'ediff-merge-revisions merge-buffer-file))))
8122a6da 232
ec6aebe8
MK
233
234;; delete version file on exit unless ediff-keep-tmp-versions is true
235(defun ediff-delete-version-file (file)
236 (or ediff-keep-tmp-versions (delete-file file)))
8122a6da 237
8ea74b0e
MK
238
239(provide 'ediff-vers)
240
b6178721 241
8122a6da
MK
242;;; Local Variables:
243;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
e756eb9f
MK
244;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
245;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
8122a6da
MK
246;;; End:
247
cbee283d 248;; arch-tag: bbb34f0c-2a90-426a-a77a-c75f479ebbbf
8122a6da 249;;; ediff-vers.el ends here