@matheusbsbs / matheus-bagliano / commits / f686d03034
Fork 0

git-apply --reverse: simplify reverse option.

Having is_reverse in each patch did not make sense. This will hopefully simplify the work needed to introduce reversible binary diff format. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Aug 14, 2006 at 23:26 UTC f686d03034c74bd0de2002b7c277a0838662ea00
1 file changed +12 -16
builtin-apply.c
+12 -16
@@ -37,6 +37,7 @@ static int numstat = 0;
37 static int summary = 0;
38 static int check = 0;
39 static int apply = 1;
40 +static int apply_in_reverse = 0;
41 static int no_add = 0;
42 static int show_index_info = 0;
43 static int line_termination = '\n';
@@ -120,7 +121,7 @@ struct fragment {
121 struct patch {
122 char *new_name, *old_name, *def_name;
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;
125 #define BINARY_DELTA_DEFLATED 1
126 #define BINARY_LITERAL_DEFLATED 2
127 unsigned long deflate_origlen;
@@ -1143,7 +1144,6 @@ static void reverse_patches(struct patch *p)
1144 swap(frag->newpos, frag->oldpos);
1145 swap(frag->newlines, frag->oldlines);
1146 }
1146 - p->is_reverse = !p->is_reverse;
1147 }
1148 }
1149
@@ -1363,8 +1363,7 @@ static int apply_line(char *output, const char *patch, int plen)
1363 return plen;
1364 }
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)
1367 {
1368 int match_beginning, match_end;
1369 char *buf = desc->buffer;
@@ -1396,7 +1395,7 @@ static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag,
1395 if (len < size && patch[len] == '\\')
1396 plen--;
1397 first = *patch;
1399 - if (reverse) {
1398 + if (apply_in_reverse) {
1399 if (first == '-')
1400 first = '+';
1401 else if (first == '+')
@@ -1536,7 +1535,7 @@ static int apply_binary_fragment(struct buffer_desc *desc, struct patch *patch)
1535 void *result;
1536
1537 /* Binary patch is irreversible */
1539 - if (patch->is_reverse)
1538 + if (apply_in_reverse)
1539 return error("cannot reverse-apply a binary patch to '%s'",
1540 patch->new_name
1541 ? patch->new_name : patch->old_name);
@@ -1657,8 +1656,7 @@ static int apply_fragments(struct buffer_desc *desc, struct patch *patch)
1656 return apply_binary(desc, patch);
1657
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)
1660 return error("patch failed: %s:%ld",
1661 name, frag->oldpos);
1662 frag = frag->next;
@@ -2194,8 +2192,7 @@ static int use_patch(struct patch *p)
2192 return 1;
2193 }
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)
2196 {
2197 unsigned long offset, size;
2198 char *buffer = read_patch_file(fd, &size);
@@ -2215,7 +2212,7 @@ static int apply_patch(int fd, const char *filename,
2212 nr = parse_chunk(buffer + offset, size, patch);
2213 if (nr < 0)
2214 break;
2218 - if (reverse)
2215 + if (apply_in_reverse)
2216 reverse_patches(patch);
2217 if (use_patch(patch)) {
2218 patch_stats(patch);
@@ -2278,7 +2275,6 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
2275 {
2276 int i;
2277 int read_stdin = 1;
2281 - int reverse = 0;
2278 int inaccurate_eof = 0;
2279
2280 const char *whitespace_option = NULL;
@@ -2289,7 +2285,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
2285 int fd;
2286
2287 if (!strcmp(arg, "-")) {
2292 - apply_patch(0, "<stdin>", reverse, inaccurate_eof);
2288 + apply_patch(0, "<stdin>", inaccurate_eof);
2289 read_stdin = 0;
2290 continue;
2291 }
@@ -2367,7 +2363,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
2363 continue;
2364 }
2365 if (!strcmp(arg, "-R") || !strcmp(arg, "--reverse")) {
2370 - reverse = 1;
2366 + apply_in_reverse = 1;
2367 continue;
2368 }
2369 if (!strcmp(arg, "--inaccurate-eof")) {
@@ -2390,12 +2386,12 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
2386 usage(apply_usage);
2387 read_stdin = 0;
2388 set_default_whitespace_mode(whitespace_option);
2393 - apply_patch(fd, arg, reverse, inaccurate_eof);
2389 + apply_patch(fd, arg, inaccurate_eof);
2390 close(fd);
2391 }
2392 set_default_whitespace_mode(whitespace_option);
2393 if (read_stdin)
2398 - apply_patch(0, "<stdin>", reverse, inaccurate_eof);
2394 + apply_patch(0, "<stdin>", inaccurate_eof);
2395 if (whitespace_error) {
2396 if (squelch_whitespace_errors &&
2397 squelch_whitespace_errors < whitespace_error) {