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