]> source.dussan.org Git - jgit.git/commit
Make blame work correctly on merge conflicts 30/147130/13
authorThomas Wolf <thomas.wolf@paranor.ch>
Tue, 6 Aug 2019 16:31:35 +0000 (18:31 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 27 Nov 2019 02:03:06 +0000 (03:03 +0100)
commit59f9d206c954b5633f5978723bd0a2e7db31c2e8
treeeee0571db82d18ebbeb7b9f396c04a174277720e
parente9d728ceb7365b6cf0b1472021fdbb76d59a02d1
Make blame work correctly on merge conflicts

When a conflicting file was blamed, JGit would not identify lines
coming from the merge parents. The main cause for this was that
Blame and BlameCommand simply added the first DirCacheEntry found
for a file to its queue of candidates (blobs or commits) to consider.
In case of a conflict this typically is the merge base commit, and
comparing a auto-merged contents against that base would yield
incorrect results.

Such cases have to be handled specially. The candidate to be
considered by the blame must use the working tree contents, but
at the same time behave like a merge commit/candidate with HEAD
and the MERGE_HEADs as parents. Canonical git does something very
similar, see [1].

Implement that and add tests.

I first did this for the JGit pgm Blame command. When I then tried
to do the same in BlameCommand, I noticed that the latter also
included some fancy but incomplete CR-LF handling. In order to
be able to use the new BlameGenerator.prepareHead() also in
BlameCommand this CR-LF handling was also moved into BlameGenerator
and corrected in doing so.

(Just considering the git config settings was not good enough,
CR-LF behavior can also be influenced by .gitattributes, and even
by whether the file in the index has CR-LF. To correctly determine
CR-LF handling for check-in one needs to do a TreeWalk with at
least a FileTreeIterator and a DirCacheIterator.)

[1] https://github.com/git/git/blob/v2.22.0/blame.c#L174

Bug: 434330
Change-Id: I9d763dd6ba478b0b6ebf9456049d6301f478ef7c
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BlameTest.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
org.eclipse.jgit/src/org/eclipse/jgit/api/BlameCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
org.eclipse.jgit/src/org/eclipse/jgit/blame/Candidate.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java