@ -67,6 +67,7 @@ import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.dircache.DirCacheIterator ;
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.IncorrectObjectTypeException ;
import org.eclipse.jgit.errors.LargeObjectException ;
import org.eclipse.jgit.errors.LargeObjectException ;
import org.eclipse.jgit.errors.MissingObjectException ;
import org.eclipse.jgit.errors.MissingObjectException ;
import org.eclipse.jgit.internal.JGitText ;
import org.eclipse.jgit.internal.JGitText ;
@ -89,6 +90,7 @@ import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.pack.PackConfig ;
import org.eclipse.jgit.storage.pack.PackConfig ;
import org.eclipse.jgit.treewalk.AbstractTreeIterator ;
import org.eclipse.jgit.treewalk.AbstractTreeIterator ;
import org.eclipse.jgit.treewalk.CanonicalTreeParser ;
import org.eclipse.jgit.treewalk.CanonicalTreeParser ;
import org.eclipse.jgit.treewalk.EmptyTreeIterator ;
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 ;
@ -391,11 +393,14 @@ public class DiffFormatter {
* returned . Callers may choose to format these paths themselves , or convert
* returned . Callers may choose to format these paths themselves , or convert
* them into { @link FileHeader } instances with a complete edit list by
* them into { @link FileHeader } instances with a complete edit list by
* calling { @link # toFileHeader ( DiffEntry ) } .
* calling { @link # toFileHeader ( DiffEntry ) } .
* < p >
* Either side may be null to indicate that the tree has beed added or
* removed . The diff will be computed against nothing .
*
*
* @param a
* @param a
* the old ( or previous ) side .
* the old ( or previous ) side or null
* @param b
* @param b
* the new ( or updated ) side .
* the new ( or updated ) side or null
* @return the paths that are different .
* @return the paths that are different .
* @throws IOException
* @throws IOException
* trees cannot be read or file contents cannot be read .
* trees cannot be read or file contents cannot be read .
@ -405,7 +410,9 @@ public class DiffFormatter {
assertHaveRepository ( ) ;
assertHaveRepository ( ) ;
RevWalk rw = new RevWalk ( reader ) ;
RevWalk rw = new RevWalk ( reader ) ;
return scan ( rw . parseTree ( a ) , rw . parseTree ( b ) ) ;
RevTree aTree = a ! = null ? rw . parseTree ( a ) : null ;
RevTree bTree = b ! = null ? rw . parseTree ( b ) : null ;
return scan ( aTree , bTree ) ;
}
}
/ * *
/ * *
@ -415,11 +422,14 @@ public class DiffFormatter {
* returned . Callers may choose to format these paths themselves , or convert
* returned . Callers may choose to format these paths themselves , or convert
* them into { @link FileHeader } instances with a complete edit list by
* them into { @link FileHeader } instances with a complete edit list by
* calling { @link # toFileHeader ( DiffEntry ) } .
* calling { @link # toFileHeader ( DiffEntry ) } .
* < p >
* Either side may be null to indicate that the tree has beed added or
* removed . The diff will be computed against nothing .
*
*
* @param a
* @param a
* the old ( or previous ) side .
* the old ( or previous ) side or null
* @param b
* @param b
* the new ( or updated ) side .
* the new ( or updated ) side or null
* @return the paths that are different .
* @return the paths that are different .
* @throws IOException
* @throws IOException
* trees cannot be read or file contents cannot be read .
* trees cannot be read or file contents cannot be read .
@ -427,13 +437,19 @@ public class DiffFormatter {
public List < DiffEntry > scan ( RevTree a , RevTree b ) throws IOException {
public List < DiffEntry > scan ( RevTree a , RevTree b ) throws IOException {
assertHaveRepository ( ) ;
assertHaveRepository ( ) ;
CanonicalTreeParser aParser = new CanonicalTreeParser ( ) ;
AbstractTreeIterator aIterator = makeIteratorFromTreeOrNull ( a ) ;
CanonicalTreeParser bParser = new CanonicalTreeParser ( ) ;
AbstractTreeIterator bIterator = makeIteratorFromTreeOrNull ( b ) ;
return scan ( aIterator , bIterator ) ;
aParser . reset ( reader , a ) ;
}
bParser . reset ( reader , b ) ;
return scan ( aParser , bParser ) ;
private AbstractTreeIterator makeIteratorFromTreeOrNull ( RevTree tree )
throws IncorrectObjectTypeException , IOException {
if ( tree ! = null ) {
CanonicalTreeParser parser = new CanonicalTreeParser ( ) ;
parser . reset ( reader , tree ) ;
return parser ;
} else
return new EmptyTreeIterator ( ) ;
}
}
/ * *
/ * *
@ -553,11 +569,14 @@ public class DiffFormatter {
*
*
* The patch is expressed as instructions to modify { @code a } to make it
* The patch is expressed as instructions to modify { @code a } to make it
* { @code b } .
* { @code b } .
* < p >
* Either side may be null to indicate that the tree has beed added or
* removed . The diff will be computed against nothing .
*
*
* @param a
* @param a
* the old ( or previous ) side .
* the old ( or previous ) side or null
* @param b
* @param b
* the new ( or updated ) side .
* the new ( or updated ) side or null
* @throws IOException
* @throws IOException
* trees cannot be read , file contents cannot be read , or the
* trees cannot be read , file contents cannot be read , or the
* patch cannot be output .
* patch cannot be output .
@ -572,10 +591,14 @@ public class DiffFormatter {
* The patch is expressed as instructions to modify { @code a } to make it
* The patch is expressed as instructions to modify { @code a } to make it
* { @code b } .
* { @code b } .
*
*
* < p >
* Either side may be null to indicate that the tree has beed added or
* removed . The diff will be computed against nothing .
*
* @param a
* @param a
* the old ( or previous ) side .
* the old ( or previous ) side or null
* @param b
* @param b
* the new ( or updated ) side .
* the new ( or updated ) side or null
* @throws IOException
* @throws IOException
* trees cannot be read , file contents cannot be read , or the
* trees cannot be read , file contents cannot be read , or the
* patch cannot be output .
* patch cannot be output .
@ -589,11 +612,14 @@ public class DiffFormatter {
*
*
* The patch is expressed as instructions to modify { @code a } to make it
* The patch is expressed as instructions to modify { @code a } to make it
* { @code b } .
* { @code b } .
* < p >
* Either side may be null to indicate that the tree has beed added or
* removed . The diff will be computed against nothing .
*
*
* @param a
* @param a
* the old ( or previous ) side .
* the old ( or previous ) side or null
* @param b
* @param b
* the new ( or updated ) side .
* the new ( or updated ) side or null
* @throws IOException
* @throws IOException
* trees cannot be read , file contents cannot be read , or the
* trees cannot be read , file contents cannot be read , or the
* patch cannot be output .
* patch cannot be output .