From 99d698f1e703754422f1dd780487ddbff3726dc3 Mon Sep 17 00:00:00 2001 From: Olivier Marin Date: Mon, 7 Jul 2008 14:42:48 +0200 Subject: builtin-rerere: more carefully find conflict markers When a conflicting file contains a line that begin with "=======", rerere failed to parse conflict markers. This result to a wrong preimage file and an unexpected error for the user. The boundary between ours and theirs not just begin with 7 equals, but is followed by either a SP or a LF. This patch enforces parsing rules so that markers match in the right order, and when ambiguous, the command does not autoresolve the conflicted file. 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. Signed-off-by: Olivier Marin Signed-off-by: Junio C Hamano --- builtin-rerere.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'builtin-rerere.c') diff --git a/builtin-rerere.c b/builtin-rerere.c index 839b26e8e0..69c3a52d5e 100644 --- a/builtin-rerere.c +++ b/builtin-rerere.c @@ -112,11 +112,17 @@ static int handle_file(const char *path, strbuf_init(&one, 0); strbuf_init(&two, 0); while (fgets(buf, sizeof(buf), f)) { - if (!prefixcmp(buf, "<<<<<<< ")) + if (!prefixcmp(buf, "<<<<<<< ")) { + if (hunk) + goto bad; hunk = 1; - else if (!prefixcmp(buf, "=======")) + } else if (!prefixcmp(buf, "=======") && isspace(buf[7])) { + if (hunk != 1) + goto bad; hunk = 2; - else if (!prefixcmp(buf, ">>>>>>> ")) { + } else if (!prefixcmp(buf, ">>>>>>> ")) { + if (hunk != 2) + goto bad; if (strbuf_cmp(&one, &two) > 0) strbuf_swap(&one, &two); hunk_no++; @@ -142,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); -- cgit v1.2.3