@matheusbsbs / matheus-bagliano / commits / 3eaa38da94
Fork 0

apply: replace NO_ACCURATE_DIFF with --inaccurate-eof runtime flag.

It does not make much sense to build git whose behaviour is different depending on the brokenness of diff implementation of the platform because the brokenness of the patch that is applied with the tool depends on brokenness of the diff the person who generates the patch uses. So we do not use NO_ACCURATE_DIFF anymore, but help people to apply patches that do not record incomplete lines correctly with a runtime flag. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Jun 24, 2006 at 22:10 UTC 3eaa38da94c7e683163ebf78465b8681d3e8a211
1 file changed +16 -9
builtin-apply.c
+16 -9
@@ -125,6 +125,7 @@ struct patch {
125 unsigned long deflate_origlen;
126 int lines_added, lines_deleted;
127 int score;
128 + int inaccurate_eof:1;
129 struct fragment *fragments;
130 char *result;
131 unsigned long resultsize;
@@ -1333,7 +1334,8 @@ static int apply_line(char *output, const char *patch, int plen)
1334 return plen;
1335 }
1336
1336 -static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag)
1337 +static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag,
1338 + int inaccurate_eof)
1339 {
1340 int match_beginning, match_end;
1341 char *buf = desc->buffer;
@@ -1386,13 +1388,11 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag)
1388 size -= len;
1389 }
1390
1389 -#ifdef NO_ACCURATE_DIFF
1390 - if (oldsize > 0 && old[oldsize - 1] == '\n' &&
1391 + if (inaccurate_eof && oldsize > 0 && old[oldsize - 1] == '\n' &&
1392 newsize > 0 && new[newsize - 1] == '\n') {
1393 oldsize--;
1394 newsize--;
1395 }
1395 -#endif
1396
1397 oldlines = old;
1398 newlines = new;
@@ -1614,7 +1614,7 @@ static int apply_fragments(struct buffer_desc *desc, struct patch *patch)
1614 return apply_binary(desc, patch);
1615
1616 while (frag) {
1617 - if (apply_one_fragment(desc, frag) < 0)
1617 + if (apply_one_fragment(desc, frag, patch->inaccurate_eof) < 0)
1618 return error("patch failed: %s:%ld",
1619 name, frag->oldpos);
1620 frag = frag->next;
@@ -2097,7 +2097,7 @@ static int use_patch(struct patch *p)
2097 return 1;
2098 }
2099
2100 -static int apply_patch(int fd, const char *filename)
2100 +static int apply_patch(int fd, const char *filename, int inaccurate_eof)
2101 {
2102 unsigned long offset, size;
2103 char *buffer = read_patch_file(fd, &size);
@@ -2113,6 +2113,7 @@ static int apply_patch(int fd, const char *filename)
2113 int nr;
2114
2115 patch = xcalloc(1, sizeof(*patch));
2116 + patch->inaccurate_eof = inaccurate_eof;
2117 nr = parse_chunk(buffer + offset, size, patch);
2118 if (nr < 0)
2119 break;
@@ -2180,6 +2181,8 @@ int cmd_apply(int argc, const char **argv, char **envp)
2181 {
2182 int i;
2183 int read_stdin = 1;
2184 + int inaccurate_eof = 0;
2185 +
2186 const char *whitespace_option = NULL;
2187
2188 for (i = 1; i < argc; i++) {
@@ -2188,7 +2191,7 @@ int cmd_apply(int argc, const char **argv, char **envp)
2191 int fd;
2192
2193 if (!strcmp(arg, "-")) {
2191 - apply_patch(0, "<stdin>");
2194 + apply_patch(0, "<stdin>", inaccurate_eof);
2195 read_stdin = 0;
2196 continue;
2197 }
@@ -2265,6 +2268,10 @@ int cmd_apply(int argc, const char **argv, char **envp)
2268 parse_whitespace_option(arg + 13);
2269 continue;
2270 }
2271 + if (!strcmp(arg, "--inaccurate-eof")) {
2272 + inaccurate_eof = 1;
2273 + continue;
2274 + }
2275
2276 if (check_index && prefix_length < 0) {
2277 prefix = setup_git_directory();
@@ -2281,12 +2288,12 @@ int cmd_apply(int argc, const char **argv, char **envp)
2288 usage(apply_usage);
2289 read_stdin = 0;
2290 set_default_whitespace_mode(whitespace_option);
2284 - apply_patch(fd, arg);
2291 + apply_patch(fd, arg, inaccurate_eof);
2292 close(fd);
2293 }
2294 set_default_whitespace_mode(whitespace_option);
2295 if (read_stdin)
2289 - apply_patch(0, "<stdin>");
2296 + apply_patch(0, "<stdin>", inaccurate_eof);
2297 if (whitespace_error) {
2298 if (squelch_whitespace_errors &&
2299 squelch_whitespace_errors < whitespace_error) {