1
Generate a global reject file
3
diff -urNad patch~/patch.c patch/patch.c
4
--- patch~/patch.c 2006-01-28 19:20:06.725012144 +0100
5
+++ patch/patch.c 2006-01-28 19:22:34.100607648 +0100
7
static bool spew_output (struct outstate *);
8
static char const *make_temp (char);
9
static int numeric_string (char const *, bool, char const *);
10
+static void reject_header (const char *filename);
11
static void abort_hunk (void);
12
static void cleanup (void);
13
static void get_some_switches (void);
15
static char * const *Argv;
17
static FILE *rejfp; /* reject file pointer */
18
+static char *global_reject;
20
static char const *patchname;
23
/* Make sure we clean up in case of disaster. */
26
+ /* initialize global reject file */
31
open_patch_file (patchname);
32
there_is_another_patch();
34
init_output (TMPOUTNAME, exclusive, &outstate);
37
- /* initialize reject file */
39
+ /* initialize per-patch reject file */
43
/* find out where all the lines are */
44
if (!skip_rest_of_patch)
47
newwhere = pch_newfirst() + last_offset;
48
if (skip_rest_of_patch) {
50
+ reject_header(outname);
53
if (verbosity == VERBOSE)
55
say ("Patch attempted to create file %s, which already exists.\n",
59
+ reject_header(outname);
62
if (verbosity != SILENT)
64
format_linenum (numbuf, newwhere));
66
else if (! apply_hunk (&outstate, where)) {
68
+ reject_header(outname);
71
if (verbosity != SILENT)
73
fclose (outstate.ofp);
85
if (diff_type != ED_DIFF) {
86
- if (fclose (rejfp) != 0)
87
+ if (!global_reject && fclose (rejfp) != 0)
91
say ("%d out of %d hunk%s %s", failed, hunk, "s" + (hunk == 1),
92
skip_rest_of_patch ? "ignored" : "FAILED");
94
+ if (!global_reject && outname) {
97
rej = xmalloc (strlen (outname) + 5);
104
+ if (fclose (rejfp) != 0)
108
+ say (" -- saving rejects to file %s\n", quotearg (global_reject));
111
+ move_file (TMPREJNAME, &TMPREJNAME_needs_removal,
112
+ global_reject, 0644, false);
116
if (outstate.ofp && (ferror (outstate.ofp) || fclose (outstate.ofp) != 0))
120
{"no-backup-if-mismatch", no_argument, NULL, CHAR_MAX + 6},
121
{"posix", no_argument, NULL, CHAR_MAX + 7},
122
{"quoting-style", required_argument, NULL, CHAR_MAX + 8},
123
+ {"global-reject-file", required_argument, NULL, CHAR_MAX + 9},
124
{NULL, no_argument, NULL, 0}
128
" --dry-run Do not actually change any files; just print what would happen.",
129
" --posix Conform to the POSIX standard.",
130
" -U --unified-reject-files Create unified reject files.",
131
+" --global-reject-file=file Put all rejects into one file.",
133
" -d DIR --directory=DIR Change the working directory to DIR first.",
136
(enum quoting_style) i);
140
+ global_reject = savestr (optarg);
149
+format_timestamp (char timebuf[37], bool which)
151
+ time_t ts = pch_timestamp(which);
154
+ struct tm *tm = localtime(&ts);
155
+ strftime(timebuf, 37, "\t%Y-%m-%d %H:%M:%S.000000000 %z", tm);
162
+/* Write a header in a reject file that combines multiple hunks. */
164
+reject_header (const char *outname)
166
+ char timebuf0[37], timebuf1[37];
167
+ if (!global_reject)
169
+ if (diff_type == UNI_DIFF)
170
+ fprintf(rejfp, "--- %s.orig%s\n+++ %s%s\n",
171
+ outname, format_timestamp(timebuf0, reverse),
172
+ outname, format_timestamp(timebuf1, !reverse));
174
+ fprintf(rejfp, "*** %s.orig%s\n--- %s%s\n",
175
+ outname, format_timestamp(timebuf0, reverse),
176
+ outname, format_timestamp(timebuf1, !reverse));
180
format_linerange (char rangebuf[LINENUM_LENGTH_BOUND*2 + 2],
181
LINENUM first, LINENUM lines)
183
diff -urNad patch~/patch.man patch/patch.man
184
--- patch~/patch.man 2006-01-28 19:20:06.726011992 +0100
185
+++ patch/patch.man 2006-01-28 19:20:06.839994664 +0100
187
\fB\-U\fP or \fB\*=unified\-reject\-files\fP
188
Produce unified reject files. The default is to produce context type reject files.
190
+.BI \*=global\-reject\-file= rejectfile
191
+Put all rejects into
193
+instead of creating separate reject files for all files that have rejects. The
195
+will contain headers that identify which file each reject refers to. Note that
196
+the global reject file is created even if \-\-dry\-run is specified (while
197
+non-global reject files will only be created without \-\-dry\-run).
199
\fB\-R\fP or \fB\*=reverse\fP
200
Assume that this patch was created with the old and new files swapped.
201
(Yes, I'm afraid that does happen occasionally, human nature being what it