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

Re: [PATCH v1 8/9] diff --color-moved-ws: modify allow-indentation-change

From
Stefan Beller <sbeller@google.com>
Date
Nov 16, 2018, 21:47 UTC
Message-ID
<CAGZ79kb2fY+6xg=B+t=gSEBQ+u-wKAff++z5A=KiN2u0yYFF6g@mail.gmail.com>
In-Reply-To
<20181116110356.12311-9-phillip.wood@talktalk.net>
On Fri, Nov 16, 2018 at 3:04 AM Phillip Wood <phillip.wood@talktalk.net> wrote:
Show 19 quoted lines
>
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> Currently diff --color-moved-ws=allow-indentation-change does not
> support indentation that contains a mix of tabs and spaces. For
> example in commit 546f70f377 ("convert.h: drop 'extern' from function
> declaration", 2018-06-30) the function parameters in the following
> lines are not colored as moved [1].
>
> -extern int stream_filter(struct stream_filter *,
> -                        const char *input, size_t *isize_p,
> -                        char *output, size_t *osize_p);
> +int stream_filter(struct stream_filter *,
> +                 const char *input, size_t *isize_p,
> +                 char *output, size_t *osize_p);
>
> This commit changes the way the indentation is handled to track the
> visual size of the indentation rather than the characters in the
> indentation. This has they benefit that any whitespace errors do not
s/they/the/
Show 41 quoted lines
> interfer with the move detection (the whitespace errors will still be
> highlighted according to --ws-error-highlight). During the discussion
> of this feature there were concerns about the correct detection of
> indentation for python. However those concerns apply whether or not
> we're detecting moved lines so no attempt is made to determine if the
> indentation is 'pythonic'.
>
> [1] Note that before the commit to fix the erroneous coloring of moved
>     lines each line was colored as a different block, since that commit
>     they are uncolored.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>
> Notes:
>     Changes since rfc:
>      - It now replaces the existing implementation rather than adding a new
>        mode.
>      - The indentation deltas are now calculated once for each line and
>        cached.
>      - Optimized the whitespace delta comparison to compare string lengths
>        before comparing the actual strings.
>      - Modified the calculation of tabs as suggested by Stefan.
>      - Split out the blank line handling into a separate commit as suggest
>        by Stefan.
>      - Fixed some comments pointed out by Stefan.
>
>  diff.c                     | 130 +++++++++++++++++++++----------------
>  t/t4015-diff-whitespace.sh |  56 ++++++++++++++++
>  2 files changed, 129 insertions(+), 57 deletions(-)
>
> diff --git a/diff.c b/diff.c
> index c378ce3daf..89559293e7 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -750,6 +750,8 @@ struct emitted_diff_symbol {
>         const char *line;
>         int len;
>         int flags;
> +       int indent_off;
> +       int indent_width;

So this is the trick how we compute the ws related data only once per line. :-)

On the other hand, we do not save memory by disabling the ws detection, but I guess that is not a problem for now.

Would it make sense to have the new variables be unsigned? (Also a comment on what they are, I needed to read the code to understand off to be offset into the line, where the content starts, and width to be the visual width, as I did not recall the RFC.)

> +static void fill_es_indent_data(struct emitted_diff_symbol *es)
> [...]
> +               if (o->color_moved_ws_handling &
> +                   COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
> +                       fill_es_indent_data(&o->emitted_symbols->buf[n]);
Nice.

By reducing the information kept around to ints, we also do not need to alloc/free memory for each line.

Show 6 quoted lines
> +++ b/t/t4015-diff-whitespace.sh
> @@ -1901,4 +1901,60 @@ test_expect_success 'compare whitespace delta incompatible with other space opti
>         test_i18ngrep allow-indentation-change err
>  '
>
> +test_expect_success 'compare mixed whitespace delta across moved blocks' '
Looks good,

Thanks! Stefan

Previous: Phillip WoodNext: Phillip Wood
Message 19 of 44 in “diff --color-moved-ws: allow mixed spaces and tabs in indentation change”
  1. 0/3 diff --color-moved-ws: allow mixed spaces and tabs in indentation changePhillip Wood, Sep 24, 2018
  2. 1/3 xdiff-interface: make xdl_blankline() availablePhillip Wood, Sep 24, 2018
  3. Stefan BellerSep 24, 2018
  4. 2/3 diff.c: remove unused variablesPhillip Wood, Sep 24, 2018
  5. 3/3 diff: add --color-moved-ws=allow-mixed-indentation-changePhillip Wood, Sep 24, 2018
  6. Stefan BellerSep 25, 2018
  7. 3/3 diff: add --color-moved-ws=allow-mixed-indentation-changePhillip Wood, Oct 9, 2018
  8. Stefan BellerOct 9, 2018
  9. Phillip WoodOct 10, 2018
  10. Stefan BellerOct 10, 2018
  11. Phillip WoodSep 24, 2018
  12. 0/9 diff --color-moved-ws fixes and enhancmentPhillip Wood, Nov 16, 2018
  13. 1/9 diff: document --no-color-movedPhillip Wood, Nov 16, 2018
  14. 7/9 diff --color-moved-ws: optimize allow-indentation-changePhillip Wood, Nov 16, 2018
  15. Stefan BellerNov 16, 2018
  16. Phillip WoodNov 17, 2018
  17. 4/9 diff --color-moved-ws: demonstrate false positivesPhillip Wood, Nov 16, 2018
  18. 8/9 diff --color-moved-ws: modify allow-indentation-changePhillip Wood, Nov 16, 2018
  19. Stefan BellerNov 16, 2018
  20. Phillip WoodNov 17, 2018
  21. 6/9 diff --color-moved=zebra: be stricter with color alternationPhillip Wood, Nov 16, 2018
  22. 9/9 diff --color-moved-ws: handle blank linesPhillip Wood, Nov 16, 2018
  23. Stefan BellerNov 20, 2018
  24. Phillip WoodNov 21, 2018
  25. 5/9 diff --color-moved-ws: fix false positivesPhillip Wood, Nov 16, 2018
  26. 3/9 diff: allow --no-color-moved-wsPhillip Wood, Nov 16, 2018
  27. 2/9 diff: use whitespace consistentlyPhillip Wood, Nov 16, 2018
  28. Stefan BellerNov 16, 2018
  29. 0/9 diff --color-moved-ws fixes and enhancmentPhillip Wood, Nov 23, 2018
  30. 1/9 diff: document --no-color-movedPhillip Wood, Nov 23, 2018
  31. 5/9 diff --color-moved-ws: fix false positivesPhillip Wood, Nov 23, 2018
  32. 4/9 diff --color-moved-ws: demonstrate false positivesPhillip Wood, Nov 23, 2018
  33. 6/9 diff --color-moved=zebra: be stricter with color alternationPhillip Wood, Nov 23, 2018
  34. 7/9 diff --color-moved-ws: optimize allow-indentation-changePhillip Wood, Nov 23, 2018
  35. 8/9 diff --color-moved-ws: modify allow-indentation-changePhillip Wood, Nov 23, 2018
  36. 9/9 diff --color-moved-ws: handle blank linesPhillip Wood, Nov 23, 2018
  37. 3/9 diff: allow --no-color-moved-wsPhillip Wood, Nov 23, 2018
  38. 2/9 Use "whitespace" consistentlyPhillip Wood, Nov 23, 2018
  39. Stefan BellerNov 26, 2018
  40. Phillip WoodNov 27, 2018
  41. Phillip WoodJan 8, 2019
  42. Junio C HamanoJan 8, 2019
  43. Stefan BellerJan 10, 2019
  44. Junio C HamanoJan 10, 2019

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.