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

`git diff` fails to detect large re-indented blocks even with --color-moved-ws=allow-indentation-change

From
TCTimothee Cour <thelastmammoth@gmail.com>
Date
Feb 24, 2020, 00:44 UTC
Message-ID
<CANri+EzQZLg2djKvLxbPWh_8fr8oEqvaFF5BB1eAMCOYuB+4_w@mail.gmail.com>

see https://github.com/timotheecour/Nim/pull/37 for a self-contained minimal example

the actual diff contains a single large re-indented block (re-indented by 2 spaces); and a single re-indented line within that large block: ## * getTempDir proc <#getTempDir>_

none of the tools I know of helps viewing the diff in this case:
* problem 1: https://github.com/timotheecour/Nim/pull/37/files?w=1
completely ignores the re-indented single line within the block
* problem 2: https://github.com/timotheecour/Nim/pull/37/files shows a
large complex diff composed of multiple diff blocks, hard to spot
whether code was changed or whether it's just re-indent
* git diff --color-moved-ws=allow-indentation-change --color-moved=blocks HEAD^
this suffers from problem 1 and problem 2: the diff is complex and
shows multiple blocks
* git diff --color-moved-ws=allow-indentation-change --color-moved
HEAD^ does not suffer from problem 1 but suffers from problem 2: the
diff is complex and shows multiple blocks; see comment below
* even without reasoning about moved code (eg `--color-moved`), there
is no `git diff` option I know of that correctly identifies blocks of
text that were merely re-indented UNIFORMLY.

I've show the `git diff` output in that PR. It makes it really hard to review diffs that are composed of essentially re-indentation; and to identify deviations from uniform re-indentation within re-indented blocks. Uniform re-indentation is important for correctness in whitespace sensitive languages such as python, nim, where a spurious re-indentation could introduce a subtle behavior change; this should be visible, not ignored.

## expected git diff output perhaps an option `--color-moved-ws=smart-indentation-change` should be introduced which would group code by uniform re-indentation level, and would show how much each block was re-indented by (positive or negative). In example from that PR, it should show a large re-indented block in 1 color, and show in another color the re-indented single line

(ref: D20200223T154500)
Message 1 of 1 in “`git diff` fails to detect large re-indented blocks even with --color-moved-ws=allow-indentation-change”
  1. Timothee CourFeb 24, 2020

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.