@@ -37,6 +37,7 @@ static int numstat = 0;
37
37
static int summary = 0 ;
38
38
static int check = 0 ;
39
39
static int apply = 1 ;
40
+ static int apply_in_reverse = 0 ;
40
41
static int no_add = 0 ;
41
42
static int show_index_info = 0 ;
42
43
static int line_termination = '\n' ;
@@ -120,7 +121,7 @@ struct fragment {
120
121
struct patch {
121
122
char * new_name , * old_name , * def_name ;
122
123
unsigned int old_mode , new_mode ;
123
- int is_rename , is_copy , is_new , is_delete , is_binary , is_reverse ;
124
+ int is_rename , is_copy , is_new , is_delete , is_binary ;
124
125
#define BINARY_DELTA_DEFLATED 1
125
126
#define BINARY_LITERAL_DEFLATED 2
126
127
unsigned long deflate_origlen ;
@@ -1143,7 +1144,6 @@ static void reverse_patches(struct patch *p)
1143
1144
swap (frag -> newpos , frag -> oldpos );
1144
1145
swap (frag -> newlines , frag -> oldlines );
1145
1146
}
1146
- p -> is_reverse = !p -> is_reverse ;
1147
1147
}
1148
1148
}
1149
1149
@@ -1363,8 +1363,7 @@ static int apply_line(char *output, const char *patch, int plen)
1363
1363
return plen ;
1364
1364
}
1365
1365
1366
- static int apply_one_fragment (struct buffer_desc * desc , struct fragment * frag ,
1367
- int reverse , int inaccurate_eof )
1366
+ static int apply_one_fragment (struct buffer_desc * desc , struct fragment * frag , int inaccurate_eof )
1368
1367
{
1369
1368
int match_beginning , match_end ;
1370
1369
char * buf = desc -> buffer ;
@@ -1396,7 +1395,7 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag,
1396
1395
if (len < size && patch [len ] == '\\' )
1397
1396
plen -- ;
1398
1397
first = * patch ;
1399
- if (reverse ) {
1398
+ if (apply_in_reverse ) {
1400
1399
if (first == '-' )
1401
1400
first = '+' ;
1402
1401
else if (first == '+' )
@@ -1536,7 +1535,7 @@ static int apply_binary_fragment(struct buffer_desc *desc, struct patch *patch)
1536
1535
void * result ;
1537
1536
1538
1537
/* Binary patch is irreversible */
1539
- if (patch -> is_reverse )
1538
+ if (apply_in_reverse )
1540
1539
return error ("cannot reverse-apply a binary patch to '%s'" ,
1541
1540
patch -> new_name
1542
1541
? patch -> new_name : patch -> old_name );
@@ -1657,8 +1656,7 @@ static int apply_fragments(struct buffer_desc *desc, struct patch *patch)
1657
1656
return apply_binary (desc , patch );
1658
1657
1659
1658
while (frag ) {
1660
- if (apply_one_fragment (desc , frag , patch -> is_reverse ,
1661
- patch -> inaccurate_eof ) < 0 )
1659
+ if (apply_one_fragment (desc , frag , patch -> inaccurate_eof ) < 0 )
1662
1660
return error ("patch failed: %s:%ld" ,
1663
1661
name , frag -> oldpos );
1664
1662
frag = frag -> next ;
@@ -2194,8 +2192,7 @@ static int use_patch(struct patch *p)
2194
2192
return 1 ;
2195
2193
}
2196
2194
2197
- static int apply_patch (int fd , const char * filename ,
2198
- int reverse , int inaccurate_eof )
2195
+ static int apply_patch (int fd , const char * filename , int inaccurate_eof )
2199
2196
{
2200
2197
unsigned long offset , size ;
2201
2198
char * buffer = read_patch_file (fd , & size );
@@ -2215,7 +2212,7 @@ static int apply_patch(int fd, const char *filename,
2215
2212
nr = parse_chunk (buffer + offset , size , patch );
2216
2213
if (nr < 0 )
2217
2214
break ;
2218
- if (reverse )
2215
+ if (apply_in_reverse )
2219
2216
reverse_patches (patch );
2220
2217
if (use_patch (patch )) {
2221
2218
patch_stats (patch );
@@ -2278,7 +2275,6 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
2278
2275
{
2279
2276
int i ;
2280
2277
int read_stdin = 1 ;
2281
- int reverse = 0 ;
2282
2278
int inaccurate_eof = 0 ;
2283
2279
2284
2280
const char * whitespace_option = NULL ;
@@ -2289,7 +2285,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
2289
2285
int fd ;
2290
2286
2291
2287
if (!strcmp (arg , "-" )) {
2292
- apply_patch (0 , "<stdin>" , reverse , inaccurate_eof );
2288
+ apply_patch (0 , "<stdin>" , inaccurate_eof );
2293
2289
read_stdin = 0 ;
2294
2290
continue ;
2295
2291
}
@@ -2367,7 +2363,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
2367
2363
continue ;
2368
2364
}
2369
2365
if (!strcmp (arg , "-R" ) || !strcmp (arg , "--reverse" )) {
2370
- reverse = 1 ;
2366
+ apply_in_reverse = 1 ;
2371
2367
continue ;
2372
2368
}
2373
2369
if (!strcmp (arg , "--inaccurate-eof" )) {
@@ -2390,12 +2386,12 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
2390
2386
usage (apply_usage );
2391
2387
read_stdin = 0 ;
2392
2388
set_default_whitespace_mode (whitespace_option );
2393
- apply_patch (fd , arg , reverse , inaccurate_eof );
2389
+ apply_patch (fd , arg , inaccurate_eof );
2394
2390
close (fd );
2395
2391
}
2396
2392
set_default_whitespace_mode (whitespace_option );
2397
2393
if (read_stdin )
2398
- apply_patch (0 , "<stdin>" , reverse , inaccurate_eof );
2394
+ apply_patch (0 , "<stdin>" , inaccurate_eof );
2399
2395
if (whitespace_error ) {
2400
2396
if (squelch_whitespace_errors &&
2401
2397
squelch_whitespace_errors < whitespace_error ) {
0 commit comments