@ -55,6 +55,7 @@ import java.util.Comparator;
import java.util.HashMap ;
import java.util.HashMap ;
import java.util.List ;
import java.util.List ;
import org.eclipse.jgit.api.errors.CanceledException ;
import org.eclipse.jgit.diff.DiffEntry.ChangeType ;
import org.eclipse.jgit.diff.DiffEntry.ChangeType ;
import org.eclipse.jgit.diff.SimilarityIndex.TableFullException ;
import org.eclipse.jgit.diff.SimilarityIndex.TableFullException ;
import org.eclipse.jgit.internal.JGitText ;
import org.eclipse.jgit.internal.JGitText ;
@ -320,7 +321,11 @@ public class RenameDetector {
* file contents cannot be read from the repository .
* file contents cannot be read from the repository .
* /
* /
public List < DiffEntry > compute ( ) throws IOException {
public List < DiffEntry > compute ( ) throws IOException {
try {
return compute ( NullProgressMonitor . INSTANCE ) ;
return compute ( NullProgressMonitor . INSTANCE ) ;
} catch ( CanceledException e ) {
return Collections . emptyList ( ) ;
}
}
}
/ * *
/ * *
@ -332,8 +337,11 @@ public class RenameDetector {
* representing all files that have been changed .
* representing all files that have been changed .
* @throws java . io . IOException
* @throws java . io . IOException
* file contents cannot be read from the repository .
* file contents cannot be read from the repository .
* @throws CanceledException
* if rename detection was cancelled
* /
* /
public List < DiffEntry > compute ( ProgressMonitor pm ) throws IOException {
public List < DiffEntry > compute ( ProgressMonitor pm )
throws IOException , CanceledException {
if ( ! done ) {
if ( ! done ) {
try {
try {
return compute ( objectReader , pm ) ;
return compute ( objectReader , pm ) ;
@ -355,9 +363,11 @@ public class RenameDetector {
* representing all files that have been changed .
* representing all files that have been changed .
* @throws java . io . IOException
* @throws java . io . IOException
* file contents cannot be read from the repository .
* file contents cannot be read from the repository .
* @throws CanceledException
* if rename detection was cancelled
* /
* /
public List < DiffEntry > compute ( ObjectReader reader , ProgressMonitor pm )
public List < DiffEntry > compute ( ObjectReader reader , ProgressMonitor pm )
throws IOException {
throws IOException , CanceledException {
final ContentSource cs = ContentSource . create ( reader ) ;
final ContentSource cs = ContentSource . create ( reader ) ;
return compute ( new ContentSource . Pair ( cs , cs ) , pm ) ;
return compute ( new ContentSource . Pair ( cs , cs ) , pm ) ;
}
}
@ -373,9 +383,11 @@ public class RenameDetector {
* representing all files that have been changed .
* representing all files that have been changed .
* @throws java . io . IOException
* @throws java . io . IOException
* file contents cannot be read from the repository .
* file contents cannot be read from the repository .
* @throws CanceledException
* if rename detection was cancelled
* /
* /
public List < DiffEntry > compute ( ContentSource . Pair reader , ProgressMonitor pm )
public List < DiffEntry > compute ( ContentSource . Pair reader , ProgressMonitor pm )
throws IOException {
throws IOException , CanceledException {
if ( ! done ) {
if ( ! done ) {
done = true ;
done = true ;
@ -415,8 +427,15 @@ public class RenameDetector {
done = false ;
done = false ;
}
}
private void advanceOrCancel ( ProgressMonitor pm ) throws CanceledException {
if ( pm . isCancelled ( ) ) {
throw new CanceledException ( JGitText . get ( ) . renameCancelled ) ;
}
pm . update ( 1 ) ;
}
private void breakModifies ( ContentSource . Pair reader , ProgressMonitor pm )
private void breakModifies ( ContentSource . Pair reader , ProgressMonitor pm )
throws IOException {
throws IOException , CanceledException {
ArrayList < DiffEntry > newEntries = new ArrayList < > ( entries . size ( ) ) ;
ArrayList < DiffEntry > newEntries = new ArrayList < > ( entries . size ( ) ) ;
pm . beginTask ( JGitText . get ( ) . renamesBreakingModifies , entries . size ( ) ) ;
pm . beginTask ( JGitText . get ( ) . renamesBreakingModifies , entries . size ( ) ) ;
@ -437,13 +456,13 @@ public class RenameDetector {
} else {
} else {
newEntries . add ( e ) ;
newEntries . add ( e ) ;
}
}
pm . update ( 1 ) ;
advanceOrCancel ( pm ) ;
}
}
entries = newEntries ;
entries = newEntries ;
}
}
private void rejoinModifies ( ProgressMonitor pm ) {
private void rejoinModifies ( ProgressMonitor pm ) throws CanceledException {
HashMap < String , DiffEntry > nameMap = new HashMap < > ( ) ;
HashMap < String , DiffEntry > nameMap = new HashMap < > ( ) ;
ArrayList < DiffEntry > newAdded = new ArrayList < > ( added . size ( ) ) ;
ArrayList < DiffEntry > newAdded = new ArrayList < > ( added . size ( ) ) ;
@ -452,7 +471,7 @@ public class RenameDetector {
for ( DiffEntry src : deleted ) {
for ( DiffEntry src : deleted ) {
nameMap . put ( src . oldPath , src ) ;
nameMap . put ( src . oldPath , src ) ;
pm . update ( 1 ) ;
advanceOrCancel ( pm ) ;
}
}
for ( DiffEntry dst : added ) {
for ( DiffEntry dst : added ) {
@ -468,7 +487,7 @@ public class RenameDetector {
} else {
} else {
newAdded . add ( dst ) ;
newAdded . add ( dst ) ;
}
}
pm . update ( 1 ) ;
advanceOrCancel ( pm ) ;
}
}
added = newAdded ;
added = newAdded ;
@ -498,7 +517,7 @@ public class RenameDetector {
private void findContentRenames ( ContentSource . Pair reader ,
private void findContentRenames ( ContentSource . Pair reader ,
ProgressMonitor pm )
ProgressMonitor pm )
throws IOException {
throws IOException , CanceledException {
int cnt = Math . max ( added . size ( ) , deleted . size ( ) ) ;
int cnt = Math . max ( added . size ( ) , deleted . size ( ) ) ;
if ( getRenameLimit ( ) = = 0 | | cnt < = getRenameLimit ( ) ) {
if ( getRenameLimit ( ) = = 0 | | cnt < = getRenameLimit ( ) ) {
SimilarityRenameDetector d ;
SimilarityRenameDetector d ;
@ -516,7 +535,7 @@ public class RenameDetector {
}
}
@SuppressWarnings ( "unchecked" )
@SuppressWarnings ( "unchecked" )
private void findExactRenames ( ProgressMonitor pm ) {
private void findExactRenames ( ProgressMonitor pm ) throws CanceledException {
pm . beginTask ( JGitText . get ( ) . renamesFindingExact , //
pm . beginTask ( JGitText . get ( ) . renamesFindingExact , //
added . size ( ) + added . size ( ) + deleted . size ( )
added . size ( ) + added . size ( ) + deleted . size ( )
+ added . size ( ) * deleted . size ( ) ) ;
+ added . size ( ) * deleted . size ( ) ) ;
@ -562,7 +581,7 @@ public class RenameDetector {
} else {
} else {
left . add ( a ) ;
left . add ( a ) ;
}
}
pm . update ( 1 ) ;
advanceOrCancel ( pm ) ;
}
}
for ( List < DiffEntry > adds : nonUniqueAdds ) {
for ( List < DiffEntry > adds : nonUniqueAdds ) {
@ -604,6 +623,10 @@ public class RenameDetector {
int score = SimilarityRenameDetector . nameScore ( addedName , deletedName ) ;
int score = SimilarityRenameDetector . nameScore ( addedName , deletedName ) ;
matrix [ mNext ] = SimilarityRenameDetector . encode ( score , delIdx , addIdx ) ;
matrix [ mNext ] = SimilarityRenameDetector . encode ( score , delIdx , addIdx ) ;
mNext + + ;
mNext + + ;
if ( pm . isCancelled ( ) ) {
throw new CanceledException (
JGitText . get ( ) . renameCancelled ) ;
}
}
}
}
}
@ -617,7 +640,7 @@ public class RenameDetector {
DiffEntry a = adds . get ( addIdx ) ;
DiffEntry a = adds . get ( addIdx ) ;
if ( a = = null ) {
if ( a = = null ) {
pm . update ( 1 ) ;
advanceOrCancel ( pm ) ;
continue ; // was already matched earlier
continue ; // was already matched earlier
}
}
@ -635,11 +658,12 @@ public class RenameDetector {
entries . add ( DiffEntry . pair ( type , d , a , 100 ) ) ;
entries . add ( DiffEntry . pair ( type , d , a , 100 ) ) ;
adds . set ( addIdx , null ) ; // Claim the destination was matched.
adds . set ( addIdx , null ) ; // Claim the destination was matched.
pm . update ( 1 ) ;
advanceOrCancel ( pm ) ;
}
}
} else {
} else {
left . addAll ( adds ) ;
left . addAll ( adds ) ;
}
}
advanceOrCancel ( pm ) ;
}
}
added = left ;
added = left ;
@ -692,7 +716,8 @@ public class RenameDetector {
@SuppressWarnings ( "unchecked" )
@SuppressWarnings ( "unchecked" )
private HashMap < AbbreviatedObjectId , Object > populateMap (
private HashMap < AbbreviatedObjectId , Object > populateMap (
List < DiffEntry > diffEntries , ProgressMonitor pm ) {
List < DiffEntry > diffEntries , ProgressMonitor pm )
throws CanceledException {
HashMap < AbbreviatedObjectId , Object > map = new HashMap < > ( ) ;
HashMap < AbbreviatedObjectId , Object > map = new HashMap < > ( ) ;
for ( DiffEntry de : diffEntries ) {
for ( DiffEntry de : diffEntries ) {
Object old = map . put ( id ( de ) , de ) ;
Object old = map . put ( id ( de ) , de ) ;
@ -706,7 +731,7 @@ public class RenameDetector {
( ( List < DiffEntry > ) old ) . add ( de ) ;
( ( List < DiffEntry > ) old ) . add ( de ) ;
map . put ( id ( de ) , old ) ;
map . put ( id ( de ) , old ) ;
}
}
pm . update ( 1 ) ;
advanceOrCancel ( pm ) ;
}
}
return map ;
return map ;
}
}