1
Generate unified diff style reject files. Also include the C function names
2
in reject files whenever possible.
13
$ sed -e 's/5/5a/' f.orig > f
14
$ diff -U2 -p f.orig f > f.diff
15
$ sed -e 's/5/5a/' -e 's/6/6x/' f.orig > f
16
$ ./patch -F0 -s --no-backup-if-mismatch f --unified-reject-files < f.diff
17
> 1 out of 1 hunk FAILED -- saving rejects to file f.rej
20
> @@ -3,5 +3,5 @@ a() {
28
$ ./patch -F0 -s --no-backup-if-mismatch f < f.diff
29
> 1 out of 1 hunk FAILED -- saving rejects to file f.rej
32
> *************** a() {
46
$ diff -Nu -p /dev/null f.orig > f2.diff
47
$ ./patch -F0 -s --no-backup-if-mismatch f --unified-reject-files < f2.diff
48
> Patch attempted to create file f, which already exists.
49
> 1 out of 1 hunk FAILED -- saving rejects to file f.rej
61
$ rm -f f f.orig f.rej f.diff f2.diff
63
diff -urNad patch~/common.h patch/common.h
64
--- patch~/common.h 2006-01-28 18:58:09.000000000 +0100
65
+++ patch/common.h 2006-01-28 18:58:55.304946176 +0100
67
XTERN struct stat instat;
69
XTERN bool posixly_correct;
70
+XTERN bool unified_reject_files;
72
XTERN char const *origprae;
73
XTERN char const *origbase;
74
diff -urNad patch~/patch.c patch/patch.c
75
--- patch~/patch.c 2006-01-28 18:58:25.000000000 +0100
76
+++ patch/patch.c 2006-01-28 19:16:19.624536664 +0100
78
skip_rest_of_patch = false;
81
-static char const shortopts[] = "bB:cd:D:eEfF:g:i:lnNo:p:r:RstTuvV:x:Y:z:Z";
82
+static char const shortopts[] = "bB:cd:D:eEfF:g:i:lnNo:p:r:RstTuUvV:x:Y:z:Z";
83
static struct option const longopts[] =
85
{"backup", no_argument, NULL, 'b'},
87
{"batch", no_argument, NULL, 't'},
88
{"set-time", no_argument, NULL, 'T'},
89
{"unified", no_argument, NULL, 'u'},
90
+ {"unified-reject-files", no_argument, NULL, 'U'},
91
{"version", no_argument, NULL, 'v'},
92
{"version-control", required_argument, NULL, 'V'},
93
{"debug", required_argument, NULL, 'x'},
95
" --verbose Output extra information about the work being done.",
96
" --dry-run Do not actually change any files; just print what would happen.",
97
" --posix Conform to the POSIX standard.",
98
+" -U --unified-reject-files Create unified reject files.",
100
" -d DIR --directory=DIR Change the working directory to DIR first.",
104
diff_type = UNI_DIFF;
107
+ unified_reject_files = true;
117
+format_linerange (char rangebuf[LINENUM_LENGTH_BOUND*2 + 2],
118
+ LINENUM first, LINENUM lines)
121
+ rangebuf = format_linenum (rangebuf, first);
125
+ rangebuf = format_linenum (rangebuf + LINENUM_LENGTH_BOUND + 1, lines);
127
+ rangebuf = format_linenum (rangebuf - LINENUM_LENGTH_BOUND - 1,
128
+ (lines > 0) ? first : 0);
134
/* We did not find the pattern, dump out the hunk so they can handle it. */
138
(int) NEW_CONTEXT_DIFF <= (int) diff_type ? " ****" : "";
139
char const *minuses =
140
(int) NEW_CONTEXT_DIFF <= (int) diff_type ? " ----" : " -----";
141
+ char const *function = pch_c_function();
142
+ if (function == NULL)
145
- fprintf(rejfp, "***************\n");
146
+ if (unified_reject_files)
148
+ /* produce unified reject files */
149
+ char rangebuf0[LINENUM_LENGTH_BOUND*2 + 2];
150
+ char rangebuf1[LINENUM_LENGTH_BOUND*2 + 2];
153
+ /* Find the beginning of the remove and insert section. */
154
+ for (j = 0; j <= pat_end; j++)
155
+ if (pch_char (j) == '=')
157
+ for (i = j+1; i <= pat_end; i++)
158
+ if (pch_char (i) == '^')
160
+ if (pch_char (0) != '*' || j > pat_end || i > pat_end+1)
161
+ fatal ("internal error in abort_hunk");
164
+ /* @@ -from,lines +to,lines @@ */
165
+ fprintf (rejfp, "@@ -%s +%s @@%s\n",
166
+ format_linerange (rangebuf0, oldfirst, pch_ptrn_lines()),
167
+ format_linerange (rangebuf1, newfirst, pch_repl_lines()),
170
+ while ( (i <= pat_end && pch_char (i) != '=')
171
+ || (j <= pat_end && pch_char (j) != '^'))
174
+ && (pch_char (i) == '-' || pch_char (i) == '!'))
177
+ pch_write_line (i++, rejfp);
179
+ else if (j <= pat_end
180
+ && (pch_char (j) == '+' || pch_char (j) == '!'))
183
+ pch_write_line (j++, rejfp);
185
+ else if ((i <= pat_end
186
+ && (pch_char (i) == ' ' || pch_char (i) == '\n')) &&
188
+ || (pch_char (j) == ' ' || pch_char (j) == '\n')))
190
+ /* Unless j is already past the end, lines i and j
191
+ must be equal here. */
193
+ if (pch_char (i) == ' ')
195
+ pch_write_line (i++, rejfp);
199
+ else if ((j <= pat_end &&
200
+ (pch_char (j) == ' ' || pch_char (j) == '\n')) &&
201
+ (pch_char (i) == '='))
203
+ if (pch_char (j) == ' ')
205
+ pch_write_line (j++, rejfp);
208
+ fatal ("internal error in abort_hunk");
211
+ if (ferror (rejfp))
216
+ /* produce context type reject files */
218
+ fprintf(rejfp, "***************%s\n", function);
219
for (i=0; i<=pat_end; i++) {
220
char numbuf0[LINENUM_LENGTH_BOUND + 1];
221
char numbuf1[LINENUM_LENGTH_BOUND + 1];
222
diff -urNad patch~/patch.man patch/patch.man
223
--- patch~/patch.man 2006-01-28 18:58:25.000000000 +0100
224
+++ patch/patch.man 2006-01-28 19:14:48.146443448 +0100
229
+\fB\-U\fP or \fB\*=unified\-reject\-files\fP
230
+Produce unified reject files. The default is to produce context type reject files.
232
\fB\-R\fP or \fB\*=reverse\fP
233
Assume that this patch was created with the old and new files swapped.
234
(Yes, I'm afraid that does happen occasionally, human nature being what it
235
diff -urNad patch~/pch.c patch/pch.c
236
--- patch~/pch.c 2006-01-28 18:58:04.000000000 +0100
237
+++ patch/pch.c 2006-01-28 18:58:55.303946328 +0100
239
static LINENUM p_hunk_beg; /* line number of current hunk */
240
static LINENUM p_efake = -1; /* end of faked up lines--don't free */
241
static LINENUM p_bfake = -1; /* beg of faked up lines */
242
+static char *p_c_function; /* the C function a hunk is in */
244
enum nametype { OLD, NEW, INDEX, NONE };
247
next_intuit_at(line_beginning,p_input_line);
248
return chars_read == (size_t) -1 ? -1 : 0;
259
+ p_c_function = savestr (p_c_function);
262
+ p_c_function = NULL;
263
p_hunk_beg = p_input_line + 1;
264
while (p_end < p_max) {
265
chars_read = get_line ();
266
@@ -1277,8 +1291,18 @@
273
+ if (*s++ == '@' && *s == ' ' && *s != '\0')
279
+ p_c_function = savestr (p_c_function);
282
+ p_c_function = NULL;
284
p_first++; /* do append rather than insert */
286
@@ -1884,6 +1908,12 @@
291
+pch_c_function (void)
293
+ return p_c_function;
296
/* Is the newline-terminated line a valid `ed' command for patch
297
input? If so, return the command character; if not, return 0.
298
This accepts accepts just a subset of the valid commands, but it's
299
diff -urNad patch~/pch.h patch/pch.h
300
--- patch~/pch.h 2006-01-28 18:58:09.000000000 +0100
301
+++ patch/pch.h 2006-01-28 18:58:55.303946328 +0100
303
LINENUM pch_end (void);
304
LINENUM pch_first (void);
305
LINENUM pch_hunk_beg (void);
306
+char const *pch_c_function (void);
307
LINENUM pch_newfirst (void);
308
LINENUM pch_prefix_context (void);
309
LINENUM pch_ptrn_lines (void);