From: Junio C Hamano <gitster@pobox.com>
To: Olivier Marin <dkr+ml.git@free.fr>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>, git@vger.kernel.org
Subject: Re* [PATCH] builtin-rerere: fix conflict markers parsing
Date: Tue, 08 Jul 2008 00:52:55 -0700 [thread overview]
Message-ID: <7vwsjwvmlk.fsf_-_@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <7vy74d4mr8.fsf@gitster.siamese.dyndns.org> (Junio C. Hamano's message of "Mon, 07 Jul 2008 10:39:23 -0700")
Junio C Hamano <gitster@pobox.com> writes:
> Johannes Schindelin <Johannes.Schindelin@gmx.de> 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);
next prev parent reply other threads:[~2008-07-08 7:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-07 12:42 [PATCH] builtin-rerere: fix conflict markers parsing Olivier Marin
2008-07-07 13:02 ` Johannes Schindelin
2008-07-07 13:55 ` Olivier Marin
2008-07-07 14:06 ` Johannes Schindelin
2008-07-07 14:44 ` Olivier Marin
2008-07-07 15:29 ` Johannes Schindelin
2008-07-07 17:39 ` Junio C Hamano
2008-07-08 7:52 ` Junio C Hamano [this message]
2008-07-08 10:42 ` Re* " Olivier Marin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vwsjwvmlk.fsf_-_@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=dkr+ml.git@free.fr \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).