Junio C Hamano <gitster@xxxxxxxxx> writes: > Johannes Schindelin <Johannes.Schindelin@xxxxxx> writes: > >> So what about >> >> <<<<<<< This hunk contains ===== >> anythin >> ======= >> >> Hello >> ======= >> somethin else >> >>>>>>> problem! >> ... > I however think detecting that we have this ambiguous hunk is easy, and > punting gracefully and not re-resolving in such a case is million times > better than producing random results that the users need to be worried > about. I am wondering if a patch like this on top of your patch may make things even safer. The idea is the same as the earlier a1b32fd (git-rerere: detect unparsable conflicts, 2008-06-22) to fail rerere unless the markers are unambiguous. Thanks to your isspace(buf[7]), it is slightly less likely that this safety triggers on false positives. Thoughts? -- >8 -- rerere: punt and do not resolve if conflict markers are ambiguous Especially because we are introducing rerere.autoupdate configuration (which is off by default for safety) that automatically stages the resolution made by rerere, it is necessary to make sure that we do not autoresolve when there is any ambiguity. builtin-rerere.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-) diff --git a/builtin-rerere.c b/builtin-rerere.c index e618862..69c3a52 100644 --- a/builtin-rerere.c +++ b/builtin-rerere.c @@ -112,12 +112,17 @@ static int handle_file(const char *path, strbuf_init(&one, 0); strbuf_init(&two, 0); while (fgets(buf, sizeof(buf), f)) { - if (hunk == 0 && !prefixcmp(buf, "<<<<<<< ")) + if (!prefixcmp(buf, "<<<<<<< ")) { + if (hunk) + goto bad; hunk = 1; - else if (hunk == 1 && !prefixcmp(buf, "=======") && - isspace(buf[7])) + } else if (!prefixcmp(buf, "=======") && isspace(buf[7])) { + if (hunk != 1) + goto bad; hunk = 2; - else if (hunk == 2 && !prefixcmp(buf, ">>>>>>> ")) { + } else if (!prefixcmp(buf, ">>>>>>> ")) { + if (hunk != 2) + goto bad; if (strbuf_cmp(&one, &two) > 0) strbuf_swap(&one, &two); hunk_no++; @@ -143,6 +148,10 @@ static int handle_file(const char *path, strbuf_addstr(&two, buf); else if (out) fputs(buf, out); + continue; + bad: + hunk = 99; /* force error exit */ + break; } strbuf_release(&one); strbuf_release(&two); -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html