forked from pool/patch
131 lines
4.0 KiB
Diff
131 lines
4.0 KiB
Diff
---
|
|
patch.c | 33 ++++++++++++++++++++++++++++-----
|
|
patch.man | 9 +++++++++
|
|
2 files changed, 37 insertions(+), 5 deletions(-)
|
|
|
|
Index: b/patch.c
|
|
===================================================================
|
|
--- a/patch.c
|
|
+++ b/patch.c
|
|
@@ -101,6 +101,7 @@ static int Argc;
|
|
static char * const *Argv;
|
|
|
|
static FILE *rejfp; /* reject file pointer */
|
|
+char *global_reject;
|
|
|
|
static char const *patchname;
|
|
static char *rejname;
|
|
@@ -175,6 +176,10 @@ main (int argc, char **argv)
|
|
/* Make sure we clean up in case of disaster. */
|
|
set_signals (false);
|
|
|
|
+ /* initialize global reject file */
|
|
+ if (global_reject)
|
|
+ init_reject ();
|
|
+
|
|
for (
|
|
open_patch_file (patchname);
|
|
there_is_another_patch();
|
|
@@ -211,8 +216,9 @@ main (int argc, char **argv)
|
|
init_output (TMPOUTNAME, exclusive, &outstate);
|
|
}
|
|
|
|
- /* initialize reject file */
|
|
- init_reject ();
|
|
+ /* initialize per-patch reject file */
|
|
+ if (!global_reject)
|
|
+ init_reject ();
|
|
|
|
/* find out where all the lines are */
|
|
if (!skip_rest_of_patch)
|
|
@@ -335,7 +341,8 @@ main (int argc, char **argv)
|
|
fclose (outstate.ofp);
|
|
outstate.ofp = 0;
|
|
}
|
|
- fclose (rejfp);
|
|
+ if (!global_reject)
|
|
+ fclose (rejfp);
|
|
continue;
|
|
}
|
|
|
|
@@ -415,13 +422,13 @@ main (int argc, char **argv)
|
|
}
|
|
}
|
|
if (diff_type != ED_DIFF) {
|
|
- if (fclose (rejfp) != 0)
|
|
+ if (!global_reject && fclose (rejfp) != 0)
|
|
write_fatal ();
|
|
if (failed) {
|
|
somefailed = true;
|
|
say ("%d out of %d hunk%s %s", failed, hunk, "s" + (hunk == 1),
|
|
skip_rest_of_patch ? "ignored" : "FAILED");
|
|
- if (outname) {
|
|
+ if (!global_reject && outname) {
|
|
char *rej = rejname;
|
|
if (!rejname) {
|
|
rej = xmalloc (strlen (outname) + 5);
|
|
@@ -448,6 +455,17 @@ main (int argc, char **argv)
|
|
}
|
|
set_signals (true);
|
|
}
|
|
+ if (global_reject)
|
|
+ {
|
|
+ if (fclose (rejfp) != 0)
|
|
+ write_fatal ();
|
|
+ if (somefailed)
|
|
+ {
|
|
+ say (" -- saving rejects to file %s\n", quotearg (global_reject));
|
|
+ move_file (TMPREJNAME, &TMPREJNAME_needs_removal,
|
|
+ global_reject, 0644, false);
|
|
+ }
|
|
+ }
|
|
if (outstate.ofp && (ferror (outstate.ofp) || fclose (outstate.ofp) != 0))
|
|
write_fatal ();
|
|
cleanup ();
|
|
@@ -526,6 +544,7 @@ static struct option const longopts[] =
|
|
{"posix", no_argument, NULL, CHAR_MAX + 7},
|
|
{"quoting-style", required_argument, NULL, CHAR_MAX + 8},
|
|
{"unified-reject-files", no_argument, NULL, CHAR_MAX + 9},
|
|
+ {"global-reject-file", required_argument, NULL, CHAR_MAX + 10},
|
|
{NULL, no_argument, NULL, 0}
|
|
};
|
|
|
|
@@ -585,6 +604,7 @@ static char const *const option_help[] =
|
|
" --dry-run Do not actually change any files; just print what would happen.",
|
|
" --posix Conform to the POSIX standard.",
|
|
" --unified-reject-files Create unified reject files.",
|
|
+" --global-reject-file=file Put all rejects into one file.",
|
|
"",
|
|
" -d DIR --directory=DIR Change the working directory to DIR first.",
|
|
#if HAVE_SETMODE_DOS
|
|
@@ -787,6 +807,9 @@ get_some_switches (void)
|
|
case CHAR_MAX + 9:
|
|
abort_hunk = abort_hunk_unified;
|
|
break;
|
|
+ case CHAR_MAX + 10:
|
|
+ global_reject = savestr (optarg);
|
|
+ break;
|
|
default:
|
|
usage (stderr, 2);
|
|
}
|
|
Index: b/patch.man
|
|
===================================================================
|
|
--- a/patch.man
|
|
+++ b/patch.man
|
|
@@ -520,6 +520,15 @@ file.
|
|
\fB\*=unified\-reject\-files\fP
|
|
Produce unified reject files. The default is to produce context type reject files.
|
|
.TP
|
|
+.BI \*=global\-reject\-file= rejectfile
|
|
+Put all rejects into
|
|
+.I rejectfile
|
|
+instead of creating separate reject files for all files that have rejects. The
|
|
+.I rejectfile
|
|
+will contain headers that identify which file each reject refers to. Note that
|
|
+the global reject file is created even if \-\-dry\-run is specified (while
|
|
+non-global reject files will only be created without \-\-dry\-run).
|
|
+.TP
|
|
\fB\-R\fP or \fB\*=reverse\fP
|
|
Assume that this patch was created with the old and new files swapped.
|
|
(Yes, I'm afraid that does happen occasionally, human nature being what it
|