All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Pablo <pabloosabaterr@gmail.com>, Javier Bassi <javierbassi@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Abraham Samuel Adekunle <abrahamadekunle50@gmail.com>,
	Rene Scharfe <l.s.r@web.de>, Elijah Newren <newren@gmail.com>,
	Ruben Justo <rjusto@gmail.com>, Patrick Steinhardt <ps@pks.im>
Subject: Re: [PATCH] add -p: introduce 'w' command to view hunk with --word-diff
Date: Thu, 7 May 2026 14:24:31 +0100	[thread overview]
Message-ID: <1f811deb-7cbb-4fe0-ab40-49274b1db165@gmail.com> (raw)
In-Reply-To: <CAN5EUNRT7V3BrtyU0UYwGVnJ51LWSsNi1OnzMB5WL=w8vhKmrw@mail.gmail.com>

On 07/05/2026 08:55, Pablo wrote:
> El jue, 7 may 2026 a las 1:58, Javier Bassi (<javierbassi@gmail.com>) escribió:
>>
>> +static void add_word_diff_line(struct strbuf *old, struct strbuf *new,
>> +                              const char *line, size_t len, char marker)
>> +{
>> +       if (marker == '-' || marker == '+' || *line == ' ') {
>> +               line++;
>> +               len--;
>> +       }
> 
> Maybe a tiny comment here would help, to know why '*line' is being
> checked here instead of 'marker'. They seem the same and one has to go
> to marker declaration and see the comment at 'normalize_marker()'
> 
>    /* Empty context lines may omit the leading ' ' */

That's a good point - it might be clearer to use

	if (marker == *line) {
		line++;
		len--;
	}

instead. That also trims lines starting with '\' but that shouldn't 
matter as the code should be checking "marker" rather than "line".

>> +
>> +               if (marker == '\\') {
>> +                       if (last_marker != '+')
>> +                               trim_trailing_lf(old);
>> +                       if (last_marker != '-')
>> +                               trim_trailing_lf(new);
>> +                       continue;
>> +               }
> 
> Here we check about "\No newline at end of file", after this point I
> believe that 'buf->buf[buf->len - 1] == '\n'' will always be true.
> Same should be for 'buf->len' because "\No newline at end of file"
> shouldn't come first and a '+' '-' line should have been added on a
> previous iteration, but the check it's fine, just in case I'm wrong.
> 
> What I want to point out is, is the 'trim_trailing_lf' function
> necessary? It's only called in the same place and it carries a check
> that could be on the caller instead, leaving  the function only with
> 'strbuf_setlen(buf, buf->len - 1);" making sense to inline it at this
> point.
> You could keep the buf->len check:
> 
>    if (marker == '\\') {
>            if (last_marker != '+' && old->len)
>                     strbuf_setlen(old, old->len - 1);
>            if (last_marker != '-' && new->len)
>                     strbuf_setlen(new, new->len - 1);
>            continue;
>    }

Should we be trimming '\r\n' if the file has dos style line endings?

Thanks

Phillip


  reply	other threads:[~2026-05-07 13:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-06 23:54 [PATCH] add -p: introduce 'w' command to view hunk with --word-diff Javier Bassi
2026-05-07  7:55 ` Pablo
2026-05-07 13:24   ` Phillip Wood [this message]
2026-05-07 14:53     ` Pablo
2026-05-07 13:24 ` Phillip Wood
2026-05-07 14:39   ` D. Ben Knoble
2026-05-11  0:16     ` Junio C Hamano
2026-05-11 19:16       ` D. Ben Knoble
2026-05-12  0:04         ` Junio C Hamano

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=1f811deb-7cbb-4fe0-ab40-49274b1db165@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=abrahamadekunle50@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=javierbassi@gmail.com \
    --cc=l.s.r@web.de \
    --cc=newren@gmail.com \
    --cc=pabloosabaterr@gmail.com \
    --cc=ps@pks.im \
    --cc=rjusto@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.
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.