[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] Creating the equivalent of "git diff"

Hmmmm, I do think we have a JGit bug specific to exFAT. I could reproduce problems that JGit does not honor core.filemode=false correctly on exFAT. I could reproduce that problem with the java code of Zach and also with commandline jgit. Here comes the script of a command line session on my Linux box which seems to proove that. Look at the lines with "###" where I give some comments on what I think I have found out. I'll open a bug if nobody find's an explanation for that.

/tmp> sudo lsblk -o NAME,FSTYPE,MOUNTPOINT /dev/sda1 /dev/sdb1
NAME FSTYPE MOUNTPOINT
sda1 ext4   /
sdb1 exfat  /mnt/sdb1
/tmp> ### I have ext4 on / and and exfat fs on /mnt/sdb1

/tmp> ### Try to clone on ext4
/tmp> git clone -q https://github.com/chalstrick/differentFileModes.git
/tmp> cd differentFileModes/
/tmp/differentFileModes> git config --get core.filemode
true
/tmp/differentFileModes> ### git trusts this fs!

/tmp/differentFileModes> ls -l
total 12
-rw-rw-r-- 1 user user 38 Sep 22 15:07 README.md
-rwxrwxr-x 1 user user 61 Sep 22 15:07 script.sh
-rw-rw-r-- 1 user user 47 Sep 22 15:07 text.txt
/tmp/differentFileModes> echo newContent >>text.txt 
/tmp/differentFileModes> git add text.txt 
/tmp/differentFileModes> echo moreNewContent >>text.txt 
/tmp/differentFileModes> git diff
diff --git a/text.txt b/text.txt
index 1575c9b..a33ec19 100644
--- a/text.txt
+++ b/text.txt
@@ -1,2 +1,3 @@
 text file originally created on linux with 664
 newContent
+moreNewContent
/tmp/differentFileModes> ### See the difference: a "git diff" is not comparing HEAD vs. worktree but HEAD vs. index.
/tmp/differentFileModes> ### Compared to HEAD we have added two lines but this diff is showing only one line

/tmp/differentFileModes> ### Now try the same on exFAT
/tmp/differentFileModes> cd /mnt/sdb1/
/mnt/sdb1> git clone -q https://github.com/chalstrick/differentFileModes.git
/mnt/sdb1> cd differentFileModes/
/mnt/sdb1/differentFileModes> git config --get core.filemode
false
/mnt/sdb1/differentFileModes> ### Native git automatically found out we cannot trust this fs and set
/mnt/sdb1/differentFileModes> ### core.filemode different than on a ext4 fs.

/mnt/sdb1/differentFileModes> ls -l
total 96
-rwxr-xr-x 1 root root 38 Sep 22 15:08 README.md
-rwxr-xr-x 1 root root 61 Sep 22 15:08 script.sh
-rwxr-xr-x 1 root root 47 Sep 22 15:08 text.txt
/mnt/sdb1/differentFileModes> ### And here you see the reason. The filemodes after a clone differ from the
/mnt/sdb1/differentFileModes> ### situation on ext4. exFAT doesn't supports filemodes fully

/mnt/sdb1/differentFileModes> echo newContent >>text.txt 
/mnt/sdb1/differentFileModes> git add text.txt 
/mnt/sdb1/differentFileModes> echo moreNewContent >>text.txt 
/mnt/sdb1/differentFileModes> git diff
diff --git a/text.txt b/text.txt
index 1575c9b..a33ec19 100644
--- a/text.txt
+++ b/text.txt
@@ -1,2 +1,3 @@
 text file originally created on linux with 664
 newContent
+moreNewContent
/mnt/sdb1/differentFileModes> ### Native git doesn't complain about a change in filemode!

/mnt/sdb1/differentFileModes> ### try the same with jgit
/mnt/sdb1/differentFileModes> wget -q -O /tmp/jgit.sh https://repo.eclipse.org/content/groups/releases//org/eclipse/jgit/org.eclipse.jgit.pgm/3.4.1.201406201815-r/org.eclipse.jgit.pgm-3.4.1.201406201815-r.sh
/mnt/sdb1/differentFileModes> chmod +x /tmp/jgit.sh 
/mnt/sdb1/differentFileModes> /tmp/jgit.sh diff
diff --git a/text.txt b/text.txt
old mode 100644
new mode 100755
index 1575c9b..a33ec19
--- a/text.txt
+++ b/text.txt
@@ -1,2 +1,3 @@
 text file originally created on linux with 664
 newContent
+moreNewContent
/mnt/sdb1/differentFileModes> ### JGit computes the right content diff (also compares index vs. worktree) but also complains
/mnt/sdb1/differentFileModes> ### about a filemode change. This should not happen if core.filemode is set to false.

/mnt/sdb1/differentFileModes> ### How does native git behaves if we tell to explicitly trust the fs
/mnt/sdb1/differentFileModes> git config core.filemode true
/mnt/sdb1/differentFileModes> git diff
diff --git a/README.md b/README.md
old mode 100644
new mode 100755
diff --git a/text.txt b/text.txt
old mode 100644
new mode 100755
index 1575c9b..a33ec19
--- a/text.txt
+++ b/text.txt
@@ -1,2 +1,3 @@
 text file originally created on linux with 664
 newContent
+moreNewContent
/mnt/sdb1/differentFileModes> ### Now native git also complains about mode changes ... but for some more files. That's correct.
/mnt/sdb1/differentFileModes> ### JGit behaves the same with core.filemode=true. Good.

























Ciao
  Chris

On Thu, Sep 18, 2014 at 5:00 PM, Zach Oakes <zsoakes@xxxxxxxxx> wrote:
I spoke too soon...I accidentally tested with the older code which used DirCacheIterator, not the newer code that used CanonicalTreeParser. The latter still shows all files in my repo after running "git config --global core.filemode false".

On Thu, Sep 18, 2014 at 10:57 AM, Zach Oakes <zsoakes@xxxxxxxxx> wrote:
Thanks Christian; I originally took your comment to mean that the command would only work on Windows. I tried it out and JGit behaves as expected now.

On Thu, Sep 18, 2014 at 12:42 AM, Christian Halstrick <christian.halstrick@xxxxxxxxx> wrote:
Do you work on windows? If yes switch to your repo and try "git config core.filemode false". Then run your test again.

Ciao
  Chris

On Wed, Sep 17, 2014 at 4:39 PM, Zach Oakes <zsoakes@xxxxxxxxx> wrote:
I think it may be related to the fact that my repos are stored on an external drive (EXFAT format, if that matters). When I run my code with CanonicalTreeParser, I get diffs for every file that look like this:

diff --git a/README.md b/README.md
old mode 100644
new mode 100755

So I think something about being stored on an external drive is making it detect a file mode change. I'm still not sure why it appears here, but not with "git diff", but it's at least reassuring that this is probably specific to my setup.

Zach

On Wed, Sep 17, 2014 at 9:48 AM, Robin Stocker <robin@xxxxxxxxx> wrote:
Yes. Just tried your code here and it works as expected. So it
sounds like your problem may be specific to your repository or
configuration.

Are you able to share your repository?

Can you share the output of `git config --list` when executed
in your repository?

You mentioned at the beginning that files that should be ignored
are included, could you share your .gitignore files?


By the way, the most straightforward way to do "git diff" using
the API is this:

Git git = Git.wrap(repo);
List<DiffEntry> entries = git.diff().call();

(Unfortunately, doing "git diff HEAD" isn't as straighforward,
something we should fix. I filed a bug for that [1].)

Regards,
  Robin

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=444363


Zach Oakes wrote:
> That sounds like what I'm looking to do. Is it correct to use
> CanonicalTreeParser the way I did to accomplish this?
> On Sep 16, 2014 1:43 PM, "Dave Borowitz" <dborowitz@xxxxxxxxxx>
> wrote:
>
> > My mistake, "git diff" diffs the work tree against the index. I
> > don't have
> > it in front of me but I'll bet if you look at the implementation,
> > that's
> > what pgm.Diff is doing :)
> >
> > On Mon, Sep 15, 2014 at 10:16 PM, Robin Stocker <robin@xxxxxxxxx>
> > wrote:
> >
> >> Dave Borowitz wrote:
> >> > "git diff" is the same as "git diff HEAD".
> >>
> >> That's not correct in general:
> >>
> >> $ mkdir git-diff-test && cd git-diff-test && git init -q
> >> $ echo "a" > file.txt
> >> $ git add file.txt
> >> $ git commit -qm "Initial"
> >> $ echo "b" >> file.txt
> >> $ git add file.txt
> >> $ echo "c" >> file.txt
> >> $ git diff
> >> diff --git a/file.txt b/file.txt
> >> index 422c2b7..de98044 100644
> >> --- a/file.txt
> >> +++ b/file.txt
> >> @@ -1,2 +1,3 @@
> >>  a
> >>  b
> >> +c
> >> $ git diff HEAD
> >> diff --git a/file.txt b/file.txt
> >> index 7898192..de98044 100644
> >> --- a/file.txt
> >> +++ b/file.txt
> >> @@ -1 +1,3 @@
> >>  a
> >> +b
> >> +c
> >>
> >>
> >> It's only the same if there are no changes between index and HEAD.
> >>
> >> Having said that, I don't know which one Zach actually wants :).


_______________________________________________
jgit-dev mailing list
jgit-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jgit-dev