annotate lisp/ediff/ediff-ptch.el @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents 9ee227acff29
children 131b0175ea99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; ediff-ptch.el --- Ediff's patch support
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Code:
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
26
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
27 (provide 'ediff-ptch)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
28
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
29 ;; compiler pacifier
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
30 (defvar ediff-window-A)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
31 (defvar ediff-window-B)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
32 (defvar ediff-window-C)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
33 (defvar ediff-use-last-dir)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
34 (defvar ediff-shell)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
35
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
36 (eval-when-compile
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
37 (let ((load-path (cons (expand-file-name ".") load-path)))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
38 (or (featurep 'ediff-init)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
39 (load "ediff-init.el" nil nil 'nosuffix))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
40 (or (featurep 'ediff)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
41 (load "ediff.el" nil nil 'nosuffix))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
42 ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
43 ;; end pacifier
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
45 (require 'ediff-init)
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
46
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (defvar ediff-last-dir-patch nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 "Last directory used by an Ediff command for file to patch.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (defvar ediff-backup-extension
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (if (memq system-type '(vax-vms axp-vms emx ms-dos windows-nt windows-95))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 "_orig" ".orig")
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
53 "Backup extension used by the patch program.
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
54 See also `ediff-backup-specs'.")
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
55
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
56 (defvar ediff-backup-specs (format "-b %s" ediff-backup-extension)
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
57 "*Backup directives to pass to the patch program.
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
58 Ediff requires that the old version of the file \(before applying the patch\)
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
59 is saved in a file named `the-patch-file.extension'. Usually `extension' is
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
60 `.orig', but this can be changed by the user and may depend on the system.
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
61 Therefore, Ediff needs to know the backup extension used by the patch program.
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
62
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
63 Some versions of the patch program let you specify `-b backup-extension'.
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
64 Other versions only permit `-b', which assumes some canned extension
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
65 \(usually `.orig'\).
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
66
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
67 Note that both `ediff-backup-extension' and `ediff-backup-specs'
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
68 must be properly set. If your patch program takes the option `-b',
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
69 but not `-b extension', the variable `ediff-backup-extension' must
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
70 still be set so Ediff will know which extension to use.")
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
71
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (defvar ediff-patch-default-directory nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 "*Default directory to look for patches.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (defvar ediff-context-diff-label-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (concat "\\(" ; context diff 2-liner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 "^\\*\\*\\* \\([^ \t]+\\)[^*]+[\t ]*\n--- \\([^ \t]+\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 "\\|" ; GNU unified format diff 2-liner
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
80 "^--- \\([^ \t]+\\)[\t ]+.*\n\\+\\+\\+ \\([^ \t]+\\)"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 "\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 "*Regexp matching filename 2-liners at the start of each context diff.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defvar ediff-patch-program "patch"
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
85 "*Name of the program that applies patches.
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
86 It is recommended to use GNU-compatible versions.")
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
87 (defvar ediff-patch-options "-f"
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
88 "*Options to pass to ediff-patch-program.
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
89
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
90 Note: the `-b' option should be specified in `ediff-backup-specs'.
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
91
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
92 It is recommended to pass the `-f' option to the patch program, so it won't ask
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
93 questions. However, some implementations don't accept this option, in which
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
94 case the default value for this variable should be changed.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;; The buffer of the patch file. Local to control buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (ediff-defvar-local ediff-patchbufer nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; The buffer where patch displays its diagnostics.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (ediff-defvar-local ediff-patch-diagnostics nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;; Map of patch buffer. Has the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; ((filename1 marker1 marker2) (filename2 marker1 marker2) ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; where filenames are files to which patch would have applied the patch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;; marker1 delimits the beginning of the corresponding patch and marker2 does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; it for the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (ediff-defvar-local ediff-patch-map nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;; strip prefix from filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;; returns /dev/null, if can't strip prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (defsubst ediff-file-name-sans-prefix (filename prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (if (string-match (concat "^" prefix) filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (substring filename (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (concat "/null/" filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;; no longer used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;; return the number of matches of regexp in buf starting from the beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (defun ediff-count-matches (regexp buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (ediff-eval-in-buffer buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (let ((count 0) opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (while (and (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (progn (setq opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (re-search-forward regexp nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (if (= opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (setq count (1+ count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; Scan BUF (which is supposed to contain a patch) and make a list of the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; ((filename1 marker1 marker2) (filename2 marker1 marker2) ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; where filenames are files to which patch would have applied the patch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;; marker1 delimits the beginning of the corresponding patch and marker2 does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;; it for the end. This list is then assigned to ediff-patch-map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;; Returns the number of elements in the list ediff-patch-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (defun ediff-map-patch-buffer (buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (ediff-eval-in-buffer buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (let ((count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (mark1 (move-marker (make-marker) (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (mark1-end (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (possible-file-names '("/dev/null" . "/dev/null"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 mark2-end mark2 filenames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 beg1 beg2 end1 end2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 patch-map opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (setq opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (while (and (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (re-search-forward ediff-context-diff-label-regexp nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (if (= opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (forward-char 1) ; ensure progress towards the end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (setq mark2 (move-marker (make-marker) (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 mark2-end (match-end 0)
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
158 beg1 (or (match-beginning 2) (match-beginning 4))
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
159 end1 (or (match-end 2) (match-end 4))
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
160 beg2 (or (match-beginning 3) (match-beginning 5))
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
161 end2 (or (match-end 3) (match-end 5)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;; possible-file-names is holding the new file names until we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;; insert the old file name in the patch map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;; It is a pair (filename from 1st header line . fn from 2nd line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (setq possible-file-names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (cons (if (and beg1 end1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (buffer-substring beg1 end1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 "/dev/null")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (if (and beg2 end2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (buffer-substring beg2 end2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 "/dev/null")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;; check for any `Index:' or `Prereq:' lines, but don't use them
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (if (re-search-backward "^Index:" mark1-end 'noerror)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (move-marker mark2 (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (if (re-search-backward "^Prereq:" mark1-end 'noerror)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (move-marker mark2 (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (goto-char mark2-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (if filenames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (setq patch-map (cons (list filenames mark1 mark2) patch-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (setq mark1 mark2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 mark1-end mark2-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 filenames possible-file-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (setq opoint (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 count (1+ count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (setq mark2 (point-max-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 patch-map (cons (list possible-file-names mark1 mark2) patch-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (setq ediff-patch-map (nreverse patch-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; Fix up the file names in the list using the argument FILENAME
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;; Algorithm: find the first file's directory and cut it out from each file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;; name in the patch. Prepend the directory of FILENAME to each file in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ;; patch. In addition, the first file in the patch is replaced by FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;; Each file is actually a file-pair of files found in the context diff header
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;; In the end, for each pair, we select the shortest existing file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;; Note: Ediff doesn't recognize multi-file patches that are separated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;; with the `Index:' line. It treats them as a single-file patch.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;; Executes inside the patch buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (defun ediff-fixup-patch-map (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (setq filename (expand-file-name filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (let ((actual-dir (if (file-directory-p filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; directory part of filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (file-name-as-directory filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (file-name-directory filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;; directory part of the first file in the patch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (base-dir1 (file-name-directory (car (car (car ediff-patch-map)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (base-dir2 (file-name-directory (cdr (car (car ediff-patch-map)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;; chop off base-dirs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (mapcar (function (lambda (triple)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (or (string= (car (car triple)) "/dev/null")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (setcar (car triple)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (ediff-file-name-sans-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (car (car triple)) base-dir1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (or (string= (cdr (car triple)) "/dev/null")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (setcdr (car triple)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (ediff-file-name-sans-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (cdr (car triple)) base-dir2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 ediff-patch-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ;; take the given file name into account
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (or (file-directory-p filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (string= "/dev/null" filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (setcar (car ediff-patch-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (cons (file-name-nondirectory filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (file-name-nondirectory filename)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;; prepend actual-dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (mapcar (function (lambda (triple)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (if (and (string-match "^/null/" (car (car triple)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (string-match "^/null/" (cdr (car triple))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ;; couldn't strip base-dir1 and base-dir2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ;; hence, something wrong
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (with-output-to-temp-buffer ediff-msg-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (princ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (format "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 The patch file contains a context diff for
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
245
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 %s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 %s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 However, Ediff cannot infer the name of the actual file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 to be patched on your system. If you know the correct file name,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 please enter it now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 If you don't know and still would like to apply patches to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 other files, enter /dev/null
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (substring (car (car triple)) 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (substring (cdr (car triple)) 6))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (let ((directory t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 user-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (while directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (setq user-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (read-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 "Please enter file name: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 actual-dir actual-dir t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (if (not (file-directory-p user-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (setq directory nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (setq directory t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (message "%s is a directory" user-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (sit-for 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (setcar triple (cons user-file user-file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (setcar (car triple)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (concat actual-dir (car (car triple)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (setcdr (car triple)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (concat actual-dir (cdr (car triple))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ediff-patch-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ;; check for the shorter existing file in each pair and discard the other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;; one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (mapcar (function (lambda (triple)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (let* ((file1 (car (car triple)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (file2 (cdr (car triple)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (f1-exists (file-exists-p file1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (f2-exists (file-exists-p file2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 ((and (< (length file2) (length file1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 f2-exists)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (setcar triple file2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ((and (< (length file1) (length file2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 f1-exists)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (setcar triple file1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 ((and f1-exists f2-exists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (string= file1 file2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (setcar triple file1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ((and f1-exists f2-exists)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (with-output-to-temp-buffer ediff-msg-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (princ (format "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 Ediff has inferred that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 %s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 %s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 are possible targets for applying the patch.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 Both files seem to be plausible alternatives.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 Please advice:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 Type `y' to use %s as the target;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 Type `n' to use %s as the target.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 file1 file2 file2 file1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (setcar triple
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (if (y-or-n-p (format "Use %s ? " file2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 file2 file1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (f2-exists (setcar triple file2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (f1-exists (setcar triple file1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (with-output-to-temp-buffer ediff-msg-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (princ (format "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 Ediff inferred that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 %s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 %s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 are possible alternative targets for this patch.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 However, these files do not exist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 Please enter an alternative patch target ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 file1 file2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (let ((directory t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 target)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (while directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (setq target (read-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 "Please enter a patch target: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 actual-dir actual-dir t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (if (not (file-directory-p target))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (setq directory nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (message "%s is a directory" target)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (sit-for 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (setcar triple target)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 ediff-patch-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (defun ediff-show-patch-diagnostics ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (cond ((window-live-p ediff-window-A)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (set-window-buffer ediff-window-A ediff-patch-diagnostics))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 ((window-live-p ediff-window-B)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (set-window-buffer ediff-window-B ediff-patch-diagnostics))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (t (display-buffer ediff-patch-diagnostics 'not-this-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (defun ediff-get-patch-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 "Obtain patch buffer. If patch is already in a buffer---use it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 Else, read patch file into a new buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (let ((dir (cond (ediff-patch-default-directory) ; try patch default dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (ediff-use-last-dir ediff-last-dir-patch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (t default-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 patch-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (if (y-or-n-p "Is the patch already in a buffer? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (setq patch-buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (get-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (read-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 "Which buffer contains the patch? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (current-buffer) 'must-match)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (setq patch-buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (find-file-noselect
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
367 (read-file-name "Which file contains the patch? "
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
368 dir nil 'must-match))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (ediff-eval-in-buffer patch-buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (or (ediff-get-visible-buffer-window patch-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (pop-to-buffer patch-buf 'other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (select-window (previous-window)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (ediff-map-patch-buffer patch-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 patch-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 ;; Dispatch the right patch file function: regular or meta-level,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 ;; depending on how many patches are in the patch file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 ;; At present, there is no support for meta-level patches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 ;; Should return either the ctl buffer or the meta-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (defun ediff-dispatch-file-patching-job (patch-buf filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 &optional startup-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (ediff-eval-in-buffer patch-buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ;; relativize names in the patch with respect to source-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (ediff-fixup-patch-map filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (if (< (length ediff-patch-map) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (ediff-patch-file-internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 patch-buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (if (and (not (string-match "^/dev/null" (car (car ediff-patch-map))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (> (length (car (car ediff-patch-map))) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (car (car ediff-patch-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 startup-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (ediff-multi-patch-internal patch-buf startup-hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (defun ediff-patch-buffer-internal (patch-buf buf-to-patch-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 &optional startup-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (let* ((buf-to-patch (get-buffer buf-to-patch-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (file-name-ok (if buf-to-patch (buffer-file-name buf-to-patch)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (buf-mod-status (buffer-modified-p buf-to-patch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (multifile-patch-p (> (length (ediff-eval-in-buffer patch-buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 ediff-patch-map)) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 default-dir file-name ctl-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (if file-name-ok
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (setq file-name file-name-ok)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (if multifile-patch-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 "Can't apply multi-file patches to buffers that visit no files"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (ediff-eval-in-buffer buf-to-patch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (setq default-dir default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (setq file-name (ediff-make-temp-file buf-to-patch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (set-visited-file-name file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (setq buffer-auto-save-file-name nil) ; don't create auto-save file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 ;;don't confuse the user with a new bufname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (rename-buffer buf-to-patch-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (set-visited-file-modtime) ; sync buffer and temp file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (setq default-directory default-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ;; dispatch a patch function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (setq ctl-buf (ediff-dispatch-file-patching-job
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 patch-buf file-name startup-hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (if file-name-ok
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 ;; buffer wasn't visiting any file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 ;; so we will not run meta-level ediff here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (ediff-eval-in-buffer ctl-buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (delete-file (buffer-file-name ediff-buffer-A))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (delete-file (buffer-file-name ediff-buffer-B))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (ediff-eval-in-buffer ediff-buffer-A
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (if default-dir (setq default-directory default-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (set-visited-file-name nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (rename-buffer buf-to-patch-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (set-buffer-modified-p buf-mod-status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (ediff-eval-in-buffer ediff-buffer-B
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (setq buffer-auto-save-file-name nil) ; don't create auto-save file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (if default-dir (setq default-directory default-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (set-visited-file-name nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (rename-buffer (ediff-unique-buffer-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (concat buf-to-patch-name "_patched") ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (set-buffer-modified-p t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (defun ediff-patch-file-internal (patch-buf source-filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 &optional startup-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (setq source-filename (expand-file-name source-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
454 (let* ((shell-file-name ediff-shell)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (patch-diagnostics (get-buffer-create "*ediff patch diagnostics*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ;; ediff-find-file may use a temp file to do the patch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 ;; so, we save source-filename and true-source-filename as a var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ;; that initially is source-filename but may be changed to a temp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 ;; file for the purpose of patching.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (true-source-filename source-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (target-filename source-filename)
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
462 target-buf buf-to-patch file-name-magic-p
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
463 patch-return-code ctl-buf backup-style aux-wind)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (if (string-match "-V" ediff-patch-options)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 "Ediff doesn't take the -V option in `ediff-patch-options'--sorry"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 ;; Make a temp file, if source-filename has a magic file handler (or if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ;; it is handled via auto-mode-alist and similar magic).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 ;; Check if there is a buffer visiting source-filename and if they are in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ;; sync; arrange for the deletion of temp file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (ediff-find-file 'true-source-filename 'buf-to-patch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 'ediff-last-dir-patch 'startup-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 ;; Check if source file name has triggered black magic, such as file name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 ;; handlers or auto mode alist, and make a note of it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ;; true-source-filename should be either the original name or a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ;; temporary file where we put the after-product of the file handler.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (setq file-name-magic-p (not (equal (file-truename true-source-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (file-truename source-filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
483 ;; Checkout orig file, if necessary, so that the patched file
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
484 ;; could be checked back in.
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
485 (ediff-maybe-checkout buf-to-patch)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (ediff-eval-in-buffer patch-diagnostics
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (insert-buffer patch-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (message "Applying patch ... ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;; fix environment for gnu patch, so it won't make numbered extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (setq backup-style (getenv "VERSION_CONTROL"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (setenv "VERSION_CONTROL" nil)
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
493 (setq patch-return-code
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
494 (call-process-region
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
495 (point-min) (point-max)
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
496 shell-file-name
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
497 t ; delete region (which contains the patch
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
498 t ; insert output (patch diagnostics) in current buffer
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
499 nil ; don't redisplay
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
500 shell-command-switch ; usually -c
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
501 (format "%s %s %s %s"
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
502 ediff-patch-program
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
503 ediff-patch-options
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
504 ediff-backup-specs
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
505 (expand-file-name true-source-filename))
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
506 ))
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
507
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ;; restore environment for gnu patch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (setenv "VERSION_CONTROL" backup-style))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (message "Applying patch ... done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (switch-to-buffer patch-diagnostics)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (sit-for 0) ; synchronize - let the user see diagnostics
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
517 (or (and (eq patch-return-code 0) ; patch reported success
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
518 (file-exists-p
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
519 (concat true-source-filename ediff-backup-extension)))
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
520 (progn
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
521 (with-output-to-temp-buffer ediff-msg-buffer
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
522 (princ (format "
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
523 Patch has failed OR the backup version of the patched file was not created by
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
524 the patch program.
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
525
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
526 One reason may be that the values of the variables
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
527
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
528 ediff-patch-options = %S
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
529 ediff-backup-extension = %S
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
530 ediff-backup-specs = %S
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
531
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
532 are not appropriate for the program specified in the variable
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
533
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
534 ediff-patch-program = %S
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
535
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
536 Another reason could be that the %S program doesn't understand
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
537 the format of the patch file you used.
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
538
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
539 See Ediff on-line manual for more details on these variables.
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
540 \(Or use a GNU-compatible patch program and stay out of trouble.\)
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
541
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
542 Type any key to continue...
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
543 "
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
544 ediff-patch-options
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
545 ediff-backup-extension
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
546 ediff-backup-specs
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
547 ediff-patch-program
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
548 ediff-patch-program)))
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
549 (beep 1)
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
550 (if (setq aux-wind (get-buffer-window ediff-msg-buffer))
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
551 (progn
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
552 (select-window aux-wind)
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
553 (goto-char (point-max))))
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
554 (read-char-exclusive)
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
555 (if aux-wind (bury-buffer)) ; ediff-msg-buffer
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
556 (if (setq aux-wind (get-buffer-window patch-diagnostics))
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
557 (progn
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
558 (select-window aux-wind)
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
559 (bury-buffer)))
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
560 (error "Patch appears to have failed")))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
561
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 ;; If black magic is involved, apply patch to a temp copy of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 ;; file. Otherwise, apply patch to the orig copy. If patch is applied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 ;; to temp copy, we name the result old-name_patched for local files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 ;; and temp-copy_patched for remote files. The orig file name isn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 ;; changed, and the temp copy of the original is later deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 ;; Without magic, the original file is renamed (usually into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 ;; old-name_orig) and the result of patching will have the same name as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 ;; the original.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (if (not file-name-magic-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (ediff-eval-in-buffer buf-to-patch
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
572 (set-visited-file-name
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
573 (concat source-filename ediff-backup-extension))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (set-buffer-modified-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 ;; Black magic in effect.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 ;; If orig file was remote, put the patched file in the temp directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 ;; If orig file is local, put the patched file in the directory of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 ;; the orig file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (setq target-filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (if (ediff-file-remote-p (file-truename source-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 true-source-filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 source-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 "_patched"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (rename-file true-source-filename target-filename t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 ;; arrange that the temp copy of orig will be deleted
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
590 (rename-file (concat true-source-filename ediff-backup-extension)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 true-source-filename t))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
592
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 ;; make orig buffer read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (setq startup-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (cons 'ediff-set-read-only-in-buf-A startup-hooks))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 12
diff changeset
596
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 ;; set up a buf for the patched file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (setq target-buf (find-file-noselect target-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (setq ctl-buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (ediff-buffers-internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 buf-to-patch target-buf nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 startup-hooks 'epatch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (ediff-eval-in-buffer ctl-buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (setq ediff-patchbufer patch-buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 ediff-patch-diagnostics patch-diagnostics))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (bury-buffer patch-diagnostics)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (message "Type `P', if you need to see patch diagnostics")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 ctl-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (defun ediff-multi-patch-internal (patch-buf &optional startup-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (let (meta-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (setq startup-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 ;; this sets various vars in the meta buffer inside
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 ;; ediff-prepare-meta-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (cons (` (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 ;; tell what to do if the user clicks on a session record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (setq ediff-session-action-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 'ediff-patch-file-form-meta
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 ediff-meta-patchbufer patch-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 startup-hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (setq meta-buf (ediff-prepare-meta-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 'ediff-filegroup-action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (ediff-eval-in-buffer patch-buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 ;; nil replaces a regular expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (cons (list nil (format "%S" patch-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 ediff-patch-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 "*Ediff Session Group Panel"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 'ediff-redraw-directory-group-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 'ediff-multifile-patch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 startup-hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (ediff-show-meta-buffer meta-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 ;;; Local Variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1)
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
643 ;;; eval: (put 'ediff-eval-in-buffer 'edebug-form-spec '(form body))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 ;;; End:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 ;;; ediff-ptch.el ends here