From: Junio C Hamano <gitster@pobox.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2 2/2] diff: --ignore-cr-at-eol
Date: Wed, 15 Nov 2017 13:28:24 +0900 [thread overview]
Message-ID: <xmqq60ac17yv.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1.1711071345430.6482@virtualbox> (Johannes Schindelin's message of "Tue, 7 Nov 2017 14:23:00 +0100 (CET)")
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
I notice that I left a few things unanswered even after giving
answers to the most important part (i.e. "what is this for was
sold incorrectly"). Here are the leftover bits.
>> diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
>> index 89cc0f48de..aa2c0ff74d 100644
>> --- a/Documentation/diff-options.txt
>> +++ b/Documentation/diff-options.txt
>> @@ -519,6 +519,9 @@ endif::git-format-patch[]
>> --text::
>> Treat all files as text.
>>
>> +--ignore-cr-at-eol::
>> + Ignore carrige-return at the end of line when doing a comparison.
>
> I am not a native speaker, either, yet I have the impression that "do a
> comparison" may be more colloquial than not. Also, it is a carriage-return
> (as in Sinatra's famous song about Love and Marriage) not a carrige-return.
>
> How about "Hide changed line endings"?
That felt like a good suggestion when I saw your reaction,
especially with only the parts visible in the patch and its context,
but after reviewing descriptions of other --ignore-* options, I no
longer think so. The existing description of "--ignore-*" matches
manpages of GNU diff and they do not say "hide", either.
>> diff --git a/xdiff/xutils.c b/xdiff/xutils.c
>> index 04d7b32e4e..b2cbcc818f 100644
>> --- a/xdiff/xutils.c
>> +++ b/xdiff/xutils.c
>> @@ -156,6 +156,24 @@ int xdl_blankline(const char *line, long size, long flags)
>> return (i == size);
>> }
>>
>> +/*
>> + * Have we eaten everything on the line, except for an optional
>> + * CR at the very end?
>> + */
>> +static int ends_with_optional_cr(const char *l, long s, long i)
>> +{
>> + int complete = s && l[s-1] == '\n';
>> +
>> + if (complete)
>> + s--;
>> + if (s == i)
>> + return 1;
>
> What is the role of `s`, what of `i`? Maybe `length` and `current_offset`?
I'd agree with that sentiment if this file were not borrowed code
but our own, but after looking at xdiff/ code, I think the names of
these variables follow the convention used there better, which
consistently names the variable for lines they deal with l1, l2, etc.,
their sizes s1, s2, etc., and the indices into the line i1, i2, etc.
>> + /* do not ignore CR at the end of an incomplete line */
>> + if (complete && s == i + 1 && l[i] == '\r')
>> + return 1;
>
> This made me scratch my head: too many negations. The comment may better
> read "ignore CR only at the end of a complete line".
Perhaps. "incomplete line" is a term with a specific definition
(and I think by "complete line" you mean a line that is not an
incomplete line), so I do not see the above comment as having too
many negations, though. If you feel strongly about it, you could
"fix" it with a follow-up patch.
>> @@ -204,6 +223,14 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)
>> i1++;
>> i2++;
>> }
>> + } else if (flags & XDF_IGNORE_CR_AT_EOL) {
>> + /* Find the first difference and see how the line ends */
>> + while (i1 < s1 && i2 < s2 && l1[i1] == l2[i2]) {
>> + i1++;
>> + i2++;
>> + }
>> + return (ends_with_optional_cr(l1, s1, i1) &&
>> + ends_with_optional_cr(l2, s2, i2));
>
> There are extra parentheses around the `return` expression.
Yes, everybody knows that return is not a function that needs a
parentheses around its parameter. I would drop them if this
expression were not split into two lines, but because the expression
is split at &&, I think it reads better with the extra parens. So
I'll leave them as-is.
Thanks.
next prev parent reply other threads:[~2017-11-15 4:28 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-24 17:48 Consequences of CRLF in index? Lars Schneider
2017-10-24 18:14 ` Jonathan Nieder
2017-10-24 19:02 ` Torsten Bögershausen
2017-10-25 12:13 ` Johannes Schindelin
2017-10-25 1:51 ` Junio C Hamano
2017-10-25 4:53 ` Junio C Hamano
2017-10-25 16:44 ` Stefan Beller
2017-10-26 5:54 ` Junio C Hamano
2017-10-27 6:13 ` Re* " Junio C Hamano
2017-10-27 17:06 ` Stefan Beller
2017-10-27 17:07 ` [PATCH 0/2] " Stefan Beller
2017-10-27 17:07 ` [PATCH 1/2] xdiff/xdiff.h: remove unused flags Stefan Beller
2017-10-27 17:07 ` [PATCH 2/2] xdiff/xdiffi.c: remove unneeded function declarations Stefan Beller
2017-10-30 17:20 ` [PATCH 0/2] Re* Consequences of CRLF in index? Stefan Beller
2017-10-31 2:44 ` Junio C Hamano
2017-10-31 16:41 ` Stefan Beller
2017-10-31 17:01 ` Jeff King
2017-11-07 6:40 ` [PATCH v2 0/2] Teach "diff" to ignore only CR at EOL Junio C Hamano
2017-11-07 6:40 ` [PATCH v2 1/2] xdiff: reassign xpparm_t.flags bits Junio C Hamano
2017-11-07 12:44 ` Johannes Schindelin
2017-11-07 15:02 ` Junio C Hamano
2017-11-07 6:40 ` [PATCH v2 2/2] diff: --ignore-cr-at-eol Junio C Hamano
2017-11-07 13:23 ` Johannes Schindelin
2017-11-08 0:43 ` Junio C Hamano
2017-11-08 0:49 ` Junio C Hamano
2017-11-15 4:28 ` Junio C Hamano [this message]
2017-11-07 12:30 ` [PATCH v2 0/2] Teach "diff" to ignore only CR at EOL Johannes Schindelin
2017-11-07 15:12 ` Junio C Hamano
2017-11-07 17:42 ` Stefan Beller
2017-10-25 17:04 ` Consequences of CRLF in index? Lars Schneider
2017-10-25 17:13 ` Jonathan Nieder
2017-10-26 11:06 ` Lars Schneider
2017-10-26 19:15 ` Torsten Bögershausen
2017-10-24 21:04 ` Johannes Sixt
2017-10-25 12:19 ` Johannes Schindelin
2017-10-26 7:09 ` Johannes Sixt
2017-10-26 11:01 ` Lars Schneider
2017-10-26 19:22 ` Torsten Bögershausen
2017-10-26 20:20 ` Johannes Sixt
2017-10-26 20:30 ` Jonathan Nieder
2017-10-26 20:51 ` Johannes Sixt
2017-10-26 22:27 ` Ross Kabus
2017-10-27 1:05 ` Junio C Hamano
2017-10-27 15:18 ` Johannes Schindelin
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=xmqq60ac17yv.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.