* class. Each instance of this class should only be used for one invocation
* of the command. Don't call this method twice on an instance.
* @return a DiffEntry for each path which is different
*/
public List<DiffEntry> call() throws GitAPIException {
final DiffFormatter diffFmt;
if ( out != null && !showNameAndStatusOnly ) {
diffFmt = new DiffFormatter( new BufferedOutputStream( out ) );
} else {
diffFmt = new DiffFormatter( NullOutputStream.INSTANCE );
}
diffFmt.setRepository( repo );
diffFmt.setProgressMonitor( monitor );
diffFmt.setDetectRenames( true );
try {
if ( cached ) {
if ( oldTree == null ) {
ObjectId head = repo.resolve( HEAD + "^{tree}" ); //$NON-NLS-1$
if ( head == null ) {
throw new NoHeadException( JGitText.get().cannotReadTree );
}
CanonicalTreeParser p = new CanonicalTreeParser();
ObjectReader reader = repo.newObjectReader();
try {
p.reset( reader, head );
} finally {
reader.release();
}
oldTree = p;
}
newTree = new DirCacheIterator( repo.readDirCache() );
} else {
if ( oldTree == null ) {
oldTree = new DirCacheIterator( repo.readDirCache() );
}
if ( newTree == null ) {
newTree = new FileTreeIterator( repo );
}
}
diffFmt.setPathFilter( pathFilter );
List<DiffEntry> result = diffFmt.scan( oldTree, newTree );
if ( showNameAndStatusOnly ) {
return result;
} else {
if ( contextLines >= 0 ) {
diffFmt.setContext( contextLines );
}
if ( destinationPrefix != null ) {
diffFmt.setNewPrefix( destinationPrefix );
}
if ( sourcePrefix != null ) {
diffFmt.setOldPrefix( sourcePrefix );
}
diffFmt.format( result );
diffFmt.flush();
return result;
}
} catch ( IOException e ) {
throw new JGitInternalException( e.getMessage(), e );
} finally {
diffFmt.release();
}
}