@matheusbsbs / matheus-bagliano / commits / 387c9d4981
Fork 0

rerere: understand "diff3 -m" style conflicts with the original

This teaches rerere to grok conflicts expressed in "diff3 -m" style output, where the version from the common ancestor is output after the first side, preceded by a "|||||||" line. The rerere database needs to keep only the versions from two sides, so the code parses the original copy and discards it. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 29, 2008 at 10:24 UTC 387c9d49815ef4b1cefda71cf27f199d9fb24083
1 file changed +8 -2
rerere.c
+8 -2
@@ -77,7 +77,7 @@ static int handle_file(const char *path,
77 char buf[1024];
78 int hunk_no = 0;
79 enum {
80 - RR_CONTEXT = 0, RR_SIDE_1, RR_SIDE_2,
80 + RR_CONTEXT = 0, RR_SIDE_1, RR_SIDE_2, RR_ORIGINAL,
81 } hunk = RR_CONTEXT;
82 struct strbuf one, two;
83 FILE *f = fopen(path, "r");
@@ -104,9 +104,13 @@ static int handle_file(const char *path,
104 if (hunk != RR_CONTEXT)
105 goto bad;
106 hunk = RR_SIDE_1;
107 - } else if (!prefixcmp(buf, "=======") && isspace(buf[7])) {
107 + } else if (!prefixcmp(buf, "|||||||") && isspace(buf[7])) {
108 if (hunk != RR_SIDE_1)
109 goto bad;
110 + hunk = RR_ORIGINAL;
111 + } else if (!prefixcmp(buf, "=======") && isspace(buf[7])) {
112 + if (hunk != RR_SIDE_1 && hunk != RR_ORIGINAL)
113 + goto bad;
114 hunk = RR_SIDE_2;
115 } else if (!prefixcmp(buf, ">>>>>>> ")) {
116 if (hunk != RR_SIDE_2)
@@ -132,6 +136,8 @@ static int handle_file(const char *path,
136 strbuf_reset(&two);
137 } else if (hunk == RR_SIDE_1)
138 strbuf_addstr(&one, buf);
139 + else if (hunk == RR_ORIGINAL)
140 + ; /* discard */
141 else if (hunk == RR_SIDE_2)
142 strbuf_addstr(&two, buf);
143 else if (out)