Package org.eclipse.jgit.diff
Class RenameDetector
- java.lang.Object
-
- org.eclipse.jgit.diff.RenameDetector
-
public class RenameDetector extends java.lang.ObjectDetect and resolve object renames.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<DiffEntry>addedprivate intbreakScoreSimilarity score required to keep modified file pairs together.private java.util.List<DiffEntry>deletedprivate static java.util.Comparator<DiffEntry>DIFF_COMPARATORprivate booleandoneprivate java.util.List<DiffEntry>entriesprivate static intEXACT_RENAME_SCOREprivate ObjectReaderobjectReaderprivate booleanoverRenameLimitSet if the number of adds or deletes was over the limit.private intrenameLimitLimit in the number of files to consider for renames.private intrenameScoreSimilarity score required to pair an add/delete as a rename.
-
Constructor Summary
Constructors Constructor Description RenameDetector(ObjectReader reader, DiffConfig cfg)Create a new rename detector with a specified reader and diff config.RenameDetector(Repository repo)Create a new rename detector for the given repository
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(DiffEntry entry)Add an entry to be considered for rename detection.voidaddAll(java.util.Collection<DiffEntry> entriesToAdd)Add entries to be considered for rename detection.private voidadvanceOrCancel(ProgressMonitor pm)private static DiffEntrybestPathMatch(DiffEntry src, java.util.List<DiffEntry> list)Find the best match by file path for a given DiffEntry from a list of DiffEntrys.private voidbreakModifies(ContentSource.Pair reader, ProgressMonitor pm)private intcalculateModifyScore(ContentSource.Pair reader, DiffEntry d)java.util.List<DiffEntry>compute()Detect renames in the current file set.java.util.List<DiffEntry>compute(ContentSource.Pair reader, ProgressMonitor pm)Detect renames in the current file set.java.util.List<DiffEntry>compute(ObjectReader reader, ProgressMonitor pm)Detect renames in the current file set.java.util.List<DiffEntry>compute(ProgressMonitor pm)Detect renames in the current file set.private static DiffEntryexactCopy(DiffEntry src, DiffEntry dst)private static DiffEntryexactRename(DiffEntry src, DiffEntry dst)private voidfindContentRenames(ContentSource.Pair reader, ProgressMonitor pm)private voidfindExactRenames(ProgressMonitor pm)intgetBreakScore()Get break scoreintgetRenameLimit()Get rename limitintgetRenameScore()Get rename scoreprivate static AbbreviatedObjectIdid(DiffEntry de)booleanisOverRenameLimit()Check if the detector is over the rename limit.private static FileModemode(DiffEntry de)private static java.lang.Stringpath(DiffEntry de)private java.util.HashMap<AbbreviatedObjectId,java.lang.Object>populateMap(java.util.List<DiffEntry> diffEntries, ProgressMonitor pm)private voidrejoinModifies(ProgressMonitor pm)voidreset()Reset this rename detector for another rename detection pass.(package private) static booleansameType(FileMode a, FileMode b)voidsetBreakScore(int breakScore)Set break scorevoidsetRenameLimit(int limit)Set the limit on the number of files to perform inexact rename detection.voidsetRenameScore(int score)Set the minimum score required to pair an add/delete as a rename.
-
-
-
Field Detail
-
EXACT_RENAME_SCORE
private static final int EXACT_RENAME_SCORE
- See Also:
- Constant Field Values
-
DIFF_COMPARATOR
private static final java.util.Comparator<DiffEntry> DIFF_COMPARATOR
-
entries
private java.util.List<DiffEntry> entries
-
deleted
private java.util.List<DiffEntry> deleted
-
added
private java.util.List<DiffEntry> added
-
done
private boolean done
-
objectReader
private final ObjectReader objectReader
-
renameScore
private int renameScore
Similarity score required to pair an add/delete as a rename.
-
breakScore
private int breakScore
Similarity score required to keep modified file pairs together. Any modified file pairs with a similarity score below this will be broken apart.
-
renameLimit
private int renameLimit
Limit in the number of files to consider for renames.
-
overRenameLimit
private boolean overRenameLimit
Set if the number of adds or deletes was over the limit.
-
-
Constructor Detail
-
RenameDetector
public RenameDetector(Repository repo)
Create a new rename detector for the given repository- Parameters:
repo- the repository to use for rename detection
-
RenameDetector
public RenameDetector(ObjectReader reader, DiffConfig cfg)
Create a new rename detector with a specified reader and diff config.- Parameters:
reader- reader to obtain objects from the repository with.cfg- diff config specifying rename detection options.- Since:
- 3.0
-
-
Method Detail
-
getRenameScore
public int getRenameScore()
Get rename score- Returns:
- minimum score required to pair an add/delete as a rename. The score ranges are within the bounds of (0, 100).
-
setRenameScore
public void setRenameScore(int score)
Set the minimum score required to pair an add/delete as a rename.When comparing two files together their score must be greater than or equal to the rename score for them to be considered a rename match. The score is computed based on content similarity, so a score of 60 implies that approximately 60% of the bytes in the files are identical.
- Parameters:
score- new rename score, must be within [0, 100].- Throws:
java.lang.IllegalArgumentException- the score was not within [0, 100].
-
getBreakScore
public int getBreakScore()
Get break score- Returns:
- the similarity score required to keep modified file pairs together. Any modify pairs that score below this will be broken apart into separate add/deletes. Values less than or equal to zero indicate that no modifies will be broken apart. Values over 100 cause all modify pairs to be broken.
-
setBreakScore
public void setBreakScore(int breakScore)
Set break score- Parameters:
breakScore- the similarity score required to keep modified file pairs together. Any modify pairs that score below this will be broken apart into separate add/deletes. Values less than or equal to zero indicate that no modifies will be broken apart. Values over 100 cause all modify pairs to be broken.
-
getRenameLimit
public int getRenameLimit()
Get rename limit- Returns:
- limit on number of paths to perform inexact rename detection
-
setRenameLimit
public void setRenameLimit(int limit)
Set the limit on the number of files to perform inexact rename detection.The rename detector has to build a square matrix of the rename limit on each side, then perform that many file compares to determine similarity. If 1000 files are added, and 1000 files are deleted, a 1000*1000 matrix must be allocated, and 1,000,000 file compares may need to be performed.
- Parameters:
limit- new file limit. 0 means no limit; a negative number means no inexact rename detection will be performed, only exact rename detection.
-
isOverRenameLimit
public boolean isOverRenameLimit()
Check if the detector is over the rename limit.This method can be invoked either before or after
getEntrieshas been used to perform rename detection.- Returns:
- true if the detector has more file additions or removals than the rename limit is currently set to. In such configurations the detector will skip expensive computation.
-
addAll
public void addAll(java.util.Collection<DiffEntry> entriesToAdd)
Add entries to be considered for rename detection.- Parameters:
entriesToAdd- one or more entries to add.- Throws:
java.lang.IllegalStateException- ifgetEntrieswas already invoked.
-
add
public void add(DiffEntry entry)
Add an entry to be considered for rename detection.- Parameters:
entry- to add.- Throws:
java.lang.IllegalStateException- ifgetEntrieswas already invoked.
-
compute
public java.util.List<DiffEntry> compute() throws java.io.IOException
Detect renames in the current file set.This convenience function runs without a progress monitor.
- Returns:
- an unmodifiable list of
DiffEntrys representing all files that have been changed. - Throws:
java.io.IOException- file contents cannot be read from the repository.
-
compute
public java.util.List<DiffEntry> compute(ProgressMonitor pm) throws java.io.IOException, CancelledException
Detect renames in the current file set.- Parameters:
pm- report progress during the detection phases.- Returns:
- an unmodifiable list of
DiffEntrys representing all files that have been changed. - Throws:
java.io.IOException- file contents cannot be read from the repository.CancelledException- if rename detection was cancelled
-
compute
public java.util.List<DiffEntry> compute(ObjectReader reader, ProgressMonitor pm) throws java.io.IOException, CancelledException
Detect renames in the current file set.- Parameters:
reader- reader to obtain objects from the repository with.pm- report progress during the detection phases.- Returns:
- an unmodifiable list of
DiffEntrys representing all files that have been changed. - Throws:
java.io.IOException- file contents cannot be read from the repository.CancelledException- if rename detection was cancelled
-
compute
public java.util.List<DiffEntry> compute(ContentSource.Pair reader, ProgressMonitor pm) throws java.io.IOException, CancelledException
Detect renames in the current file set.- Parameters:
reader- reader to obtain objects from the repository with.pm- report progress during the detection phases.- Returns:
- an unmodifiable list of
DiffEntrys representing all files that have been changed. - Throws:
java.io.IOException- file contents cannot be read from the repository.CancelledException- if rename detection was cancelled
-
reset
public void reset()
Reset this rename detector for another rename detection pass.
-
advanceOrCancel
private void advanceOrCancel(ProgressMonitor pm) throws CancelledException
- Throws:
CancelledException
-
breakModifies
private void breakModifies(ContentSource.Pair reader, ProgressMonitor pm) throws java.io.IOException, CancelledException
- Throws:
java.io.IOExceptionCancelledException
-
rejoinModifies
private void rejoinModifies(ProgressMonitor pm) throws CancelledException
- Throws:
CancelledException
-
calculateModifyScore
private int calculateModifyScore(ContentSource.Pair reader, DiffEntry d) throws java.io.IOException
- Throws:
java.io.IOException
-
findContentRenames
private void findContentRenames(ContentSource.Pair reader, ProgressMonitor pm) throws java.io.IOException, CancelledException
- Throws:
java.io.IOExceptionCancelledException
-
findExactRenames
private void findExactRenames(ProgressMonitor pm) throws CancelledException
- Throws:
CancelledException
-
bestPathMatch
private static DiffEntry bestPathMatch(DiffEntry src, java.util.List<DiffEntry> list)
Find the best match by file path for a given DiffEntry from a list of DiffEntrys. The returned DiffEntry will be of the same type as. If no DiffEntry can be found that has the same type, this method will return null. - Parameters:
src- the DiffEntry to try to find a match forlist- a list of DiffEntrys to search through- Returns:
- the DiffEntry from
- who's file path best matches
-
populateMap
private java.util.HashMap<AbbreviatedObjectId,java.lang.Object> populateMap(java.util.List<DiffEntry> diffEntries, ProgressMonitor pm) throws CancelledException
- Throws:
CancelledException
-
path
private static java.lang.String path(DiffEntry de)
-
id
private static AbbreviatedObjectId id(DiffEntry de)
-
-