From: Eric Sunshine <sunshine@sunshineco.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jerzy Kozera <jerzy.kozera@gmail.com>, Git List <git@vger.kernel.org>
Subject: Re: [PATCH v2] gpg-interface: strip CR chars for Windows gpg2
Date: Mon, 13 Nov 2017 05:24:14 -0500 [thread overview]
Message-ID: <CAPig+cQqLJsBTSMSPCVJ+_2JxkO=i4v681rK=THoN7xQ+jB91g@mail.gmail.com> (raw)
In-Reply-To: <xmqqk1yvaq2e.fsf@gitster.mtv.corp.google.com>
On Sun, Nov 12, 2017 at 9:08 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Eric Sunshine <sunshine@sunshineco.com> writes:
>>> + size_t i, j;
>>> + for (i = j = bottom; i < buffer->len; i++)
>>> + if (!(i < buffer->len - 1 &&
>>> + buffer->buf[i] == '\r' &&
>>> + buffer->buf[i + 1] == '\n')) {
>>
>> Hmm, was this tested? If I'm reading this correctly, this strips out
>> the entire CRLF pair, whereas the original code only stripped the CR
>> and left what followed it (typically LF) alone. Junio's suggestion was
>> to enhance this to be more careful and strip CR only when followed
>> immediately by LF (but to leave the LF intact). Therefore, this seems
>> like a regression.
>>
>>> + if (i != j)
>>> + buffer->buf[j] = buffer->buf[i];
>>> + j++;
>>> + }
>
> I think the "negate the entire thing" condition confuses the
> readers. The negated condition is "Do we still have enough bytes to
> see if we are looking at CRLF? Are we at CR? Is the one byte
> beyond what we have a LF? Do all of these three conditions hold
> true?" If not, i.e. for all the bytes on the line except for that
> narrow "we are at CR of a CRLF sequence" case, the body of the loop
> makes a literal copy and advances the destination pointer 'j'. The
> only thing that is skipped is CR that comes at the beginning of a
> CRLF sequence.
>
> So I think the loop does what it wants to do.
You're right. I misunderstood it. Rephrasing the logic in a simpler
fashion would help.
> In any case, I think this should be a two patch series---one with
> the code as-is with a better explanation, but without "make sure
> only CR in CRLF and no other CR are stripped" improvement, and the
> other as a follow-up to it to make the improvement.
Agreed, a 2-patch series makes sense.
next prev parent reply other threads:[~2017-11-13 10:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-12 13:07 [PATCH v2] gpg-interface: strip CR chars for Windows gpg2 Jerzy Kozera
2017-11-12 17:32 ` Eric Sunshine
2017-11-13 2:08 ` Junio C Hamano
2017-11-13 10:24 ` Eric Sunshine [this message]
2017-11-12 20:25 ` Torsten Bögershausen
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPig+cQqLJsBTSMSPCVJ+_2JxkO=i4v681rK=THoN7xQ+jB91g@mail.gmail.com' \
--to=sunshine@sunshineco.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jerzy.kozera@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).