diff options
author | Richard Purdie <rpurdie@rpsys.net> | 2006-08-26 18:01:57 +0000 |
---|---|---|
committer | Richard Purdie <rpurdie@rpsys.net> | 2006-08-26 18:01:57 +0000 |
commit | 597967252af15df8cc5a7baddfe9b7d87d2280b3 (patch) | |
tree | 441bb54cf2adf7b7cdd34851ec67fdf1d2e0ef69 /packages/patch | |
parent | 01bd80f46affbbfd3000b116c67c1052f5f2f344 (diff) |
patch: Add patches to enable unifed reject files and a global reject file (from debian)
Diffstat (limited to 'packages/patch')
-rw-r--r-- | packages/patch/patch-2.5.9/global-reject-file.diff | 201 | ||||
-rw-r--r-- | packages/patch/patch-2.5.9/unified-reject-files.diff | 305 | ||||
-rw-r--r-- | packages/patch/patch_2.5.9.bb | 5 |
3 files changed, 510 insertions, 1 deletions
diff --git a/packages/patch/patch-2.5.9/global-reject-file.diff b/packages/patch/patch-2.5.9/global-reject-file.diff new file mode 100644 index 0000000000..66065fcbf5 --- /dev/null +++ b/packages/patch/patch-2.5.9/global-reject-file.diff @@ -0,0 +1,201 @@ +Index: patch-2.5.9/patch.man +=================================================================== +--- patch-2.5.9.orig/patch.man ++++ patch-2.5.9/patch.man +@@ -520,6 +520,15 @@ file. + \fB\*=reject\-unified\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 +Index: patch-2.5.9/patch.c +=================================================================== +--- patch-2.5.9.orig/patch.c ++++ patch-2.5.9/patch.c +@@ -67,6 +67,7 @@ static bool similar (char const *, size_ + static bool spew_output (struct outstate *); + static char const *make_temp (char); + static int numeric_string (char const *, bool, char const *); ++static void reject_header (const char *filename); + static void abort_hunk (void); + static void cleanup (void); + static void get_some_switches (void); +@@ -98,6 +99,7 @@ static int Argc; + static char * const *Argv; + + static FILE *rejfp; /* reject file pointer */ ++static char *global_reject; + + static char const *patchname; + static char *rejname; +@@ -172,6 +174,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(); +@@ -208,8 +214,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) +@@ -278,6 +285,8 @@ main (int argc, char **argv) + + newwhere = pch_newfirst() + last_offset; + if (skip_rest_of_patch) { ++ if (!failed) ++ reject_header(outname); + abort_hunk(); + failed++; + if (verbosity == VERBOSE) +@@ -292,6 +301,8 @@ main (int argc, char **argv) + say ("Patch attempted to create file %s, which already exists.\n", + quotearg (inname)); + ++ if (!failed) ++ reject_header(outname); + abort_hunk(); + failed++; + if (verbosity != SILENT) +@@ -299,6 +310,8 @@ main (int argc, char **argv) + format_linenum (numbuf, newwhere)); + } + else if (! apply_hunk (&outstate, where)) { ++ if (!failed) ++ reject_header(outname); + abort_hunk (); + failed++; + if (verbosity != SILENT) +@@ -332,7 +345,8 @@ main (int argc, char **argv) + fclose (outstate.ofp); + outstate.ofp = 0; + } +- fclose (rejfp); ++ if (!global_reject) ++ fclose (rejfp); + continue; + } + +@@ -412,13 +426,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); +@@ -445,6 +459,20 @@ 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)); ++ /*if (! dry_run) ++ {*/ ++ move_file (TMPREJNAME, &TMPREJNAME_needs_removal, ++ global_reject, 0644, false); ++ /*}*/ ++ } ++ } + if (outstate.ofp && (ferror (outstate.ofp) || fclose (outstate.ofp) != 0)) + write_fatal (); + cleanup (); +@@ -523,6 +551,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} + }; + +@@ -582,6 +611,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 +@@ -784,6 +814,9 @@ get_some_switches (void) + case CHAR_MAX + 9: + unified_reject_files = true; + break; ++ case CHAR_MAX + 10: ++ global_reject = savestr (optarg); ++ break; + default: + usage (stderr, 2); + } +@@ -933,6 +966,37 @@ locate_hunk (LINENUM fuzz) + } + + static char * ++format_timestamp (char timebuf[37], bool which) ++{ ++ time_t ts = pch_timestamp(which); ++ if (ts != -1) ++ { ++ struct tm *tm = localtime(&ts); ++ strftime(timebuf, 37, "\t%Y-%m-%d %H:%M:%S.000000000 %z", tm); ++ } ++ else ++ timebuf[0] = 0; ++ return timebuf; ++} ++ ++/* Write a header in a reject file that combines multiple hunks. */ ++static void ++reject_header (const char *outname) ++{ ++ char timebuf0[37], timebuf1[37]; ++ if (!global_reject) ++ return; ++ if (diff_type == UNI_DIFF) ++ fprintf(rejfp, "--- %s.orig%s\n+++ %s%s\n", ++ outname, format_timestamp(timebuf0, reverse), ++ outname, format_timestamp(timebuf1, !reverse)); ++ else ++ fprintf(rejfp, "*** %s.orig%s\n--- %s%s\n", ++ outname, format_timestamp(timebuf0, reverse), ++ outname, format_timestamp(timebuf1, !reverse)); ++} ++ ++static char * + format_linerange (char rangebuf[LINENUM_LENGTH_BOUND*2 + 2], + LINENUM first, LINENUM lines) + { diff --git a/packages/patch/patch-2.5.9/unified-reject-files.diff b/packages/patch/patch-2.5.9/unified-reject-files.diff new file mode 100644 index 0000000000..6bfa00dd75 --- /dev/null +++ b/packages/patch/patch-2.5.9/unified-reject-files.diff @@ -0,0 +1,305 @@ +Generate unified diff style reject files. Also include the C function names +in reject files whenever possible. + + $ cat > f.orig + < a() { + < 2 + < 3 + < + < 5 + < 6 + < } + + $ sed -e 's/5/5a/' f.orig > f + $ diff -U2 -p f.orig f > f.diff + $ sed -e 's/5/5a/' -e 's/6/6x/' f.orig > f + $ ./patch -F0 -s --no-backup-if-mismatch f --reject-unified < f.diff + > 1 out of 1 hunk FAILED -- saving rejects to file f.rej + + $ cat f.rej + > @@ -3,5 +3,5 @@ a() { + > 3 + > + > -5 + > +5a + > 6 + > } + + $ ./patch -F0 -s --no-backup-if-mismatch f < f.diff + > 1 out of 1 hunk FAILED -- saving rejects to file f.rej + + $ cat f.rej + > *************** a() { + > *** 3,7 **** + > 3 + > + > - 5 + > 6 + > } + > --- 3,7 ---- + > 3 + > + > + 5a + > 6 + > } + + $ diff -Nu -p /dev/null f.orig > f2.diff + $ ./patch -F0 -s --no-backup-if-mismatch f --reject-unified < f2.diff + > Patch attempted to create file f, which already exists. + > 1 out of 1 hunk FAILED -- saving rejects to file f.rej + + $ cat f.rej + > @@ -0,0 +1,7 @@ + > +a() { + > +2 + > +3 + > + + > +5 + > +6 + > +} + + $ rm -f f f.orig f.rej f.diff f2.diff + +Index: patch-2.5.9/pch.c +=================================================================== +--- patch-2.5.9.orig/pch.c ++++ patch-2.5.9/pch.c +@@ -68,6 +68,7 @@ static LINENUM p_sline; /* and the lin + static LINENUM p_hunk_beg; /* line number of current hunk */ + static LINENUM p_efake = -1; /* end of faked up lines--don't free */ + static LINENUM p_bfake = -1; /* beg of faked up lines */ ++static char *p_c_function; /* the C function a hunk is in */ + + enum nametype { OLD, NEW, INDEX, NONE }; + +@@ -888,6 +889,19 @@ another_hunk (enum diff difftype, bool r + next_intuit_at(line_beginning,p_input_line); + return chars_read == (size_t) -1 ? -1 : 0; + } ++ s = buf; ++ while (*s == '*') ++ s++; ++ if (*s == ' ') ++ { ++ p_c_function = s; ++ while (*s != '\n') ++ s++; ++ *s = '\0'; ++ p_c_function = savestr (p_c_function); ++ } ++ else ++ p_c_function = NULL; + p_hunk_beg = p_input_line + 1; + while (p_end < p_max) { + chars_read = get_line (); +@@ -1277,8 +1291,18 @@ another_hunk (enum diff difftype, bool r + else + p_repl_lines = 1; + if (*s == ' ') s++; +- if (*s != '@') ++ if (*s++ != '@') + malformed (); ++ if (*s++ == '@' && *s == ' ' && *s != '\0') ++ { ++ p_c_function = s; ++ while (*s != '\n') ++ s++; ++ *s = '\0'; ++ p_c_function = savestr (p_c_function); ++ } ++ else ++ p_c_function = NULL; + if (!p_ptrn_lines) + p_first++; /* do append rather than insert */ + if (!p_repl_lines) +@@ -1884,6 +1908,12 @@ pch_hunk_beg (void) + return p_hunk_beg; + } + ++char const * ++pch_c_function (void) ++{ ++ return p_c_function; ++} ++ + /* Is the newline-terminated line a valid `ed' command for patch + input? If so, return the command character; if not, return 0. + This accepts accepts just a subset of the valid commands, but it's +Index: patch-2.5.9/pch.h +=================================================================== +--- patch-2.5.9.orig/pch.h ++++ patch-2.5.9/pch.h +@@ -25,6 +25,7 @@ + LINENUM pch_end (void); + LINENUM pch_first (void); + LINENUM pch_hunk_beg (void); ++char const *pch_c_function (void); + LINENUM pch_newfirst (void); + LINENUM pch_prefix_context (void); + LINENUM pch_ptrn_lines (void); +Index: patch-2.5.9/patch.man +=================================================================== +--- patch-2.5.9.orig/patch.man ++++ patch-2.5.9/patch.man +@@ -517,6 +517,9 @@ instead of the default + .B \&.rej + file. + .TP ++\fB\*=reject\-unified\fP ++Produce unified reject files. The default is to produce context type reject files. ++.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 +Index: patch-2.5.9/common.h +=================================================================== +--- patch-2.5.9.orig/common.h ++++ patch-2.5.9/common.h +@@ -146,6 +146,7 @@ XTERN int invc; + XTERN struct stat instat; + XTERN bool dry_run; + XTERN bool posixly_correct; ++XTERN bool unified_reject_files; + + XTERN char const *origprae; + XTERN char const *origbase; +Index: patch-2.5.9/patch.c +=================================================================== +--- patch-2.5.9.orig/patch.c ++++ patch-2.5.9/patch.c +@@ -522,6 +522,7 @@ static struct option const longopts[] = + {"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}, ++ {"unified-reject-files", no_argument, NULL, CHAR_MAX + 9}, + {NULL, no_argument, NULL, 0} + }; + +@@ -580,6 +581,7 @@ static char const *const option_help[] = + " --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.", ++" --unified-reject-files Create unified reject files.", + "", + " -d DIR --directory=DIR Change the working directory to DIR first.", + #if HAVE_SETMODE_DOS +@@ -779,6 +781,9 @@ get_some_switches (void) + (enum quoting_style) i); + } + break; ++ case CHAR_MAX + 9: ++ unified_reject_files = true; ++ break; + default: + usage (stderr, 2); + } +@@ -927,6 +932,24 @@ locate_hunk (LINENUM fuzz) + return 0; + } + ++static char * ++format_linerange (char rangebuf[LINENUM_LENGTH_BOUND*2 + 2], ++ LINENUM first, LINENUM lines) ++{ ++ if (lines == 1) ++ rangebuf = format_linenum (rangebuf, first); ++ else ++ { ++ char *rb; ++ rangebuf = format_linenum (rangebuf + LINENUM_LENGTH_BOUND + 1, lines); ++ rb = rangebuf-1; ++ rangebuf = format_linenum (rangebuf - LINENUM_LENGTH_BOUND - 1, ++ (lines > 0) ? first : 0); ++ *rb = ','; ++ } ++ return rangebuf; ++} ++ + /* We did not find the pattern, dump out the hunk so they can handle it. */ + + static void +@@ -943,8 +966,83 @@ abort_hunk (void) + (int) NEW_CONTEXT_DIFF <= (int) diff_type ? " ****" : ""; + char const *minuses = + (int) NEW_CONTEXT_DIFF <= (int) diff_type ? " ----" : " -----"; ++ char const *function = pch_c_function(); ++ if (function == NULL) ++ function = ""; ++ ++ if (unified_reject_files) ++ { ++ /* produce unified reject files */ ++ char rangebuf0[LINENUM_LENGTH_BOUND*2 + 2]; ++ char rangebuf1[LINENUM_LENGTH_BOUND*2 + 2]; ++ LINENUM j; ++ ++ /* Find the beginning of the remove and insert section. */ ++ for (j = 0; j <= pat_end; j++) ++ if (pch_char (j) == '=') ++ break; ++ for (i = j+1; i <= pat_end; i++) ++ if (pch_char (i) == '^') ++ break; ++ if (pch_char (0) != '*' || j > pat_end || i > pat_end+1) ++ fatal ("internal error in abort_hunk"); ++ i = 1; j++; ++ ++ /* @@ -from,lines +to,lines @@ */ ++ fprintf (rejfp, "@@ -%s +%s @@%s\n", ++ format_linerange (rangebuf0, oldfirst, pch_ptrn_lines()), ++ format_linerange (rangebuf1, newfirst, pch_repl_lines()), ++ function); ++ ++ while ( (i <= pat_end && pch_char (i) != '=') ++ || (j <= pat_end && pch_char (j) != '^')) ++ { ++ if (i <= pat_end ++ && (pch_char (i) == '-' || pch_char (i) == '!')) ++ { ++ fputc('-', rejfp); ++ pch_write_line (i++, rejfp); ++ } ++ else if (j <= pat_end ++ && (pch_char (j) == '+' || pch_char (j) == '!')) ++ { ++ fputc('+', rejfp); ++ pch_write_line (j++, rejfp); ++ } ++ else if ((i <= pat_end ++ && (pch_char (i) == ' ' || pch_char (i) == '\n')) && ++ (j > pat_end ++ || (pch_char (j) == ' ' || pch_char (j) == '\n'))) ++ { ++ /* Unless j is already past the end, lines i and j ++ must be equal here. */ ++ ++ if (pch_char (i) == ' ') ++ fputc(' ', rejfp); ++ pch_write_line (i++, rejfp); ++ if (j <= pat_end) ++ j++; ++ } ++ else if ((j <= pat_end && ++ (pch_char (j) == ' ' || pch_char (j) == '\n')) && ++ (pch_char (i) == '=')) ++ { ++ if (pch_char (j) == ' ') ++ fputc(' ', rejfp); ++ pch_write_line (j++, rejfp); ++ } ++ else ++ fatal ("internal error in abort_hunk"); ++ } ++ ++ if (ferror (rejfp)) ++ write_fatal (); ++ return; ++ } + +- fprintf(rejfp, "***************\n"); ++ /* produce context type reject files */ ++ ++ fprintf(rejfp, "***************%s\n", function); + for (i=0; i<=pat_end; i++) { + char numbuf0[LINENUM_LENGTH_BOUND + 1]; + char numbuf1[LINENUM_LENGTH_BOUND + 1]; diff --git a/packages/patch/patch_2.5.9.bb b/packages/patch/patch_2.5.9.bb index 103337b4c9..940b15a205 100644 --- a/packages/patch/patch_2.5.9.bb +++ b/packages/patch/patch_2.5.9.bb @@ -3,5 +3,8 @@ require patch.inc SRC_URI = "${GNU_MIRROR}/patch/patch-2.5.4.tar.gz \ file://2.5.9.patch;patch=1 \ file://debian.patch;patch=1 \ - file://install.patch;patch=1" + file://install.patch;patch=1 \ + file://unified-reject-files.diff;patch=1 \ + file://global-reject-file.diff;patch=1 " S = "${WORKDIR}/patch-2.5.4" +PR = "r1"
\ No newline at end of file |