bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Add --global-reject option to patch.


From: Andi Kleen
Subject: [PATCH] Add --global-reject option to patch.
Date: Fri, 4 May 2001 17:20:30 +0200

Hallo,

In --dry-run mode patch didn't give any way to get to the reject files.
I found this a bit inconvenient, because it makes --dry-run less useful.
This patch adds a new --global-reject option that adds all reject output
into a single global file in addition to the normal files, even when
--dry-run is active. It also adds the output file name to the reject file
(slight file format change, I hope it won't break anything).

Patch against 3.5.4.

-Andi

diff -ur patch-2.5.4/patch.c patch-2.5.4-hacked/patch.c
--- patch-2.5.4/patch.c Fri May  4 16:55:41 2001
+++ patch-2.5.4-hacked/patch.c  Fri May  4 17:02:02 2001
@@ -65,7 +65,7 @@
 static bool spew_output PARAMS ((struct outstate *));
 static char const *make_temp PARAMS ((int));
 static int numeric_string PARAMS ((char const *, int, char const *));
-static void abort_hunk PARAMS ((void));
+static void abort_hunk PARAMS ((char *name));
 static void cleanup PARAMS ((void));
 static void get_some_switches PARAMS ((void));
 static void init_output PARAMS ((char const *, int, struct outstate *));
@@ -79,6 +79,7 @@
 static char const *version_control;
 static char const *version_control_context;
 static int remove_empty_files;
+static char *global_reject;
 
 /* TRUE if -R was specified on command line.  */
 static int reverse_flag_specified;
@@ -280,7 +281,7 @@
 
            newwhere = pch_newfirst() + last_offset;
            if (skip_rest_of_patch) {
-               abort_hunk();
+               abort_hunk(outname);
                failed++;
                if (verbosity == VERBOSE)
                  say ("Hunk #%d ignored at %s.\n", hunk,
@@ -294,14 +295,14 @@
                  say ("Patch attempted to create file %s, which already 
exists.\n",
                       quotearg (inname));
 
-               abort_hunk();
+               abort_hunk(outname);
                failed++;
                if (verbosity != SILENT)
                  say ("Hunk #%d FAILED at %s.\n", hunk,
                       format_linenum (numbuf, newwhere));
            }
            else if (! apply_hunk (&outstate, where)) {
-               abort_hunk ();
+               abort_hunk (outname);
                failed++;
                if (verbosity != SILENT)
                  say ("Hunk #%d FAILED at %s.\n", hunk,
@@ -427,6 +428,14 @@
                    strcpy (rej, outname);
                    addext (rej, ".rej", '#');
                }
+
+               if (global_reject)
+                 {
+                   static int file_flags = O_CREAT;
+                   copy_file (TMPREJNAME, global_reject, file_flags, 0664); 
+                   file_flags = O_APPEND;
+                 }
+
                say (" -- saving rejects to file %s", quotearg (rej));
                if (! dry_run)
                  {
@@ -524,6 +534,7 @@
   {"no-backup-if-mismatch", no_argument, NULL, CHAR_MAX + 6},
   {"posix", no_argument, NULL, CHAR_MAX + 7},
   {"quoting-style", required_argument, NULL, CHAR_MAX + 8},
+  {"global-reject", required_argument, NULL, CHAR_MAX + 9},
   {NULL, no_argument, NULL, 0}
 };
 
@@ -582,6 +593,7 @@
 "  --verbose  Output extra information about the work being done.",
 "  --dry-run  Do not actually change any files; just print what would happen.",
 "  --posix  Conform to the POSIX standard.",
+"  --global-reject=file     Put all rejects into file (even with --dry-run).",
 "",
 "  -d DIR  --directory=DIR  Change the working directory to DIR first.",
 #if HAVE_SETMODE
@@ -780,6 +792,8 @@
                  set_quoting_style ((struct quoting_options *) 0,
                                     (enum quoting_style) i);
                }
+           case CHAR_MAX+9:
+               global_reject = savestr (optarg);
                break;
            default:
                usage (stderr, 2);
@@ -932,7 +946,7 @@
 /* We did not find the pattern, dump out the hunk so they can handle it. */
 
 static void
-abort_hunk (void)
+abort_hunk (char *name)
 {
     register LINENUM i;
     register LINENUM pat_end = pch_end ();
@@ -946,7 +960,7 @@
     char const *minuses =
       (int) NEW_CONTEXT_DIFF <= (int) diff_type ? " ----" : " -----";
 
-    fprintf(rejfp, "***************\n");
+    fprintf(rejfp, "*************** %s\n", name ? name : "");
     for (i=0; i<=pat_end; i++) {
        char numbuf0[LINENUM_LENGTH_BOUND + 1];
        char numbuf1[LINENUM_LENGTH_BOUND + 1];
diff -ur patch-2.5.4/util.c patch-2.5.4-hacked/util.c
--- patch-2.5.4/util.c  Fri May  4 16:55:41 2001
+++ patch-2.5.4-hacked/util.c   Fri May  4 16:55:13 2001
@@ -209,7 +209,9 @@
   mode &= ~ (S_IXUSR | S_IXGRP | S_IXOTH);
   if (! (O_CREAT && O_TRUNC))
     close (creat (file, mode));
-  fd = open (file, O_CREAT | O_TRUNC | open_flags, mode);
+  if (!(open_flags & O_APPEND))
+    open_flags |= O_CREAT | O_TRUNC;
+  fd = open (file, open_flags, mode);
   if (fd < 0)
     pfatal ("Can't create file %s", quotearg (file));
   return fd;


-- 
Life would be so much easier if we could just look at the source code.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]