Bug 563570 - RawTextComparator.WS_IGNORE_CHANGE doesn't handle TAB vs. SPACE correctly
Summary: RawTextComparator.WS_IGNORE_CHANGE doesn't handle TAB vs. SPACE correctly
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 5.8   Edit
Assignee: Thomas Wolf CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-26 02:40 EDT by Thomas Wolf CLA
Modified: 2020-05-28 08:11 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wolf CLA 2020-05-26 02:40:31 EDT
Reproducer:

$ mkdir difftest
$ cd difftest
$ git init
$ echo "foo bar" > foo.txt
$ git add .
$ git commit -m "Space"
[master (root-commit) c2c9c5a] Space
 1 file changed, 1 insertion(+)
 create mode 100644 foo.txt
$ echo -e "foo\tbar" > foo.txt
$ git add .
$ git commit -m "Tab"
[master 51a56a0] Tab
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git diff HEAD^1 HEAD
diff --git a/foo.txt b/foo.txt
index d675fa4..9a9b36b 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-foo bar
+foo    bar
$ git diff -b HEAD^1 HEAD
$ jgit.sh diff HEAD^1 HEAD
diff --git a/foo.txt b/foo.txt
index d675fa4..9a9b36b 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-foo bar
+foo    bar
$ jgit.sh diff -b HEAD^1 HEAD
diff --git a/foo.txt b/foo.txt
index d675fa4..9a9b36b 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-foo bar
+foo    bar
$
Comment 1 Thomas Wolf CLA 2020-05-26 02:44:19 EDT
The problem is that JGit compares the first whitespace characters of a sequence of whitespace characters. Continuing from above:

$ echo -e "foo \tbar" > foo.txt
$ git add .
$ git commit -m "SpaceTab"
[master ba0542f] SpaceTab
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git diff -b HEAD~2 HEAD
$ jgit.sh diff -b HEAD~2 HEAD
diff --git a/foo.txt b/foo.txt
index d675fa4..835a234 100644
--- a/foo.txt
+++ b/foo.txt
$ git diff -b HEAD~1 HEAD
$ jgit.sh diff -b HEAD~1 HEAD
diff --git a/foo.txt b/foo.txt
index 9a9b36b..835a234 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-foo    bar
+foo    bar
$
Comment 2 Eclipse Genie CLA 2020-05-26 02:55:19 EDT
New Gerrit change created: https://git.eclipse.org/r/163573
Comment 3 Thomas Wolf CLA 2020-05-26 03:45:54 EDT
Note that a difference between whitespace/no whitespace at the front _is_ significant. Continuing again:

$ echo -e "  foo\tbar" > foo.txt
$ git add .
$ git commit -m "Leading ws"
$ git diff -b HEAD~2 HEAD
diff --git a/foo.txt b/foo.txt
index 9a9b36b..897da1b 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-foo    bar
+  foo  bar
$ jgit.sh diff -b HEAD~2 HEAD
diff --git a/foo.txt b/foo.txt
index 9a9b36b..897da1b 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-foo    bar
+  foo  bar
$ echo -e "\tfoo   bar" > foo.txt
$ git add .
$ git commit -m "Leading tab"
[master dfa7b42] Leading tab
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git diff -b HEAD~1 HEAD
$ jgit.sh diff -b HEAD~1 HEAD
diff --git a/foo.txt b/foo.txt
index 897da1b..2a883d6 100644
--- a/foo.txt
+++ b/foo.txt
@@ -1 +1 @@
-  foo  bar
+       foo   bar
$
Comment 4 Eclipse Genie CLA 2020-05-28 08:07:23 EDT
Gerrit change https://git.eclipse.org/r/163573 was merged to [master].
Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=6f17f9ed3fdadec1e6995f42ca34f570c0dee1b5