Bug 560054 - diff with --ignore-all-space produces wrong result
Summary: diff with --ignore-all-space produces wrong result
Status: NEW
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.6   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-12 08:55 EST by Petr Hrebejk CLA
Modified: 2020-03-27 17:49 EDT (History)
1 user (show)

See Also:


Attachments
Repository demonstrating the bug. (9.43 KB, application/gzip)
2020-02-12 08:55 EST, Petr Hrebejk CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Hrebejk CLA 2020-02-12 08:55:52 EST
Created attachment 281797 [details]
Repository demonstrating the bug.

Create two commits which produce following diff in native git. (In attached repo it is enough to use: git show --ignore-all-space ) 

diff --git a/ws.java b/ws.java
index 4217297..30b4aa9 100644
--- a/ws.java
+++ b/ws.java
@@ -1,11 +1,11 @@
+if ( cond ) {
     my
     first
     code
     block
+}
 
-if (cond) {
 my
 second
 code
 block
-}

Now try to show the diff using jgit (jgit show --ignore-all-space) it will give:

diff --git a/ws.java b/ws.java
index 4217297..30b4aa9 100644
--- a/ws.java
+++ b/ws.java
@@ -1,11 +1,11 @@
+if ( cond ) {
 my
 first
 code
 block
+}
  
-if (cond) {
     my
     second
     code
     block
-}

Notice that the indentation is wrong.
Comment 1 Thomas Wolf CLA 2020-03-27 17:49:51 EDT
Why would JGit be wrong? The lines are considered equivalent since the differ is instructed to ignore whitespace.

That said, git/xdiff/xemit.c emits context lines (same in both files) from file B, whereas org.eclipse.jgit.diff.DiffFormatter.java emits them from file A.

Normally that doesn't matter since the lines will be the same in both files, but when whitespace is ignored, there may be such differences.

JGit's way has the advantage that the resulting diff could be applied as a patch even without "whitespace ignore" flags.