summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/patch/patch/unified-reject-files.diff
diff options
context:
space:
mode:
authorAdrian Dudau <adrian.dudau@enea.com>2014-06-26 14:36:22 +0200
committerAdrian Dudau <adrian.dudau@enea.com>2014-06-26 15:32:53 +0200
commitf4cf9fe05bb3f32fabea4e54dd92d368967a80da (patch)
tree487180fa9866985ea7b28e625651765d86f515c3 /meta/recipes-devtools/patch/patch/unified-reject-files.diff
downloadpoky-f4cf9fe05bb3f32fabea4e54dd92d368967a80da.tar.gz
initial commit for Enea Linux 4.0
Migrated from the internal git server on the daisy-enea branch Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'meta/recipes-devtools/patch/patch/unified-reject-files.diff')
-rw-r--r--meta/recipes-devtools/patch/patch/unified-reject-files.diff307
1 files changed, 307 insertions, 0 deletions
diff --git a/meta/recipes-devtools/patch/patch/unified-reject-files.diff b/meta/recipes-devtools/patch/patch/unified-reject-files.diff
new file mode 100644
index 0000000000..4b59212dba
--- /dev/null
+++ b/meta/recipes-devtools/patch/patch/unified-reject-files.diff
@@ -0,0 +1,307 @@
1Upstream-Status: Inappropriate [debian patch]
2
3Generate unified diff style reject files. Also include the C function names
4in reject files whenever possible.
5
6 $ cat > f.orig
7 < a() {
8 < 2
9 < 3
10 <
11 < 5
12 < 6
13 < }
14
15 $ sed -e 's/5/5a/' f.orig > f
16 $ diff -U2 -p f.orig f > f.diff
17 $ sed -e 's/5/5a/' -e 's/6/6x/' f.orig > f
18 $ ./patch -F0 -s --no-backup-if-mismatch f --reject-unified < f.diff
19 > 1 out of 1 hunk FAILED -- saving rejects to file f.rej
20
21 $ cat f.rej
22 > @@ -3,5 +3,5 @@ a() {
23 > 3
24 >
25 > -5
26 > +5a
27 > 6
28 > }
29
30 $ ./patch -F0 -s --no-backup-if-mismatch f < f.diff
31 > 1 out of 1 hunk FAILED -- saving rejects to file f.rej
32
33 $ cat f.rej
34 > *************** a() {
35 > *** 3,7 ****
36 > 3
37 >
38 > - 5
39 > 6
40 > }
41 > --- 3,7 ----
42 > 3
43 >
44 > + 5a
45 > 6
46 > }
47
48 $ diff -Nu -p /dev/null f.orig > f2.diff
49 $ ./patch -F0 -s --no-backup-if-mismatch f --reject-unified < f2.diff
50 > Patch attempted to create file f, which already exists.
51 > 1 out of 1 hunk FAILED -- saving rejects to file f.rej
52
53 $ cat f.rej
54 > @@ -0,0 +1,7 @@
55 > +a() {
56 > +2
57 > +3
58 > +
59 > +5
60 > +6
61 > +}
62
63 $ rm -f f f.orig f.rej f.diff f2.diff
64
65Index: patch-2.5.9/pch.c
66===================================================================
67--- patch-2.5.9.orig/pch.c
68+++ patch-2.5.9/pch.c
69@@ -68,6 +68,7 @@ static LINENUM p_sline; /* and the lin
70 static LINENUM p_hunk_beg; /* line number of current hunk */
71 static LINENUM p_efake = -1; /* end of faked up lines--don't free */
72 static LINENUM p_bfake = -1; /* beg of faked up lines */
73+static char *p_c_function; /* the C function a hunk is in */
74
75 enum nametype { OLD, NEW, INDEX, NONE };
76
77@@ -888,6 +889,19 @@ another_hunk (enum diff difftype, bool r
78 next_intuit_at(line_beginning,p_input_line);
79 return chars_read == (size_t) -1 ? -1 : 0;
80 }
81+ s = buf;
82+ while (*s == '*')
83+ s++;
84+ if (*s == ' ')
85+ {
86+ p_c_function = s;
87+ while (*s != '\n')
88+ s++;
89+ *s = '\0';
90+ p_c_function = savestr (p_c_function);
91+ }
92+ else
93+ p_c_function = NULL;
94 p_hunk_beg = p_input_line + 1;
95 while (p_end < p_max) {
96 chars_read = get_line ();
97@@ -1277,8 +1291,18 @@ another_hunk (enum diff difftype, bool r
98 else
99 p_repl_lines = 1;
100 if (*s == ' ') s++;
101- if (*s != '@')
102+ if (*s++ != '@')
103 malformed ();
104+ if (*s++ == '@' && *s == ' ' && *s != '\0')
105+ {
106+ p_c_function = s;
107+ while (*s != '\n')
108+ s++;
109+ *s = '\0';
110+ p_c_function = savestr (p_c_function);
111+ }
112+ else
113+ p_c_function = NULL;
114 if (!p_ptrn_lines)
115 p_first++; /* do append rather than insert */
116 if (!p_repl_lines)
117@@ -1884,6 +1908,12 @@ pch_hunk_beg (void)
118 return p_hunk_beg;
119 }
120
121+char const *
122+pch_c_function (void)
123+{
124+ return p_c_function;
125+}
126+
127 /* Is the newline-terminated line a valid `ed' command for patch
128 input? If so, return the command character; if not, return 0.
129 This accepts accepts just a subset of the valid commands, but it's
130Index: patch-2.5.9/pch.h
131===================================================================
132--- patch-2.5.9.orig/pch.h
133+++ patch-2.5.9/pch.h
134@@ -25,6 +25,7 @@
135 LINENUM pch_end (void);
136 LINENUM pch_first (void);
137 LINENUM pch_hunk_beg (void);
138+char const *pch_c_function (void);
139 LINENUM pch_newfirst (void);
140 LINENUM pch_prefix_context (void);
141 LINENUM pch_ptrn_lines (void);
142Index: patch-2.5.9/patch.man
143===================================================================
144--- patch-2.5.9.orig/patch.man
145+++ patch-2.5.9/patch.man
146@@ -517,6 +517,9 @@ instead of the default
147 .B \&.rej
148 file.
149 .TP
150+\fB\*=reject\-unified\fP
151+Produce unified reject files. The default is to produce context type reject files.
152+.TP
153 \fB\-R\fP or \fB\*=reverse\fP
154 Assume that this patch was created with the old and new files swapped.
155 (Yes, I'm afraid that does happen occasionally, human nature being what it
156Index: patch-2.5.9/common.h
157===================================================================
158--- patch-2.5.9.orig/common.h
159+++ patch-2.5.9/common.h
160@@ -146,6 +146,7 @@ XTERN int invc;
161 XTERN struct stat instat;
162 XTERN bool dry_run;
163 XTERN bool posixly_correct;
164+XTERN bool unified_reject_files;
165
166 XTERN char const *origprae;
167 XTERN char const *origbase;
168Index: patch-2.5.9/patch.c
169===================================================================
170--- patch-2.5.9.orig/patch.c
171+++ patch-2.5.9/patch.c
172@@ -522,6 +522,7 @@ static struct option const longopts[] =
173 {"no-backup-if-mismatch", no_argument, NULL, CHAR_MAX + 6},
174 {"posix", no_argument, NULL, CHAR_MAX + 7},
175 {"quoting-style", required_argument, NULL, CHAR_MAX + 8},
176+ {"unified-reject-files", no_argument, NULL, CHAR_MAX + 9},
177 {NULL, no_argument, NULL, 0}
178 };
179
180@@ -580,6 +581,7 @@ static char const *const option_help[] =
181 " --verbose Output extra information about the work being done.",
182 " --dry-run Do not actually change any files; just print what would happen.",
183 " --posix Conform to the POSIX standard.",
184+" --unified-reject-files Create unified reject files.",
185 "",
186 " -d DIR --directory=DIR Change the working directory to DIR first.",
187 #if HAVE_SETMODE_DOS
188@@ -779,6 +781,9 @@ get_some_switches (void)
189 (enum quoting_style) i);
190 }
191 break;
192+ case CHAR_MAX + 9:
193+ unified_reject_files = true;
194+ break;
195 default:
196 usage (stderr, 2);
197 }
198@@ -927,6 +932,24 @@ locate_hunk (LINENUM fuzz)
199 return 0;
200 }
201
202+static char *
203+format_linerange (char rangebuf[LINENUM_LENGTH_BOUND*2 + 2],
204+ LINENUM first, LINENUM lines)
205+{
206+ if (lines == 1)
207+ rangebuf = format_linenum (rangebuf, first);
208+ else
209+ {
210+ char *rb;
211+ rangebuf = format_linenum (rangebuf + LINENUM_LENGTH_BOUND + 1, lines);
212+ rb = rangebuf-1;
213+ rangebuf = format_linenum (rangebuf - LINENUM_LENGTH_BOUND - 1,
214+ (lines > 0) ? first : 0);
215+ *rb = ',';
216+ }
217+ return rangebuf;
218+}
219+
220 /* We did not find the pattern, dump out the hunk so they can handle it. */
221
222 static void
223@@ -943,8 +966,83 @@ abort_hunk (void)
224 (int) NEW_CONTEXT_DIFF <= (int) diff_type ? " ****" : "";
225 char const *minuses =
226 (int) NEW_CONTEXT_DIFF <= (int) diff_type ? " ----" : " -----";
227+ char const *function = pch_c_function();
228+ if (function == NULL)
229+ function = "";
230+
231+ if (unified_reject_files)
232+ {
233+ /* produce unified reject files */
234+ char rangebuf0[LINENUM_LENGTH_BOUND*2 + 2];
235+ char rangebuf1[LINENUM_LENGTH_BOUND*2 + 2];
236+ LINENUM j;
237+
238+ /* Find the beginning of the remove and insert section. */
239+ for (j = 0; j <= pat_end; j++)
240+ if (pch_char (j) == '=')
241+ break;
242+ for (i = j+1; i <= pat_end; i++)
243+ if (pch_char (i) == '^')
244+ break;
245+ if (pch_char (0) != '*' || j > pat_end || i > pat_end+1)
246+ fatal ("internal error in abort_hunk");
247+ i = 1; j++;
248+
249+ /* @@ -from,lines +to,lines @@ */
250+ fprintf (rejfp, "@@ -%s +%s @@%s\n",
251+ format_linerange (rangebuf0, oldfirst, pch_ptrn_lines()),
252+ format_linerange (rangebuf1, newfirst, pch_repl_lines()),
253+ function);
254+
255+ while ( (i <= pat_end && pch_char (i) != '=')
256+ || (j <= pat_end && pch_char (j) != '^'))
257+ {
258+ if (i <= pat_end
259+ && (pch_char (i) == '-' || pch_char (i) == '!'))
260+ {
261+ fputc('-', rejfp);
262+ pch_write_line (i++, rejfp);
263+ }
264+ else if (j <= pat_end
265+ && (pch_char (j) == '+' || pch_char (j) == '!'))
266+ {
267+ fputc('+', rejfp);
268+ pch_write_line (j++, rejfp);
269+ }
270+ else if ((i <= pat_end
271+ && (pch_char (i) == ' ' || pch_char (i) == '\n')) &&
272+ (j > pat_end
273+ || (pch_char (j) == ' ' || pch_char (j) == '\n')))
274+ {
275+ /* Unless j is already past the end, lines i and j
276+ must be equal here. */
277+
278+ if (pch_char (i) == ' ')
279+ fputc(' ', rejfp);
280+ pch_write_line (i++, rejfp);
281+ if (j <= pat_end)
282+ j++;
283+ }
284+ else if ((j <= pat_end &&
285+ (pch_char (j) == ' ' || pch_char (j) == '\n')) &&
286+ (pch_char (i) == '='))
287+ {
288+ if (pch_char (j) == ' ')
289+ fputc(' ', rejfp);
290+ pch_write_line (j++, rejfp);
291+ }
292+ else
293+ fatal ("internal error in abort_hunk");
294+ }
295+
296+ if (ferror (rejfp))
297+ write_fatal ();
298+ return;
299+ }
300
301- fprintf(rejfp, "***************\n");
302+ /* produce context type reject files */
303+
304+ fprintf(rejfp, "***************%s\n", function);
305 for (i=0; i<=pat_end; i++) {
306 char numbuf0[LINENUM_LENGTH_BOUND + 1];
307 char numbuf1[LINENUM_LENGTH_BOUND + 1];