public class RenameDetector
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.List<DiffEntry> |
added |
private int |
breakScore
Similarity score required to keep modified file pairs together.
|
private java.util.List<DiffEntry> |
deleted |
private static java.util.Comparator<DiffEntry> |
DIFF_COMPARATOR |
private boolean |
done |
private java.util.List<DiffEntry> |
entries |
private static int |
EXACT_RENAME_SCORE |
private ObjectReader |
objectReader |
private boolean |
overRenameLimit
Set if the number of adds or deletes was over the limit.
|
private int |
renameLimit
Limit in the number of files to consider for renames.
|
private int |
renameScore
Similarity score required to pair an add/delete as a rename.
|
Constructor and 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
|
Modifier and Type | Method and Description |
---|---|
void |
add(DiffEntry entry)
Add an entry to be considered for rename detection.
|
void |
addAll(java.util.Collection<DiffEntry> entriesToAdd)
Add entries to be considered for rename detection.
|
private void |
advanceOrCancel(ProgressMonitor pm) |
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.
|
private void |
breakModifies(ContentSource.Pair reader,
ProgressMonitor pm) |
private int |
calculateModifyScore(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 DiffEntry |
exactCopy(DiffEntry src,
DiffEntry dst) |
private static DiffEntry |
exactRename(DiffEntry src,
DiffEntry dst) |
private void |
findContentRenames(ContentSource.Pair reader,
ProgressMonitor pm) |
private void |
findExactRenames(ProgressMonitor pm) |
int |
getBreakScore()
Get break score
|
int |
getRenameLimit()
Get rename limit
|
int |
getRenameScore()
Get rename score
|
private static AbbreviatedObjectId |
id(DiffEntry de) |
boolean |
isOverRenameLimit()
Check if the detector is over the rename limit.
|
private static FileMode |
mode(DiffEntry de) |
private static java.lang.String |
path(DiffEntry de) |
private java.util.HashMap<AbbreviatedObjectId,java.lang.Object> |
populateMap(java.util.List<DiffEntry> diffEntries,
ProgressMonitor pm) |
private void |
rejoinModifies(ProgressMonitor pm) |
void |
reset()
Reset this rename detector for another rename detection pass.
|
(package private) static boolean |
sameType(FileMode a,
FileMode b) |
void |
setBreakScore(int breakScore)
Set break score
|
void |
setRenameLimit(int limit)
Set the limit on the number of files to perform inexact rename detection.
|
void |
setRenameScore(int score)
Set the minimum score required to pair an add/delete as a rename.
|
private static final int EXACT_RENAME_SCORE
private static final java.util.Comparator<DiffEntry> DIFF_COMPARATOR
private java.util.List<DiffEntry> entries
private java.util.List<DiffEntry> deleted
private java.util.List<DiffEntry> added
private boolean done
private final ObjectReader objectReader
private int renameScore
private int breakScore
private int renameLimit
private boolean overRenameLimit
public RenameDetector(Repository repo)
repo
- the repository to use for rename detectionpublic RenameDetector(ObjectReader reader, DiffConfig cfg)
reader
- reader to obtain objects from the repository with.cfg
- diff config specifying rename detection options.public int getRenameScore()
public void setRenameScore(int score)
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.
score
- new rename score, must be within [0, 100].java.lang.IllegalArgumentException
- the score was not within [0, 100].public int getBreakScore()
public void setBreakScore(int breakScore)
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.public int getRenameLimit()
public void setRenameLimit(int limit)
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.
limit
- new file limit. 0 means no limit; a negative number means no
inexact rename detection will be performed, only exact rename
detection.public boolean isOverRenameLimit()
This method can be invoked either before or after getEntries
has
been used to perform rename detection.
public void addAll(java.util.Collection<DiffEntry> entriesToAdd)
entriesToAdd
- one or more entries to add.java.lang.IllegalStateException
- if getEntries
was already invoked.public void add(DiffEntry entry)
entry
- to add.java.lang.IllegalStateException
- if getEntries
was already invoked.public java.util.List<DiffEntry> compute() throws java.io.IOException
This convenience function runs without a progress monitor.
DiffEntry
s
representing all files that have been changed.java.io.IOException
- file contents cannot be read from the repository.public java.util.List<DiffEntry> compute(ProgressMonitor pm) throws java.io.IOException, CancelledException
pm
- report progress during the detection phases.DiffEntry
s
representing all files that have been changed.java.io.IOException
- file contents cannot be read from the repository.CancelledException
- if rename detection was cancelledpublic java.util.List<DiffEntry> compute(ObjectReader reader, ProgressMonitor pm) throws java.io.IOException, CancelledException
reader
- reader to obtain objects from the repository with.pm
- report progress during the detection phases.DiffEntry
s
representing all files that have been changed.java.io.IOException
- file contents cannot be read from the repository.CancelledException
- if rename detection was cancelledpublic java.util.List<DiffEntry> compute(ContentSource.Pair reader, ProgressMonitor pm) throws java.io.IOException, CancelledException
reader
- reader to obtain objects from the repository with.pm
- report progress during the detection phases.DiffEntry
s
representing all files that have been changed.java.io.IOException
- file contents cannot be read from the repository.CancelledException
- if rename detection was cancelledpublic void reset()
private void advanceOrCancel(ProgressMonitor pm) throws CancelledException
CancelledException
private void breakModifies(ContentSource.Pair reader, ProgressMonitor pm) throws java.io.IOException, CancelledException
java.io.IOException
CancelledException
private void rejoinModifies(ProgressMonitor pm) throws CancelledException
CancelledException
private int calculateModifyScore(ContentSource.Pair reader, DiffEntry d) throws java.io.IOException
java.io.IOException
private void findContentRenames(ContentSource.Pair reader, ProgressMonitor pm) throws java.io.IOException, CancelledException
java.io.IOException
CancelledException
private void findExactRenames(ProgressMonitor pm) throws CancelledException
CancelledException
private static DiffEntry bestPathMatch(DiffEntry src, java.util.List<DiffEntry> list)
src
- the DiffEntry to try to find a match forlist
- a list of DiffEntrys to search throughprivate java.util.HashMap<AbbreviatedObjectId,java.lang.Object> populateMap(java.util.List<DiffEntry> diffEntries, ProgressMonitor pm) throws CancelledException
CancelledException
private static java.lang.String path(DiffEntry de)
private static AbbreviatedObjectId id(DiffEntry de)