Skip to content

Commit 3eaa38d

Browse files
dschoJunio C Hamano
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d2543b8 commit 3eaa38d

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

builtin-apply.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ struct patch {
125125
unsigned long deflate_origlen;
126126
int lines_added, lines_deleted;
127127
int score;
128+
int inaccurate_eof:1;
128129
struct fragment *fragments;
129130
char *result;
130131
unsigned long resultsize;
@@ -1333,7 +1334,8 @@ static int apply_line(char *output, const char *patch, int plen)
13331334
return plen;
13341335
}
13351336

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)
13371339
{
13381340
int match_beginning, match_end;
13391341
char *buf = desc->buffer;
@@ -1386,13 +1388,11 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag)
13861388
size -= len;
13871389
}
13881390

1389-
#ifdef NO_ACCURATE_DIFF
1390-
if (oldsize > 0 && old[oldsize - 1] == '\n' &&
1391+
if (inaccurate_eof && oldsize > 0 && old[oldsize - 1] == '\n' &&
13911392
newsize > 0 && new[newsize - 1] == '\n') {
13921393
oldsize--;
13931394
newsize--;
13941395
}
1395-
#endif
13961396

13971397
oldlines = old;
13981398
newlines = new;
@@ -1614,7 +1614,7 @@ static int apply_fragments(struct buffer_desc *desc, struct patch *patch)
16141614
return apply_binary(desc, patch);
16151615

16161616
while (frag) {
1617-
if (apply_one_fragment(desc, frag) < 0)
1617+
if (apply_one_fragment(desc, frag, patch->inaccurate_eof) < 0)
16181618
return error("patch failed: %s:%ld",
16191619
name, frag->oldpos);
16201620
frag = frag->next;
@@ -2097,7 +2097,7 @@ static int use_patch(struct patch *p)
20972097
return 1;
20982098
}
20992099

2100-
static int apply_patch(int fd, const char *filename)
2100+
static int apply_patch(int fd, const char *filename, int inaccurate_eof)
21012101
{
21022102
unsigned long offset, size;
21032103
char *buffer = read_patch_file(fd, &size);
@@ -2113,6 +2113,7 @@ static int apply_patch(int fd, const char *filename)
21132113
int nr;
21142114

21152115
patch = xcalloc(1, sizeof(*patch));
2116+
patch->inaccurate_eof = inaccurate_eof;
21162117
nr = parse_chunk(buffer + offset, size, patch);
21172118
if (nr < 0)
21182119
break;
@@ -2180,6 +2181,8 @@ int cmd_apply(int argc, const char **argv, char **envp)
21802181
{
21812182
int i;
21822183
int read_stdin = 1;
2184+
int inaccurate_eof = 0;
2185+
21832186
const char *whitespace_option = NULL;
21842187

21852188
for (i = 1; i < argc; i++) {
@@ -2188,7 +2191,7 @@ int cmd_apply(int argc, const char **argv, char **envp)
21882191
int fd;
21892192

21902193
if (!strcmp(arg, "-")) {
2191-
apply_patch(0, "<stdin>");
2194+
apply_patch(0, "<stdin>", inaccurate_eof);
21922195
read_stdin = 0;
21932196
continue;
21942197
}
@@ -2265,6 +2268,10 @@ int cmd_apply(int argc, const char **argv, char **envp)
22652268
parse_whitespace_option(arg + 13);
22662269
continue;
22672270
}
2271+
if (!strcmp(arg, "--inaccurate-eof")) {
2272+
inaccurate_eof = 1;
2273+
continue;
2274+
}
22682275

22692276
if (check_index && prefix_length < 0) {
22702277
prefix = setup_git_directory();
@@ -2281,12 +2288,12 @@ int cmd_apply(int argc, const char **argv, char **envp)
22812288
usage(apply_usage);
22822289
read_stdin = 0;
22832290
set_default_whitespace_mode(whitespace_option);
2284-
apply_patch(fd, arg);
2291+
apply_patch(fd, arg, inaccurate_eof);
22852292
close(fd);
22862293
}
22872294
set_default_whitespace_mode(whitespace_option);
22882295
if (read_stdin)
2289-
apply_patch(0, "<stdin>");
2296+
apply_patch(0, "<stdin>", inaccurate_eof);
22902297
if (whitespace_error) {
22912298
if (squelch_whitespace_errors &&
22922299
squelch_whitespace_errors < whitespace_error) {

0 commit comments

Comments
 (0)