* git diff --ignore-space-change -- ignore whitespace prefers unmodified next line to modified one in patch
@ 2020-12-21 14:43 Dipl. Ing. Sergey Brester
0 siblings, 0 replies; only message in thread
From: Dipl. Ing. Sergey Brester @ 2020-12-21 14:43 UTC (permalink / raw)
To: git
Steps to reproduce the issue:
1. create two simple C files and diff both ignoring whitespaces:
```
printf "if (some_var1) {\n do {\n some-code\n } while (1);\n}\n" >
a.c
printf "if (some_var1) {\n do {\n if (some_var2) {\n
some-code\n }\n } while (1);\n}\n" > b.c
git diff --ignore-space-change --no-index a.c b.c
```
which would produce fully correct resulting patch:
```
diff --git a/a.c b/b.c
--- a/a.c
+++ b/b.c
@@ -1,5 +1,7 @@
if (some_var1) {
do {
+ if (some_var2) {
some-code
+ }
} while (1);
}
```
but this behavior will change if line 5 would be equal line 6
(containing only brace ...).
2. now we'll modify that a bit (e. g. use while instead of do, to make
the lines more similar
(containing only braces):
```
printf "if (some_var1) {\n while (1) {\n some-code\n }\n}\n" > a.c
printf "if (some_var1) {\n while (1) {\n if (some_var2) {\n
some-code\n }\n }\n}\n" > b.c
git diff --ignore-space-change --no-index a.c b.c
```
which then would produce this result:
```
diff --git a/a.c b/b.c
--- a/a.c
+++ b/b.c
@@ -1,5 +1,7 @@
if (some_var1) {
while (1) {
+ if (some_var2) {
some-code
}
+ }
}
```
As one can see, a line 6 instead of line 5 is marked as new (thereby
line 6 was **completely unmodified**).
In my opinion correct would be this variant (also similar patch of
test in step 1):
```
diff --git a/a.c b/b.c
--- a/a.c
+++ b/b.c
@@ -1,5 +1,7 @@
if (some_var1) {
while (1) {
+ if (some_var2) {
some-code
+ }
}
}
```
I understand that using --ignore-space-change both lines are quasi
"equal", and then first "change"
will be noticed as a new created line, but from point of view of the
developer (and common sense)
it is very strange either, especially if one considers that whole code
starting from line 6 is totally unmodified.
This causes that on some much complex nested blocks, this simple "first
wins" logic (without a simple look-ahead),
confuses still more (because affects several unmodified blocks, braces
etc), especially if some
conflicts should be resolved or a 3-way merge/review takes place.
This makes the usage of option "--ignore-space-change" pretty pointless,
because the diff of larger nested blocks
is often error prune on braces, brackets etc, so the review is often
needless complicated.
[System Info]
git version:
git version 2.28.0.windows.1
cpu: x86_64
built from commit: 77982caf269b7ee713a76da2bcf260c34d3bf7a7
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
uname: Windows 10.0 18363
compiler info: gnuc: 10.2
libc info: no libc information available
$SHELL (typically, interactive shell): <unset>
--
Regards,
Sergey Brester
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-12-21 15:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-21 14:43 git diff --ignore-space-change -- ignore whitespace prefers unmodified next line to modified one in patch Dipl. Ing. Sergey Brester
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).