git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] add -p: introduce 'w' command to view hunk with --word-diff

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
May 7, 2026, 13:24 UTC
Message-ID
<1f811deb-7cbb-4fe0-ab40-49274b1db165@gmail.com>
In-Reply-To
<CAN5EUNRT7V3BrtyU0UYwGVnJ51LWSsNi1OnzMB5WL=w8vhKmrw@mail.gmail.com>
On 07/05/2026 08:55, Pablo wrote:
Show 15 quoted lines
> 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".

Show 29 quoted lines
>> +
>> +               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
Previous: PabloNext: Pablo
Message 3 of 9 in “add -p: introduce 'w' command to view hunk with --word-diff”
  1. add -p: introduce 'w' command to view hunk with --word-diffJavier Bassi, May 6, 2026
  2. PabloMay 7, 2026
  3. Phillip WoodMay 7, 2026
  4. PabloMay 7, 2026
  5. Phillip WoodMay 7, 2026
  6. D. Ben KnobleMay 7, 2026
  7. Junio C HamanoMay 11, 2026
  8. D. Ben KnobleMay 11, 2026
  9. Junio C HamanoMay 12, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.