@ -65,6 +65,7 @@ import java.util.List;
import org.eclipse.jgit.JGitText ;
import org.eclipse.jgit.JGitText ;
import org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm ;
import org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm ;
import org.eclipse.jgit.diff.DiffEntry.ChangeType ;
import org.eclipse.jgit.diff.DiffEntry.ChangeType ;
import org.eclipse.jgit.dircache.DirCacheIterator ;
import org.eclipse.jgit.errors.AmbiguousObjectException ;
import org.eclipse.jgit.errors.AmbiguousObjectException ;
import org.eclipse.jgit.errors.CorruptObjectException ;
import org.eclipse.jgit.errors.CorruptObjectException ;
import org.eclipse.jgit.errors.LargeObjectException ;
import org.eclipse.jgit.errors.LargeObjectException ;
@ -91,7 +92,9 @@ import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.eclipse.jgit.treewalk.TreeWalk ;
import org.eclipse.jgit.treewalk.TreeWalk ;
import org.eclipse.jgit.treewalk.WorkingTreeIterator ;
import org.eclipse.jgit.treewalk.WorkingTreeIterator ;
import org.eclipse.jgit.treewalk.filter.AndTreeFilter ;
import org.eclipse.jgit.treewalk.filter.AndTreeFilter ;
import org.eclipse.jgit.treewalk.filter.IndexDiffFilter ;
import org.eclipse.jgit.treewalk.filter.NotIgnoredFilter ;
import org.eclipse.jgit.treewalk.filter.NotIgnoredFilter ;
import org.eclipse.jgit.treewalk.filter.PathFilter ;
import org.eclipse.jgit.treewalk.filter.TreeFilter ;
import org.eclipse.jgit.treewalk.filter.TreeFilter ;
import org.eclipse.jgit.util.QuotedString ;
import org.eclipse.jgit.util.QuotedString ;
import org.eclipse.jgit.util.io.DisabledOutputStream ;
import org.eclipse.jgit.util.io.DisabledOutputStream ;
@ -435,15 +438,14 @@ public class DiffFormatter {
walk . addTree ( b ) ;
walk . addTree ( b ) ;
walk . setRecursive ( true ) ;
walk . setRecursive ( true ) ;
TreeFilter filter = pathFilter ;
TreeFilter filter = getDiffTreeFilterFor ( a , b ) ;
if ( pathFilter instanceof FollowFilter ) {
if ( a instanceof WorkingTreeIterator )
walk . setFilter ( AndTreeFilter . create (
filter = AndTreeFilter . create ( filter , new NotIgnoredFilter ( 0 ) ) ;
PathFilter . create ( ( ( FollowFilter ) pathFilter ) . getPath ( ) ) ,
if ( b instanceof WorkingTreeIterator )
filter ) ) ;
filter = AndTreeFilter . create ( filter , new NotIgnoredFilter ( 1 ) ) ;
} else {
if ( ! ( pathFilter instanceof FollowFilter ) )
walk . setFilter ( AndTreeFilter . create ( pathFilter , filter ) ) ;
filter = AndTreeFilter . create ( filter , TreeFilter . ANY_DIFF ) ;
}
walk . setFilter ( filter ) ;
source = new ContentSource . Pair ( source ( a ) , source ( b ) ) ;
source = new ContentSource . Pair ( source ( a ) , source ( b ) ) ;
@ -458,12 +460,6 @@ public class DiffFormatter {
walk . reset ( ) ;
walk . reset ( ) ;
walk . addTree ( a ) ;
walk . addTree ( a ) ;
walk . addTree ( b ) ;
walk . addTree ( b ) ;
filter = TreeFilter . ANY_DIFF ;
if ( a instanceof WorkingTreeIterator )
filter = AndTreeFilter . create ( new NotIgnoredFilter ( 0 ) , filter ) ;
if ( b instanceof WorkingTreeIterator )
filter = AndTreeFilter . create ( new NotIgnoredFilter ( 1 ) , filter ) ;
walk . setFilter ( filter ) ;
walk . setFilter ( filter ) ;
if ( renameDetector = = null )
if ( renameDetector = = null )
@ -476,6 +472,22 @@ public class DiffFormatter {
return files ;
return files ;
}
}
private static TreeFilter getDiffTreeFilterFor ( AbstractTreeIterator a ,
AbstractTreeIterator b ) {
if ( a instanceof DirCacheIterator & & b instanceof WorkingTreeIterator )
return new IndexDiffFilter ( 0 , 1 ) ;
if ( a instanceof WorkingTreeIterator & & b instanceof DirCacheIterator )
return new IndexDiffFilter ( 1 , 0 ) ;
TreeFilter filter = TreeFilter . ANY_DIFF ;
if ( a instanceof WorkingTreeIterator )
filter = AndTreeFilter . create ( new NotIgnoredFilter ( 0 ) , filter ) ;
if ( b instanceof WorkingTreeIterator )
filter = AndTreeFilter . create ( new NotIgnoredFilter ( 1 ) , filter ) ;
return filter ;
}
private ContentSource source ( AbstractTreeIterator iterator ) {
private ContentSource source ( AbstractTreeIterator iterator ) {
if ( iterator instanceof WorkingTreeIterator )
if ( iterator instanceof WorkingTreeIterator )
return ContentSource . create ( ( WorkingTreeIterator ) iterator ) ;
return ContentSource . create ( ( WorkingTreeIterator ) iterator ) ;