@ -53,12 +53,12 @@ import java.util.List;
import org.eclipse.jgit.diff.DiffEntry ;
import org.eclipse.jgit.diff.DiffEntry ;
import org.eclipse.jgit.diff.DiffFormatter ;
import org.eclipse.jgit.diff.DiffFormatter ;
import org.eclipse.jgit.diff.RawText ;
import org.eclipse.jgit.diff.RawTextIgnoreAllWhitespace ;
import org.eclipse.jgit.diff.RawTextIgnoreAllWhitespace ;
import org.eclipse.jgit.diff.RawTextIgnoreLeadingWhitespace ;
import org.eclipse.jgit.diff.RawTextIgnoreLeadingWhitespace ;
import org.eclipse.jgit.diff.RawTextIgnoreTrailingWhitespace ;
import org.eclipse.jgit.diff.RawTextIgnoreTrailingWhitespace ;
import org.eclipse.jgit.diff.RawTextIgnoreWhitespaceChange ;
import org.eclipse.jgit.diff.RawTextIgnoreWhitespaceChange ;
import org.eclipse.jgit.diff.RenameDetector ;
import org.eclipse.jgit.diff.RenameDetector ;
import org.eclipse.jgit.lib.Constants ;
import org.eclipse.jgit.lib.TextProgressMonitor ;
import org.eclipse.jgit.lib.TextProgressMonitor ;
import org.eclipse.jgit.pgm.opt.PathTreeFilterHandler ;
import org.eclipse.jgit.pgm.opt.PathTreeFilterHandler ;
import org.eclipse.jgit.treewalk.AbstractTreeIterator ;
import org.eclipse.jgit.treewalk.AbstractTreeIterator ;
@ -70,6 +70,9 @@ import org.kohsuke.args4j.Option;
@Command ( common = true , usage = "usage_ShowDiffs" )
@Command ( common = true , usage = "usage_ShowDiffs" )
class Diff extends TextBuiltin {
class Diff extends TextBuiltin {
private final DiffFormatter diffFmt = new DiffFormatter ( //
new BufferedOutputStream ( System . out ) ) ;
@Argument ( index = 0 , metaVar = "metaVar_treeish" , required = true )
@Argument ( index = 0 , metaVar = "metaVar_treeish" , required = true )
void tree_0 ( final AbstractTreeIterator c ) {
void tree_0 ( final AbstractTreeIterator c ) {
trees . add ( c ) ;
trees . add ( c ) ;
@ -81,45 +84,55 @@ class Diff extends TextBuiltin {
@Option ( name = "--" , metaVar = "metaVar_paths" , multiValued = true , handler = PathTreeFilterHandler . class )
@Option ( name = "--" , metaVar = "metaVar_paths" , multiValued = true , handler = PathTreeFilterHandler . class )
private TreeFilter pathFilter = TreeFilter . ALL ;
private TreeFilter pathFilter = TreeFilter . ALL ;
// BEGIN -- Options shared with Log
@Option ( name = "-p" , usage = "usage_showPatch" )
boolean showPatch ;
@Option ( name = "-M" , usage = "usage_detectRenames" )
@Option ( name = "-M" , usage = "usage_detectRenames" )
private boolean detectRenames ;
private boolean detectRenames ;
@Option ( name = "-l" , usage = "usage_renameLimit" )
private Integer renameLimit ;
@Option ( name = "--name-status" , usage = "usage_nameStatus" )
@Option ( name = "--name-status" , usage = "usage_nameStatus" )
private boolean showNameAndStatusOnly ;
private boolean showNameAndStatusOnly ;
@Option ( name = "--ignore-space-at-eol" )
@Option ( name = "--ignore-space-at-eol" )
private boolean ignoreWsTrailing ;
void ignoreSpaceAtEol ( @SuppressWarnings ( "unused" ) boolean on ) {
diffFmt . setRawTextFactory ( RawTextIgnoreTrailingWhitespace . FACTORY ) ;
}
@Option ( name = "--ignore-leading-space" )
@Option ( name = "--ignore-leading-space" )
private boolean ignoreWsLeading ;
void ignoreLeadingSpace ( @SuppressWarnings ( "unused" ) boolean on ) {
diffFmt . setRawTextFactory ( RawTextIgnoreLeadingWhitespace . FACTORY ) ;
}
@Option ( name = "-b" , aliases = { "--ignore-space-change" } )
@Option ( name = "-b" , aliases = { "--ignore-space-change" } )
private boolean ignoreWsChange ;
void ignoreSpaceChange ( @SuppressWarnings ( "unused" ) boolean on ) {
diffFmt . setRawTextFactory ( RawTextIgnoreWhitespaceChange . FACTORY ) ;
}
@Option ( name = "-w" , aliases = { "--ignore-all-space" } )
@Option ( name = "-w" , aliases = { "--ignore-all-space" } )
private boolean ignoreWsAll ;
void ignoreAllSpace ( @SuppressWarnings ( "unused" ) boolean on ) {
diffFmt . setRawTextFactory ( RawTextIgnoreAllWhitespace . FACTORY ) ;
}
@Option ( name = "-U" , aliases = { "--unified" } , metaVar = "metaVar_linesOfContext" )
@Option ( name = "-U" , aliases = { "--unified" } , metaVar = "metaVar_linesOfContext" )
void unified ( int lines ) {
void unified ( int lines ) {
fmt . setContext ( lines ) ;
di ffF mt. setContext ( lines ) ;
}
}
private DiffFormatter fmt = new DiffFormatter ( //
@Option ( name = "--abbrev" , metaVar = "n" )
new BufferedOutputStream ( System . out ) ) {
void abbrev ( int lines ) {
@Override
diffFmt . setAbbreviationLength ( lines ) ;
protected RawText newRawText ( byte [ ] raw ) {
if ( ignoreWsAll )
return new RawTextIgnoreAllWhitespace ( raw ) ;
else if ( ignoreWsTrailing )
return new RawTextIgnoreTrailingWhitespace ( raw ) ;
else if ( ignoreWsChange )
return new RawTextIgnoreWhitespaceChange ( raw ) ;
else if ( ignoreWsLeading )
return new RawTextIgnoreLeadingWhitespace ( raw ) ;
else
return new RawText ( raw ) ;
}
}
} ;
@Option ( name = "--full-index" )
void abbrev ( @SuppressWarnings ( "unused" ) boolean on ) {
diffFmt . setAbbreviationLength ( Constants . OBJECT_ID_STRING_LENGTH ) ;
}
// END -- Options shared with Log
@Override
@Override
protected void run ( ) throws Exception {
protected void run ( ) throws Exception {
@ -130,9 +143,9 @@ class Diff extends TextBuiltin {
out . flush ( ) ;
out . flush ( ) ;
} else {
} else {
fmt . setRepository ( db ) ;
di ffF mt. setRepository ( db ) ;
fmt . format ( files ) ;
di ffF mt. format ( files ) ;
fmt . flush ( ) ;
di ffF mt. flush ( ) ;
}
}
}
}
@ -173,6 +186,8 @@ class Diff extends TextBuiltin {
List < DiffEntry > files = DiffEntry . scan ( walk ) ;
List < DiffEntry > files = DiffEntry . scan ( walk ) ;
if ( detectRenames ) {
if ( detectRenames ) {
RenameDetector rd = new RenameDetector ( db ) ;
RenameDetector rd = new RenameDetector ( db ) ;
if ( renameLimit ! = null )
rd . setRenameLimit ( renameLimit . intValue ( ) ) ;
rd . addAll ( files ) ;
rd . addAll ( files ) ;
files = rd . compute ( new TextProgressMonitor ( ) ) ;
files = rd . compute ( new TextProgressMonitor ( ) ) ;
}
}